+ /* That much about our sub menus, let's get to checking the current menu: */
+ x = window->State.MouseX;
+ y = window->State.MouseY;
+
+ for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
+ menuEntry;
+ menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
+ menuEntry->IsActive = GL_FALSE;
+
+ menu->IsActive = GL_FALSE;
+
+ /* Check if the mouse cursor is contained within the current menu box */
+ if( ( x >= FREEGLUT_MENU_BORDER ) &&
+ ( x < menu->Width - FREEGLUT_MENU_BORDER ) &&
+ ( y >= FREEGLUT_MENU_BORDER ) &&
+ ( y < menu->Height - FREEGLUT_MENU_BORDER ) &&
+ ( window == menu->Window ) )
+ {
+ int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENU_HEIGHT;
+
+ /* The mouse cursor is somewhere over our box, check it out. */
+ menuEntry = fghFindMenuEntry( menu, menuID + 1 );
+ FREEGLUT_INTERNAL_ERROR_EXIT( menuEntry, "Cannot find menu entry",
+ "fghCheckMenuStatus" );
+
+ menuEntry->IsActive = GL_TRUE;
+ menuEntry->Ordinal = menuID;
+
+ /*
+ * If this is not the same as the last active menu entry, deactivate
+ * the previous entry. Specifically, if the previous active entry
+ * was a submenu then deactivate it.
+ */
+ if( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
+ if( menu->ActiveEntry->SubMenu )
+ fghDeactivateSubMenu( menu->ActiveEntry );
+
+ menu->ActiveEntry = menuEntry;
+ menu->IsActive = GL_TRUE;
+
+ /*
+ * OKi, we have marked that entry as active, but it would be also
+ * nice to have its contents updated, in case it's a sub menu.
+ * Also, ignore the return value of the check function:
+ */
+ if( menuEntry->SubMenu )
+ {
+ if ( ! menuEntry->SubMenu->IsActive )
+ {
+ 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 > max_x )
+ menuEntry->SubMenu->X = menu->X - menuEntry->SubMenu->Width;
+
+ if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height > max_y )
+ menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
+ FREEGLUT_MENU_HEIGHT -
+ 2 * FREEGLUT_MENU_BORDER );
+
+ fgSetWindow( menuEntry->SubMenu->Window );
+ glutPositionWindow( menuEntry->SubMenu->X,
+ menuEntry->SubMenu->Y );
+ glutReshapeWindow( menuEntry->SubMenu->Width,
+ menuEntry->SubMenu->Height );
+ glutPopWindow( );
+ glutShowWindow( );
+ menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu;
+ fgSetWindow( current_window );
+ }
+
+ fghCheckMenuStatus( window, menuEntry->SubMenu );
+
+ /* Activate it because its parent entry is active */
+ menuEntry->SubMenu->IsActive = GL_TRUE;
+ }
+
+ /* Report back that we have caught the menu cursor */
+ return GL_TRUE;
+ }