@@ -518,7 +518,7 @@ struct gui_context * gui_create_context(int argc, char * argv[])
518518
519519 // Render the east face button icon
520520 context -> surfaces .bars .bottom .actions .select .surface = gui_render_select_legend_surface (context );
521-
521+
522522 // We failed to render the east face button icon
523523 if (context -> surfaces .bars .bottom .actions .select .surface == NULL )
524524 {
@@ -586,6 +586,7 @@ struct gui_context * gui_create_context(int argc, char * argv[])
586586 context -> surfaces .overlays .notch .position .w = context -> surfaces .overlays .notch .surface -> w ;
587587 context -> surfaces .overlays .notch .position .h = context -> surfaces .overlays .notch .surface -> h ;
588588
589+ #ifndef __MACOSX__
589590 // We couldn't enumerate the joysticks
590591 if (SDL_NumJoysticks () <= 0 )
591592 {
@@ -602,7 +603,7 @@ struct gui_context * gui_create_context(int argc, char * argv[])
602603 // No use going further if we have no way of controlling the UI
603604 goto free_menu_action_surface ;
604605 }
605-
606+ #endif
606607 // Allocate memory for the additional main menu data
607608 main_menu_node_data = calloc (1 , sizeof (struct gui_menu_node_data ));
608609
@@ -630,7 +631,9 @@ struct gui_context * gui_create_context(int argc, char * argv[])
630631 context -> menu .root -> activate (context -> menu .root );
631632
632633 // Enable joystick input
634+ #ifndef __MACOSX__
633635 SDL_JoystickEventState (SDL_ENABLE );
636+ #endif
634637
635638 // Restore the previous UI state
636639 gui_restore_ui_state (context , (const char * )context -> settings .ui_state );
@@ -684,8 +687,10 @@ struct gui_context * gui_create_context(int argc, char * argv[])
684687 free (main_menu_node_data );
685688
686689close_internal_joystick :
690+ #ifndef __MACOSX__
687691 // Close the internal joystick
688692 SDL_JoystickClose (context -> inputs .internal .joystick );
693+ #endif
689694
690695free_notch_overlay_surface :
691696 // Free the notch overlay
@@ -1026,6 +1031,150 @@ void gui_update(struct gui_context * context)
10261031 // Differentiate input event types
10271032 switch (event .type )
10281033 {
1034+ // Keyboard button events
1035+ case SDL_KEYUP :
1036+ case SDL_KEYDOWN :
1037+ {
1038+ // Determine the pressed state
1039+ int pressed = event .type == SDL_KEYDOWN ;
1040+
1041+ // Differentiate between buttons
1042+ switch (event .key .keysym .sym )
1043+ {
1044+ // The up button
1045+ case SDLK_UP :
1046+ {
1047+ // Update
1048+ context -> inputs .internal .current .dpad_y = pressed ? 1 : 0 ;
1049+
1050+ // Break
1051+ break ;
1052+ }
1053+
1054+ // The right button
1055+ case SDLK_RIGHT :
1056+ {
1057+ // Update
1058+ context -> inputs .internal .current .dpad_x = pressed ? 1 : 0 ;
1059+
1060+ // Break
1061+ break ;
1062+ }
1063+
1064+ // The down button
1065+ case SDLK_DOWN :
1066+ {
1067+ // Update
1068+ context -> inputs .internal .current .dpad_y = pressed ? -1 : 0 ;
1069+
1070+ // Break
1071+ break ;
1072+ }
1073+
1074+ // The left button
1075+ case SDLK_LEFT :
1076+ {
1077+ // Update
1078+ context -> inputs .internal .current .dpad_x = pressed ? -1 : 0 ;
1079+
1080+ // Break
1081+ break ;
1082+ }
1083+
1084+ // The south-facing face button (A on XBOX, B on Nintendo, Cross on PlayStation)
1085+ case SDLK_z :
1086+ {
1087+ // Update
1088+ context -> inputs .internal .current .south = pressed ;
1089+
1090+ // Break
1091+ break ;
1092+ }
1093+
1094+ // The east-facing face button (B on XBOX, A on Nintendo, Circle on PlayStation)
1095+ case SDLK_x :
1096+ {
1097+ // Update
1098+ context -> inputs .internal .current .east = pressed ;
1099+
1100+ // Break
1101+ break ;
1102+ }
1103+
1104+ // The north-facing face button (Y on XBOX, X on Nintendo, Triangle on PlayStation)
1105+ case SDLK_c :
1106+ {
1107+ // Update
1108+ context -> inputs .internal .current .north = pressed ;
1109+
1110+ // Break
1111+ break ;
1112+ }
1113+
1114+ // The west-facing face button (X on XBOX, Y on Nintendo, Square on PlayStation)
1115+ case SDLK_v :
1116+ {
1117+ // Update
1118+ context -> inputs .internal .current .west = pressed ;
1119+
1120+ // Break
1121+ break ;
1122+ }
1123+
1124+ // The enter button
1125+ case SDLK_RETURN :
1126+ {
1127+ // Update
1128+ context -> inputs .internal .current .start = pressed ;
1129+
1130+ // Break
1131+ break ;
1132+ }
1133+
1134+ // The backspace button
1135+ case SDLK_BACKSPACE :
1136+ {
1137+ // Update
1138+ context -> inputs .internal .current .select = pressed ;
1139+
1140+ // Break
1141+ break ;
1142+ }
1143+
1144+ // The space button
1145+ case SDLK_SPACE :
1146+ {
1147+ // Update
1148+ context -> inputs .internal .current .mode = pressed ;
1149+
1150+ // Break
1151+ break ;
1152+ }
1153+
1154+ // The escape button
1155+ case SDLK_ESCAPE :
1156+ {
1157+ // Update
1158+ context -> inputs .internal .current .power = pressed ;
1159+
1160+ // Break
1161+ break ;
1162+ }
1163+
1164+ // Other buttons
1165+ default :
1166+ {
1167+ // Break
1168+ break ;
1169+ }
1170+ }
1171+
1172+ // Log the event
1173+ // printf("button %d state %d\n", event.jbutton.button, pressed);
1174+
1175+ // Break
1176+ break ;
1177+ }
10291178 // Regular button events
10301179 case SDL_JOYBUTTONUP :
10311180 case SDL_JOYBUTTONDOWN :
@@ -1888,4 +2037,4 @@ void gui_write_configuration(struct gui_context * context)
18882037 // Cleanup
18892038 xmlFreeDoc (document );
18902039 }
1891- }
2040+ }
0 commit comments