1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
#pragma once
#ifdef USE_TILE_LOCAL
# include "tiletex.h"
# include "tiles-build-specific.h"
#endif
enum wm_event_type
{
WME_NOEVENT = 0,
WME_ACTIVEEVENT,
WME_KEYDOWN,
WME_KEYUP,
WME_MOUSEMOTION,
WME_MOUSEBUTTONUP,
WME_MOUSEBUTTONDOWN,
WME_MOUSEWHEEL,
WME_MOUSEENTER,
WME_MOUSELEAVE,
WME_QUIT,
WME_CUSTOMEVENT,
WME_RESIZE,
WME_EXPOSE,
WME_MOVE,
WME_NUMEVENTS = 15
};
struct wm_keysym
{
unsigned char scancode;
int sym;
unsigned char key_mod;
unsigned int unicode;
};
struct wm_active_event
{
unsigned char type;
unsigned char gain;
unsigned char state;
};
struct wm_keyboard_event
{
unsigned char type;
unsigned char state;
wm_keysym keysym;
};
struct wm_mouse_event
{
enum mouse_event_type
{
PRESS,
RELEASE,
MOVE,
WHEEL,
};
enum mouse_event_button
{
NONE = 0x00,
LEFT = 0x01,
MIDDLE = 0x02,
RIGHT = 0x04,
SCROLL_UP = 0x08,
SCROLL_DOWN = 0x10,
};
// Padding for ui_event
unsigned char type;
// kind of event
mouse_event_type event;
// if PRESS or RELEASE, the button pressed
mouse_event_button button;
// bitwise-or of buttons currently pressed
unsigned short held;
// bitwise-or of key mods currently pressed
unsigned char mod;
// location of events in pixels and in window coordinate space
unsigned int px;
unsigned int py;
};
struct wm_resize_event
{
unsigned char type;
int w, h;
};
struct wm_expose_event
{
unsigned char type;
};
struct wm_quit_event
{
unsigned char type;
};
struct wm_custom_event
{
unsigned char type;
int code;
void *data1;
void *data2;
};
// Basically a generic SDL_Event
struct wm_event
{
unsigned char type;
wm_active_event active;
wm_keyboard_event key;
wm_mouse_event mouse_event;
wm_resize_event resize;
wm_expose_event expose;
wm_quit_event quit;
wm_custom_event custom;
};
#ifdef USE_TILE_LOCAL
enum mouse_cursor_type
{
MOUSE_CURSOR_ARROW = 0,
MOUSE_CURSOR_POINTER,
NUM_MOUSE_CURSORS,
};
// custom timer callback function
typedef unsigned int (*wm_timer_callback)(unsigned int interval, void* param);
class WindowManager
{
public:
// To silence pre 4.3 g++ compiler warnings
virtual ~WindowManager() {};
// Static Alloc/deallocators
// Note: Write this function in each implementation-specific file,
// e.g. windowmanager-sdl.cc has its own WindowManager::create().
static void create();
static void shutdown();
// Class functions
virtual int init(coord_def *m_windowsz) = 0;
// Environment state functions
virtual void set_window_title(const char *title) = 0;
virtual bool set_window_icon(const char* icon_name) = 0;
virtual unsigned char get_mod_state() const = 0;
virtual void set_mod_state(tiles_key_mod mod) = 0;
virtual void set_mouse_cursor(mouse_cursor_type id) = 0;
virtual unsigned short get_mouse_state(int *x, int *y) const = 0;
virtual string get_clipboard() = 0;
virtual bool has_clipboard() = 0;
// System time functions
virtual unsigned int set_timer(unsigned int interval,
wm_timer_callback callback) = 0;
virtual void remove_timer(unsigned int& timer_id) = 0;
virtual unsigned int get_ticks() const = 0;
virtual void delay(unsigned int ms) = 0;
// Event functions
virtual int wait_event(wm_event *event, int timeout) = 0;
virtual bool next_event_is(wm_event_type type) = 0;
// Display functions
virtual bool init_hidpi() = 0;
virtual void resize(coord_def &m_windowsz) = 0;
virtual void swap_buffers() = 0;
virtual int screen_width() const = 0;
virtual int screen_height() const = 0;
virtual int desktop_width() const = 0;
virtual int desktop_height() const = 0;
// Texture loading
virtual bool load_texture(GenericTexture *tex, const char *filename,
MipMapOptions mip_opt, unsigned int &orig_width,
unsigned int &orig_height,
tex_proc_func proc = nullptr,
bool force_power_of_two = true) = 0;
};
// Main interface for UI functions
extern WindowManager *wm;
#endif //USE_TILE_LOCAL
|