Newer
Older
Import / research / ui / toolkit / include / Events.h
#pragma once
#include "Common.h"
BEGIN_NAMESPACE


enum Key
{
	Key_a,
	Key_b,
	Key_c,
	Key_A,
	Key_B,
	Key_C,

#if _WIN32
	Key_Left = 0x25,
	Key_Up = 0x26,
	Key_Right = 0x27,
	Key_Down = 0x28,

	Key_BackSpace = 8,
#else
	Key_Left = 63234,
	Key_Up = 63232,
	Key_Right = 63235,
	Key_Down = 63233,

  Key_BackSpace = 127,
#endif

	Key_Delete = 46,

	// TODO ...
};


enum MouseButtons
{
	MB_None    = 0,
	MB_Left    = 1 << 0,
	MB_Middle  = 1 << 1,
	MB_Right   = 1 << 2
};
ENUM_AS_FLAGS(MouseButtons)


enum KeyState
{
	KS_Pressed,
	KS_Released
};


enum Modifiers
{
	M_None     = 0,
	M_Shift    = 1 << 0,
	M_Control  = 1 << 1,
	M_Alt      = 1 << 2,
	M_OS       = 1 << 3
};
ENUM_AS_FLAGS(Modifiers)


typedef uintptr_t		TimerId;


struct BaseEvent
{
	void accept() { m_accepted = true; }
	void reject() { m_accepted = false; }
	bool m_accepted;
};


struct MouseEvent : public BaseEvent
{
	union {
		Point    m_oldPosition;
		struct
		{
			int  m_oldX;
			int  m_oldY;
		};
	};
	MouseButtons m_oldButtons;
	union {
		Point    m_position;
		struct
		{
			int  m_x;
			int  m_y;
		};
	};
	MouseButtons m_buttons;
};


struct WheelEvent : public BaseEvent
{
	int  m_degreesRotation;
};


struct KeyEvent : public BaseEvent
{
	Key          m_key;
	KeyState     m_state;
	Modifiers    m_modifiers;
};


struct PaintEvent : public BaseEvent
{
	Rectangle	m_rectangle;
};


struct TimerEvent : public BaseEvent
{
	TimerId		m_timerId;
};


struct SizeEvent : public BaseEvent
{
	union {
		Size     m_old;
		struct
		{
			int  m_oldWidth;
			int  m_oldHeight;
		};
	};
	union {
		Size     m_new;
		struct
		{
			int  m_newWidth;
			int  m_newHeight;
		};
	};
};


struct Event
{
	enum EventType
	{
		ET_MouseEvent,
		ET_WheelEvent,
		ET_KeyEvent,
		ET_PaintEvent,
		ET_TimerEvent,
		ET_SizeEvent
	};
	
	EventType m_type;

	union
	{
		BaseEvent        m_commonEvent;
		MouseEvent       m_mouseEvent;
		WheelEvent       m_wheelEvent;
		KeyEvent         m_keyEvent;
		PaintEvent       m_paintEvent;
		TimerEvent       m_timerEvent;
		SizeEvent        m_sizeEvent;
	};
};


END_NAMESPACE