Annotation of frontvm/hardware/dialog.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.