|
|
1.1 ! root 1: /* ! 2: Hatari - shortcut.c ! 3: ! 4: This file is distributed under the GNU Public License, version 2 or at ! 5: your option any later version. Read the file gpl.txt for details. ! 6: ! 7: Shortcut keys ! 8: */ ! 9: const char ShortCut_fileid[] = "Hatari shortcut.c : " __DATE__ " " __TIME__; ! 10: ! 11: #include <SDL.h> ! 12: ! 13: #include "main.h" ! 14: #include "dialog.h" ! 15: #include "file.h" ! 16: #include "m68000.h" ! 17: #include "memorySnapShot.h" ! 18: #include "reset.h" ! 19: #include "screen.h" ! 20: #include "screenSnapShot.h" ! 21: #include "configuration.h" ! 22: #include "shortcut.h" ! 23: #include "debugui.h" ! 24: #include "sdlgui.h" ! 25: #include "video.h" ! 26: #include "avi_record.h" ! 27: ! 28: static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE; /* current shortcut key */ ! 29: ! 30: ! 31: /*-----------------------------------------------------------------------*/ ! 32: /** ! 33: * Shortcut to toggle full-screen ! 34: */ ! 35: static void ShortCut_FullScreen(void) ! 36: { ! 37: if (!bInFullScreen) ! 38: { ! 39: Screen_EnterFullScreen(); ! 40: } ! 41: else ! 42: { ! 43: Screen_ReturnFromFullScreen(); ! 44: } ! 45: } ! 46: ! 47: ! 48: /*-----------------------------------------------------------------------*/ ! 49: /** ! 50: * Shortcut to toggle mouse grabbing mode ! 51: */ ! 52: static void ShortCut_MouseGrab(void) ! 53: { ! 54: bGrabMouse = !bGrabMouse; /* Toggle flag */ ! 55: ! 56: /* If we are in windowed mode, toggle the mouse cursor mode now: */ ! 57: if (!bInFullScreen) ! 58: { ! 59: if (bGrabMouse) ! 60: { ! 61: SDL_WM_GrabInput(SDL_GRAB_ON); ! 62: } ! 63: else ! 64: { ! 65: SDL_WM_GrabInput(SDL_GRAB_OFF); ! 66: } ! 67: } ! 68: } ! 69: ! 70: ! 71: /*-----------------------------------------------------------------------*/ ! 72: /** ! 73: * Shortcut to toggle YM/WAV sound recording ! 74: */ ! 75: static void ShortCut_RecordSound(void) ! 76: { ! 77: } ! 78: ! 79: ! 80: /*-----------------------------------------------------------------------*/ ! 81: /** ! 82: * Shortcut to toggle screen animation recording ! 83: */ ! 84: static void ShortCut_RecordAnimation(void) ! 85: { ! 86: } ! 87: ! 88: ! 89: /*-----------------------------------------------------------------------*/ ! 90: /** ! 91: * Shortcut to sound on/off ! 92: */ ! 93: static void ShortCut_SoundOnOff(void) ! 94: { ! 95: } ! 96: ! 97: ! 98: /*-----------------------------------------------------------------------*/ ! 99: /** ! 100: * Shortcut to fast forward ! 101: */ ! 102: static void ShortCut_FastForward(void) ! 103: { ! 104: /* Set maximum speed */ ! 105: ConfigureParams.System.bFastForward = true; ! 106: } ! 107: ! 108: ! 109: /*-----------------------------------------------------------------------*/ ! 110: /** ! 111: * Shortcut to 'Boss' key, ie minmize Window and switch to another application ! 112: */ ! 113: static void ShortCut_BossKey(void) ! 114: { ! 115: /* If we are in full-screen, then return to a window */ ! 116: Screen_ReturnFromFullScreen(); ! 117: ! 118: if (bGrabMouse) ! 119: { ! 120: SDL_WM_GrabInput(SDL_GRAB_OFF); ! 121: bGrabMouse = false; ! 122: } ! 123: Main_PauseEmulation(true); ! 124: ! 125: /* Minimize Window and give up processing to next one! */ ! 126: SDL_WM_IconifyWindow(); ! 127: } ! 128: ! 129: ! 130: /*-----------------------------------------------------------------------*/ ! 131: /** ! 132: * Shorcut to debug interface ! 133: */ ! 134: static void ShortCut_Debug(void) ! 135: { ! 136: int running; ! 137: ! 138: /* Call the debugger */ ! 139: running = Main_PauseEmulation(true); ! 140: DebugUI(); ! 141: if (running) ! 142: Main_UnPauseEmulation(); ! 143: } ! 144: ! 145: ! 146: /*-----------------------------------------------------------------------*/ ! 147: /** ! 148: * Shorcut to pausing ! 149: */ ! 150: static void ShortCut_Pause(void) ! 151: { ! 152: if (!Main_UnPauseEmulation()) ! 153: Main_PauseEmulation(true); ! 154: } ! 155: ! 156: /** ! 157: * Shorcut to load a disk image ! 158: */ ! 159: static void ShortCut_InsertDisk(int drive) ! 160: { ! 161: } ! 162: ! 163: ! 164: /*-----------------------------------------------------------------------*/ ! 165: /** ! 166: * Check to see if pressed any shortcut keys, and call handling function ! 167: */ ! 168: void ShortCut_ActKey(void) ! 169: { ! 170: if (ShortCutKey == SHORTCUT_NONE) ! 171: return; ! 172: ! 173: switch (ShortCutKey) ! 174: { ! 175: case SHORTCUT_OPTIONS: ! 176: Dialog_DoProperty(); /* Show options dialog */ ! 177: break; ! 178: case SHORTCUT_FULLSCREEN: ! 179: ShortCut_FullScreen(); /* Switch between fullscreen/windowed mode */ ! 180: break; ! 181: case SHORTCUT_MOUSEGRAB: ! 182: ShortCut_MouseGrab(); /* Toggle mouse grab */ ! 183: break; ! 184: case SHORTCUT_COLDRESET: ! 185: Main_UnPauseEmulation(); ! 186: Reset_Cold(); /* Reset emulator with 'cold' (clear all) */ ! 187: break; ! 188: case SHORTCUT_WARMRESET: ! 189: Main_UnPauseEmulation(); ! 190: Reset_Warm(); /* Emulator 'warm' reset */ ! 191: break; ! 192: case SHORTCUT_SCREENSHOT: ! 193: ScreenSnapShot_SaveScreen(); /* Grab screenshot */ ! 194: break; ! 195: case SHORTCUT_BOSSKEY: ! 196: ShortCut_BossKey(); /* Boss key */ ! 197: break; ! 198: case SHORTCUT_CURSOREMU: /* Toggle joystick emu on/off */ ! 199: // Joy_ToggleCursorEmulation(); ! 200: break; ! 201: case SHORTCUT_FASTFORWARD: ! 202: ShortCut_FastForward(); /* Toggle Min/Max speed */ ! 203: break; ! 204: case SHORTCUT_RECANIM: ! 205: ShortCut_RecordAnimation(); /* Record animation */ ! 206: break; ! 207: case SHORTCUT_RECSOUND: ! 208: // ShortCut_RecordSound(); /* Toggle sound recording */ ! 209: break; ! 210: case SHORTCUT_SOUND: ! 211: ShortCut_SoundOnOff(); /* Enable/disable sound */ ! 212: break; ! 213: case SHORTCUT_DEBUG: ! 214: ShortCut_Debug(); /* Invoke the Debug UI */ ! 215: break; ! 216: case SHORTCUT_PAUSE: ! 217: ShortCut_Pause(); /* Invoke Pause */ ! 218: break; ! 219: case SHORTCUT_QUIT: ! 220: Main_RequestQuit(); ! 221: break; ! 222: case SHORTCUT_LOADMEM: ! 223: MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, true); ! 224: break; ! 225: case SHORTCUT_SAVEMEM: ! 226: MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, true); ! 227: break; ! 228: case SHORTCUT_INSERTDISKA: ! 229: // ShortCut_InsertDisk(0); ! 230: break; ! 231: case SHORTCUT_KEYS: ! 232: case SHORTCUT_NONE: ! 233: /* ERROR: cannot happen, just make compiler happy */ ! 234: break; ! 235: } ! 236: ShortCutKey = SHORTCUT_NONE; ! 237: } ! 238: ! 239: ! 240: /*-----------------------------------------------------------------------*/ ! 241: /** ! 242: * Invoke shortcut identified by name. This supports only keys for ! 243: * functionality that cannot be invoked with command line options ! 244: * or otherwise for remote GUIs etc. ! 245: */ ! 246: bool Shortcut_Invoke(const char *shortcut) ! 247: { ! 248: struct { ! 249: SHORTCUTKEYIDX id; ! 250: const char *name; ! 251: } shortcuts[] = { ! 252: { SHORTCUT_MOUSEGRAB, "mousegrab" }, ! 253: { SHORTCUT_COLDRESET, "coldreset" }, ! 254: { SHORTCUT_WARMRESET, "warmreset" }, ! 255: { SHORTCUT_SCREENSHOT, "screenshot" }, ! 256: { SHORTCUT_BOSSKEY, "bosskey" }, ! 257: { SHORTCUT_RECANIM, "recanim" }, ! 258: { SHORTCUT_RECSOUND, "recsound" }, ! 259: { SHORTCUT_SAVEMEM, "savemem" }, ! 260: { SHORTCUT_QUIT, "quit" }, ! 261: { SHORTCUT_NONE, NULL } ! 262: }; ! 263: int i; ! 264: ! 265: if (ShortCutKey != SHORTCUT_NONE) ! 266: { ! 267: fprintf(stderr, "Shortcut invocation failed, shortcut already active\n"); ! 268: return false; ! 269: } ! 270: for (i = 0; shortcuts[i].name; i++) ! 271: { ! 272: if (strcmp(shortcut, shortcuts[i].name) == 0) ! 273: { ! 274: ShortCutKey = shortcuts[i].id; ! 275: ShortCut_ActKey(); ! 276: ShortCutKey = SHORTCUT_NONE; ! 277: return true; ! 278: } ! 279: } ! 280: fprintf(stderr, "WARNING: unknown shortcut '%s'\n\n", shortcut); ! 281: fprintf(stderr, "Hatari shortcuts are:\n"); ! 282: for (i = 0; shortcuts[i].name; i++) ! 283: { ! 284: fprintf(stderr, "- %s\n", shortcuts[i].name); ! 285: } ! 286: return false; ! 287: } ! 288: ! 289: ! 290: /*-----------------------------------------------------------------------*/ ! 291: /** ! 292: * Check whether given key was any of the ones in given shortcut array. ! 293: * Return corresponding array index or SHORTCUT_NONE for no match ! 294: */ ! 295: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys) ! 296: { ! 297: SHORTCUTKEYIDX key; ! 298: for (key = SHORTCUT_OPTIONS; key < SHORTCUT_KEYS; key++) ! 299: { ! 300: if (symkey == keys[key]) ! 301: return key; ! 302: } ! 303: return SHORTCUT_NONE; ! 304: } ! 305: ! 306: /*-----------------------------------------------------------------------*/ ! 307: /** ! 308: * Check which Shortcut key is pressed/released. ! 309: * If press is set, store the key array index. ! 310: * Return zero if key didn't match to a shortcut ! 311: */ ! 312: int ShortCut_CheckKeys(int modkey, int symkey, bool press) ! 313: { ! 314: SHORTCUTKEYIDX key; ! 315: ! 316: if (modkey & (KMOD_RALT|KMOD_LMETA|KMOD_RMETA|KMOD_MODE)) ! 317: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier); ! 318: else ! 319: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier); ! 320: ! 321: if (key == SHORTCUT_NONE) ! 322: return 0; ! 323: if (press) { ! 324: ShortCutKey = key; ! 325: fprintf(stderr,"Short :%x\n",ShortCutKey); ! 326: } ! 327: return 1; ! 328: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.