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