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