|
|
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.8 ! root 9: const char ShortCut_rcsid[] = "Hatari $Id: shortcut.c,v 1.23 2006/08/09 08:14:24 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"
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 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.4 root 35: if(!bInFullScreen)
36: {
37: Screen_EnterFullScreen();
38: }
39: else
40: {
41: Screen_ReturnFromFullScreen();
1.1 root 42: }
43: }
44:
1.1.1.4 root 45:
46: /*-----------------------------------------------------------------------*/
1.1 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.4 root 52: bGrabMouse = !bGrabMouse; /* Toggle flag */
1.1 root 53:
1.1.1.4 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);
1.1 root 60: }
61: else
1.1.1.4 root 62: {
63: SDL_WM_GrabInput(SDL_GRAB_OFF);
64: }
1.1 root 65: }
66: }
67:
1.1.1.4 root 68:
1.1.1.5 root 69: /*-----------------------------------------------------------------------*/
1.1 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.5 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();
1.1 root 83: }
1.1.1.5 root 84: else
85: {
86: /* Begin recording */
87: Sound_BeginRecording(ConfigureParams.Sound.szYMCaptureFileName);
1.1 root 88: }
89: }
90: }
91:
1.1.1.5 root 92:
93: /*-----------------------------------------------------------------------*/
1.1 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.5 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, ConfigureParams.Screen.nFramesPerSecond);
1.1 root 109: }
110: }
111:
1.1.1.4 root 112:
113: /*-----------------------------------------------------------------------*/
1.1 root 114: /*
115: Shortcut to toggle joystick cursor emulation
116: */
1.1.1.5 root 117: static void ShortCut_JoystickCursorEmulation(void)
1.1 root 118: {
1.1.1.4 root 119: /* Toggle it on/off */
1.1 root 120: Joy_ToggleCursorEmulation();
121: }
122:
1.1.1.4 root 123:
1.1.1.5 root 124: /*-----------------------------------------------------------------------*/
1.1 root 125: /*
126: Shortcut to sound on/off
127: */
1.1.1.5 root 128: static void ShortCut_SoundOnOff(void)
1.1 root 129: {
1.1.1.5 root 130: /* Toggle sound on/off */
1.1 root 131: ConfigureParams.Sound.bEnableSound ^= TRUE;
1.1.1.5 root 132: /* And start/stop if need to */
133: if (!ConfigureParams.Sound.bEnableSound)
134: {
1.1 root 135: if (Sound_AreWeRecording())
1.1.1.5 root 136: Sound_EndRecording();
137: Audio_UnInit();
1.1 root 138: }
139: else
1.1.1.5 root 140: {
141: Audio_Init();
142: }
1.1 root 143: }
144:
1.1.1.5 root 145:
146: /*-----------------------------------------------------------------------*/
1.1 root 147: /*
148: Shortcut to maximum speed
149: */
1.1.1.5 root 150: static void ShortCut_MaximumSpeed(void)
1.1 root 151: {
1.1.1.5 root 152: /* If already on max speed, switch back to normal */
153: if (ConfigureParams.System.nMinMaxSpeed == MINMAXSPEED_MAX)
154: {
155: /* Restore */
156: ConfigureParams.System.nMinMaxSpeed = MINMAXSPEED_MIN;
157:
158: /* Reset the sound emulation variables: */
1.1.1.7 root 159: Sound_ResetBufferIndex();
1.1 root 160: }
1.1.1.5 root 161: else
162: {
163: /* Set maximum speed */
164: ConfigureParams.System.nMinMaxSpeed = MINMAXSPEED_MAX;
1.1 root 165: }
166: }
167:
1.1.1.5 root 168:
169: /*-----------------------------------------------------------------------*/
1.1 root 170: /*
171: Shortcut to 'Boss' key, ie minmize Window and switch to another application
172: */
1.1.1.5 root 173: static void ShortCut_BossKey(void)
1.1 root 174: {
1.1.1.5 root 175: /* If we are in full-screen, then return to a window */
1.1 root 176: Screen_ReturnFromFullScreen();
1.1.1.5 root 177:
178: if(bGrabMouse)
179: {
180: SDL_WM_GrabInput(SDL_GRAB_OFF);
181: bGrabMouse = FALSE;
182: }
183:
184: /* Minimize Window and give up processing to next one! */
185: SDL_WM_IconifyWindow();
1.1 root 186: }
187:
1.1.1.4 root 188:
189: /*-----------------------------------------------------------------------*/
1.1 root 190: /*
191: Shortcut to 'Cold' reset
192: */
1.1.1.5 root 193: static void ShortCut_ColdReset(void)
1.1 root 194: {
1.1.1.2 root 195: Reset_Cold(); /* Reset emulator with 'cold' (clear all) */
1.1 root 196: }
197:
1.1.1.4 root 198:
199: /*-----------------------------------------------------------------------*/
1.1 root 200: /*
201: Shortcut to 'Warm' reset
202: */
1.1.1.5 root 203: static void ShortCut_WarmReset(void)
1.1 root 204: {
1.1.1.2 root 205: Reset_Warm(); /* Emulator 'warm' reset */
1.1 root 206: }
1.1.1.5 root 207:
208:
209: /*-----------------------------------------------------------------------*/
210: /*
1.1.1.8 ! root 211: Shortcut for quitting
1.1.1.5 root 212: */
1.1.1.8 ! root 213: static void ShortCut_Quit(void)
1.1.1.5 root 214: {
1.1.1.8 ! root 215: bQuitProgram = TRUE; /* Quit program */
! 216: set_special(SPCFLAG_BRK);
1.1.1.5 root 217: }
218:
219:
220: /*-----------------------------------------------------------------------*/
221: /*
222: Check to see if pressed any shortcut keys, and call handling function
223: */
1.1.1.8 ! root 224: void ShortCut_ActKey(void)
1.1.1.5 root 225: {
1.1.1.8 ! root 226: if (ShortCutKey == SHORTCUT_NONE)
! 227: return;
! 228:
! 229: switch(ShortCutKey)
1.1.1.5 root 230: {
1.1.1.8 ! root 231: case SHORTCUT_OPTIONS:
! 232: Dialog_DoProperty(); /* Show options dialog */
! 233: break;
! 234: case SHORTCUT_FULLSCREEN:
! 235: ShortCut_FullScreen(); /* Switch between fullscreen/windowed mode */
1.1.1.5 root 236: break;
1.1.1.8 ! root 237: case SHORTCUT_MOUSEMODE:
! 238: ShortCut_MouseMode(); /* Toggle mouse mode */
1.1.1.5 root 239: break;
1.1.1.8 ! root 240: case SHORTCUT_COLDRESET:
! 241: ShortCut_ColdReset(); /* Cold reset */
1.1.1.5 root 242: break;
1.1.1.8 ! root 243: case SHORTCUT_WARMRESET:
! 244: ShortCut_WarmReset(); /* Warm reset */
1.1.1.5 root 245: break;
1.1.1.8 ! root 246: case SHORTCUT_SCREENSHOT:
! 247: ScreenSnapShot_SaveScreen(); /* Grab screenshot */
1.1.1.5 root 248: break;
1.1.1.8 ! root 249: case SHORTCUT_BOSSKEY:
! 250: ShortCut_BossKey(); /* Boss key */
1.1.1.5 root 251: break;
1.1.1.8 ! root 252: case SHORTCUT_CURSOREMU:
1.1.1.5 root 253: ShortCut_JoystickCursorEmulation();
254: break;
1.1.1.8 ! root 255: case SHORTCUT_MAXSPEED:
! 256: ShortCut_MaximumSpeed(); /* Toggle Min/Max speed */
1.1.1.5 root 257: break;
1.1.1.8 ! root 258: case SHORTCUT_RECANIM:
! 259: ShortCut_RecordAnimation(); /* Record animation */
1.1.1.5 root 260: break;
1.1.1.8 ! root 261: case SHORTCUT_RECSOUND:
! 262: ShortCut_RecordSound(); /* Toggle sound recording */
1.1.1.5 root 263: break;
1.1.1.8 ! root 264: case SHORTCUT_SOUND:
! 265: ShortCut_SoundOnOff(); /* Enable/disable sound */
1.1.1.5 root 266: break;
1.1.1.8 ! root 267: case SHORTCUT_QUIT:
! 268: ShortCut_Quit(); /* Quit program */
1.1.1.5 root 269: break;
1.1.1.8 ! root 270: case SHORTCUT_KEYS:
! 271: case SHORTCUT_NONE:
! 272: /* ERROR: cannot happen, just make compiler happy */
1.1.1.5 root 273: break;
274: }
1.1.1.8 ! root 275: ShortCutKey = SHORTCUT_NONE;
! 276: }
! 277:
! 278:
! 279: /*-----------------------------------------------------------------------*/
! 280: /*
! 281: Check whether given key was any of the ones in given shortcut array.
! 282: Return corresponding array index or SHORTCUT_NONE for no match
! 283: */
! 284: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
! 285: {
! 286: SHORTCUTKEYIDX key;
! 287: for (key = 0; key < SHORTCUT_KEYS; key++)
! 288: {
! 289: if (symkey == keys[key])
! 290: return key;
! 291: }
! 292: return SHORTCUT_NONE;
! 293: }
! 294:
! 295: /*-----------------------------------------------------------------------*/
! 296: /*
! 297: Check which Shortcut key is pressed/released.
! 298: If press is set, store the key array index.
! 299: Return zero if key didn't match to a shortcut
! 300: */
! 301: int ShortCut_CheckKeys(int modkey, int symkey, BOOL press)
! 302: {
! 303: SHORTCUTKEYIDX key;
! 304:
! 305: if (modkey & (KMOD_RALT|KMOD_LMETA|KMOD_RMETA|KMOD_MODE))
! 306: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
! 307: else
! 308: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
1.1.1.5 root 309:
1.1.1.8 ! root 310: if (key == SHORTCUT_NONE)
! 311: return 0;
! 312: if (press)
! 313: ShortCutKey = key;
! 314: return 1;
1.1.1.5 root 315: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.