Moving the source code files from 'src' to 'src/Common' as a first step towards separ...
[freeglut] / src / Common / freeglut_internal.h
1 /*\r
2  * freeglut_internal.h\r
3  *\r
4  * The freeglut library private include file.\r
5  *\r
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.\r
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>\r
8  * Creation date: Thu Dec 2 1999\r
9  *\r
10  * Permission is hereby granted, free of charge, to any person obtaining a\r
11  * copy of this software and associated documentation files (the "Software"),\r
12  * to deal in the Software without restriction, including without limitation\r
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
14  * and/or sell copies of the Software, and to permit persons to whom the\r
15  * Software is furnished to do so, subject to the following conditions:\r
16  *\r
17  * The above copyright notice and this permission notice shall be included\r
18  * in all copies or substantial portions of the Software.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
26  */\r
27 \r
28 #ifndef  FREEGLUT_INTERNAL_H\r
29 #define  FREEGLUT_INTERNAL_H\r
30 \r
31 #ifdef HAVE_CONFIG_H\r
32 #    include "config.h"\r
33 #endif\r
34 \r
35 /* XXX Update these for each release! */\r
36 #define  VERSION_MAJOR 2\r
37 #define  VERSION_MINOR 7\r
38 #define  VERSION_PATCH 0\r
39 \r
40 /* Freeglut is intended to function under all Unix/X11 and Win32 platforms. */\r
41 /* XXX: Don't all MS-Windows compilers (except Cygwin) have _WIN32 defined?\r
42  * XXX: If so, remove the first set of defined()'s below.\r
43  */\r
44 #if !defined(TARGET_HOST_POSIX_X11) && !defined(TARGET_HOST_MS_WINDOWS) && !defined(TARGET_HOST_MAC_OSX) && !defined(TARGET_HOST_SOLARIS)\r
45 #if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__) \\r
46     || defined(_WIN32) || defined(_WIN32_WCE) \\r
47     || ( defined(__CYGWIN__) && defined(X_DISPLAY_MISSING) )\r
48 #   define  TARGET_HOST_MS_WINDOWS 1\r
49 \r
50 #elif defined(__posix__) || defined(__unix__) || defined(__linux__) || defined(__sun)\r
51 #   define  TARGET_HOST_POSIX_X11  1\r
52 \r
53 #elif defined(__APPLE__)\r
54 /* This is a placeholder until we get native OSX support ironed out -- JFF 11/18/09 */\r
55 #   define  TARGET_HOST_POSIX_X11  1\r
56 /* #   define  TARGET_HOST_MAC_OSX    1 */\r
57 \r
58 #else\r
59 #   error "Unrecognized target host!"\r
60 \r
61 #endif\r
62 #endif\r
63 \r
64 /* Detect both SunPro and gcc compilers on Sun Solaris */\r
65 #if defined (__SVR4) && defined (__sun)\r
66 #   define TARGET_HOST_SOLARIS 1\r
67 #endif\r
68 \r
69 #ifndef TARGET_HOST_MS_WINDOWS\r
70 #   define  TARGET_HOST_MS_WINDOWS 0\r
71 #endif\r
72 \r
73 #ifndef  TARGET_HOST_POSIX_X11\r
74 #   define  TARGET_HOST_POSIX_X11  0\r
75 #endif\r
76 \r
77 #ifndef  TARGET_HOST_MAC_OSX\r
78 #   define  TARGET_HOST_MAC_OSX    0\r
79 #endif\r
80 \r
81 #ifndef  TARGET_HOST_SOLARIS\r
82 #   define  TARGET_HOST_SOLARIS    0\r
83 #endif\r
84 \r
85 /* -- FIXED CONFIGURATION LIMITS ------------------------------------------- */\r
86 \r
87 #define  FREEGLUT_MAX_MENUS         3\r
88 \r
89 /* -- PLATFORM-SPECIFIC INCLUDES ------------------------------------------- */\r
90 \r
91 /* All Win32 headers depend on the huge windows.h recursive include.\r
92  * Note: Lower-case header names are used, for best cross-platform\r
93  * compatibility.\r
94  */\r
95 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
96 #    include <windows.h>\r
97 #    include <windowsx.h>\r
98 #    include <mmsystem.h>\r
99 /* CYGWIN does not have tchar.h, but has TEXT(x), defined in winnt.h. */\r
100 #    ifndef __CYGWIN__\r
101 #      include <tchar.h>\r
102 #    else\r
103 #      define _TEXT(x) TEXT(x)\r
104 #      define _T(x)    TEXT(x)\r
105 #    endif\r
106 \r
107 #elif TARGET_HOST_POSIX_X11\r
108 #    include <GL/glx.h>\r
109 #    include <X11/Xlib.h>\r
110 #    include <X11/Xatom.h>\r
111 #    include <X11/keysym.h>\r
112 #    include <X11/extensions/XInput.h>\r
113 #    ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H\r
114 #        include <X11/extensions/xf86vmode.h>\r
115 #    endif\r
116 #    ifdef HAVE_X11_EXTENSIONS_XRANDR_H\r
117 #        include <X11/extensions/Xrandr.h>\r
118 #    endif\r
119 /* If GLX is too old, we will fail during runtime when multisampling\r
120    is requested, but at least freeglut compiles. */\r
121 #    ifndef GLX_SAMPLE_BUFFERS\r
122 #        define GLX_SAMPLE_BUFFERS 0x80A8\r
123 #    endif\r
124 #    ifndef GLX_SAMPLES\r
125 #        define GLX_SAMPLES 0x80A9\r
126 #    endif\r
127 \r
128 #endif\r
129 \r
130 /* These files should be available on every platform. */\r
131 #include <stdio.h>\r
132 #include <string.h>\r
133 #include <math.h>\r
134 #include <stdlib.h>\r
135 #include <stdarg.h>\r
136 \r
137 /* These are included based on autoconf directives. */\r
138 #ifdef HAVE_SYS_TYPES_H\r
139 #    include <sys/types.h>\r
140 #endif\r
141 #ifdef HAVE_UNISTD_H\r
142 #    include <unistd.h>\r
143 #endif\r
144 #ifdef TIME_WITH_SYS_TIME\r
145 #    include <sys/time.h>\r
146 #    include <time.h>\r
147 #elif defined(HAVE_SYS_TIME_H)\r
148 #    include <sys/time.h>\r
149 #else\r
150 #    include <time.h>\r
151 #endif\r
152 \r
153 /* -- AUTOCONF HACKS --------------------------------------------------------*/\r
154 \r
155 /* XXX: Update autoconf to avoid these.\r
156  * XXX: Are non-POSIX platforms intended not to use autoconf?\r
157  * If so, perhaps there should be a config_guess.h for them. Alternatively,\r
158  * config guesses could be placed above, just after the config.h exclusion.\r
159  */\r
160 #if defined(__FreeBSD__) || defined(__NetBSD__)\r
161 #    define HAVE_USB_JS 1\r
162 #    if defined(__NetBSD__) || ( defined(__FreeBSD__) && __FreeBSD_version >= 500000)\r
163 #        define HAVE_USBHID_H 1\r
164 #    endif\r
165 #endif\r
166 \r
167 #if TARGET_HOST_MS_WINDOWS\r
168 #    define  HAVE_VFPRINTF 1\r
169 #endif\r
170 \r
171 /* MinGW may lack a prototype for ChangeDisplaySettingsEx() (depending on the version?) */\r
172 #if TARGET_HOST_MS_WINDOWS && !defined(ChangeDisplaySettingsEx)\r
173 LONG WINAPI ChangeDisplaySettingsExA(LPCSTR,LPDEVMODEA,HWND,DWORD,LPVOID);\r
174 LONG WINAPI ChangeDisplaySettingsExW(LPCWSTR,LPDEVMODEW,HWND,DWORD,LPVOID);\r
175 #    ifdef UNICODE\r
176 #        define ChangeDisplaySettingsEx ChangeDisplaySettingsExW\r
177 #    else\r
178 #        define ChangeDisplaySettingsEx ChangeDisplaySettingsExA\r
179 #    endif\r
180 #endif\r
181 \r
182 #if defined(_MSC_VER) || defined(__WATCOMC__)\r
183 /* strdup() is non-standard, for all but POSIX-2001 */\r
184 #define strdup   _strdup\r
185 #endif\r
186 \r
187 /* M_PI is non-standard (defined by BSD, not ISO-C) */\r
188 #ifndef M_PI\r
189 #    define  M_PI  3.14159265358979323846\r
190 #endif\r
191 \r
192 #ifdef HAVE_STDBOOL_H\r
193 #    include <stdbool.h>\r
194 #    ifndef TRUE\r
195 #        define TRUE true\r
196 #    endif\r
197 #    ifndef FALSE\r
198 #        define FALSE false\r
199 #    endif\r
200 #else\r
201 #    ifndef TRUE\r
202 #        define  TRUE  1\r
203 #    endif\r
204 #    ifndef FALSE\r
205 #        define  FALSE  0\r
206 #    endif\r
207 #endif\r
208 \r
209 /* General defines */\r
210 \r
211 #define INVALID_MODIFIERS 0xffffffff\r
212 \r
213 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */\r
214 \r
215 /* Freeglut callbacks type definitions */\r
216 typedef void (* FGCBDisplay       )( void );\r
217 typedef void (* FGCBReshape       )( int, int );\r
218 typedef void (* FGCBVisibility    )( int );\r
219 typedef void (* FGCBKeyboard      )( unsigned char, int, int );\r
220 typedef void (* FGCBSpecial       )( int, int, int );\r
221 typedef void (* FGCBMouse         )( int, int, int, int );\r
222 typedef void (* FGCBMouseWheel    )( int, int, int, int );\r
223 typedef void (* FGCBMotion        )( int, int );\r
224 typedef void (* FGCBPassive       )( int, int );\r
225 typedef void (* FGCBEntry         )( int );\r
226 typedef void (* FGCBWindowStatus  )( int );\r
227 typedef void (* FGCBSelect        )( int, int, int );\r
228 typedef void (* FGCBJoystick      )( unsigned int, int, int, int );\r
229 typedef void (* FGCBKeyboardUp    )( unsigned char, int, int );\r
230 typedef void (* FGCBSpecialUp     )( int, int, int );\r
231 typedef void (* FGCBOverlayDisplay)( void );\r
232 typedef void (* FGCBSpaceMotion   )( int, int, int );\r
233 typedef void (* FGCBSpaceRotation )( int, int, int );\r
234 typedef void (* FGCBSpaceButton   )( int, int );\r
235 typedef void (* FGCBDials         )( int, int );\r
236 typedef void (* FGCBButtonBox     )( int, int );\r
237 typedef void (* FGCBTabletMotion  )( int, int );\r
238 typedef void (* FGCBTabletButton  )( int, int, int, int );\r
239 typedef void (* FGCBDestroy       )( void );\r
240 \r
241 typedef void (* FGCBMultiEntry   )( int, int );\r
242 typedef void (* FGCBMultiButton  )( int, int, int, int, int );\r
243 typedef void (* FGCBMultiMotion  )( int, int, int );\r
244 typedef void (* FGCBMultiPassive )( int, int, int );\r
245 \r
246 /* The global callbacks type definitions */\r
247 typedef void (* FGCBIdle          )( void );\r
248 typedef void (* FGCBTimer         )( int );\r
249 typedef void (* FGCBMenuState     )( int );\r
250 typedef void (* FGCBMenuStatus    )( int, int, int );\r
251 \r
252 /* The callback used when creating/using menus */\r
253 typedef void (* FGCBMenu          )( int );\r
254 \r
255 /* The FreeGLUT error/warning handler type definition */\r
256 typedef void (* FGError           ) ( const char *fmt, va_list ap);\r
257 typedef void (* FGWarning         ) ( const char *fmt, va_list ap);\r
258 \r
259 \r
260 /* A list structure */\r
261 typedef struct tagSFG_List SFG_List;\r
262 struct tagSFG_List\r
263 {\r
264     void *First;\r
265     void *Last;\r
266 };\r
267 \r
268 /* A list node structure */\r
269 typedef struct tagSFG_Node SFG_Node;\r
270 struct tagSFG_Node\r
271 {\r
272     void *Next;\r
273     void *Prev;\r
274 };\r
275 \r
276 /* A helper structure holding two ints and a boolean */\r
277 typedef struct tagSFG_XYUse SFG_XYUse;\r
278 struct tagSFG_XYUse\r
279 {\r
280     GLint           X, Y;               /* The two integers...               */\r
281     GLboolean       Use;                /* ...and a single boolean.          */\r
282 };\r
283 \r
284 /*\r
285  * An enumeration containing the state of the GLUT execution:\r
286  * initializing, running, or stopping\r
287  */\r
288 typedef enum\r
289 {\r
290   GLUT_EXEC_STATE_INIT,\r
291   GLUT_EXEC_STATE_RUNNING,\r
292   GLUT_EXEC_STATE_STOP\r
293 } fgExecutionState ;\r
294 \r
295 /* This structure holds different freeglut settings */\r
296 typedef struct tagSFG_State SFG_State;\r
297 struct tagSFG_State\r
298 {\r
299     SFG_XYUse        Position;             /* The default windows' position  */\r
300     SFG_XYUse        Size;                 /* The default windows' size      */\r
301     unsigned int     DisplayMode;          /* Display mode for new windows   */\r
302 \r
303     GLboolean        Initialised;          /* freeglut has been initialised  */\r
304 \r
305     int              DirectContext;        /* Direct rendering state         */\r
306 \r
307     GLboolean        ForceIconic;          /* New top windows are iconified  */\r
308     GLboolean        UseCurrentContext;    /* New windows share with current */\r
309 \r
310     GLboolean        GLDebugSwitch;        /* OpenGL state debugging switch  */\r
311     GLboolean        XSyncSwitch;          /* X11 sync protocol switch       */\r
312 \r
313     int              KeyRepeat;            /* Global key repeat mode.        */\r
314     int              Modifiers;            /* Current ALT/SHIFT/CTRL state   */\r
315 \r
316     GLuint           FPSInterval;          /* Interval between FPS printfs   */\r
317     GLuint           SwapCount;            /* Count of glutSwapBuffer calls  */\r
318     GLuint           SwapTime;             /* Time of last SwapBuffers       */\r
319 \r
320     unsigned long    Time;                 /* Time that glutInit was called  */\r
321     SFG_List         Timers;               /* The freeglut timer hooks       */\r
322     SFG_List         FreeTimers;           /* The unused timer hooks         */\r
323 \r
324     FGCBIdle         IdleCallback;         /* The global idle callback       */\r
325 \r
326     int              ActiveMenus;          /* Num. of currently active menus */\r
327     FGCBMenuState    MenuStateCallback;    /* Menu callbacks are global      */\r
328     FGCBMenuStatus   MenuStatusCallback;\r
329 \r
330     SFG_XYUse        GameModeSize;         /* Game mode screen's dimensions  */\r
331     int              GameModeDepth;        /* The pixel depth for game mode  */\r
332     int              GameModeRefresh;      /* The refresh rate for game mode */\r
333 \r
334     int              ActionOnWindowClose; /* Action when user closes window  */\r
335 \r
336     fgExecutionState ExecState;           /* Used for GLUT termination       */\r
337     char            *ProgramName;         /* Name of the invoking program    */\r
338     GLboolean        JoysticksInitialised;  /* Only initialize if application calls for them */\r
339     int              NumActiveJoysticks;    /* Number of active joysticks -- if zero, don't poll joysticks */\r
340     GLboolean        InputDevsInitialised;  /* Only initialize if application calls for them */\r
341 \r
342         int              MouseWheelTicks;      /* Number of ticks the mouse wheel has turned */\r
343 \r
344     int              AuxiliaryBufferNumber;  /* Number of auxiliary buffers */\r
345     int              SampleNumber;         /*  Number of samples per pixel  */\r
346 \r
347     int              MajorVersion;         /* Major OpenGL context version  */\r
348     int              MinorVersion;         /* Minor OpenGL context version  */\r
349     int              ContextFlags;         /* OpenGL context flags          */\r
350     int              ContextProfile;       /* OpenGL context profile        */\r
351     FGError          ErrorFunc;            /* User defined error handler    */\r
352     FGWarning        WarningFunc;          /* User defined warning handler  */\r
353 };\r
354 \r
355 /* The structure used by display initialization in freeglut_init.c */\r
356 typedef struct tagSFG_Display SFG_Display;\r
357 struct tagSFG_Display\r
358 {\r
359 #if TARGET_HOST_POSIX_X11\r
360     Display*        Display;            /* The display we are being run in.  */\r
361     int             Screen;             /* The screen we are about to use.   */\r
362     Window          RootWindow;         /* The screen's root window.         */\r
363     int             Connection;         /* The display's connection number   */\r
364     Atom            DeleteWindow;       /* The window deletion atom          */\r
365     Atom            State;              /* The state atom                    */\r
366     Atom            StateFullScreen;    /* The full screen atom              */\r
367 \r
368 #ifdef HAVE_X11_EXTENSIONS_XRANDR_H\r
369     int prev_xsz, prev_ysz;\r
370     int prev_refresh;\r
371     int prev_size_valid;\r
372 #endif  /* HAVE_X11_EXTENSIONS_XRANDR_H */\r
373 \r
374 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H\r
375     /*\r
376      * XF86VidMode may be compilable even if it fails at runtime.  Therefore,\r
377      * the validity of the VidMode has to be tracked\r
378      */\r
379     int             DisplayModeValid;   /* Flag that indicates runtime status*/\r
380     XF86VidModeModeLine DisplayMode;    /* Current screen's display settings */\r
381     int             DisplayModeClock;   /* The display mode's refresh rate   */\r
382     int             DisplayViewPortX;   /* saved X location of the viewport  */\r
383     int             DisplayViewPortY;   /* saved Y location of the viewport  */\r
384 #endif /* HAVE_X11_EXTENSIONS_XF86VMODE_H */\r
385 \r
386     int             DisplayPointerX;    /* saved X location of the pointer   */\r
387     int             DisplayPointerY;    /* saved Y location of the pointer   */\r
388 \r
389 #elif TARGET_HOST_MS_WINDOWS\r
390     HINSTANCE       Instance;           /* The application's instance        */\r
391     DEVMODE         DisplayMode;        /* Desktop's display settings        */\r
392     char           *DisplayName;        /* Display name for multi display support*/ \r
393 \r
394 #endif\r
395 \r
396     int             ScreenWidth;        /* The screen's width in pixels      */\r
397     int             ScreenHeight;       /* The screen's height in pixels     */\r
398     int             ScreenWidthMM;      /* The screen's width in milimeters  */\r
399     int             ScreenHeightMM;     /* The screen's height in milimeters */\r
400 };\r
401 \r
402 \r
403 /* The user can create any number of timer hooks */\r
404 typedef struct tagSFG_Timer SFG_Timer;\r
405 struct tagSFG_Timer\r
406 {\r
407     SFG_Node        Node;\r
408     int             ID;                 /* The timer ID integer              */\r
409     FGCBTimer       Callback;           /* The timer callback                */\r
410     long            TriggerTime;        /* The timer trigger time            */\r
411 };\r
412 \r
413 /*\r
414  * Make "freeglut" window handle and context types so that we don't need so\r
415  * much conditionally-compiled code later in the library.\r
416  */\r
417 #if TARGET_HOST_POSIX_X11\r
418 \r
419 typedef Window     SFG_WindowHandleType ;\r
420 typedef GLXContext SFG_WindowContextType ;\r
421 \r
422 #elif TARGET_HOST_MS_WINDOWS\r
423 \r
424 typedef HWND    SFG_WindowHandleType ;\r
425 typedef HGLRC   SFG_WindowContextType ;\r
426 \r
427 #endif\r
428 \r
429 /*\r
430  * A window and its OpenGL context. The contents of this structure\r
431  * are highly dependant on the target operating system we aim at...\r
432  */\r
433 typedef struct tagSFG_Context SFG_Context;\r
434 struct tagSFG_Context\r
435 {\r
436     SFG_WindowHandleType  Handle;    /* The window's handle                 */\r
437     SFG_WindowContextType Context;   /* The window's OpenGL/WGL context     */\r
438 \r
439 #if TARGET_HOST_POSIX_X11\r
440     GLXFBConfig*    FBConfig;        /* The window's FBConfig               */\r
441 #elif TARGET_HOST_MS_WINDOWS\r
442     HDC             Device;          /* The window's device context         */\r
443 #endif\r
444 \r
445     int             DoubleBuffered;  /* Treat the window as double-buffered */\r
446 };\r
447 \r
448 /* Window's state description. This structure should be kept portable. */\r
449 typedef struct tagSFG_WindowState SFG_WindowState;\r
450 struct tagSFG_WindowState\r
451 {\r
452     /* Note that on Windows, sizes always refer to the client area, thus without the window decorations */\r
453     int             Width;              /* Window's width in pixels          */\r
454     int             Height;             /* The same about the height         */\r
455 #if TARGET_HOST_POSIX_X11\r
456     int             OldWidth;           /* Window width from before a resize */\r
457     int             OldHeight;          /*   "    height  "    "    "   "    */\r
458 #elif TARGET_HOST_MS_WINDOWS\r
459     RECT            OldRect;            /* window rect - stored before the window is made fullscreen */\r
460     DWORD           OldStyle;           /* window style - stored before the window is made fullscreen */\r
461 #endif\r
462 \r
463     GLboolean       Redisplay;          /* Do we have to redisplay?          */\r
464     GLboolean       Visible;            /* Is the window visible now         */\r
465 \r
466     int             Cursor;             /* The currently selected cursor     */\r
467 \r
468     long            JoystickPollRate;   /* The joystick polling rate         */\r
469     long            JoystickLastPoll;   /* When the last poll happened       */\r
470 \r
471     int             MouseX, MouseY;     /* The most recent mouse position    */\r
472 \r
473     GLboolean       IgnoreKeyRepeat;    /* Whether to ignore key repeat.     */\r
474     GLboolean       KeyRepeating;       /* Currently in repeat mode          */\r
475 \r
476     GLboolean       NeedToResize;       /* Do we need to resize the window?  */\r
477 \r
478     GLboolean       IsFullscreen;       /* is the window fullscreen? */\r
479 };\r
480 \r
481 \r
482 /*\r
483  * A generic function pointer.  We should really use the GLUTproc type\r
484  * defined in freeglut_ext.h, but if we include that header in this file\r
485  * a bunch of other stuff (font-related) blows up!\r
486  */\r
487 typedef void (*SFG_Proc)();\r
488 \r
489 \r
490 /*\r
491  * SET_WCB() is used as:\r
492  *\r
493  *     SET_WCB( window, cbname, func );\r
494  *\r
495  * ...where {window} is the freeglut window to set the callback,\r
496  *          {cbname} is the window-specific callback to set,\r
497  *          {func} is a function-pointer.\r
498  *\r
499  * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,\r
500  * but this can cause warnings because the FETCH_WCB() macro type-\r
501  * casts its result, and a type-cast value shouldn't be an lvalue.\r
502  *\r
503  * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking\r
504  * and for no other reason.  Since it's hidden in the macro, the\r
505  * ugliness is felt to be rather benign.\r
506  */\r
507 #define SET_WCB(window,cbname,func)                            \\r
508 do                                                             \\r
509 {                                                              \\r
510     if( FETCH_WCB( window, cbname ) != (SFG_Proc)(func) )      \\r
511         (((window).CallBacks[CB_ ## cbname]) = (SFG_Proc)(func)); \\r
512 } while( 0 )\r
513 \r
514 /*\r
515  * FETCH_WCB() is used as:\r
516  *\r
517  *     FETCH_WCB( window, cbname );\r
518  *\r
519  * ...where {window} is the freeglut window to fetch the callback from,\r
520  *          {cbname} is the window-specific callback to fetch.\r
521  *\r
522  * The result is correctly type-cast to the callback function pointer\r
523  * type.\r
524  */\r
525 #define FETCH_WCB(window,cbname) \\r
526     ((window).CallBacks[CB_ ## cbname])\r
527 \r
528 /*\r
529  * INVOKE_WCB() is used as:\r
530  *\r
531  *     INVOKE_WCB( window, cbname, ( arg_list ) );\r
532  *\r
533  * ...where {window} is the freeglut window,\r
534  *          {cbname} is the window-specific callback to be invoked,\r
535  *          {(arg_list)} is the parameter list.\r
536  *\r
537  * The callback is invoked as:\r
538  *\r
539  *    callback( arg_list );\r
540  *\r
541  * ...so the parentheses are REQUIRED in the {arg_list}.\r
542  *\r
543  * NOTE that it does a sanity-check and also sets the\r
544  * current window.\r
545  *\r
546  */\r
547 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: also WinCE? */\r
548 #define INVOKE_WCB(window,cbname,arg_list)    \\r
549 do                                            \\r
550 {                                             \\r
551     if( FETCH_WCB( window, cbname ) )         \\r
552     {                                         \\r
553         FGCB ## cbname func = (FGCB ## cbname)(FETCH_WCB( window, cbname )); \\r
554         fgSetWindow( &window );               \\r
555         func arg_list;                        \\r
556     }                                         \\r
557 } while( 0 )\r
558 #else\r
559 #define INVOKE_WCB(window,cbname,arg_list)    \\r
560 do                                            \\r
561 {                                             \\r
562     if( FETCH_WCB( window, cbname ) )         \\r
563     {                                         \\r
564         fgSetWindow( &window );               \\r
565         ((FGCB ## cbname)FETCH_WCB( window, cbname )) arg_list; \\r
566     }                                         \\r
567 } while( 0 )\r
568 #endif\r
569 \r
570 /*\r
571  * The window callbacks the user can supply us with. Should be kept portable.\r
572  *\r
573  * This enumeration provides the freeglut CallBack numbers.\r
574  * The symbolic constants are indices into a window's array of\r
575  * function callbacks.  The names are formed by splicing a common\r
576  * prefix onto the callback's base name.  (This was originally\r
577  * done so that an early stage of development could live side-by-\r
578  * side with the old callback code.  The old callback code used\r
579  * the bare callback's name as a structure member, so I used a\r
580  * prefix for the array index name.)\r
581  *\r
582  * XXX For consistancy, perhaps the prefix should match the\r
583  * XXX FETCH* and INVOKE* macro suffices.  I.e., WCB_, rather than\r
584  * XXX CB_.\r
585  */\r
586 enum\r
587 {\r
588     CB_Display,\r
589     CB_Reshape,\r
590     CB_Keyboard,\r
591     CB_KeyboardUp,\r
592     CB_Special,\r
593     CB_SpecialUp,\r
594     CB_Mouse,\r
595     CB_MouseWheel,\r
596     CB_Motion,\r
597     CB_Passive,\r
598     CB_Entry,\r
599     CB_Visibility,\r
600     CB_WindowStatus,\r
601     CB_Joystick,\r
602     CB_Destroy,\r
603 \r
604     /* MPX-related */\r
605     CB_MultiEntry,\r
606     CB_MultiButton,\r
607     CB_MultiMotion,\r
608     CB_MultiPassive,\r
609 \r
610     /* Presently ignored */\r
611     CB_Select,\r
612     CB_OverlayDisplay,\r
613     CB_SpaceMotion,     /* presently implemented only on UNIX/X11 */\r
614     CB_SpaceRotation,   /* presently implemented only on UNIX/X11 */\r
615     CB_SpaceButton,     /* presently implemented only on UNIX/X11 */\r
616     CB_Dials,\r
617     CB_ButtonBox,\r
618     CB_TabletMotion,\r
619     CB_TabletButton,\r
620 \r
621     /* Always make this the LAST one */\r
622     TOTAL_CALLBACKS\r
623 };\r
624 \r
625 \r
626 /* This structure holds the OpenGL rendering context for all the menu windows */\r
627 typedef struct tagSFG_MenuContext SFG_MenuContext;\r
628 struct tagSFG_MenuContext\r
629 {\r
630     SFG_WindowContextType MContext;       /* The menu window's WGL context   */\r
631 };\r
632 \r
633 /* This structure describes a menu */\r
634 typedef struct tagSFG_Window SFG_Window;\r
635 typedef struct tagSFG_MenuEntry SFG_MenuEntry;\r
636 typedef struct tagSFG_Menu SFG_Menu;\r
637 struct tagSFG_Menu\r
638 {\r
639     SFG_Node            Node;\r
640     void               *UserData;     /* User data passed back at callback   */\r
641     int                 ID;           /* The global menu ID                  */\r
642     SFG_List            Entries;      /* The menu entries list               */\r
643     FGCBMenu            Callback;     /* The menu callback                   */\r
644     FGCBDestroy         Destroy;      /* Destruction callback                */\r
645     GLboolean           IsActive;     /* Is the menu selected?               */\r
646     int                 Width;        /* Menu box width in pixels            */\r
647     int                 Height;       /* Menu box height in pixels           */\r
648     int                 X, Y;         /* Menu box raster position            */\r
649 \r
650     SFG_MenuEntry      *ActiveEntry;  /* Currently active entry in the menu  */\r
651     SFG_Window         *Window;       /* Window for menu                     */\r
652     SFG_Window         *ParentWindow; /* Window in which the menu is invoked */\r
653 };\r
654 \r
655 /* This is a menu entry */\r
656 struct tagSFG_MenuEntry\r
657 {\r
658     SFG_Node            Node;\r
659     int                 ID;                     /* The menu entry ID (local) */\r
660     int                 Ordinal;                /* The menu's ordinal number */\r
661     char*               Text;                   /* The text to be displayed  */\r
662     SFG_Menu*           SubMenu;                /* Optional sub-menu tree    */\r
663     GLboolean           IsActive;               /* Is the entry highlighted? */\r
664     int                 Width;                  /* Label's width in pixels   */\r
665 };\r
666 \r
667 /*\r
668  * A window, making part of freeglut windows hierarchy.\r
669  * Should be kept portable.\r
670  *\r
671  * NOTE that ActiveMenu is set to menu itself if the window is a menu.\r
672  */\r
673 struct tagSFG_Window\r
674 {\r
675     SFG_Node            Node;\r
676     int                 ID;                     /* Window's ID number        */\r
677 \r
678     SFG_Context         Window;                 /* Window and OpenGL context */\r
679     SFG_WindowState     State;                  /* The window state          */\r
680     SFG_Proc            CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */\r
681     void               *UserData ;              /* For use by user           */\r
682 \r
683     SFG_Menu*       Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window  */\r
684     SFG_Menu*       ActiveMenu;                 /* The window's active menu  */\r
685 \r
686     SFG_Window*         Parent;                 /* The parent to this window */\r
687     SFG_List            Children;               /* The subwindows d.l. list  */\r
688 \r
689     GLboolean           IsMenu;                 /* Set to 1 if we are a menu */\r
690 };\r
691 \r
692 \r
693 /* A linked list structure of windows */\r
694 typedef struct tagSFG_WindowList SFG_WindowList ;\r
695 struct tagSFG_WindowList\r
696 {\r
697     SFG_Node node;\r
698     SFG_Window *window ;\r
699 };\r
700 \r
701 /* This holds information about all the windows, menus etc. */\r
702 typedef struct tagSFG_Structure SFG_Structure;\r
703 struct tagSFG_Structure\r
704 {\r
705     SFG_List        Windows;         /* The global windows list            */\r
706     SFG_List        Menus;           /* The global menus list              */\r
707     SFG_List        WindowsToDestroy;\r
708 \r
709     SFG_Window*     CurrentWindow;   /* The currently set window          */\r
710     SFG_Menu*       CurrentMenu;     /* Same, but menu...                 */\r
711 \r
712     SFG_MenuContext* MenuContext;    /* OpenGL rendering context for menus */\r
713 \r
714     SFG_Window*      GameModeWindow; /* The game mode window               */\r
715 \r
716     int              WindowID;       /* The new current window ID          */\r
717     int              MenuID;         /* The new current menu ID            */\r
718 };\r
719 \r
720 /*\r
721  * This structure is used for the enumeration purposes.\r
722  * You can easily extend its functionalities by declaring\r
723  * a structure containing enumerator's contents and custom\r
724  * data, then casting its pointer to (SFG_Enumerator *).\r
725  */\r
726 typedef struct tagSFG_Enumerator SFG_Enumerator;\r
727 struct tagSFG_Enumerator\r
728 {\r
729     GLboolean   found;                          /* Used to terminate search  */\r
730     void*       data;                           /* Custom data pointer       */\r
731 };\r
732 typedef void (* FGCBenumerator  )( SFG_Window *, SFG_Enumerator * );\r
733 \r
734 /* The bitmap font structure */\r
735 typedef struct tagSFG_Font SFG_Font;\r
736 struct tagSFG_Font\r
737 {\r
738     char*           Name;         /* The source font name             */\r
739     int             Quantity;     /* Number of chars in font          */\r
740     int             Height;       /* Height of the characters         */\r
741     const GLubyte** Characters;   /* The characters mapping           */\r
742 \r
743     float           xorig, yorig; /* Relative origin of the character */\r
744 };\r
745 \r
746 /* The stroke font structures */\r
747 \r
748 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;\r
749 struct tagSFG_StrokeVertex\r
750 {\r
751     GLfloat         X, Y;\r
752 };\r
753 \r
754 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;\r
755 struct tagSFG_StrokeStrip\r
756 {\r
757     int             Number;\r
758     const SFG_StrokeVertex* Vertices;\r
759 };\r
760 \r
761 typedef struct tagSFG_StrokeChar SFG_StrokeChar;\r
762 struct tagSFG_StrokeChar\r
763 {\r
764     GLfloat         Right;\r
765     int             Number;\r
766     const SFG_StrokeStrip* Strips;\r
767 };\r
768 \r
769 typedef struct tagSFG_StrokeFont SFG_StrokeFont;\r
770 struct tagSFG_StrokeFont\r
771 {\r
772     char*           Name;                       /* The source font name      */\r
773     int             Quantity;                   /* Number of chars in font   */\r
774     GLfloat         Height;                     /* Height of the characters  */\r
775     const SFG_StrokeChar** Characters;          /* The characters mapping    */\r
776 };\r
777 \r
778 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */\r
779 \r
780 /* Freeglut display related stuff (initialized once per session) */\r
781 extern SFG_Display fgDisplay;\r
782 \r
783 /* Freeglut internal structure */\r
784 extern SFG_Structure fgStructure;\r
785 \r
786 /* The current freeglut settings */\r
787 extern SFG_State fgState;\r
788 \r
789 \r
790 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */\r
791 \r
792 /*\r
793  * A call to this function makes us sure that the Display and Structure\r
794  * subsystems have been properly initialized and are ready to be used\r
795  */\r
796 #define  FREEGLUT_EXIT_IF_NOT_INITIALISED( string )               \\r
797   if ( ! fgState.Initialised )                                    \\r
798   {                                                               \\r
799     fgError ( " ERROR:  Function <%s> called"                     \\r
800               " without first calling 'glutInit'.", (string) ) ;  \\r
801   }\r
802 \r
803 #define  FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED( string )  \\r
804   if ( ! fgState.Initialised )                                      \\r
805   {                                                                 \\r
806     fgError ( " ERROR:  Internal <%s> function called"              \\r
807               " without first calling 'glutInit'.", (string) ) ;    \\r
808   }\r
809 \r
810 #define  FREEGLUT_INTERNAL_ERROR_EXIT( cond, string, function )  \\r
811   if ( ! ( cond ) )                                              \\r
812   {                                                              \\r
813     fgError ( " ERROR:  Internal error <%s> in function %s",     \\r
814               (string), (function) ) ;                           \\r
815   }\r
816 \r
817 /*\r
818  * Following definitions are somewhat similiar to GLib's,\r
819  * but do not generate any log messages:\r
820  */\r
821 #define  freeglut_return_if_fail( expr ) \\r
822     if( !(expr) )                        \\r
823         return;\r
824 #define  freeglut_return_val_if_fail( expr, val ) \\r
825     if( !(expr) )                                 \\r
826         return val ;\r
827 \r
828 /*\r
829  * A call to those macros assures us that there is a current\r
830  * window set, respectively:\r
831  */\r
832 #define  FREEGLUT_EXIT_IF_NO_WINDOW( string )                               \\r
833   if ( ! fgStructure.CurrentWindow &&                                       \\r
834        ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION ) )  \\r
835   {                                                                         \\r
836     fgError ( " ERROR:  Function <%s> called"                               \\r
837               " with no current window defined.", (string) ) ;              \\r
838   }\r
839 \r
840 /*\r
841  * The deinitialize function gets called on glutMainLoop() end. It should clean up\r
842  * everything inside of the freeglut\r
843  */\r
844 void fgDeinitialize( void );\r
845 \r
846 /*\r
847  * Those two functions are used to create/destroy the freeglut internal\r
848  * structures. This actually happens when calling glutInit() and when\r
849  * quitting the glutMainLoop() (which actually happens, when all windows\r
850  * have been closed).\r
851  */\r
852 void fgCreateStructure( void );\r
853 void fgDestroyStructure( void );\r
854 \r
855 /* A helper function to check if a display mode is possible to use */\r
856 #if TARGET_HOST_POSIX_X11\r
857 GLXFBConfig* fgChooseFBConfig( int* numcfgs );\r
858 #endif\r
859 \r
860 /* The window procedure for Win32 events handling */\r
861 #if TARGET_HOST_MS_WINDOWS\r
862 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,\r
863                                WPARAM wParam, LPARAM lParam );\r
864 void fgNewWGLCreateContext( SFG_Window* window );\r
865 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,\r
866                               unsigned char layer_type );\r
867 #endif\r
868 \r
869 /*\r
870  * Window creation, opening, closing and destruction.\r
871  * Also CallBack clearing/initialization.\r
872  * Defined in freeglut_structure.c, freeglut_window.c.\r
873  */\r
874 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,\r
875                             GLboolean positionUse, int x, int y,\r
876                             GLboolean sizeUse, int w, int h,\r
877                             GLboolean gameMode, GLboolean isMenu );\r
878 void        fgSetWindow ( SFG_Window *window );\r
879 void        fgOpenWindow( SFG_Window* window, const char* title,\r
880                           GLboolean positionUse, int x, int y,\r
881                           GLboolean sizeUse, int w, int h,\r
882                           GLboolean gameMode, GLboolean isSubWindow );\r
883 void        fgCloseWindow( SFG_Window* window );\r
884 void        fgAddToWindowDestroyList ( SFG_Window* window );\r
885 void        fgCloseWindows ();\r
886 void        fgDestroyWindow( SFG_Window* window );\r
887 \r
888 /* Menu creation and destruction. Defined in freeglut_structure.c */\r
889 SFG_Menu*   fgCreateMenu( FGCBMenu menuCallback );\r
890 void        fgDestroyMenu( SFG_Menu* menu );\r
891 \r
892 /* Joystick device management functions, defined in freeglut_joystick.c */\r
893 int         fgJoystickDetect( void );\r
894 void        fgInitialiseJoysticks( void );\r
895 void        fgJoystickClose( void );\r
896 void        fgJoystickPollWindow( SFG_Window* window );\r
897 \r
898 /* InputDevice Initialisation and Closure */\r
899 int         fgInputDeviceDetect( void );\r
900 void        fgInitialiseInputDevices( void );\r
901 void        fgInputDeviceClose( void );\r
902 \r
903 /* spaceball device functions, defined in freeglut_spaceball.c */\r
904 void        fgInitialiseSpaceball( void );\r
905 void        fgSpaceballClose( void );\r
906 void        fgSpaceballSetWindow( SFG_Window *window );\r
907 \r
908 int         fgHasSpaceball( void );\r
909 int         fgSpaceballNumButtons( void );\r
910 \r
911 #if TARGET_HOST_POSIX_X11\r
912 int         fgIsSpaceballXEvent( const XEvent *ev );\r
913 void        fgSpaceballHandleXEvent( const XEvent *ev );\r
914 #endif\r
915 \r
916 /* Setting the cursor for a given window */\r
917 void fgSetCursor ( SFG_Window *window, int cursorID );\r
918 \r
919 /*\r
920  * Helper function to enumerate through all registered windows\r
921  * and one to enumerate all of a window's subwindows...\r
922  *\r
923  * The GFunc callback for those functions will be defined as:\r
924  *\r
925  *      void enumCallback( gpointer window, gpointer enumerator );\r
926  *\r
927  * where window is the enumerated (sub)window pointer (SFG_Window *),\r
928  * and userData is the a custom user-supplied pointer. Functions\r
929  * are defined and exported from freeglut_structure.c file.\r
930  */\r
931 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );\r
932 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,\r
933                        SFG_Enumerator* enumerator );\r
934 \r
935 #if TARGET_HOST_MS_WINDOWS\r
936 /* \r
937  * Helper functions for getting client area from the window rect\r
938  * and the window rect from the client area given the style of the window\r
939  * (or a valid window pointer from which the style can be queried).\r
940  */\r
941 void fghComputeWindowRectFromClientArea_UseStyle   ( const DWORD windowStyle , RECT *clientRect, BOOL posIsOutside );\r
942 void fghComputeWindowRectFromClientArea_QueryWindow( const SFG_Window *window, RECT *clientRect, BOOL posIsOutside );\r
943 void fghComputeClientAreaFromWindowRect            ( const SFG_Window *window, RECT *windowRect, BOOL wantPosOutside );\r
944 RECT fghGetClientArea                              ( const SFG_Window *window,                   BOOL wantPosOutside );\r
945 void fghGetBorderWidth(const DWORD windowStyle, int* xBorderWidth, int* yBorderWidth);\r
946 #endif\r
947 \r
948 /*\r
949  * fgWindowByHandle returns a (SFG_Window *) value pointing to the\r
950  * first window in the queue matching the specified window handle.\r
951  * The function is defined in freeglut_structure.c file.\r
952  */\r
953 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );\r
954 \r
955 /*\r
956  * This function is similiar to the previous one, except it is\r
957  * looking for a specified (sub)window identifier. The function\r
958  * is defined in freeglut_structure.c file.\r
959  */\r
960 SFG_Window* fgWindowByID( int windowID );\r
961 \r
962 /*\r
963  * Looks up a menu given its ID. This is easier than fgWindowByXXX\r
964  * as all menus are placed in a single doubly linked list...\r
965  */\r
966 SFG_Menu* fgMenuByID( int menuID );\r
967 \r
968 /*\r
969  * The menu activation and deactivation the code. This is the meat\r
970  * of the menu user interface handling code...\r
971  */\r
972 void fgUpdateMenuHighlight ( SFG_Menu *menu );\r
973 GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,\r
974                               int mouse_x, int mouse_y );\r
975 void fgDeactivateMenu( SFG_Window *window );\r
976 \r
977 /*\r
978  * This function gets called just before the buffers swap, so that\r
979  * freeglut can display the pull-down menus via OpenGL. The function\r
980  * is defined in freeglut_menu.c file.\r
981  */\r
982 void fgDisplayMenu( void );\r
983 \r
984 /* Elapsed time as per glutGet(GLUT_ELAPSED_TIME). */\r
985 long fgElapsedTime( void );\r
986 \r
987 /* System time in milliseconds */\r
988 long unsigned fgSystemTime(void);\r
989 \r
990 /* List functions */\r
991 void fgListInit(SFG_List *list);\r
992 void fgListAppend(SFG_List *list, SFG_Node *node);\r
993 void fgListRemove(SFG_List *list, SFG_Node *node);\r
994 int fgListLength(SFG_List *list);\r
995 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);\r
996 \r
997 /* Error Message functions */\r
998 void fgError( const char *fmt, ... );\r
999 void fgWarning( const char *fmt, ... );\r
1000 \r
1001 /*\r
1002  * Check if "hint" is present in "property" for "window".  See freeglut_init.c\r
1003  */\r
1004 #if TARGET_HOST_POSIX_X11\r
1005 int fgHintPresent(Window window, Atom property, Atom hint);\r
1006 \r
1007 /* Handler for X extension Events */\r
1008 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H\r
1009   void fgHandleExtensionEvents( XEvent * ev );\r
1010   void fgRegisterDevices( Display* dpy, Window* win );\r
1011 #endif\r
1012 \r
1013 #endif\r
1014 \r
1015 SFG_Proc fghGetProcAddress( const char *procName );\r
1016 \r
1017 #if TARGET_HOST_MS_WINDOWS\r
1018 extern void (__cdecl *__glutExitFunc)( int return_value );\r
1019 #endif\r
1020 \r
1021 #endif /* FREEGLUT_INTERNAL_H */\r
1022 \r
1023 /*** END OF FILE ***/\r