66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
bool AppIsRunning = true;
|
|
bool WaitForEvents = true;
|
|
|
|
enum EventKind {
|
|
EVENT_NONE,
|
|
EVENT_UPDATE,
|
|
EVENT_QUIT,
|
|
|
|
EVENT_MOUSE_LEFT,
|
|
EVENT_MOUSE_RIGHT,
|
|
EVENT_MOUSE_MIDDLE,
|
|
EVENT_MOUSE_LEFT_UP,
|
|
EVENT_MOUSE_RIGHT_UP,
|
|
EVENT_MOUSE_MIDDLE_UP,
|
|
EVENT_MOUSE_WHEEL,
|
|
EVENT_MOUSE_MOVE,
|
|
|
|
EVENT_KEY_PRESS,
|
|
EVENT_TEXT_INPUT,
|
|
|
|
EVENT_DROP_FILE,
|
|
};
|
|
|
|
struct Event {
|
|
EventKind kind;
|
|
SDL_Keycode key;
|
|
int16_t xmouse;
|
|
int16_t ymouse;
|
|
int16_t xwindow;
|
|
int16_t ywindow;
|
|
uint8_t clicks;
|
|
struct {
|
|
uint8_t shift : 1;
|
|
uint8_t ctrl : 1;
|
|
uint8_t alt : 1;
|
|
uint8_t super : 1;
|
|
};
|
|
Vec2 wheel;
|
|
const char *text;
|
|
};
|
|
|
|
inline bool IsMouseEvent(EventKind kind) { return kind >= EVENT_MOUSE_LEFT && kind <= EVENT_MOUSE_MOVE; }
|
|
|
|
const int DIR_RIGHT = 0;
|
|
const int DIR_LEFT = 1;
|
|
const int DIR_DOWN = 2;
|
|
const int DIR_UP = 3;
|
|
const int DIR_COUNT = 4;
|
|
const bool CTRL_PRESSED = true;
|
|
bool SHIFT_PRESSED = true;
|
|
|
|
#define Press(KEY) (event.key == KEY)
|
|
#define Ctrl(KEY) (event.key == KEY && event.ctrl)
|
|
#define Shift(KEY) (event.key == KEY && event.shift)
|
|
#define Alt(KEY) (event.key == KEY && event.alt)
|
|
#define CtrlShift(KEY) (event.key == KEY && event.ctrl && event.shift)
|
|
#define CtrlAlt(KEY) (event.key == KEY && event.ctrl && event.alt)
|
|
#define AltShift(KEY) (event.key == KEY && event.shift && event.alt)
|
|
#define MouseVec2() \
|
|
Vec2 { (float)event.xmouse, (float)event.ymouse }
|
|
#define MouseVec2I() \
|
|
Vec2I { (Int) event.xmouse, (Int)event.ymouse }
|
|
#define Mouse(x) (event.kind == EVENT_MOUSE_##x)
|
|
#define MousePress() (Mouse(LEFT) || Mouse(RIGHT) || Mouse(MIDDLE))
|
|
#define MouseUp() (Mouse(LEFT_UP) || Mouse(RIGHT_UP) || Mouse(MIDDLE_UP))
|