touchscreen controls
[drnoksnes] / platform / hgw.cpp
index e511d9a..dee9427 100644 (file)
@@ -12,7 +12,6 @@
        } while (0);
 
 
-
 bool hgwLaunched;
 static HgwContext *hgw;
 
@@ -66,7 +65,7 @@ void HgwConfig()
 
        char no_audio = FALSE;
        if (hgw_conf_request_bool(hgw, kGConfDisableAudio, &no_audio) == HGW_ERR_NONE) {
-               Config.enableAudio = no_audio ? true : false;
+               Config.enableAudio = no_audio ? false : true;
        }
 
        char turbo = FALSE;
@@ -199,20 +198,47 @@ static void parseGConfKeyMappings()
        ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
        ZeroMemory(Config.action, sizeof(Config.action));
 
+       // If the user does not map fullscreen or quit
+       bool quit_mapped = false;
+
        printf("Hgw: Using gconf key mappings\n");
 
        int i, scancode;
        for (i = 0; buttons[i].gconf_key; i++) {
                if (hgw_conf_request_int(hgw, buttons[i].gconf_key, &scancode) == HGW_ERR_NONE) {
-                       if (scancode < 0) scancode = 0;
-                       else if (scancode > 255) scancode = 0;
+                       if (scancode <= 0 || scancode > 255) continue;
 
                        if (buttons[i].is_action) {
-                               Config.action[scancode] = buttons[i].mask;
+                               Config.action[scancode] |= buttons[i].mask;
+                               if (buttons[i].mask & (kActionQuit | kActionToggleFullscreen)) {
+                                       quit_mapped = true;
+                               }
                        } else {
-                               Config.joypad1Mapping[scancode] = buttons[i].mask;
+                               Config.joypad1Mapping[scancode] |= buttons[i].mask;
                        }
                }
        }
+
+       // Safeguards
+       if (!quit_mapped) {
+               // Newbie user won't know how to quit game.
+               if (!Config.joypad1Mapping[72] && !Config.action[72]) {
+                       // Fullscreen key is not mapped, map
+                       Config.action[72] = kActionQuit;
+                       quit_mapped = true;
+               }
+               if (!quit_mapped && !Config.joypad1Mapping[9] && !Config.action[9]) {
+                       // Escape key is not mapped, map
+                       // But only if we couldn't map quit to fullscreen. Some people
+                       // actually want Quit not to be mapped.
+                       Config.action[9] = kActionQuit;
+                       quit_mapped = true;
+               }
+               if (!quit_mapped) {
+                       // Force mapping of fullscreen to Quit if can't map anywhere else.
+                       Config.joypad1Mapping[72] = 0;
+                       Config.action[72] = kActionQuit;
+               }
+       }
 }