|
|
1.1 root 1: /*
2: Hatari - dialog.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: This is normal 'C' code to handle our options dialog. We keep all our configuration details
8: in a variable 'ConfigureParams'. When we open our dialog we copy this and then when we 'OK'
9: or 'Cancel' the dialog we can compare and makes the necessary changes.
10: */
11:
12: #include <unistd.h>
13:
14: #include "main.h"
15: #include "configuration.h"
16: #include "audio.h"
17: #include "dialog.h"
18: #include "file.h"
19: #include "keymap.h"
20: #include "memAlloc.h"
21: #include "misc.h"
22: #include "screen.h"
23: #include "sdlgui.h"
24:
25:
26: /* The main dialog: */
27: #define MAINDLG_ABOUT 2
28: #define MAINDLG_SCREEN 3
29: #define MAINDLG_KEYBD 4
30: #define MAINDLG_OK 5
31: #define MAINDLG_CANCEL 6
32: #define MAINDLG_QUIT 7
33: SGOBJ maindlg[] =
34: {
35: { SGBOX, 0, 0, 0,0, 24,18, NULL },
36: { SGTEXT, 0, 0, 2,1, 16,1, "Virtual Machine Menu" },
37: { SGBUTTON, 0, 0, 6,4, 12,1, "About" },
38: { SGBUTTON, 0, 0, 6,6, 12,1, "Screen" },
39: { SGBUTTON, 0, 0, 6,8, 12,1, "Keyboard" },
40: { SGBUTTON, 0, 0, 3,13, 8,1, "Okay" },
41: { SGBUTTON, 0, 0, 3,15, 8,1, "Cancel" },
42: { SGBUTTON, 0, 0, 13,13, 8,3, "Quit" },
43: { -1, 0, 0, 0,0, 0,0, NULL }
44: };
45:
46:
47: /* The "About"-dialog: */
48: SGOBJ aboutdlg[] =
49: {
50: { SGBOX, 0, 0, 0,0, 40,21, NULL },
51: { SGTEXT, 0, 0, 12,1, 12,1, "Frontier: Elite 2" },
52: { SGTEXT, 0, 0, 12,2, 12,1, "=================" },
53: { SGTEXT, 0, 0, 1,4, 38,1, "This Frontier virtual machine is based" },
54: { SGTEXT, 0, 0, 1,5, 38,1, "on Hatari, by T. Huth, S. Marothy," },
55: { SGTEXT, 0, 0, 1,6, 38,1, "S. Berndtsson, P. Bates, B.Schmidt and" },
56: { SGTEXT, 0, 0, 1,7, 38,1, "many others."},
57: { SGTEXT, 0, 0, 1,8, 38,1, "Hatari code and all additions to it"},
58: { SGTEXT, 0, 0, 1,9, 38,1, "are licensed under the terms of the"},
59: { SGTEXT, 0, 0, 1,10,38,1, "GNU General Public License version 2."},
60: { SGTEXT, 0, 0, 1,11,38,1, "FE2.S and FE2.BIN are reverse-"},
61: { SGTEXT, 0, 0, 1,12,38,1, "engineered source and binary of"},
62: { SGTEXT, 0, 0, 1,13,38,1, "Frontier: Elite 2, by David Braben."},
63: { SGTEXT, 0, 0, 1,14,38,1, "They are probably not legal in many"},
64: { SGTEXT, 0, 0, 1,15,38,1, "countries even if you own a copy of"},
65: { SGTEXT, 0, 0, 1,16,38,1, "Atari ST Frontier (which they are"},
66: { SGTEXT, 0, 0, 1,17,38,1, "based on,) so play quietly."},
67: { SGBUTTON, 0, 0, 17,19, 7,1, "YES" },
68: { -1, 0, 0, 0,0, 0,0, NULL }
69: };
70:
71:
72:
73: /* The screen dialog: */
74: #define DLGSCRN_FULLSCRN 3
75: #define DLGSCRN_1X 5
76: #define DLGSCRN_2X 6
77: #define DLGSCRN_SCALE2X 7
78: #define DLGSCRN_EXIT 8
79:
80: SGOBJ screendlg[] =
81: {
82: { SGBOX, 0, 0, 0,0, 24,20, NULL },
83: { SGBOX, 0, 0, 1,1, 21,15, NULL },
84: { SGTEXT, 0, 0, 5,2, 14,1, "Screen options" },
85: { SGCHECKBOX, 0, 0, 4,6, 12,1, "Fullscreen" },
86: { SGTEXT, 0, 0, 2,8, 12,1, "Screen size:" },
87: { SGRADIOBUT, 0, 0, 4,10, 8,1, "Normal" },
88: { SGRADIOBUT, 0, 0, 4,12, 8,1, "Zoomed" },
89: { SGRADIOBUT, 0, 0, 4,14, 8,1, "Scale2x" },
90: { SGBUTTON, 0, 0, 2,17, 20,1, "Back to main menu" },
91: { -1, 0, 0, 0,0, 0,0, NULL }
92: };
93:
94:
95: /* The keyboard dialog: */
96: #define DLGKEY_SYMBOLIC 3
97: #define DLGKEY_SCANCODE 4
98: #define DLGKEY_FROMFILE 5
99: #define DLGKEY_MAPNAME 7
100: #define DLGKEY_MAPBROWSE 8
101: #define DLGKEY_EXIT 9
102: SGOBJ keyboarddlg[] =
103: {
104: { SGBOX, 0, 0, 0,0, 40,12, NULL },
105: { SGTEXT, 0, 0, 13,1, 14,1, "Keyboard setup" },
106: { SGTEXT, 0, 0, 2,3, 17,1, "Keyboard mapping:" },
107: { SGRADIOBUT, 0, 0, 3,5, 10,1, "Symbolic" },
108: { SGRADIOBUT, 0, 0, 15,5, 10,1, "Scancode" },
109: { SGRADIOBUT, 0, 0, 27,5, 11,1, "From file" },
110: { SGTEXT, 0, 0, 2,7, 13,1, "Mapping file:" },
111: { SGTEXT, 0, 0, 2,8, 36,1, NULL },
112: { SGBUTTON, 0, 0, 32,7, 6,1, "Browse" },
113: { SGBUTTON, 0, 0, 10,10, 20,1, "Back to main menu" },
114: { -1, 0, 0, 0,0, 0,0, NULL }
115: };
116:
117:
118:
119:
120: CNF_PARAMS DialogParams; /* List of configuration for dialogs (so the user can also choose 'Cancel') */
121:
122:
123:
124: /*-----------------------------------------------------------------------*/
125: /*
126: Copy details back to configuration and perform reset
127: */
128: void Dialog_CopyDialogParamsToConfiguration(BOOL bForceReset)
129: {
130: /* Copy details to configuration, so can be saved out or set on reset */
131: ConfigureParams = DialogParams;
132:
133: /* Set keyboard remap file */
134: if(ConfigureParams.Keyboard.nKeymapType == KEYMAP_LOADED)
135: Keymap_LoadRemapFile(ConfigureParams.Keyboard.szMappingFileName);
136:
137: /* Go into/return from full screen if flagged */
138: if ( (!bInFullScreen) && (DialogParams.Screen.bFullScreen) )
139: Screen_EnterFullScreen();
140: else if ( bInFullScreen && (!DialogParams.Screen.bFullScreen) )
141: Screen_ReturnFromFullScreen();
142: }
143:
144:
145:
146: /*-----------------------------------------------------------------------*/
147: /*
148: Show and process the screen dialog.
149: */
150: void Dialog_ScreenDlg(void)
151: {
152: int but, i;
153:
154: SDLGui_CenterDlg(screendlg);
155:
156: /* Set up dialog from actual values: */
157:
158: if( DialogParams.Screen.bFullScreen )
159: screendlg[DLGSCRN_FULLSCRN].state |= SG_SELECTED;
160: else
161: screendlg[DLGSCRN_FULLSCRN].state &= ~SG_SELECTED;
162:
163: for(i=0; i<3; i++)
164: screendlg[DLGSCRN_1X + i].state &= ~SG_SELECTED;
165:
166: switch (ConfigureParams.Screen.ChosenDisplayMode) {
167: case DISPLAYMODE_HICOL_1X:
168: screendlg[DLGSCRN_1X].state |= SG_SELECTED;
169: break;
170: case DISPLAYMODE_HICOL_2X:
171: screendlg[DLGSCRN_2X].state |= SG_SELECTED;
172: break;
173: default:
174: screendlg[DLGSCRN_SCALE2X].state |= SG_SELECTED;
175: break;
176: }
177:
178: /* The screen dialog main loop */
179: do
180: {
181: but = SDLGui_DoDialog(screendlg);
182: }
183: while( but!=DLGSCRN_EXIT && !bQuitProgram );
184:
185: /* Read values from dialog */
186: DialogParams.Screen.bFullScreen = (screendlg[DLGSCRN_FULLSCRN].state & SG_SELECTED);
187:
188: for(i=0; i<3; i++)
189: {
190: if(screendlg[DLGSCRN_1X + i].state & SG_SELECTED)
191: {
192: DialogParams.Screen.ChosenDisplayMode = i;
193: break;
194: }
195: }
196: }
197:
198:
199: /*-----------------------------------------------------------------------*/
200: /*
201: Show and process the "Keyboard" dialog.
202: */
203: void Dialog_KeyboardDlg(void)
204: {
205: int i, but;
206: char dlgmapfile[40];
207: char tmpname[MAX_FILENAME_LENGTH];
208:
209: SDLGui_CenterDlg(keyboarddlg);
210:
211: /* Set up dialog from actual values: */
212: for(i = DLGKEY_SYMBOLIC; i <= DLGKEY_FROMFILE; i++)
213: {
214: keyboarddlg[i].state &= ~SG_SELECTED;
215: }
216: keyboarddlg[DLGKEY_SYMBOLIC+DialogParams.Keyboard.nKeymapType].state |= SG_SELECTED;
217:
218: File_ShrinkName(dlgmapfile, DialogParams.Keyboard.szMappingFileName, keyboarddlg[DLGKEY_MAPNAME].w);
219: keyboarddlg[DLGKEY_MAPNAME].txt = dlgmapfile;
220:
221: /* Show the dialog: */
222: do
223: {
224: but = SDLGui_DoDialog(keyboarddlg);
225:
226: if(but == DLGKEY_MAPBROWSE)
227: {
228: strcpy(tmpname, DialogParams.Keyboard.szMappingFileName);
229: if(!tmpname[0])
230: {
231: getcwd(tmpname, MAX_FILENAME_LENGTH);
232: File_AddSlashToEndFileName(tmpname);
233: }
234: if( SDLGui_FileSelect(tmpname, NULL) )
235: {
236: strcpy(DialogParams.Keyboard.szMappingFileName, tmpname);
237: if( !File_DoesFileNameEndWithSlash(tmpname) && File_Exists(tmpname) )
238: File_ShrinkName(dlgmapfile, tmpname, keyboarddlg[DLGKEY_MAPNAME].w);
239: else
240: dlgmapfile[0] = 0;
241: }
242: Screen_Draw(0);
243: }
244:
245: }
246: while(but != DLGKEY_EXIT && !bQuitProgram);
247:
248: /* Read values from dialog: */
249: if(keyboarddlg[DLGKEY_SYMBOLIC].state & SG_SELECTED)
250: DialogParams.Keyboard.nKeymapType = KEYMAP_SYMBOLIC;
251: else if(keyboarddlg[DLGKEY_SCANCODE].state & SG_SELECTED)
252: DialogParams.Keyboard.nKeymapType = KEYMAP_SCANCODE;
253: else
254: DialogParams.Keyboard.nKeymapType = KEYMAP_LOADED;
255: }
256:
257:
258:
259: /*-----------------------------------------------------------------------*/
260: /*
261: This functions sets up the actual font and then displays the main dialog.
262: */
263: int Dialog_MainDlg(BOOL *bReset)
264: {
265: int retbut;
266:
267: if(SDLGui_PrepareFont())
268: return FALSE;
269:
270: SDLGui_CenterDlg(maindlg);
271: SDL_ShowCursor(SDL_ENABLE);
272:
273: do
274: {
275: retbut = SDLGui_DoDialog(maindlg);
276: switch(retbut)
277: {
278: case MAINDLG_ABOUT:
279: SDLGui_CenterDlg(aboutdlg);
280: SDLGui_DoDialog(aboutdlg);
281: break;
282: case MAINDLG_SCREEN:
283: Dialog_ScreenDlg();
284: break;
285: case MAINDLG_KEYBD:
286: SDLGui_CenterDlg(keyboarddlg);
287: Dialog_KeyboardDlg();
288: break;
289: case MAINDLG_QUIT:
290: bQuitProgram = TRUE;
291: break;
292: }
293: Screen_Draw(0);
294: }
295: while(retbut!=MAINDLG_OK && retbut!=MAINDLG_CANCEL && !bQuitProgram);
296:
297: SDL_ShowCursor(SDL_DISABLE);
298:
299: return(retbut==MAINDLG_OK);
300: }
301:
302:
303: /*-----------------------------------------------------------------------*/
304: /*
305: Open Property sheet Options dialog
306: Return TRUE if user choses OK, or FALSE if cancel!
307: */
308: BOOL Dialog_DoProperty(void)
309: {
310: BOOL bOKDialog; /* Did user 'OK' dialog? */
311: BOOL bForceReset;
312:
313: Main_PauseEmulation();
314:
315: /* Copy details to DialogParams (this is so can restore if 'Cancel' dialog) */
316: ConfigureParams.Screen.bFullScreen = bInFullScreen;
317: DialogParams = ConfigureParams;
318:
319: bForceReset = FALSE;
320:
321: bOKDialog = Dialog_MainDlg(&bForceReset);
322:
323: if (bOKDialog)
324: Dialog_CopyDialogParamsToConfiguration (bForceReset);
325:
326: /* Did want to save/restore memory save? If did, need to re-enter emulation mode so can save in 'safe-zone' */
327: Main_UnPauseEmulation();
328:
329: return(bOKDialog);
330: }
331:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.