2019-01-16 16:03:50 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.h>
|
2019-03-03 12:32:15 +01:00
|
|
|
#include <Kernel/KeyCode.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibCore/CEvent.h>
|
2019-07-18 10:15:00 +02:00
|
|
|
#include <LibDraw/Rect.h>
|
2019-03-31 23:52:02 +02:00
|
|
|
#include <WindowServer/WSCursor.h>
|
2019-04-03 19:38:44 +02:00
|
|
|
#include <WindowServer/WSWindowType.h>
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-04-14 05:23:37 +02:00
|
|
|
class WSEvent : public CEvent {
|
2019-01-16 16:03:50 +01:00
|
|
|
public:
|
2019-06-07 17:13:23 +02:00
|
|
|
enum Type {
|
2019-07-17 10:31:52 +02:00
|
|
|
Invalid = 3000,
|
2019-01-16 16:03:50 +01:00
|
|
|
MouseMove,
|
|
|
|
MouseDown,
|
2019-05-15 22:17:09 +02:00
|
|
|
MouseDoubleClick,
|
2019-01-16 16:03:50 +01:00
|
|
|
MouseUp,
|
2019-05-13 19:52:57 +02:00
|
|
|
MouseWheel,
|
2019-02-20 10:12:19 +01:00
|
|
|
WindowEntered,
|
|
|
|
WindowLeft,
|
2019-01-16 16:03:50 +01:00
|
|
|
KeyDown,
|
|
|
|
KeyUp,
|
2019-01-17 17:38:04 +01:00
|
|
|
WindowActivated,
|
|
|
|
WindowDeactivated,
|
2019-02-05 10:31:37 +01:00
|
|
|
WindowCloseRequest,
|
2019-02-20 15:34:55 +01:00
|
|
|
WindowResized,
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|
|
|
|
|
2019-05-28 11:53:16 +02:00
|
|
|
WSEvent() {}
|
|
|
|
explicit WSEvent(Type type)
|
|
|
|
: CEvent(type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~WSEvent() {}
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-05-15 22:17:09 +02:00
|
|
|
bool is_mouse_event() const { return type() == MouseMove || type() == MouseDown || type() == MouseDoubleClick || type() == MouseUp || type() == MouseWheel; }
|
2019-04-14 05:15:22 +02:00
|
|
|
bool is_key_event() const { return type() == KeyUp || type() == KeyDown; }
|
2019-01-21 07:28:04 +01:00
|
|
|
};
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
enum class MouseButton : u8 {
|
2019-01-16 16:03:50 +01:00
|
|
|
None = 0,
|
2019-01-20 05:48:43 +01:00
|
|
|
Left = 1,
|
|
|
|
Right = 2,
|
|
|
|
Middle = 4,
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|
|
|
|
|
2019-04-14 05:23:37 +02:00
|
|
|
class WSKeyEvent final : public WSEvent {
|
2019-01-16 16:03:50 +01:00
|
|
|
public:
|
2019-07-03 21:17:35 +02:00
|
|
|
WSKeyEvent(Type type, int key, char character, u8 modifiers)
|
2019-04-14 05:23:37 +02:00
|
|
|
: WSEvent(type)
|
2019-01-16 16:03:50 +01:00
|
|
|
, m_key(key)
|
2019-01-21 07:28:04 +01:00
|
|
|
, m_character(character)
|
2019-03-03 12:32:15 +01:00
|
|
|
, m_modifiers(modifiers)
|
2019-01-16 16:03:50 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int key() const { return m_key; }
|
2019-03-03 12:32:15 +01:00
|
|
|
bool ctrl() const { return m_modifiers & Mod_Ctrl; }
|
|
|
|
bool alt() const { return m_modifiers & Mod_Alt; }
|
|
|
|
bool shift() const { return m_modifiers & Mod_Shift; }
|
2019-03-03 12:56:48 +01:00
|
|
|
bool logo() const { return m_modifiers & Mod_Logo; }
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 modifiers() const { return m_modifiers; }
|
2019-01-21 07:28:04 +01:00
|
|
|
char character() const { return m_character; }
|
2019-01-16 16:03:50 +01:00
|
|
|
|
|
|
|
private:
|
2019-04-14 05:23:37 +02:00
|
|
|
friend class WSEventLoop;
|
2019-01-16 16:03:50 +01:00
|
|
|
friend class WSScreen;
|
|
|
|
int m_key { 0 };
|
2019-01-21 07:28:04 +01:00
|
|
|
char m_character { 0 };
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 m_modifiers { 0 };
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|
|
|
|
|
2019-04-14 05:23:37 +02:00
|
|
|
class WSMouseEvent final : public WSEvent {
|
2019-01-16 16:03:50 +01:00
|
|
|
public:
|
2019-05-13 19:52:57 +02:00
|
|
|
WSMouseEvent(Type type, const Point& position, unsigned buttons, MouseButton button, unsigned modifiers, int wheel_delta = 0)
|
2019-04-14 05:23:37 +02:00
|
|
|
: WSEvent(type)
|
2019-01-20 05:48:43 +01:00
|
|
|
, m_position(position)
|
|
|
|
, m_buttons(buttons)
|
2019-01-16 16:03:50 +01:00
|
|
|
, m_button(button)
|
2019-03-08 17:53:02 +01:00
|
|
|
, m_modifiers(modifiers)
|
2019-05-13 19:52:57 +02:00
|
|
|
, m_wheel_delta(wheel_delta)
|
2019-01-16 16:03:50 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Point position() const { return m_position; }
|
|
|
|
int x() const { return m_position.x(); }
|
|
|
|
int y() const { return m_position.y(); }
|
|
|
|
MouseButton button() const { return m_button; }
|
2019-01-20 05:48:43 +01:00
|
|
|
unsigned buttons() const { return m_buttons; }
|
2019-03-08 17:53:02 +01:00
|
|
|
unsigned modifiers() const { return m_modifiers; }
|
2019-05-13 19:52:57 +02:00
|
|
|
int wheel_delta() const { return m_wheel_delta; }
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-05-13 19:52:57 +02:00
|
|
|
WSMouseEvent translated(const Point& delta) const { return WSMouseEvent((Type)type(), m_position.translated(delta), m_buttons, m_button, m_modifiers, m_wheel_delta); }
|
2019-04-05 21:33:34 +02:00
|
|
|
|
2019-01-16 16:03:50 +01:00
|
|
|
private:
|
|
|
|
Point m_position;
|
2019-01-20 05:48:43 +01:00
|
|
|
unsigned m_buttons { 0 };
|
2019-01-16 16:03:50 +01:00
|
|
|
MouseButton m_button { MouseButton::None };
|
2019-03-08 17:53:02 +01:00
|
|
|
unsigned m_modifiers { 0 };
|
2019-05-13 19:52:57 +02:00
|
|
|
int m_wheel_delta { 0 };
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|
2019-02-20 15:34:55 +01:00
|
|
|
|
2019-04-14 05:23:37 +02:00
|
|
|
class WSResizeEvent final : public WSEvent {
|
2019-02-20 15:34:55 +01:00
|
|
|
public:
|
|
|
|
WSResizeEvent(const Rect& old_rect, const Rect& rect)
|
2019-04-14 05:23:37 +02:00
|
|
|
: WSEvent(WSEvent::WindowResized)
|
2019-02-20 15:34:55 +01:00
|
|
|
, m_old_rect(old_rect)
|
|
|
|
, m_rect(rect)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect old_rect() const { return m_old_rect; }
|
|
|
|
Rect rect() const { return m_rect; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Rect m_old_rect;
|
|
|
|
Rect m_rect;
|
|
|
|
};
|