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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/*
* Copyright (c) 2015~2020 chai
*/
#ifndef _WOG_H
#define _WOG_H
#include <Windows.h> // for virtual key value
#define WOG_GL 1
#define WOG_GDI 2
#define WOG_API WOG_GDI
typedef unsigned int uint32;
typedef unsigned short uint16;
enum // event type
{
WOG_EUNKNOWN = 0, // unknown event
WOG_EKEYDOWN, // key pressed
WOG_EKEYUP, // key released
WOG_EMOUSEMOTION, // mouse motion
WOG_EMOUSEWHEEL, // mouse wheel scrolling
WOG_EMOUSEBUTTONDOWN, // mosue button down
WOG_EMOUSEBUTTONUP, // mosue button down
WOG_ECLOSE, // close window
};
enum // mouse button event, e.button value
{
WOG_MOUSE_LBUTTON, // left mouse button
WOG_MOUSE_RBUTTON, // right mouse button
WOG_MOUSE_MIDDLE, // middle button
};
typedef struct wog_Event
{
int type;
//union // event value
//{
int key; // for key, simply use windows virtual key value
// see https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
struct // for mouse motion
{
int x, y; // mouse position
}pos;
int wheel; // 1 indicate scroll up and -1 indicate scrool down
int button; // mouse button
//};
}wog_Event;
//* VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
//* 0x40 : unassigned
//* VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)
//定义数据字符0~9
#define VK_0 0x30
#define VK_1 0x31
#define VK_2 0x32
#define VK_3 0x33
#define VK_4 0x34
#define VK_5 0x35
#define VK_6 0x36
#define VK_7 0x37
#define VK_8 0x38
#define VK_9 0x39
//定义数据字符A~Z
#define VK_A 0x41
#define VK_B 0x42
#define VK_C 0x43
#define VK_D 0x44
#define VK_E 0x45
#define VK_F 0x46
#define VK_G 0x47
#define VK_H 0x48
#define VK_I 0x49
#define VK_J 0x4A
#define VK_K 0x4B
#define VK_L 0x4C
#define VK_M 0x4D
#define VK_N 0x4E
#define VK_O 0x4F
#define VK_P 0x50
#define VK_Q 0x51
#define VK_R 0x52
#define VK_S 0x53
#define VK_T 0x54
#define VK_U 0x55
#define VK_V 0x56
#define VK_W 0x57
#define VK_X 0x58
#define VK_Y 0x59
#define VK_Z 0x5A
//定义数据字符a~z
#define VK_a 0x61
#define VK_b 0x62
#define VK_c 0x63
#define VK_d 0x64
#define VK_e 0x65
#define VK_f 0x66
#define VK_g 0x67
#define VK_h 0x68
#define VK_i 0x69
#define VK_j 0x6A
#define VK_k 0x6B
#define VK_l 0x6C
#define VK_m 0x6D
#define VK_n 0x6E
#define VK_o 0x6F
#define VK_p 0x70
#define VK_q 0x71
#define VK_r 0x72
#define VK_s 0x73
#define VK_t 0x74
#define VK_u 0x75
#define VK_v 0x76
#define VK_w 0x77
#define VK_x 0x78
#define VK_y 0x79
#define VK_z 0x7A
typedef struct {
int width, height, channels;
unsigned char* buffer;
} wog_Surface;
/**
* Entry of user program which defined in user project. You need provide
* this function's defination.
*/
#define main wog_main
extern int wog_main(int argc, char* argv[]);
typedef struct wog_Window wog_Window;
#if WOG_API == WOG_GL
/**
* Struct that hold opengl context generated by wglCreateContext() which
* defined in opengl32.lib
*/
typedef struct wog_GLContext wog_GLContext;
#endif
enum // window style flag
{
WOG_HIDDEN = 4,
WOG_RESIZABLE = 8,
WOG_DISABLE = 16,
};
/**
* Create window with given configures.
* flag would be:
* WOG_HIDDEN
* WOG_RESIZABLE
* WOG_DISABLE
* or just 0;
*/
wog_Window* wog_createWindow(const char* title, int width, int height, int x, int y, uint32 flags);
#if WOG_API == WOG_GL
wog_GLContext* wog_createGLContext(wog_Window* wnd);
int wog_makeCurrent(wog_Window* wnd, wog_GLContext* cxt);
void wog_destroyGLContext(wog_GLContext* cxt);
#endif
void wog_destroyWindow(wog_Window* wnd);
#if WOG_API == WOG_GL
void wog_swapBuffers(wog_Window* wnd);
#endif
#if WOG_API == WOG_GDI
void wog_updateSurface(wog_Window* wnd);
#endif
int wog_pollEvent(wog_Window* wnd, wog_Event* e);
void wog_getMouse(wog_Window* wnd, int *x, int *y);
// get current ticks
int wog_tick();
void wog_sleep(int ms);
void wog_getwindowsize(wog_Window* wnd, int* width, int* height);
void wog_show(wog_Window* wnd);
void wog_hide(wog_Window* wnd);
typedef void(*wog_Callback)(wog_Window* wnd) ;
/**
* Register callback functions.
*/
void wog_registerResizeCallback(wog_Callback cal);
void wog_registerQuitCallback(wog_Callback cal);
wog_Surface* wog_getsurface(wog_Window* wnd);
void wog_setcursor(wog_Window* wnd, unsigned int cursor);
//void wog_setcursorImage(wog_Window* wnd, const char* path);
typedef HANDLE Wog_Cursor;
void wog_setcursorImage(wog_Window* wnd, Wog_Cursor icon);
void wog_setMouseCapture(wog_Window* wnd);
void wog_releaseMouseCapture(wog_Window* wnd);
HINSTANCE wog_get_instance();
#endif
|