2019-01-16 16:03:50 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-19 23:22:46 +01:00
|
|
|
#include <SharedGraphics/Point.h>
|
|
|
|
#include <SharedGraphics/Rect.h>
|
2019-01-16 16:03:50 +01:00
|
|
|
#include <AK/AKString.h>
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
|
|
|
static const char* WSEvent_names[] = {
|
|
|
|
"Invalid",
|
|
|
|
"Show",
|
|
|
|
"Hide",
|
|
|
|
"Paint",
|
|
|
|
"MouseMove",
|
|
|
|
"MouseDown",
|
|
|
|
"MouseUp",
|
|
|
|
"KeyDown",
|
|
|
|
"KeyUp",
|
|
|
|
"Timer",
|
|
|
|
"WM_Compose",
|
|
|
|
"WM_Invalidate",
|
2019-01-17 17:38:04 +01:00
|
|
|
"WindowActivated",
|
|
|
|
"WindowDeactivated",
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class WSEvent {
|
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
Invalid = 0,
|
|
|
|
Show,
|
|
|
|
Hide,
|
|
|
|
Paint,
|
|
|
|
MouseMove,
|
|
|
|
MouseDown,
|
|
|
|
MouseUp,
|
|
|
|
KeyDown,
|
|
|
|
KeyUp,
|
|
|
|
Timer,
|
|
|
|
WM_Compose,
|
|
|
|
WM_Invalidate,
|
2019-01-17 17:38:04 +01:00
|
|
|
WindowActivated,
|
|
|
|
WindowDeactivated,
|
2019-01-24 23:40:12 +01:00
|
|
|
WM_SetWindowTitle,
|
|
|
|
WM_SetWindowRect,
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
WSEvent() { }
|
|
|
|
explicit WSEvent(Type type) : m_type(type) { }
|
|
|
|
virtual ~WSEvent() { }
|
|
|
|
|
|
|
|
Type type() const { return m_type; }
|
|
|
|
|
|
|
|
const char* name() const { return WSEvent_names[(unsigned)m_type]; }
|
|
|
|
|
2019-01-21 07:28:04 +01:00
|
|
|
bool is_mouse_event() const { return m_type == MouseMove || m_type == MouseDown || m_type == MouseUp; }
|
|
|
|
bool is_key_event() const { return m_type == KeyUp || m_type == KeyDown; }
|
|
|
|
bool is_paint_event() const { return m_type == Paint; }
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-01-21 07:28:04 +01:00
|
|
|
private:
|
|
|
|
Type m_type { Invalid };
|
|
|
|
};
|
|
|
|
|
|
|
|
class WSWindowInvalidationEvent final : public WSEvent {
|
|
|
|
public:
|
|
|
|
explicit WSWindowInvalidationEvent(const Rect& rect = Rect())
|
|
|
|
: WSEvent(WSEvent::WM_Invalidate)
|
|
|
|
, m_rect(rect)
|
2019-01-18 04:37:49 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-21 07:28:04 +01:00
|
|
|
const Rect& rect() const { return m_rect; }
|
2019-01-16 16:03:50 +01:00
|
|
|
private:
|
2019-01-18 04:37:49 +01:00
|
|
|
Rect m_rect;
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|
|
|
|
|
2019-01-24 23:40:12 +01:00
|
|
|
class WSSetWindowTitle final : public WSEvent {
|
|
|
|
public:
|
|
|
|
explicit WSSetWindowTitle(String&& title)
|
|
|
|
: WSEvent(WSEvent::WM_SetWindowTitle)
|
|
|
|
, m_title(move(title))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
String title() const { return m_title; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
String m_title;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WSSetWindowRect final : public WSEvent {
|
|
|
|
public:
|
|
|
|
explicit WSSetWindowRect(const Rect& rect)
|
|
|
|
: WSEvent(WSEvent::WM_SetWindowRect)
|
|
|
|
, m_rect(rect)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect rect() const { return m_rect; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Rect m_rect;
|
|
|
|
};
|
|
|
|
|
2019-01-21 07:28:04 +01:00
|
|
|
class WSPaintEvent final : public WSEvent {
|
2019-01-16 16:03:50 +01:00
|
|
|
public:
|
2019-01-21 07:28:04 +01:00
|
|
|
explicit WSPaintEvent(const Rect& rect = Rect())
|
2019-01-16 16:03:50 +01:00
|
|
|
: WSEvent(WSEvent::Paint)
|
|
|
|
, m_rect(rect)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const Rect& rect() const { return m_rect; }
|
|
|
|
private:
|
|
|
|
friend class WSWindowManager;
|
|
|
|
Rect m_rect;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class MouseButton : byte {
|
|
|
|
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-01-21 07:28:04 +01:00
|
|
|
class WSKeyEvent final : public WSEvent {
|
2019-01-16 16:03:50 +01:00
|
|
|
public:
|
2019-01-21 07:28:04 +01:00
|
|
|
WSKeyEvent(Type type, int key, char character)
|
2019-01-16 16:03:50 +01:00
|
|
|
: WSEvent(type)
|
|
|
|
, m_key(key)
|
2019-01-21 07:28:04 +01:00
|
|
|
, m_character(character)
|
2019-01-16 16:03:50 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int key() const { return m_key; }
|
|
|
|
bool ctrl() const { return m_ctrl; }
|
|
|
|
bool alt() const { return m_alt; }
|
|
|
|
bool shift() const { return m_shift; }
|
2019-01-21 07:28:04 +01:00
|
|
|
char character() const { return m_character; }
|
2019-01-16 16:03:50 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class WSEventLoop;
|
|
|
|
friend class WSScreen;
|
|
|
|
int m_key { 0 };
|
|
|
|
bool m_ctrl { false };
|
|
|
|
bool m_alt { false };
|
|
|
|
bool m_shift { false };
|
2019-01-21 07:28:04 +01:00
|
|
|
char m_character { 0 };
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|
|
|
|
|
2019-01-21 07:28:04 +01:00
|
|
|
class WSMouseEvent final : public WSEvent {
|
2019-01-16 16:03:50 +01:00
|
|
|
public:
|
2019-01-21 07:28:04 +01:00
|
|
|
WSMouseEvent(Type type, const Point& position, unsigned buttons, MouseButton button = MouseButton::None)
|
2019-01-16 16:03:50 +01: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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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 };
|
|
|
|
};
|