-
Notifications
You must be signed in to change notification settings - Fork 7
/
fssimplewindow.h
416 lines (338 loc) · 11.4 KB
/
fssimplewindow.h
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/* ////////////////////////////////////////////////////////////
File Name: fssimplewindow.h
Copyright (c) 2017 Soji Yamakawa. All rights reserved.
http://www.ysflight.com
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//////////////////////////////////////////////////////////// */
#ifndef FSSIMPLEWINDOW_IS_INCLUDED
#define FSSIMPLEWINDOW_IS_INCLUDED
/* { */
/*! \file
*/
#ifndef FS_MOUSEEVENT_TYPE_IS_DEFINED
#define FS_MOUSEEVENT_TYPE_IS_DEFINED
/*! Enumeration for mouse events.
*/
enum
{
FSMOUSEEVENT_NONE,
FSMOUSEEVENT_LBUTTONDOWN,
FSMOUSEEVENT_LBUTTONUP,
FSMOUSEEVENT_MBUTTONDOWN,
FSMOUSEEVENT_MBUTTONUP,
FSMOUSEEVENT_RBUTTONDOWN,
FSMOUSEEVENT_RBUTTONUP,
FSMOUSEEVENT_MOVE
};
#endif
#ifndef FS_NATIVETEXTEVENT_TYPE_IS_DEFINED
#define FS_NATIVETEXTEVENT_TYPE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KEY_COMMA,
FSKEY_DOT,
FSKEY_SLASH,
FSKEY_TEN0,
FSKEY_TEN1,
FSKEY_TEN2,
FSKEY_TEN3,
FSKEY_TEN4,
FSKEY_TEN5,
FSKEY_TEN6,
FSKEY_TEN7,
FSKEY_TEN8,
FSKEY_TEN9,
FSKEY_TENDOT,
FSKEY_TENSLASH,
FSKEY_TENSTAR,
FSKEY_TENMINUS,
FSKEY_TENPLUS,
FSKEY_TENENTER,
FSKEY_WHEELUP,
FSKEY_WHEELDOWN,
FSKEY_NUM_KEYCODE
};
#endif
#ifndef FSSIMPLEWINDOW_MACRO_ONLY
#if !defined(_WIN32) && !defined(GL_GLEXT_PROTOTYPES)
#define GL_GLEXT_PROTOTYPES
#endif
#ifndef FSSIMPLEWINDOW_DONT_INCLUDE_OPENGL_HEADERS
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
// Prevent inclusion of winsock.h
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#else
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#elif !defined(__APPLE__)
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#else
#include <TargetConditionals.h>
#if TARGET_OS_EMBEDDED!=0 || TARGET_OS_IPHONE!=0 || TARGET_OS_IPHONE_SIMULATOR!=0
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
typedef double GLdouble;
#else
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>
#endif
#endif
#endif // << #ifndef FSSIMPLEWINDOW_DONT_INCLUDE_OPENGL_HEADERS
#ifdef __cplusplus
// This needs to be included from Objective-C code for mouse-event enums.
// C++ specific declaration must be enclosed by #ifdef __cplucplus and #endif
class FsSimpleWindowInternal;
const FsSimpleWindowInternal *FsGetSimpleWindowInternal(void);
extern void *fsCloseWindowCallBackParam;
extern bool (*fsCloseWindowCallBack)(void *param);
extern void *fsOpenGLContextCreationCallBackParam;
extern bool (*fsOpenGLContextCreationCallBack)(void *param);
extern void *fsAfterWindowCreationCallBackParam;
extern void (*fsAfterWindowCreationCallBack)(void *param);
extern void *fsSwapBuffersHookParam;
extern bool (*fsSwapBuffersHook)(void *param);
extern void *fsOnPaintCallbackParam;
extern void (*fsOnPaintCallback)(void *param);
extern void *fsOnResizeCallBackParam;
extern void (*fsOnResizeCallBack)(void *param,int wid,int hei);
extern void (*fsIntervalCallBack)(void *);
extern void *fsIntervalCallBackParameter;
extern void (*fsPollDeviceHook)(void *);
extern void *fsPollDeviceHookParam;
// Memo: 2013/11/09 Clang is not capable of understanding default function parameter.
// Why the hell Apple switched to such an incomplete compiler?
class FsOpenWindowOption
{
public:
enum SIZE_OPTION
{
NORMAL_WINDOW,
MAXIMIZE_WINDOW,
FULLSCREEN
};
int x0,y0,wid,hei;
const char *windowTitle;
bool useDoubleBuffer;
bool useMultiSampleBuffer;
SIZE_OPTION sizeOpt;
FsOpenWindowOption();
};
class FsVec2i
{
public:
int v[2];
inline int x(void) const
{
return v[0];
}
inline int y(void) const
{
return v[1];
}
};
void FsOpenWindow(int x0,int y0,int wid,int hei,int useDoubleBuffer);
void FsOpenWindow(int x0,int y0,int wid,int hei,int useDoubleBuffer,const char windowTitle[]);
/*! Opes the main window according to the given options.
Currently, useMultiSampleBuffer is respected only in MacOSX. */
void FsOpenWindow(const FsOpenWindowOption &openWindowOption);
/*! This function returns non zero if the window is currently open. */
int FsCheckWindowOpen(void);
void FsCloseWindow(void);
void FsMaximizeWindow(void);
void FsUnmaximizeWindow(void);
void FsMakeFullScreen(void);
/*! FsRegisterIntervalCallBack has little meaning unless the program uses system-modal dialog boxes such as file dialog.
Since the system takes over application main loop when such a system-modal dialog is visible, the main window will appear to be blank.
If an interval function is registered (and the program is written in such a way that a single interval function drives the application), the program can draw main window image from inside the interval function. */
void FsRegisterIntervalCallBack(void (*callback)(void *),void *param);
/*! This function registers a function that is called just before OpenGL context is created and initialized.
If the OpenGL context (or can be any other 3D graphics engine) is created and initialized in the
call-back function, the function must return true. Then, the OpenGL context initialization in the
FsSimpleWindow framework will be skipped. */
void FsRegisterBeforeOpenGLContextCreationCallBack(bool (*callback)(void *),void *param);
/*! This function registers a function that is called after the window is created, and the graphics
context is ready to go. */
void FsRegisterAfterWindowCreationCallBack(void (*callback)(void *),void *param);
/*! This function registers a function that is called when the user tries to close the window from the
close button.
The call-back function must return false if the window must not be closed. This function will not be called
if the window is closed from FsCloseWindow, or by just lapsing to the end of main function. */
void FsRegisterCloseWindowCallBack(bool (*callback)(void *),void *param);
/*! This function registers a function that is called just before FsSwapBuffers exposes the back buffer to the user.
If the back buffer is exposed inside the call-back, this function must return true. */
void FsRegisterSwapBuffersCallBack(bool (*callback)(void *),void *param);
/*! This function registers a OnPaint call back function. This function will be called when
paint event (such as WM_PAINT) is sent to the window outside of the main loop. */
void FsRegisterOnPaintCallBack(void (*callback)(void *),void *param);
/*! This function pushes a OnPaint (for example WM_PAINT in Win32) event in the system's event queue so that OnPaint call back is called next time the event is processed.
Not necessary for purely polling-based program, however, for the systems that does not allow polling-based programming, such as iOS, may require to use this function. */
void FsPushOnPaintEvent(void);
/*! This function registers a function that is called when window is resized. */
void FsRegisterWindowResizeCallBack(void (*callback)(void *,int wid,int hei),void *param);
/*! This function registers a function that is called when FsPollDevice is called. */
void FsRegisterPollDeviceCallBack(void (*callback)(void *),void *param);
void FsGetWindowSize(int &wid,int &hei);
void FsGetWindowPosition(int &x0,int &y0);
void FsSetWindowTitle(const char windowTitle[]);
void FsPollDevice(void);
void FsSleep(int ms);
long long int FsPassedTime(void);
long long int FsSubSecondTimer(void);
void FsGetMouseState(int &lb,int &mb,int &rb,int &mx,int &my);
int FsGetMouseEvent(int &lb,int &mb,int &rb,int &mx,int &my);
void FsSwapBuffers(void);
int FsInkey(void);
int FsInkeyChar(void);
/*! This function pushes the key code to the key-stroke buffer and makes a virtual key-press event. */
void FsPushKey(int fskey);
/*! This function pushes the character code to the keyboard-generated character buffer and makes a virtual event. */
void FsPushChar(int c);
int FsGetKeyState(int fsKeyCode);
int FsCheckKeyHeldDown(void);
/*! This function waits (blocks) until all the event queues are flushed and keys and mouse buttons are released.
In the past, this function was blocking forever when a key or a button is stuck.
That was obvious hardware problem, but to the user it appears that the program is in trouble. */
int FsCheckWindowExposure(void);
void FsClearEventQueue(void);
void FsChangeToProgramDir(void); // Mainly for Mac OS X
const char *FsKeyCodeToString(int keyCode);
int FsStringToKeyCode(const char str[]);
/*! Enables IME for non-English language input.
Returns non-zero if successful.
Returns zero if it cannot enable IME.
*/
int FsEnableIME(void);
/*! Disable IME enabled by FsEnableIME function. */
void FsDisableIME(void);
// These functions are experimental. >>
int FsGetNumCurrentTouch(void);
const FsVec2i *FsGetCurrentTouch(void);
// These functions are experimental. <<
// These functions are even more experimental. >>
int FsIsNativeTextInputAvailable(void);
int FsOpenNativeTextInput(int x1,int y1,int wid,int hei);
void FsCloseNativeTextInput(void);
void FsSetNativeTextInputText(const wchar_t str[]);
int FsGetNativeTextInputTextLength(void);
void FsGetNativeTextInputText(wchar_t str[],int bufLen);
int FsGetNativeTextInputEvent(void);
// These functions are even more experimental. <<
#endif // << #ifdef __cplusplus
#endif // << #ifndef FSSIMPLEWINDOW_MACRO_ONLY
/* } */
#endif