Updating the ChangeLog and TODO files in preparation for the upcoming release
[freeglut] / src / freeglut_menu.c
index 25b98a3..bb04f48 100644 (file)
@@ -110,7 +110,7 @@ static SFG_MenuEntry *fghFindMenuEntry( SFG_Menu* menu, int index )
  */
 static void fghDeactivateSubMenu( SFG_MenuEntry *menuEntry )
 {
-    SFG_Window *current_window = fgStructure.Window;
+    SFG_Window *current_window = fgStructure.CurrentWindow;
     SFG_MenuEntry *subMenuIter;
     /* Hide the present menu's window */
     fgSetWindow( menuEntry->SubMenu->Window );
@@ -134,6 +134,37 @@ static void fghDeactivateSubMenu( SFG_MenuEntry *menuEntry )
 }
 
 /*
+ * Private function to get the virtual maximum screen extent
+ */
+static GLvoid fghGetVMaxExtent( SFG_Window* window, int* x, int* y )
+{
+    if( fgStructure.GameMode )
+    {
+#if TARGET_HOST_UNIX_X11
+        int wx, wy;
+        Window w;
+
+        XTranslateCoordinates(
+            fgDisplay.Display,
+            window->Window.Handle,
+            fgDisplay.RootWindow,
+            0, 0, &wx, &wy, &w);
+
+        *x = fgState.GameModeSize.X + wx;
+        *y = fgState.GameModeSize.Y + wy;
+#else
+        *x = glutGet ( GLUT_SCREEN_WIDTH );
+        *y = glutGet ( GLUT_SCREEN_HEIGHT );
+#endif
+    }
+    else
+    {
+        *x = fgDisplay.ScreenWidth;
+        *y = fgDisplay.ScreenHeight;
+    }
+}
+
+/*
  * Private function to check for the current menu/sub menu activity state
  */
 static GLboolean fghCheckMenuStatus( SFG_Window* window, SFG_Menu* menu )
@@ -215,23 +246,22 @@ static GLboolean fghCheckMenuStatus( SFG_Window* window, SFG_Menu* menu )
         {
             if ( ! menuEntry->SubMenu->IsActive )
             {
-                SFG_Window *current_window = fgStructure.Window;
+                int max_x, max_y;
+                SFG_Window *current_window = fgStructure.CurrentWindow;
 
                 /* Set up the initial menu position now... */
                 menuEntry->SubMenu->IsActive = GL_TRUE;
 
                 /* Set up the initial submenu position now: */
+                fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y);
                 menuEntry->SubMenu->X = menu->X + menu->Width;
                 menuEntry->SubMenu->Y = menu->Y +
                     menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT;
 
-                if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width >
-                    glutGet( GLUT_SCREEN_WIDTH ) )
-                    menuEntry->SubMenu->X = menu->X -
-                        menuEntry->SubMenu->Width;
+                if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width > max_x )
+                    menuEntry->SubMenu->X = menu->X - menuEntry->SubMenu->Width;
 
-                if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height >
-                    glutGet( GLUT_SCREEN_HEIGHT ) )
+                if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height > max_y )
                     menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
                                                FREEGLUT_MENU_HEIGHT -
                                                2 * FREEGLUT_MENU_BORDER );
