Annotation of hatari/src/gui-sdl/dlgNewDisc.c, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari - dlgNewDisc.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: */
1.1.1.3 ! root        7: char DlgNewDisk_rcsid[] = "Hatari $Id: dlgNewDisc.c,v 1.4 2005/09/13 01:10:09 thothy Exp $";
1.1       root        8: 
                      9: #include "main.h"
                     10: #include "configuration.h"
                     11: #include "createBlankImage.h"
                     12: #include "dialog.h"
                     13: #include "sdlgui.h"
                     14: #include "file.h"
                     15: 
                     16: 
1.1.1.3 ! root       17: #define DLGNEWDISK_DECTRACK   3
        !            18: #define DLGNEWDISK_TRACKSTR   4
        !            19: #define DLGNEWDISK_INCTRACK   5
        !            20: #define DLGNEWDISK_SECTORS9   7
        !            21: #define DLGNEWDISK_SECTORS10  8
        !            22: #define DLGNEWDISK_SECTORS11  9
        !            23: #define DLGNEWDISK_SIDES1     11
        !            24: #define DLGNEWDISK_SIDES2     12
        !            25: #define DLGNEWDISK_SAVE       13
        !            26: #define DLGNEWDISK_EXIT       14
1.1       root       27: 
                     28: static char szTracks[3];
                     29: static int nTracks = 80;
                     30: 
1.1.1.3 ! root       31: /* The new disk image dialog: */
        !            32: static SGOBJ newdiskdlg[] =
1.1       root       33: {
                     34:        { SGBOX, 0, 0, 0,0, 28,12, NULL },
                     35:        { SGTEXT, 0, 0, 6,1, 16,1, "New floppy image" },
                     36:        { SGTEXT, 0, 0, 2,3, 7,1, "Tracks:" },
                     37:        { SGBUTTON, 0, 0, 12,3, 1,1, "\x04" },   /* Left-arrow button  */
                     38:        { SGTEXT, 0, 0, 14,3, 2,1, szTracks },
                     39:        { SGBUTTON, 0, 0, 17,3, 1,1, "\x03" },   /* Right-arrow button */
                     40:        { SGTEXT, 0, 0, 2,5, 8,1, "Sectors:" },
                     41:        { SGRADIOBUT, 0, SG_SELECTED, 12,5, 4,1, "9" },
                     42:        { SGRADIOBUT, 0, 0, 17,5, 4,1, "10" },
                     43:        { SGRADIOBUT, 0, 0, 22,5, 4,1, "11" },
                     44:        { SGTEXT, 0, 0, 2,7, 6,1, "Sides:" },
                     45:        { SGRADIOBUT, 0, 0, 12,7, 4,1, "1" },
                     46:        { SGRADIOBUT, 0, SG_SELECTED, 17,7, 4,1, "2" },
                     47:        { SGBUTTON, 0, 0, 4,10, 8,1, "Create" },
                     48:        { SGBUTTON, 0, 0, 18,10, 6,1, "Back" },
                     49:        { -1, 0, 0, 0,0, 0,0, NULL }
                     50: };
                     51: 
                     52: 
                     53: /*-----------------------------------------------------------------------*/
                     54: /*
1.1.1.3 ! root       55:   Show and process the "new blank disk image" dialog.
1.1       root       56: */
1.1.1.3 ! root       57: void DlgNewDisk_Main(void)
1.1       root       58: {
                     59:        int but;
1.1.1.3 ! root       60:        char *szNewDiskName;
1.1       root       61: 
                     62:        sprintf(szTracks, "%i", nTracks);
                     63: 
1.1.1.3 ! root       64:        SDLGui_CenterDlg(newdiskdlg);
1.1       root       65: 
1.1.1.3 ! root       66:        /* Initialize disk image name: */
        !            67:        szNewDiskName = malloc(FILENAME_MAX);
        !            68:        if (!szNewDiskName)
1.1.1.2   root       69:        {
1.1.1.3 ! root       70:                perror("DlgNewDisk_Main");
1.1.1.2   root       71:                return;
                     72:        }
1.1.1.3 ! root       73:        strcpy(szNewDiskName, DialogParams.DiskImage.szDiskImageDirectory);
        !            74:        if (strlen(szNewDiskName) < FILENAME_MAX-12)
        !            75:                strcat(szNewDiskName, "new_disk.st");
1.1       root       76: 
                     77:        /* Draw and process the dialog */
                     78:        do
                     79:        {
1.1.1.3 ! root       80:                but = SDLGui_DoDialog(newdiskdlg, NULL);
1.1       root       81:                switch(but)
                     82:                {
1.1.1.3 ! root       83:                 case DLGNEWDISK_DECTRACK:
1.1       root       84:                        if (nTracks > 40)
                     85:                                nTracks -= 1;
                     86:                        sprintf(szTracks, "%i", nTracks);
                     87:                        break;
1.1.1.3 ! root       88:                 case DLGNEWDISK_INCTRACK:
1.1       root       89:                        if (nTracks < 85)
                     90:                                nTracks += 1;
                     91:                        sprintf(szTracks, "%i", nTracks);
                     92:                        break;
1.1.1.3 ! root       93:                 case DLGNEWDISK_SAVE:
        !            94:                        if (SDLGui_FileSelect(szNewDiskName, NULL, TRUE))
1.1       root       95:                        {
1.1.1.3 ! root       96:                                if (!File_DoesFileNameEndWithSlash(szNewDiskName))
1.1       root       97:                                {
                     98:                                        int nSectors, nSides;
                     99: 
                    100:                                        /* Get number of sectors */
1.1.1.3 ! root      101:                                        if (newdiskdlg[DLGNEWDISK_SECTORS11].state & SG_SELECTED)
1.1       root      102:                                                nSectors = 11;
1.1.1.3 ! root      103:                                        else if (newdiskdlg[DLGNEWDISK_SECTORS10].state & SG_SELECTED)
1.1       root      104:                                                nSectors = 10;
                    105:                                        else
                    106:                                                nSectors = 9;
                    107: 
                    108:                                        /* Get number of sides */
1.1.1.3 ! root      109:                                        if (newdiskdlg[DLGNEWDISK_SIDES1].state & SG_SELECTED)
1.1       root      110:                                                nSides = 1;
                    111:                                        else
                    112:                                                nSides = 2;
                    113: 
1.1.1.3 ! root      114:                                        CreateBlankImage_CreateFile(szNewDiskName, nTracks, nSectors, nSides);
1.1       root      115:                                }
                    116:                        }
                    117:                        break;
                    118:                }
                    119:        }
1.1.1.3 ! root      120:        while (but != DLGNEWDISK_EXIT && but != SDLGUI_QUIT && !bQuitProgram);
1.1       root      121: 
1.1.1.3 ! root      122:        free(szNewDiskName);
1.1       root      123: }

unix.superglobalmegacorp.com

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