@@ -14,6 +14,8 @@ SDL_Renderer* renderer = NULL;
1414SDL_MenuItem * checkable = NULL ;
1515SDL_MenuItem * new_window = NULL ;
1616
17+ SDL_MenuItem * menu_bar ;
18+
1719typedef enum SDL_EventType_MenuExt
1820{
1921 MENU_BAR_FILE ,
@@ -35,42 +37,68 @@ typedef enum SDL_EventType_MenuExt
3537
3638static SDL_EventType_MenuExt EVENT_START = (SDL_EventType_MenuExt )0 ;
3739
40+ void PrintMenuItems (SDL_MenuItem * menu_item , int indent , int * total_index )
41+ {
42+ if (!menu_item ) {
43+ return ;
44+ }
45+
46+ const char * label = SDL_GetMenuItemLabel (menu_item );
47+
48+ if (!label ) {
49+ label = "no label given" ;
50+ }
51+
52+ SDL_RenderDebugText (renderer , (float )(8 * indent * 2 ), (float )(* total_index * 8 ), label );
53+
54+ ++ (* total_index );
55+
56+ size_t item_count = SDL_GetMenuChildItems (menu_item );
57+
58+ for (size_t i = 0 ; i < item_count ; ++ i ) {
59+ PrintMenuItems (SDL_GetMenuChildItem (menu_item , i ), indent + 1 , total_index );
60+ }
61+ }
62+
3863
3964void CreateMenuBar ()
4065{
41- SDL_MenuItem * bar = SDL_CreateMenuBar (window );
66+ menu_bar = SDL_CreateMenuBar (window );
4267
4368 {
44- SDL_MenuItem * menu = SDL_CreateMenuItem (bar , "File" , SDL_MENU , MENU_BAR_LAST );
45- new_window = SDL_CreateMenuItem (menu , "New Window" , SDL_MENU_BUTTON , MENU_BAR_FILE_NEW_WINDOW );
46- checkable = SDL_CreateMenuItem (menu , "Enable New Window" , SDL_MENU_CHECKABLE , MENU_BAR_FILE_DISABLE_NEW_WINDOW );
69+ SDL_MenuItem * menu = SDL_CreateMenuItem (menu_bar , "File" , SDL_MENUITEM_SUBMENU , MENU_BAR_LAST );
70+ new_window = SDL_CreateMenuItem (menu , "New Window" , SDL_MENUITEM_BUTTON , MENU_BAR_FILE_NEW_WINDOW );
71+ checkable = SDL_CreateMenuItem (menu , "Enable New Window" , SDL_MENUITEM_CHECKABLE , MENU_BAR_FILE_DISABLE_NEW_WINDOW );
4772
48- SDL_CheckMenuItem (checkable );
73+ SDL_SetMenuItemChecked (checkable , true );
4974 }
5075
5176 {
52- SDL_MenuItem * menu = SDL_CreateMenuItem (bar , "Bookmarks" , SDL_MENU , MENU_BAR_LAST );
53- SDL_MenuItem * main_bookmarks = SDL_CreateMenuItem (menu , "Bookmarks Toolbar" , SDL_MENU , MENU_BAR_LAST );
54- SDL_MenuItem * discord = SDL_CreateMenuItem (main_bookmarks , "SDL Discord" , SDL_MENU_BUTTON , MENU_BAR_BOOKMARKS_TOOLBAR_DISCORD );
55- SDL_CreateMenuItem (main_bookmarks , "SDL GitHub" , SDL_MENU_BUTTON , MENU_BAR_BOOKMARKS_TOOLBAR_GITHUB );
56- SDL_CreateMenuItemAt (main_bookmarks , 0 , "SDL Wiki" , SDL_MENU_BUTTON , MENU_BAR_BOOKMARKS_TOOLBAR_WIKI );
57-
58- SDL_MenuItem * other_bookmarks = SDL_CreateMenuItem (main_bookmarks , "Other Bookmarks" , SDL_MENU , MENU_BAR_LAST );
59- SDL_CreateMenuItem (other_bookmarks , "Stack Overflow" , SDL_MENU_BUTTON , MENU_BAR_BOOKMARKS_OTHER_BOOKMARKS_STACKOVERFLOW );
77+ SDL_MenuItem * menu = SDL_CreateMenuItem (menu_bar , "Bookmarks" , SDL_MENUITEM_SUBMENU , MENU_BAR_LAST );
78+ SDL_MenuItem * main_bookmarks = SDL_CreateMenuItem (menu , "Bookmarks Toolbar" , SDL_MENUITEM_SUBMENU , MENU_BAR_LAST );
79+ SDL_MenuItem * discord = SDL_CreateMenuItem (main_bookmarks , "SDL Discord" , SDL_MENUITEM_BUTTON , MENU_BAR_BOOKMARKS_TOOLBAR_DISCORD );
80+ SDL_CreateMenuItem (main_bookmarks , "SDL GitHub" , SDL_MENUITEM_BUTTON , MENU_BAR_BOOKMARKS_TOOLBAR_GITHUB );
81+ SDL_CreateMenuItemAt (main_bookmarks , 0 , "SDL Wiki" , SDL_MENUITEM_BUTTON , MENU_BAR_BOOKMARKS_TOOLBAR_WIKI );
82+
83+ SDL_MenuItem * other_bookmarks = SDL_CreateMenuItem (main_bookmarks , "Other Bookmarks" , SDL_MENUITEM_SUBMENU , MENU_BAR_LAST );
84+ SDL_MenuItem * stack_overflow = SDL_CreateMenuItem (other_bookmarks , "Stack Overflow-test" , SDL_MENUITEM_BUTTON , MENU_BAR_BOOKMARKS_OTHER_BOOKMARKS_STACKOVERFLOW );
85+ SDL_SetMenuItemLabel (stack_overflow , "Stack Overflow" );
6086
6187 SDL_DestroyMenuItem (discord );
6288
6389
64- SDL_DisableMenuItem (other_bookmarks );
90+ SDL_SetMenuItemChecked (other_bookmarks , false );
6591 }
6692
6793 {
6894 // We can't create a top level checkable .
69- SDL_assert (!SDL_CreateMenuItem (bar , "Incognito" , SDL_MENU_CHECKABLE , MENU_BAR_INCOGNITO ));
95+ SDL_assert (!SDL_CreateMenuItem (menu_bar , "Incognito" , SDL_MENUITEM_CHECKABLE , MENU_BAR_INCOGNITO ));
7096
71- SDL_CreateMenuItem (bar , "Exit" , SDL_MENU_BUTTON , MENU_BAR_EXIT );
97+ SDL_CreateMenuItem (menu_bar , "Exit" , SDL_MENUITEM_BUTTON , MENU_BAR_EXIT );
7298 }
7399
100+ SDL_SetWindowMenuBar (window , menu_bar );
101+
74102 EVENT_START = (SDL_EventType_MenuExt )SDL_RegisterEvents (MENU_BAR_LAST );
75103}
76104
@@ -85,8 +113,13 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv) {
85113
86114SDL_AppResult SDL_AppIterate (void * appstate ) {
87115
88- SDL_SetRenderDrawColor (renderer , 128 , 128 , 128 , 255 );
116+ SDL_SetRenderDrawColor (renderer , 255 , 255 , 255 , 255 );
89117 SDL_RenderClear (renderer );
118+
119+
120+ SDL_SetRenderDrawColor (renderer , 0 , 0 , 0 , 255 );
121+ int total_index = 0 ;
122+ PrintMenuItems (menu_bar , 0 , & total_index );
90123 SDL_RenderPresent (renderer );
91124
92125 return SDL_APP_CONTINUE ;
@@ -127,23 +160,13 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
127160 case MENU_BAR_FILE_DISABLE_NEW_WINDOW :
128161 {
129162 bool is_checked = false;
130- SDL_MenuItemChecked (checkable , & is_checked );
131- if (is_checked ) {
132- SDL_UncheckMenuItem (checkable );
133- }
134- else {
135- SDL_CheckMenuItem (checkable );
136- }
163+ SDL_GetMenuItemChecked (checkable , & is_checked );
164+ SDL_SetMenuItemChecked (checkable , !is_checked );
137165
138166 bool is_enabled = false;
139- SDL_MenuItemEnabled (new_window , & is_enabled );
140-
141- if (is_enabled ) {
142- SDL_DisableMenuItem (new_window );
143- }
144- else {
145- SDL_EnableMenuItem (new_window );
146- }
167+ SDL_GetMenuItemEnabled (new_window , & is_enabled );
168+ SDL_SetMenuItemEnabled (new_window , !is_enabled );
169+
147170 break ;
148171 }
149172 case MENU_BAR_EXIT :
@@ -155,6 +178,7 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
155178 }
156179 }
157180
181+
158182 return SDL_APP_CONTINUE ;
159183}
160184
0 commit comments