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