|
|
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.9 ! root 9: const char ShortCut_rcsid[] = "Hatari $Id: shortcut.c,v 1.29 2008/02/24 20:10:47 thothy 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"
16: #include "joy.h"
1.1.1.5 root 17: #include "m68000.h"
1.1 root 18: #include "memorySnapShot.h"
19: #include "reset.h"
20: #include "screen.h"
21: #include "screenSnapShot.h"
1.1.1.8 root 22: #include "configuration.h"
1.1 root 23: #include "shortcut.h"
24: #include "sound.h"
1.1.1.2 root 25:
1.1.1.8 root 26: static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE; /* current shortcut key */
1.1 root 27:
1.1.1.4 root 28:
1.1.1.2 root 29: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 30: /**
! 31: * Shortcut to toggle full-screen
! 32: */
1.1.1.5 root 33: static void ShortCut_FullScreen(void)
1.1 root 34: {
1.1.1.9 ! root 35: if (!bInFullScreen)
! 36: {
! 37: Screen_EnterFullScreen();
! 38: }
! 39: else
! 40: {
! 41: Screen_ReturnFromFullScreen();
! 42: }
1.1 root 43: }
44:
1.1.1.4 root 45:
46: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 47: /**
! 48: * Shortcut to toggle mouse mode
! 49: */
1.1.1.5 root 50: static void ShortCut_MouseMode(void)
1.1 root 51: {
1.1.1.9 ! root 52: bGrabMouse = !bGrabMouse; /* Toggle flag */
1.1 root 53:
1.1.1.9 ! root 54: /* If we are in windowed mode, toggle the mouse cursor mode now: */
! 55: if (!bInFullScreen)
! 56: {
! 57: if (bGrabMouse)
! 58: {
! 59: SDL_WM_GrabInput(SDL_GRAB_ON);
! 60: }
! 61: else
! 62: {
! 63: SDL_WM_GrabInput(SDL_GRAB_OFF);
! 64: }
! 65: }
1.1 root 66: }
67:
1.1.1.4 root 68:
1.1.1.5 root 69: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 70: /**
! 71: * Shortcut to toggle YM/WAV sound recording
! 72: */
1.1.1.5 root 73: static void ShortCut_RecordSound(void)
1.1 root 74: {
1.1.1.9 ! root 75: /* Is working? */
! 76: if (bSoundWorking)
! 77: {
! 78: /* Are we currently recording? If so stop */
! 79: if (Sound_AreWeRecording())
! 80: {
! 81: /* Stop, and save */
! 82: Sound_EndRecording();
! 83: }
! 84: else
! 85: {
! 86: /* Begin recording */
! 87: Sound_BeginRecording(ConfigureParams.Sound.szYMCaptureFileName);
! 88: }
! 89: }
1.1 root 90: }
91:
1.1.1.5 root 92:
93: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 94: /**
! 95: * Shortcut to toggle screen animation recording
! 96: */
1.1.1.5 root 97: static void ShortCut_RecordAnimation(void)
1.1 root 98: {
1.1.1.9 ! root 99: /* Are we currently recording? If so stop */
! 100: if (ScreenSnapShot_AreWeRecording())
! 101: {
! 102: /* Stop */
! 103: ScreenSnapShot_EndRecording();
! 104: }
! 105: else
! 106: {
! 107: /* Start animation */
! 108: ScreenSnapShot_BeginRecording(ConfigureParams.Screen.bCaptureChange,
! 109: ConfigureParams.Screen.nFramesPerSecond);
! 110: }
1.1 root 111: }
112:
1.1.1.4 root 113:
114: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 115: /**
! 116: * Shortcut to sound on/off
! 117: */
1.1.1.5 root 118: static void ShortCut_SoundOnOff(void)
1.1 root 119: {
1.1.1.9 ! root 120: /* Toggle sound on/off */
! 121: ConfigureParams.Sound.bEnableSound ^= TRUE;
! 122:
! 123: /* And start/stop if need to */
! 124: if (!ConfigureParams.Sound.bEnableSound)
! 125: {
! 126: if (Sound_AreWeRecording())
! 127: Sound_EndRecording();
! 128: Audio_UnInit();
! 129: }
! 130: else
! 131: {
! 132: Audio_Init();
! 133: }
1.1 root 134: }
135:
1.1.1.5 root 136:
137: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 138: /**
! 139: * Shortcut to maximum speed
! 140: */
1.1.1.5 root 141: static void ShortCut_MaximumSpeed(void)
1.1 root 142: {
1.1.1.9 ! root 143: /* If already on max speed, switch back to normal */
! 144: if (ConfigureParams.System.nMinMaxSpeed == MINMAXSPEED_MAX)
! 145: {
! 146: /* Restore */
! 147: ConfigureParams.System.nMinMaxSpeed = MINMAXSPEED_MIN;
! 148:
! 149: /* Reset the sound emulation variables: */
! 150: Sound_ResetBufferIndex();
! 151: }
! 152: else
! 153: {
! 154: /* Set maximum speed */
! 155: ConfigureParams.System.nMinMaxSpeed = MINMAXSPEED_MAX;
! 156: }
1.1 root 157: }
158:
1.1.1.5 root 159:
160: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 161: /**
! 162: * Shortcut to 'Boss' key, ie minmize Window and switch to another application
! 163: */
1.1.1.5 root 164: static void ShortCut_BossKey(void)
1.1 root 165: {
1.1.1.9 ! root 166: /* If we are in full-screen, then return to a window */
! 167: Screen_ReturnFromFullScreen();
1.1.1.5 root 168:
1.1.1.9 ! root 169: if (bGrabMouse)
! 170: {
! 171: SDL_WM_GrabInput(SDL_GRAB_OFF);
! 172: bGrabMouse = FALSE;
! 173: }
1.1.1.5 root 174:
1.1.1.9 ! root 175: /* Minimize Window and give up processing to next one! */
! 176: SDL_WM_IconifyWindow();
1.1 root 177: }
178:
1.1.1.4 root 179:
180: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 181: /**
! 182: * Check to see if pressed any shortcut keys, and call handling function
! 183: */
1.1.1.8 root 184: void ShortCut_ActKey(void)
1.1.1.5 root 185: {
1.1.1.9 ! root 186: if (ShortCutKey == SHORTCUT_NONE)
! 187: return;
1.1.1.8 root 188:
1.1.1.9 ! root 189: switch (ShortCutKey)
! 190: {
! 191: case SHORTCUT_OPTIONS:
! 192: Dialog_DoProperty(); /* Show options dialog */
! 193: break;
! 194: case SHORTCUT_FULLSCREEN:
! 195: ShortCut_FullScreen(); /* Switch between fullscreen/windowed mode */
! 196: break;
! 197: case SHORTCUT_MOUSEMODE:
! 198: ShortCut_MouseMode(); /* Toggle mouse mode */
! 199: break;
! 200: case SHORTCUT_COLDRESET:
! 201: Reset_Cold(); /* Reset emulator with 'cold' (clear all) */
! 202: break;
! 203: case SHORTCUT_WARMRESET:
! 204: Reset_Warm(); /* Emulator 'warm' reset */
! 205: break;
! 206: case SHORTCUT_SCREENSHOT:
! 207: ScreenSnapShot_SaveScreen(); /* Grab screenshot */
! 208: break;
! 209: case SHORTCUT_BOSSKEY:
! 210: ShortCut_BossKey(); /* Boss key */
! 211: break;
! 212: case SHORTCUT_CURSOREMU: /* Toggle joystick emu on/off */
! 213: Joy_ToggleCursorEmulation();
! 214: break;
! 215: case SHORTCUT_MAXSPEED:
! 216: ShortCut_MaximumSpeed(); /* Toggle Min/Max speed */
! 217: break;
! 218: case SHORTCUT_RECANIM:
! 219: ShortCut_RecordAnimation(); /* Record animation */
! 220: break;
! 221: case SHORTCUT_RECSOUND:
! 222: ShortCut_RecordSound(); /* Toggle sound recording */
! 223: break;
! 224: case SHORTCUT_SOUND:
! 225: ShortCut_SoundOnOff(); /* Enable/disable sound */
! 226: break;
! 227: case SHORTCUT_QUIT:
! 228: Main_RequestQuit();
! 229: break;
! 230: case SHORTCUT_LOADMEM:
! 231: MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, TRUE);
! 232: break;
! 233: case SHORTCUT_SAVEMEM:
! 234: MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, TRUE);
! 235: break;
! 236: case SHORTCUT_KEYS:
! 237: case SHORTCUT_NONE:
! 238: /* ERROR: cannot happen, just make compiler happy */
! 239: break;
! 240: }
! 241: ShortCutKey = SHORTCUT_NONE;
! 242: }
! 243:
! 244:
! 245: /*-----------------------------------------------------------------------*/
! 246: /**
! 247: * Check whether given key was any of the ones in given shortcut array.
! 248: * Return corresponding array index or SHORTCUT_NONE for no match
! 249: */
1.1.1.8 root 250: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
251: {
1.1.1.9 ! root 252: SHORTCUTKEYIDX key;
! 253: for (key = 0; key < SHORTCUT_KEYS; key++)
! 254: {
! 255: if (symkey == keys[key])
! 256: return key;
! 257: }
! 258: return SHORTCUT_NONE;
1.1.1.8 root 259: }
260:
261: /*-----------------------------------------------------------------------*/
1.1.1.9 ! root 262: /**
! 263: * Check which Shortcut key is pressed/released.
! 264: * If press is set, store the key array index.
! 265: * Return zero if key didn't match to a shortcut
! 266: */
1.1.1.8 root 267: int ShortCut_CheckKeys(int modkey, int symkey, BOOL press)
268: {
1.1.1.9 ! root 269: SHORTCUTKEYIDX key;
1.1.1.8 root 270:
1.1.1.9 ! root 271: if (modkey & (KMOD_RALT|KMOD_LMETA|KMOD_RMETA|KMOD_MODE))
! 272: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
! 273: else
! 274: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
! 275:
! 276: if (key == SHORTCUT_NONE)
! 277: return 0;
! 278: if (press)
! 279: ShortCutKey = key;
! 280: return 1;
1.1.1.5 root 281: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.