summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/windowmanager.h
blob: 0cbb9f82375ab167b073e6e473c9f86c54b0ce20 (plain) (blame)
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
#ifndef WINDOWMANAGER_H
#define WINDOWMANAGER_H

#ifdef USE_TILE_LOCAL

#include "tiletex.h"

enum wm_event_type
{
    WME_NOEVENT = 0,
    WME_ACTIVEEVENT,
    WME_KEYDOWN,
    WME_KEYUP,
    WME_MOUSEMOTION,
    WME_MOUSEBUTTONUP,
    WME_MOUSEBUTTONDOWN,
    WME_QUIT,
    WME_CUSTOMEVENT,
    WME_RESIZE,
    WME_EXPOSE,
    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_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;
    MouseEvent mouse_event;
    wm_resize_event resize;
    wm_expose_event expose;
    wm_quit_event quit;
    wm_custom_event custom;
};

// custom timer callback function
typedef unsigned int (*wm_timer_callback)(unsigned int interval);

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 key_mod get_mod_state() const = 0;
    virtual void set_mod_state(key_mod mod) = 0;

    // System time functions
    virtual void set_timer(unsigned int interval,
                           wm_timer_callback callback) = 0;
    virtual unsigned int get_ticks() const = 0;
    virtual void delay(unsigned int ms) = 0;

    // Event functions
    virtual int raise_custom_event() = 0;
    virtual int wait_event(wm_event *event) = 0;
    virtual unsigned int get_event_count(wm_event_type type) = 0;

    // Display functions
    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 = NULL,
                              bool force_power_of_two = true) = 0;
};

// Main interface for UI functions
extern WindowManager *wm;

#endif //USE_TILE_LOCAL
#endif //include guard