@@ -440,10 +470,10 @@ static void fghExecuteMenuCallback( SFG_Menu* menu )
  */
 void fgDisplayMenu( void )
 {
-    SFG_Window* window = fgStructure.Window;
+    SFG_Window* window = fgStructure.CurrentWindow;
     SFG_Menu* menu = NULL;
 
-    FREEGLUT_INTERNAL_ERROR_EXIT ( fgStructure.Window, "Displaying menu in nonexistent window",
+    FREEGLUT_INTERNAL_ERROR_EXIT ( fgStructure.CurrentWindow, "Displaying menu in nonexistent window",
                                    "fgDisplayMenu" );
 
     /* Check if there is an active menu attached to this window... */
@@ -493,6 +523,8 @@ void fgDisplayMenu( void )
  */
 static void fghActivateMenu( SFG_Window* window, int button )
 {
+    int max_x, max_y;
+
     /* We'll be referencing this menu a lot, so remember its address: */
     SFG_Menu* menu = window->Menu[ button ];
 
@@ -507,13 +539,14 @@ static void fghActivateMenu( SFG_Window* window, int button )
     fgState.ActiveMenus++;
 
     /* Set up the initial menu position now: */
+    fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y);
     menu->X = window->State.MouseX + glutGet( GLUT_WINDOW_X );
     menu->Y = window->State.MouseY + glutGet( GLUT_WINDOW_Y );
 
-    if( menu->X + menu->Width > glutGet ( GLUT_SCREEN_WIDTH ) )
+    if( menu->X + menu->Width > max_x )
         menu->X -=menu->Width;
 
-    if( menu->Y + menu->Height > glutGet ( GLUT_SCREEN_HEIGHT ) )
+    if( menu->Y + menu->Height > max_y )
         menu->Y -=menu->Height;
 
     fgSetWindow( menu->Window );
@@ -564,11 +597,11 @@ GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
              * Save the current window and menu and set the current
              * window to the window whose menu this is
              */
-            SFG_Window *save_window = fgStructure.Window;
-            SFG_Menu *save_menu = fgStructure.Menu;
+            SFG_Window *save_window = fgStructure.CurrentWindow;
+            SFG_Menu *save_menu = fgStructure.CurrentMenu;
             SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
             fgSetWindow( parent_window );
-            fgStructure.Menu = window->ActiveMenu;
+            fgStructure.CurrentMenu = window->ActiveMenu;
 
             /* Execute the menu callback */
             fghExecuteMenuCallback( window->ActiveMenu );
@@ -576,7 +609,7 @@ GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
 
             /* Restore the current window and menu */
             fgSetWindow( save_window );
-            fgStructure.Menu = save_menu;
+            fgStructure.CurrentMenu = save_menu;
         }
         else if( pressed )
             /*
@@ -621,7 +654,7 @@ GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
  */
 void fgDeactivateMenu( SFG_Window *window )
 {
-    SFG_Window *current_window = fgStructure.Window;
+    SFG_Window *current_window = fgStructure.CurrentWindow;
 
     /* Check if there is an active menu attached to this window... */
     SFG_Menu* menu = window->ActiveMenu;
@@ -664,10 +697,10 @@ void fghCalculateMenuBoxSize( void )
     int width = 0, height = 0;
 
     /* Make sure there is a current menu set */
-    freeglut_return_if_fail( fgStructure.Menu );
+    freeglut_return_if_fail( fgStructure.CurrentMenu );
 
     /* The menu's box size depends on the menu entries: */
-    for( menuEntry = ( SFG_MenuEntry * )fgStructure.Menu->Entries.First;
+    for( menuEntry = ( SFG_MenuEntry * )fgStructure.CurrentMenu->Entries.First;
          menuEntry;
          menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
     {
@@ -695,8 +728,8 @@ void fghCalculateMenuBoxSize( void )
     }
 
     /* Store the menu's box size now: */
-    fgStructure.Menu->Height = height + 2 * FREEGLUT_MENU_BORDER;
-    fgStructure.Menu->Width  = width  + 4 * FREEGLUT_MENU_BORDER;
+    fgStructure.CurrentMenu->Height = height + 2 * FREEGLUT_MENU_BORDER;
+    fgStructure.CurrentMenu->Width  = width  + 4 * FREEGLUT_MENU_BORDER;
 }
 
 
@@ -735,8 +768,8 @@ int FGAPIENTRY glutGetMenu( void )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetMenu" );
 
-    if( fgStructure.Menu )
-        return fgStructure.Menu->ID;
+    if( fgStructure.CurrentMenu )
+        return fgStructure.CurrentMenu->ID;
 
     return 0;
 }
@@ -753,7 +786,7 @@ void FGAPIENTRY glutSetMenu( int menuID )
 
     freeglut_return_if_fail( menu );
 
-    fgStructure.Menu = menu;
+    fgStructure.CurrentMenu = menu;
 }
 
 /*
@@ -764,13 +797,13 @@ void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
     SFG_MenuEntry* menuEntry;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutAddMenuEntry" );
     menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
-    freeglut_return_if_fail( fgStructure.Menu );
+    freeglut_return_if_fail( fgStructure.CurrentMenu );
 
     menuEntry->Text = strdup( label );
     menuEntry->ID   = value;
 
     /* Have the new menu entry attached to the current menu */
-    fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
+    fgListAppend( &fgStructure.CurrentMenu->Entries, &menuEntry->Node );
 
     fghCalculateMenuBoxSize( );
 }
