snes mouse support
[drnoksnes] / platform / hgw.cpp
index e85dde4..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,6 +221,17 @@ 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
@@ -207,16 +246,15 @@ static void parseGConfKeyMappings()
        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;
                        }
                }
        }