Removed the state variable BuildingAMenu.
[freeglut] / src / 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 /* XXX Update these for each release! */
32 #define  VERSION_MAJOR 2
33 #define  VERSION_MINOR 0
34 #define  VERSION_PATCH 0 
35
36 /*
37  * Freeglut is meant to be available under all Unix/X11 and Win32 platforms.
38  */
39 #if !defined(_WIN32)
40 #   define  TARGET_HOST_UNIX_X11    1
41 #   define  TARGET_HOST_WIN32       0
42 #else
43 #   define  TARGET_HOST_UNIX_X11    0
44 #   define  TARGET_HOST_WIN32       1
45 #endif
46
47 #define  FREEGLUT_MAX_MENUS         3
48 #define  FREEGLUT_DEBUG             1
49
50 #if FREEGLUT_DEBUG
51     #undef   G_DISABLE_ASSERT
52     #undef   G_DISABLE_CHECKS
53 #else
54     #define  G_DISABLE_ASSERT
55     #define  G_DISABLE_CHECKS
56 #endif
57
58 /*
59  * Somehow all Win32 include headers depend on this one:
60  */
61 #if TARGET_HOST_WIN32
62 #include <windows.h>
63 #include <windowsx.h>
64
65 #define strdup   _strdup
66 #endif
67
68 /*
69  * Those files should be available on every platform.
70  */
71 #include <GL/gl.h>
72 #include <GL/glu.h>
73 #include <stdio.h>
74 #include <string.h>
75 #include <math.h>
76 #include <stdlib.h>
77 #include <assert.h>
78 #include <stdarg.h>
79 #if TARGET_HOST_UNIX_X11
80 #include <sys/time.h>
81 #endif
82
83 /*
84  * The system-dependant include files should go here:
85  */
86 #if TARGET_HOST_UNIX_X11
87     #include <GL/glx.h>
88     #include <X11/Xlib.h>
89     #include <X11/Xatom.h>
90     #include <X11/keysym.h>
91
92     #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
93     #include <X11/extensions/xf86vmode.h>
94     #endif
95 #endif
96
97 /*
98  * Microsoft VisualC++ 5.0's <math.h> does not define the PI
99  */
100 #ifndef M_PI
101 #    define  M_PI  3.14159265358979323846
102 #endif
103
104 #ifndef TRUE
105 #    define  TRUE  1
106 #endif
107
108 #ifndef FALSE
109 #    define  FALSE  0
110 #endif
111
112 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
113
114 /*
115  * Freeglut callbacks type definitions
116  */
117 typedef void (* FGCBDisplay       )( void );
118 typedef void (* FGCBReshape       )( int, int );
119 typedef void (* FGCBVisibility    )( int );
120 typedef void (* FGCBKeyboard      )( unsigned char, int, int );
121 typedef void (* FGCBSpecial       )( int, int, int );
122 typedef void (* FGCBMouse         )( int, int, int, int );
123 typedef void (* FGCBMouseWheel    )( int, int, int, int );
124 typedef void (* FGCBMotion        )( int, int );
125 typedef void (* FGCBPassive       )( int, int );
126 typedef void (* FGCBEntry         )( int );
127 typedef void (* FGCBWindowStatus  )( int );
128 typedef void (* FGCBSelect        )( int, int, int );
129 typedef void (* FGCBJoystick      )( unsigned int, int, int, int );
130 typedef void (* FGCBKeyboardUp    )( unsigned char, int, int );
131 typedef void (* FGCBSpecialUp     )( int, int, int );
132 typedef void (* FGCBOverlayDisplay)( void );
133 typedef void (* FGCBSpaceMotion   )( int, int, int );
134 typedef void (* FGCBSpaceRotation )( int, int, int );
135 typedef void (* FGCBSpaceButton   )( int, int );
136 typedef void (* FGCBDials         )( int, int );
137 typedef void (* FGCBButtonBox     )( int, int );
138 typedef void (* FGCBTabletMotion  )( int, int );
139 typedef void (* FGCBTabletButton  )( int, int, int, int );
140 typedef void (* FGCBDestroy       )( void );
141
142 /*
143  * The global callbacks type definitions
144  */
145 typedef void (* FGCBIdle          )( void );
146 typedef void (* FGCBTimer         )( int );
147 typedef void (* FGCBMenuState     )( int );
148 typedef void (* FGCBMenuStatus    )( int, int, int );
149
150 /*
151  * The callback used when creating/using menus
152  */
153 typedef void (* FGCBMenu          )( int );
154
155
156 /*
157  * A list structure
158  */
159 typedef struct tagSFG_List SFG_List;
160 struct tagSFG_List
161 {
162     void *First;
163     void *Last;
164 };
165
166 /*
167  * A list node structure
168  */
169 typedef struct tagSFG_Node SFG_Node;
170 struct tagSFG_Node
171 {
172     void *Next;
173     void *Prev;
174 };
175
176 /*
177  * A helper structure holding two ints and a boolean
178  */
179 typedef struct tagSFG_XYUse SFG_XYUse;
180 struct tagSFG_XYUse
181 {
182     GLint           X, Y;               /* The two integers...               */
183     GLboolean       Use;                /* ...and a single boolean.          */
184 };
185
186 /*
187  * A helper structure holding a timeval and a boolean
188  */
189 typedef struct tagSFG_Time SFG_Time;
190 struct tagSFG_Time
191 {
192 #ifdef WIN32
193     DWORD Value;
194 #else
195     struct timeval  Value;
196 #endif
197     GLboolean       Set;
198 };
199
200 /*
201  * An enumeration containing the state of the GLUT execution:
202  * initializing, running, or stopping
203  */
204 typedef enum
205 {
206     GLUT_EXEC_STATE_INIT,
207     GLUT_EXEC_STATE_RUNNING,
208     GLUT_EXEC_STATE_STOP
209 } fgExecutionState;
210
211 /*
212  * This structure holds different freeglut settings
213  */
214 typedef struct tagSFG_State SFG_State;
215 struct tagSFG_State
216 {
217     SFG_XYUse        Position;             /* The default windows' position  */
218     SFG_XYUse        Size;                 /* The default windows' size      */
219     unsigned int     DisplayMode;          /* Display mode for new windows   */
220
221     GLboolean        Initalized;           /* Freeglut has been initalized   */
222
223     GLboolean        ForceDirectContext;   /* Force direct rendering?        */
224     GLboolean        TryDirectContext;     /* What about giving a try to?    */
225
226     GLboolean        ForceIconic;          /* New top windows are iconified  */
227     GLboolean        UseCurrentContext;    /* New windows share with current */
228
229     GLboolean        GLDebugSwitch;        /* OpenGL state debugging switch  */
230     GLboolean        XSyncSwitch;          /* X11 sync protocol switch       */
231
232     GLboolean        IgnoreKeyRepeat;      /* Whether to ignore key repeat.  */
233
234     GLuint           FPSInterval;          /* Interval between FPS printfs   */
235     GLuint           SwapCount;            /* Count of glutSwapBuffer calls  */
236     GLuint           SwapTime;             /* Time of last SwapBuffers       */
237
238     SFG_Time         Time;                 /* Time that glutInit was called  */
239     SFG_List         Timers;               /* The freeglut timer hooks       */
240
241     FGCBIdle         IdleCallback;         /* The global idle callback       */
242
243     int              ActiveMenus;          /* Num. of currently active menus */
244     FGCBMenuState    MenuStateCallback;    /* Menu callbacks are global      */
245     FGCBMenuStatus   MenuStatusCallback;
246
247     SFG_XYUse        GameModeSize;         /* Game mode screen's dimensions  */
248     int              GameModeDepth;        /* The pixel depth for game mode  */
249     int              GameModeRefresh;      /* The refresh rate for game mode */
250
251     int              ActionOnWindowClose; /* Action when user closes window  */
252
253     fgExecutionState ExecState;           /* Used for GLUT termination       */
254     char            *ProgramName;         /* Name of the invoking program    */
255 };
256
257 /*
258  * The structure used by display initialization in freeglut_init.c
259  */
260 typedef struct tagSFG_Display SFG_Display;
261 struct tagSFG_Display
262 {
263 #if TARGET_HOST_UNIX_X11
264     Display*        Display;            /* The display we are being run in.  */
265     int             Screen;             /* The screen we are about to use.   */
266     Window          RootWindow;         /* The screen's root window.         */
267     int             Connection;         /* The display's connection number   */
268     Atom            DeleteWindow;       /* The window deletion atom          */
269
270 #ifdef X_XF86VidModeGetModeLine
271     /*
272      * XF86VidMode may be compilable even if it fails at runtime.  Therefore,
273      * the validity of the VidMode has to be tracked
274      */
275     int             DisplayModeValid;   /* Flag that indicates runtime status*/
276     XF86VidModeModeLine DisplayMode;    /* Current screen's display settings */
277     int             DisplayModeClock;   /* The display mode's refresh rate   */
278     int             DisplayViewPortX;   /* saved X location of the viewport  */
279     int             DisplayViewPortY;   /* saved Y location of the viewport  */
280     int             DisplayPointerX;    /* saved X location of the pointer   */
281     int             DisplayPointerY;    /* saved Y location of the pointer   */
282
283 #endif
284
285 #elif TARGET_HOST_WIN32
286     HINSTANCE        Instance;          /* The application's instance        */
287     DEVMODE         DisplayMode;        /* Desktop's display settings        */
288
289 #endif
290
291     int             ScreenWidth;        /* The screen's width in pixels      */
292     int             ScreenHeight;       /* The screen's height in pixels     */
293     int             ScreenWidthMM;      /* The screen's width in milimeters  */
294     int             ScreenHeightMM;     /* The screen's height in milimeters */
295 };
296
297
298 /*
299  * The user can create any number of timer hooks
300  */
301 typedef struct tagSFG_Timer SFG_Timer;
302 struct tagSFG_Timer
303 {
304     SFG_Node        Node;
305     int             ID;                 /* The timer ID integer              */
306     FGCBTimer       Callback;           /* The timer callback                */
307     long            TriggerTime;        /* The timer trigger time            */
308 };
309
310 /*
311  * A window and its OpenGL context. The contents of this structure
312  * are highly dependant on the target operating system we aim at...
313  */
314 typedef struct tagSFG_Context SFG_Context;
315 struct tagSFG_Context
316 {
317 #if TARGET_HOST_UNIX_X11
318     Window          Handle;          /* The window's handle                 */
319     GLXContext      Context;         /* The OpenGL context                  */
320     XVisualInfo*    VisualInfo;      /* The window's visual information     */
321
322 #elif TARGET_HOST_WIN32
323     HWND            Handle;          /* The window's handle                 */
324     HDC             Device;          /* The window's device context         */
325     HGLRC           Context;         /* The window's WGL context            */
326
327 #endif
328
329     int             DoubleBuffered;  /* Treat the window as double-buffered */
330 };
331
332 /*
333  * Window's state description. This structure should be kept portable.
334  */
335 typedef struct tagSFG_WindowState SFG_WindowState;
336 struct tagSFG_WindowState
337 {
338     int             Width;              /* Window's width in pixels          */
339     int             Height;             /* The same about the height         */
340
341     GLboolean       Redisplay;          /* Do we have to redisplay?          */
342     GLboolean       Visible;            /* Is the window visible now         */
343
344     int             Cursor;             /* The currently selected cursor     */
345     int             Modifiers;          /* The current ALT/SHIFT/CTRL state  */
346
347     long            JoystickPollRate;   /* The joystick polling rate         */
348     long            JoystickLastPoll;   /* When the last poll has happened   */
349
350     int             MouseX, MouseY;     /* The most recent mouse position    */
351
352     GLboolean       IsGameMode;         /* Is this the game mode window?     */
353
354 #if TARGET_HOST_WIN32
355     GLboolean       NeedToResize;       /* Do we need to explicitly resize?  */
356 #endif
357 };
358
359
360 /*
361  * FETCH_WCB() is used as:
362  *
363  *     FETCH_WCB( window, Visibility );
364  *
365  * ...where {window} is the freeglut window to fetch the callback from,
366  *          {Visibility} is the window-specific callback to fetch.
367  *
368  * The result is correctly type-cast to the callback function pointer
369  * type.
370  */
371 #define FETCH_WCB(window,cbname) \
372     ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
373
374 /*
375  * INVOKE_WCB() is used as:
376  *
377  *     INVOKE_WCB( window, Visibility, ( status ) );
378  *
379  * ...where {window} is the freeglut window,
380  *          {Visibility} is the window-specific callback,
381  *          {(status)} is the parameter list.
382  *
383  * The callback is invoked as:
384  *
385  *    callback( status );
386  *
387  * ...so the parentheses are REQUIRED in the {arg_list}.
388  *
389  * NOTE that it does a sanity-check and also sets the
390  * current window.
391  *
392  */
393 #define INVOKE_WCB(window,cbname,arg_list)    \
394 do                                            \
395 {                                             \
396     if( FETCH_WCB( window, cbname ) )         \
397     {                                         \
398         fgSetWindow( &window );               \
399         FETCH_WCB( window, cbname ) arg_list; \
400     }                                         \
401 } while( 0 )
402
403 /*
404  * The window callbacks the user can supply us with. Should be kept portable.
405  *
406  * This enumeration provides the freeglut CallBack numbers.
407  * The symbolic constants are indices into a window's array of
408  * function callbacks.  The names are formed by splicing a common
409  * prefix onto the callback's base name.  (This was originally
410  * done so that an early stage of development could live side-by-
411  * side with the old callback code.  The old callback code used
412  * the bare callback's name as a structure member, so I used a
413  * prefix for the array index name.)
414  *
415  * XXX For consistancy, perhaps the prefix should match the
416  * XXX FETCH* and INVOKE* macro suffices.  I.e., WCB_, rather than
417  * XXX CB_.
418  */
419 enum
420 {
421     CB_Display,
422     CB_Reshape,
423     CB_Keyboard,
424     CB_KeyboardUp,
425     CB_Special,
426     CB_SpecialUp,
427     CB_Mouse,
428     CB_MouseWheel,
429     CB_Motion,
430     CB_Passive,
431     CB_Entry,
432     CB_Visibility,
433     CB_WindowStatus,
434     CB_Joystick,
435     CB_Destroy,
436
437     /* Presently ignored */
438     CB_Select,
439     CB_OverlayDisplay,
440     CB_SpaceMotion,
441     CB_SpaceRotation,
442     CB_SpaceButton,
443     CB_Dials,
444     CB_ButtonBox,
445     CB_TabletMotion,
446     CB_TabletButton,
447     
448     /* Always make this the LAST one */
449     TOTAL_CALLBACKS
450 };
451
452
453 /*
454  * This structure holds the OpenGL rendering context for all the menu windows
455  */
456 typedef struct tagSFG_MenuContext SFG_MenuContext;
457 struct tagSFG_MenuContext
458 {
459 #if TARGET_HOST_UNIX_X11
460     GLXContext          Context;          /* The menu OpenGL context         */
461     XVisualInfo*        VisualInfo;       /* The window's visual information */
462 #elif TARGET_HOST_WIN32
463     HGLRC               Context;          /* The menu window's WGL context   */
464 #endif
465
466 };
467
468 /*
469  * This structure describes a menu
470  */
471 typedef struct tagSFG_Window SFG_Window;
472 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
473 typedef struct tagSFG_Menu SFG_Menu;
474 struct tagSFG_Menu
475 {
476     SFG_Node            Node;
477     void               *UserData;     /* User data passed back at callback   */
478     int                 ID;           /* The global menu ID                  */
479     SFG_List            Entries;      /* The menu entries list               */
480     FGCBMenu            Callback;     /* The menu callback                   */
481     FGCBDestroy         Destroy;      /* Destruction callback                */
482     GLboolean           IsActive;     /* Is the menu selected?               */
483     int                 Width;        /* Menu box width in pixels            */
484     int                 Height;       /* Menu box height in pixels           */
485     int                 X, Y;         /* Menu box raster position            */
486
487     SFG_MenuEntry      *ActiveEntry;  /* Currently active entry in the menu  */
488     SFG_Window         *Window;       /* Window for menu                     */
489     SFG_Window         *ParentWindow; /* Window in which the menu is defined */
490 };
491
492 /*
493  * This is a menu entry
494  */
495 struct tagSFG_MenuEntry
496 {
497     SFG_Node            Node;
498     int                 ID;                     /* The menu entry ID (local) */
499     int                 Ordinal;                /* The menu's ordinal number */
500     char*               Text;                   /* The text to be displayed  */
501     SFG_Menu*           SubMenu;                /* Optional sub-menu tree    */
502     GLboolean           IsActive;               /* Is the entry highlighted? */
503     int                 Width;                  /* Label's width in pixels   */
504 };
505
506 /*
507  * A window, making part of freeglut windows hierarchy.
508  * Should be kept portable.
509  */
510 struct tagSFG_Window
511 {
512     SFG_Node            Node;
513     int                 ID;                     /* Window's ID number        */
514
515     SFG_Context         Window;                 /* Window and OpenGL context */
516     SFG_WindowState     State;                  /* The window state          */
517     void         *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
518     void               *UserData ;              /* For use by user           */
519
520     SFG_Menu*       Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window  */
521     SFG_Menu*       ActiveMenu;                 /* The window's active menu  */
522
523     SFG_Window*         Parent;                 /* The parent to this window */
524     SFG_List            Children;               /* The subwindows d.l. list  */
525
526     GLboolean           IsMenu;                 /* Set to 1 if we are a menu */
527 };
528
529
530 /*
531  * A linked list structure of windows
532  */
533 typedef struct tagSFG_WindowList SFG_WindowList;
534 struct tagSFG_WindowList
535 {
536     SFG_Window *window;
537     GLboolean needToClose;
538     SFG_WindowList *next;
539 };
540
541 /*
542  * This holds information about all the windows, menus etc.
543  */
544 typedef struct tagSFG_Structure SFG_Structure;
545 struct tagSFG_Structure
546 {
547     SFG_List        Windows;      /* The global windows list            */
548     SFG_List        Menus;        /* The global menus list              */
549
550     SFG_Window*     Window;       /* The currently active win.          */
551     SFG_Menu*       Menu;         /* Same, but menu...                  */
552
553     SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
554
555     SFG_Window*      GameMode;    /* The game mode window               */
556
557     int              WindowID;    /* The new current window ID          */
558     int              MenuID;      /* The new current menu ID            */
559 };
560
561 /*
562  * This structure is used for the enumeration purposes.
563  * You can easily extend its functionalities by declaring
564  * a structure containing enumerator's contents and custom
565  * data, then casting its pointer to (SFG_Enumerator *).
566  */
567 typedef struct tagSFG_Enumerator SFG_Enumerator;
568 struct tagSFG_Enumerator
569 {
570     GLboolean   found;                          /* Used to terminate search  */
571     void*       data;                           /* Custom data pointer       */
572 };
573 typedef void (* FGCBenumerator  )( SFG_Window *, SFG_Enumerator * );
574
575 /*
576  * The bitmap font structure
577  */
578 typedef struct tagSFG_Font SFG_Font;
579 struct tagSFG_Font
580 {
581     char*           Name;         /* The source font name             */
582     int             Quantity;     /* Number of chars in font          */
583     int             Height;       /* Height of the characters         */
584     const GLubyte** Characters;   /* The characters mapping           */
585
586     float           xorig, yorig; /* Relative origin of the character */
587 };
588
589 /*
590  * The stroke font structures
591  */
592
593 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
594 struct tagSFG_StrokeVertex
595 {
596     GLfloat         X, Y;
597 };
598
599 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
600 struct tagSFG_StrokeStrip
601 {
602     int             Number;
603     const SFG_StrokeVertex* Vertices;
604 };
605
606 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
607 struct tagSFG_StrokeChar
608 {
609     GLfloat         Right;
610     int             Number;
611     const SFG_StrokeStrip* Strips;
612 };
613
614 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
615 struct tagSFG_StrokeFont
616 {
617     char*           Name;                       /* The source font name      */
618     int             Quantity;                   /* Number of chars in font   */
619     GLfloat         Height;                     /* Height of the characters  */
620     const SFG_StrokeChar** Characters;          /* The characters mapping    */
621 };
622
623 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
624
625 /*
626  * Freeglut display related stuff (initialized once per session)
627  */
628 extern SFG_Display fgDisplay;
629
630 /*
631  * Freeglut internal structure
632  */
633 extern SFG_Structure fgStructure;
634
635 /*
636  * The current freeglut settings
637  */
638 extern SFG_State fgState;
639
640
641 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
642
643 /*
644  * A call to this function makes us sure that the Display and Structure
645  * subsystems have been properly initialized and are ready to be used
646  */
647 #define  freeglut_assert_ready  assert( fgState.Initalized );
648
649 /*
650  * Following definitions are somewhat similiar to GLib's,
651  * but do not generate any log messages:
652  */
653 #define  freeglut_return_if_fail( expr ) \
654     if( !(expr) )                        \
655         return;
656 #define  freeglut_return_val_if_fail( expr, val ) \
657     if( !(expr) )                                 \
658         return val;
659
660 /*
661  * A call to those macros assures us that there is a current
662  * window and menu set, respectively:
663  */
664 #define  freeglut_assert_window assert( fgStructure.Window != NULL );
665 #define  freeglut_assert_menu   assert( fgStructure.Menu != NULL );
666
667 /*
668  * The initialize and deinitialize functions get called on glutInit()
669  * and glutMainLoop() end respectively. They should create/clean up
670  * everything inside of the freeglut
671  */
672 void fgInitialize( const char* displayName );
673 void fgDeinitialize( void );
674
675 /*
676  * Those two functions are used to create/destroy the freeglut internal
677  * structures. This actually happens when calling glutInit() and when
678  * quitting the glutMainLoop() (which actually happens, when all windows
679  * have been closed).
680  */
681 void fgCreateStructure( void );
682 void fgDestroyStructure( void );
683
684 /*
685  * A helper function to check if a display mode is possible to use
686  */
687 #if TARGET_HOST_UNIX_X11
688 XVisualInfo* fgChooseVisual( void );
689 #endif
690
691 /*
692  * The window procedure for Win32 events handling
693  */
694 #if TARGET_HOST_WIN32
695 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
696                                WPARAM wParam, LPARAM lParam );
697 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
698                               unsigned char layer_type );
699 #endif
700
701 /*
702  * Window creation, opening, closing and destruction.
703  * Also CallBack clearing/initialization.
704  * Defined in freeglut_structure.c, freeglut_window.c.
705  */
706 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
707                             int x, int y, int w, int h,
708                             GLboolean gameMode, GLboolean isMenu );
709 void        fgSetWindow ( SFG_Window *window );
710 void        fgOpenWindow( SFG_Window* window, const char* title,
711                           int x, int y, int w, int h, GLboolean gameMode,
712                           GLboolean isSubWindow );
713 void        fgCloseWindow( SFG_Window* window );
714 void        fgAddToWindowDestroyList ( SFG_Window* window,
715                                        GLboolean needToClose );
716 void        fgCloseWindows( );
717 void        fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
718 void        fgClearCallBacks( SFG_Window *window );
719
720 /*
721  * Menu creation and destruction. Defined in freeglut_structure.c
722  */
723 SFG_Menu*   fgCreateMenu( FGCBMenu menuCallback );
724 void        fgDestroyMenu( SFG_Menu* menu );
725
726 /*
727  * Joystick device management functions, defined in freeglut_joystick.c
728  */
729 void        fgJoystickInit( int ident );
730 void        fgJoystickClose( void );
731 void        fgJoystickPollWindow( SFG_Window* window );
732
733 /*
734  * Helper function to enumerate through all registered windows
735  * and one to enumerate all of a window's subwindows...
736  *
737  * The GFunc callback for those functions will be defined as:
738  *
739  *      void enumCallback( gpointer window, gpointer enumerator );
740  *
741  * where window is the enumerated (sub)window pointer (SFG_Window *),
742  * and userData is the a custom user-supplied pointer. Functions
743  * are defined and exported from freeglut_structure.c file.
744  */
745 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
746 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
747                        SFG_Enumerator* enumerator );
748
749 /*
750  * fgWindowByHandle returns a (SFG_Window *) value pointing to the
751  * first window in the queue matching the specified window handle.
752  * The function is defined in freeglut_structure.c file.
753  */
754 #if TARGET_HOST_UNIX_X11
755     SFG_Window* fgWindowByHandle( Window hWindow );
756 #elif TARGET_HOST_WIN32
757     SFG_Window* fgWindowByHandle( HWND hWindow );
758 #endif
759
760 /*
761  * This function is similiar to the previous one, except it is
762  * looking for a specified (sub)window identifier. The function
763  * is defined in freeglut_structure.c file.
764  */
765 SFG_Window* fgWindowByID( int windowID );
766
767 /*
768  * Looks up a menu given its ID. This is easier that fgWindowByXXX
769  * as all menus are placed in a single doubly linked list...
770  */
771 SFG_Menu* fgMenuByID( int menuID );
772
773 /*
774  * The menu activation and deactivation the code. This is the meat
775  * of the menu user interface handling code...
776  */
777 void fgActivateMenu( SFG_Window* window, int button );
778 void fgExecuteMenuCallback( SFG_Menu* menu );
779 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
780 void fgDeactivateMenu( SFG_Window *window );
781 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
782
783 /*
784  * This function gets called just before the buffers swap, so that
785  * freeglut can display the pull-down menus via OpenGL. The function
786  * is defined in freeglut_menu.c file.
787  */
788 void fgDisplayMenu( void );
789
790 /*
791  * Display the mouse cursor using OpenGL calls. The function
792  * is defined in freeglut_cursor.c file.
793  */
794 void fgDisplayCursor( void );
795
796 /*
797  * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
798  */
799 long fgElapsedTime( void );
800
801 /*
802  * List functions
803  */
804 void fgListInit(SFG_List *list);
805 void fgListAppend(SFG_List *list, SFG_Node *node);
806 void fgListRemove(SFG_List *list, SFG_Node *node);
807 int fgListLength(SFG_List *list);
808
809 /*
810  * Error Messages functions
811  */
812 void fgError( const char *fmt, ... );
813 void fgWarning( const char *fmt, ... );
814
815 #endif /* FREEGLUT_INTERNAL_H */
816
817 /*** END OF FILE ***/