|
|
1.1 root 1: /*
1.1.1.5 root 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.
1.1 root 6:
7: Shortcut keys
8: */
1.1.1.10! root 9: const char ShortCut_rcsid[] = "Hatari $Id: shortcut.c,v 1.43 2008/11/22 18:21:33 eerot Exp $";
1.1 root 10:
1.1.1.2 root 11: #include <SDL.h>
12:
1.1 root 13: #include "main.h"
14: #include "dialog.h"
15: #include "audio.h"
1.1.1.10! root 16: #include "file.h"
! 17: #include "floppy.h"
1.1 root 18: #include "joy.h"
1.1.1.5 root 19: #include "m68000.h"
1.1 root 20: #include "memorySnapShot.h"
21: #include "reset.h"
22: #include "screen.h"
23: #include "screenSnapShot.h"
1.1.1.8 root 24: #include "configuration.h"
1.1 root 25: #include "shortcut.h"
1.1.1.10! root 26: #include "debugui.h"
1.1 root 27: #include "sound.h"
1.1.1.10! root 28: #include "sdlgui.h"
1.1.1.2 root 29:
1.1.1.8 root 30: static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE; /* current shortcut key */
1.1 root 31:
1.1.1.4 root 32:
1.1.1.2 root 33: /*-----------------------------------------------------------------------*/
1.1.1.9 root 34: /**
35: * Shortcut to toggle full-screen
36: */
1.1.1.5 root 37: static void ShortCut_FullScreen(void)
1.1 root 38: {
1.1.1.9 root 39: if (!bInFullScreen)
40: {
41: Screen_EnterFullScreen();
42: }
43: else
44: {
45: Screen_ReturnFromFullScreen();
46: }
1.1 root 47: }
48:
1.1.1.4 root 49:
50: /*-----------------------------------------------------------------------*/
1.1.1.9 root 51: /**
52: * Shortcut to toggle mouse mode
53: */
1.1.1.5 root 54: static void ShortCut_MouseMode(void)
1.1 root 55: {
1.1.1.9 root 56: bGrabMouse = !bGrabMouse; /* Toggle flag */
1.1 root 57:
1.1.1.9 root 58: /* If we are in windowed mode, toggle the mouse cursor mode now: */
59: if (!bInFullScreen)
60: {
61: if (bGrabMouse)
62: {
63: SDL_WM_GrabInput(SDL_GRAB_ON);
64: }
65: else
66: {
67: SDL_WM_GrabInput(SDL_GRAB_OFF);
68: }
69: }
1.1 root 70: }
71:
1.1.1.4 root 72:
1.1.1.5 root 73: /*-----------------------------------------------------------------------*/
1.1.1.9 root 74: /**
75: * Shortcut to toggle YM/WAV sound recording
76: */
1.1.1.5 root 77: static void ShortCut_RecordSound(void)
1.1 root 78: {
1.1.1.9 root 79: /* Is working? */
80: if (bSoundWorking)
81: {
82: /* Are we currently recording? If so stop */
83: if (Sound_AreWeRecording())
84: {
85: /* Stop, and save */
86: Sound_EndRecording();
87: }
88: else
89: {
90: /* Begin recording */
91: Sound_BeginRecording(ConfigureParams.Sound.szYMCaptureFileName);
92: }
93: }
1.1 root 94: }
95:
1.1.1.5 root 96:
97: /*-----------------------------------------------------------------------*/
1.1.1.9 root 98: /**
99: * Shortcut to toggle screen animation recording
100: */
1.1.1.5 root 101: static void ShortCut_RecordAnimation(void)
1.1 root 102: {
1.1.1.9 root 103: /* Are we currently recording? If so stop */
104: if (ScreenSnapShot_AreWeRecording())
105: {
106: /* Stop */
107: ScreenSnapShot_EndRecording();
108: }
109: else
110: {
111: /* Start animation */
1.1.1.10! root 112: ScreenSnapShot_BeginRecording(ConfigureParams.Screen.bCaptureChange);
1.1.1.9 root 113: }
1.1 root 114: }
115:
1.1.1.4 root 116:
117: /*-----------------------------------------------------------------------*/
1.1.1.9 root 118: /**
119: * Shortcut to sound on/off
120: */
1.1.1.5 root 121: static void ShortCut_SoundOnOff(void)
1.1 root 122: {
1.1.1.9 root 123: /* Toggle sound on/off */
124: ConfigureParams.Sound.bEnableSound ^= TRUE;
125:
126: /* And start/stop if need to */
127: if (!ConfigureParams.Sound.bEnableSound)
128: {
129: if (Sound_AreWeRecording())
130: Sound_EndRecording();
131: Audio_UnInit();
132: }
133: else
134: {
135: Audio_Init();
136: }
1.1 root 137: }
138:
1.1.1.5 root 139:
140: /*-----------------------------------------------------------------------*/
1.1.1.9 root 141: /**
1.1.1.10! root 142: * Shortcut to fast forward
1.1.1.9 root 143: */
1.1.1.10! root 144: static void ShortCut_FastForward(void)
1.1 root 145: {
1.1.1.9 root 146: /* If already on max speed, switch back to normal */
1.1.1.10! root 147: if (ConfigureParams.System.bFastForward == TRUE)
1.1.1.9 root 148: {
149: /* Restore */
1.1.1.10! root 150: ConfigureParams.System.bFastForward = FALSE;
1.1.1.9 root 151:
152: /* Reset the sound emulation variables: */
153: Sound_ResetBufferIndex();
154: }
155: else
156: {
157: /* Set maximum speed */
1.1.1.10! root 158: ConfigureParams.System.bFastForward = TRUE;
1.1.1.9 root 159: }
1.1 root 160: }
161:
1.1.1.5 root 162:
163: /*-----------------------------------------------------------------------*/
1.1.1.9 root 164: /**
165: * Shortcut to 'Boss' key, ie minmize Window and switch to another application
166: */
1.1.1.5 root 167: static void ShortCut_BossKey(void)
1.1 root 168: {
1.1.1.9 root 169: /* If we are in full-screen, then return to a window */
170: Screen_ReturnFromFullScreen();
1.1.1.5 root 171:
1.1.1.9 root 172: if (bGrabMouse)
173: {
174: SDL_WM_GrabInput(SDL_GRAB_OFF);
175: bGrabMouse = FALSE;
176: }
1.1.1.10! root 177: Main_PauseEmulation(TRUE);
1.1.1.5 root 178:
1.1.1.9 root 179: /* Minimize Window and give up processing to next one! */
180: SDL_WM_IconifyWindow();
1.1 root 181: }
182:
1.1.1.4 root 183:
184: /*-----------------------------------------------------------------------*/
1.1.1.9 root 185: /**
1.1.1.10! root 186: * Shorcut to pause or debug interface
! 187: */
! 188: static void ShortCut_Pause(void)
! 189: {
! 190: if (bEnableDebug)
! 191: {
! 192: int running;
! 193:
! 194: if (bInFullScreen)
! 195: Screen_ReturnFromFullScreen();
! 196:
! 197: /* Call the debugger */
! 198: running = Main_PauseEmulation(TRUE);
! 199: DebugUI();
! 200: if (running)
! 201: Main_UnPauseEmulation();
! 202: }
! 203: else
! 204: {
! 205: if (!Main_UnPauseEmulation())
! 206: Main_PauseEmulation(TRUE);
! 207: }
! 208: }
! 209:
! 210:
! 211: /**
! 212: * Shorcut to load a disk image
! 213: */
! 214: static void ShortCut_InsertDisk(int drive)
! 215: {
! 216: char *selname, *zip_path = NULL;
! 217: const char *tmpname;
! 218:
! 219: if (SDLGui_SetScreen(sdlscrn))
! 220: return;
! 221:
! 222: if (ConfigureParams.DiskImage.szDiskFileName[drive][0])
! 223: tmpname = ConfigureParams.DiskImage.szDiskFileName[drive];
! 224: else
! 225: tmpname = ConfigureParams.DiskImage.szDiskImageDirectory;
! 226:
! 227: Main_PauseEmulation(TRUE);
! 228: selname = SDLGui_FileSelect(tmpname, &zip_path, FALSE);
! 229: if (selname)
! 230: {
! 231: if (File_Exists(selname))
! 232: {
! 233: const char *realname;
! 234: realname = Floppy_SetDiskFileName(drive, selname, zip_path);
! 235: if (zip_path)
! 236: free(zip_path);
! 237: }
! 238: else
! 239: {
! 240: Floppy_SetDiskFileNameNone(drive);
! 241: }
! 242: Floppy_InsertDiskIntoDrive(0);
! 243: free(selname);
! 244: }
! 245: Main_UnPauseEmulation();
! 246: }
! 247:
! 248:
! 249: /*-----------------------------------------------------------------------*/
! 250: /**
1.1.1.9 root 251: * Check to see if pressed any shortcut keys, and call handling function
252: */
1.1.1.8 root 253: void ShortCut_ActKey(void)
1.1.1.5 root 254: {
1.1.1.9 root 255: if (ShortCutKey == SHORTCUT_NONE)
256: return;
1.1.1.8 root 257:
1.1.1.9 root 258: switch (ShortCutKey)
259: {
260: case SHORTCUT_OPTIONS:
261: Dialog_DoProperty(); /* Show options dialog */
262: break;
263: case SHORTCUT_FULLSCREEN:
264: ShortCut_FullScreen(); /* Switch between fullscreen/windowed mode */
265: break;
266: case SHORTCUT_MOUSEMODE:
267: ShortCut_MouseMode(); /* Toggle mouse mode */
268: break;
269: case SHORTCUT_COLDRESET:
1.1.1.10! root 270: Main_UnPauseEmulation();
1.1.1.9 root 271: Reset_Cold(); /* Reset emulator with 'cold' (clear all) */
272: break;
273: case SHORTCUT_WARMRESET:
1.1.1.10! root 274: Main_UnPauseEmulation();
1.1.1.9 root 275: Reset_Warm(); /* Emulator 'warm' reset */
276: break;
277: case SHORTCUT_SCREENSHOT:
278: ScreenSnapShot_SaveScreen(); /* Grab screenshot */
279: break;
280: case SHORTCUT_BOSSKEY:
281: ShortCut_BossKey(); /* Boss key */
282: break;
283: case SHORTCUT_CURSOREMU: /* Toggle joystick emu on/off */
284: Joy_ToggleCursorEmulation();
285: break;
1.1.1.10! root 286: case SHORTCUT_FASTFORWARD:
! 287: ShortCut_FastForward(); /* Toggle Min/Max speed */
1.1.1.9 root 288: break;
289: case SHORTCUT_RECANIM:
290: ShortCut_RecordAnimation(); /* Record animation */
291: break;
292: case SHORTCUT_RECSOUND:
293: ShortCut_RecordSound(); /* Toggle sound recording */
294: break;
295: case SHORTCUT_SOUND:
296: ShortCut_SoundOnOff(); /* Enable/disable sound */
297: break;
1.1.1.10! root 298: case SHORTCUT_PAUSE:
! 299: ShortCut_Pause(); /* Invoke Pause or Debug UI */
! 300: break;
1.1.1.9 root 301: case SHORTCUT_QUIT:
302: Main_RequestQuit();
303: break;
304: case SHORTCUT_LOADMEM:
305: MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, TRUE);
306: break;
307: case SHORTCUT_SAVEMEM:
308: MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, TRUE);
309: break;
1.1.1.10! root 310: case SHORTCUT_INSERTDISKA:
! 311: ShortCut_InsertDisk(0);
! 312: break;
1.1.1.9 root 313: case SHORTCUT_KEYS:
314: case SHORTCUT_NONE:
315: /* ERROR: cannot happen, just make compiler happy */
316: break;
317: }
318: ShortCutKey = SHORTCUT_NONE;
319: }
320:
321:
322: /*-----------------------------------------------------------------------*/
323: /**
1.1.1.10! root 324: * Invoke shortcut identified by name. This supports only keys for
! 325: * functionality that cannot be invoked with command line options
! 326: * (for remote GUIs etc).
! 327: */
! 328: bool Shortcut_Invoke(const char *shortcut)
! 329: {
! 330: struct {
! 331: SHORTCUTKEYIDX id;
! 332: const char *name;
! 333: } shortcuts[] = {
! 334: { SHORTCUT_MOUSEMODE, "mousemode" },
! 335: { SHORTCUT_COLDRESET, "coldreset" },
! 336: { SHORTCUT_WARMRESET, "warmreset" },
! 337: { SHORTCUT_SCREENSHOT, "screenshot" },
! 338: { SHORTCUT_BOSSKEY, "bosskey" },
! 339: { SHORTCUT_RECANIM, "recanim" },
! 340: { SHORTCUT_RECSOUND, "recsound" },
! 341: { SHORTCUT_SAVEMEM, "savemem" },
! 342: { SHORTCUT_QUIT, "quit" },
! 343: { SHORTCUT_NONE, NULL }
! 344: };
! 345: int i;
! 346:
! 347: if (ShortCutKey != SHORTCUT_NONE)
! 348: {
! 349: fprintf(stderr, "Shortcut invocation failed, shortcut already active\n");
! 350: return FALSE;
! 351: }
! 352: for (i = 0; shortcuts[i].name; i++)
! 353: {
! 354: if (strcmp(shortcut, shortcuts[i].name) == 0)
! 355: {
! 356: ShortCutKey = shortcuts[i].id;
! 357: ShortCut_ActKey();
! 358: ShortCutKey = SHORTCUT_NONE;
! 359: return TRUE;
! 360: }
! 361: }
! 362: fprintf(stderr, "WARNING: unknown shortcut '%s'\n\n", shortcut);
! 363: fprintf(stderr, "Hatari shortcuts are:\n");
! 364: for (i = 0; shortcuts[i].name; i++)
! 365: {
! 366: fprintf(stderr, "- %s\n", shortcuts[i].name);
! 367: }
! 368: return FALSE;
! 369: }
! 370:
! 371:
! 372: /*-----------------------------------------------------------------------*/
! 373: /**
1.1.1.9 root 374: * Check whether given key was any of the ones in given shortcut array.
375: * Return corresponding array index or SHORTCUT_NONE for no match
376: */
1.1.1.8 root 377: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
378: {
1.1.1.9 root 379: SHORTCUTKEYIDX key;
380: for (key = 0; key < SHORTCUT_KEYS; key++)
381: {
382: if (symkey == keys[key])
383: return key;
384: }
385: return SHORTCUT_NONE;
1.1.1.8 root 386: }
387:
388: /*-----------------------------------------------------------------------*/
1.1.1.9 root 389: /**
390: * Check which Shortcut key is pressed/released.
391: * If press is set, store the key array index.
392: * Return zero if key didn't match to a shortcut
393: */
1.1.1.10! root 394: int ShortCut_CheckKeys(int modkey, int symkey, bool press)
1.1.1.8 root 395: {
1.1.1.9 root 396: SHORTCUTKEYIDX key;
1.1.1.8 root 397:
1.1.1.9 root 398: if (modkey & (KMOD_RALT|KMOD_LMETA|KMOD_RMETA|KMOD_MODE))
399: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
400: else
401: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
402:
403: if (key == SHORTCUT_NONE)
404: return 0;
405: if (press)
406: ShortCutKey = key;
407: return 1;
1.1.1.5 root 408: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.