snes mouse support
[drnoksnes] / platform / hgw.cpp
index e511d9a..11dafd9 100644 (file)
        } while (0);
 
 
-
 bool hgwLaunched;
 static HgwContext *hgw;
 
+static void createActionMappingsOnly();
 static void parseGConfKeyMappings();
 
 void HgwInit()
@@ -66,7 +66,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;
@@ -84,6 +84,13 @@ void HgwConfig()
                Settings.Transparency = transparency ? TRUE : FALSE;
        }
 
+#if 0
+       char displayFramerate = FALSE;
+       if (hgw_conf_request_bool(hgw, kGConfDisplayFramerate, &displayFramerate) == HGW_ERR_NONE) {
+               Settings.DisplayFrameRate = displayFramerate ? TRUE : FALSE;
+       }
+#endif
+
        int speedhacks = 0;
        if (hgw_conf_request_int(hgw, kGConfFrameskip, &speedhacks) == HGW_ERR_NONE) {
                if (speedhacks <= 0) {
@@ -101,7 +108,28 @@ void HgwConfig()
        int mappings = 0;
        if (hgw_conf_request_int(hgw, kGConfMapping, &mappings) == HGW_ERR_NONE) {
                switch (mappings) {
-                       case 1:
+                       case 0:
+                               // Do nothing, leave mappings as is.
+                               break;
+                       case 1: // Keys
+                               parseGConfKeyMappings();
+                               break;
+                       case 2: // Touchscreen
+                               Config.touchscreenInput = true;
+                               createActionMappingsOnly();
+                               break;
+                       case 3: // Touchscreen + keys
+                               Config.touchscreenInput = true;
+                               parseGConfKeyMappings();
+                               break;
+                       case 4: // Mouse
+                               Settings.Mouse = TRUE;
+                               Settings.ControllerOption = SNES_MOUSE_SWAPPED;
+                               createActionMappingsOnly();
+                               break;
+                       case 5: // Mouse + keys
+                               Settings.Mouse = TRUE;
+                               Settings.ControllerOption = SNES_MOUSE;
                                parseGConfKeyMappings();
                                break;
                }
@@ -193,26 +221,64 @@ static const ButtonEntry buttons[] = {
        BUTTON_LAST
 };
 
+static void createActionMappingsOnly()
+{
+       // Discard any other mapping
+       ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
+       ZeroMemory(Config.action, sizeof(Config.action));
+       
+       // Map quit to fullscreen and escape
+       Config.action[72] = kActionQuit;
+       Config.action[9] = kActionQuit;
+}
+
 static void parseGConfKeyMappings()
 {
        // Discard any other mapping
        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;
+               }
+       }
 }