@@ -787,14 +820,14 @@ void FGAPIENTRY glutAddSubMenu( const char *label, int subMenuID )
     menuEntry = ( SFG_MenuEntry * )calloc( sizeof( SFG_MenuEntry ), 1 );
     subMenu = fgMenuByID( subMenuID );
 
-    freeglut_return_if_fail( fgStructure.Menu );
+    freeglut_return_if_fail( fgStructure.CurrentMenu );
     freeglut_return_if_fail( subMenu );
 
     menuEntry->Text    = strdup( label );
     menuEntry->SubMenu = subMenu;
     menuEntry->ID      = -1;
 
-    fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
+    fgListAppend( &fgStructure.CurrentMenu->Entries, &menuEntry->Node );
     fghCalculateMenuBoxSize( );
 }
 
@@ -806,10 +839,10 @@ void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
     SFG_MenuEntry* menuEntry = NULL;
 
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutChangeToMenuEntry" );
-    freeglut_return_if_fail( fgStructure.Menu );
+    freeglut_return_if_fail( fgStructure.CurrentMenu );
 
     /* Get n-th menu entry in the current menu, starting from one: */
-    menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
+    menuEntry = fghFindMenuEntry( fgStructure.CurrentMenu, item );
 
     freeglut_return_if_fail( menuEntry );
 
@@ -836,11 +869,11 @@ void FGAPIENTRY glutChangeToSubMenu( int item, const char* label,
     subMenu = fgMenuByID( subMenuID );
     menuEntry = NULL;
 
-    freeglut_return_if_fail( fgStructure.Menu );
+    freeglut_return_if_fail( fgStructure.CurrentMenu );
     freeglut_return_if_fail( subMenu );
 
     /* Get n-th menu entry in the current menu, starting from one: */
-    menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
+    menuEntry = fghFindMenuEntry( fgStructure.CurrentMenu, item );
 
     freeglut_return_if_fail( menuEntry );
 
@@ -862,14 +895,14 @@ void FGAPIENTRY glutRemoveMenuItem( int item )
     SFG_MenuEntry* menuEntry;
 
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutRemoveMenuItem" );
-    freeglut_return_if_fail( fgStructure.Menu );
+    freeglut_return_if_fail( fgStructure.CurrentMenu );
 
     /* Get n-th menu entry in the current menu, starting from one: */
-    menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
+    menuEntry = fghFindMenuEntry( fgStructure.CurrentMenu, item );
 
     freeglut_return_if_fail( menuEntry );
 
-    fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
+    fgListRemove( &fgStructure.CurrentMenu->Entries, &menuEntry->Node );
     if ( menuEntry->Text )
       free( menuEntry->Text );
 
@@ -884,13 +917,13 @@ void FGAPIENTRY glutAttachMenu( int button )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutAttachMenu" );
 
-    freeglut_return_if_fail( fgStructure.Window );
-    freeglut_return_if_fail( fgStructure.Menu );
+    freeglut_return_if_fail( fgStructure.CurrentWindow );
+    freeglut_return_if_fail( fgStructure.CurrentMenu );
 
     freeglut_return_if_fail( button >= 0 );
     freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
 
-    fgStructure.Window->Menu[ button ] = fgStructure.Menu;
+    fgStructure.CurrentWindow->Menu[ button ] = fgStructure.CurrentMenu;
 }
 
 /*
@@ -900,13 +933,13 @@ void FGAPIENTRY glutDetachMenu( int button )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDetachMenu" );
 
-    freeglut_return_if_fail( fgStructure.Window );
-    freeglut_return_if_fail( fgStructure.Menu );
+    freeglut_return_if_fail( fgStructure.CurrentWindow );
+    freeglut_return_if_fail( fgStructure.CurrentMenu );
 
     freeglut_return_if_fail( button >= 0 );
     freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
 
-    fgStructure.Window->Menu[ button ] = NULL;
+    fgStructure.CurrentWindow->Menu[ button ] = NULL;
 }
 
 /*
@@ -915,13 +948,13 @@ void FGAPIENTRY glutDetachMenu( int button )
 void* FGAPIENTRY glutGetMenuData( void )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetMenuData" );
-    return fgStructure.Menu->UserData;
+    return fgStructure.CurrentMenu->UserData;
 }
 
 void FGAPIENTRY glutSetMenuData(void* data)
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetMenuData" );
-    fgStructure.Menu->UserData=data;
+    fgStructure.CurrentMenu->UserData=data;
 }
 
 /*** END OF FILE ***/