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