Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Prefs_Amiga.i

Go to the documentation of this file.
00001 /*
00002  *  Prefs_Amiga.i - Global preferences, Amiga specific stuff
00003  *
00004  *  Frodo (C) 1994-1997 Christian Bauer
00005  */
00006 
00007 #include <intuition/intuition.h>
00008 #include <intuition/gadgetclass.h>
00009 #include <libraries/asl.h>
00010 #include <proto/exec.h>
00011 #include <proto/gadtools.h>
00012 #include <proto/asl.h>
00013 #include <proto/dos.h>
00014 
00015 extern "C" {
00016 #include "AmigaGUI.h"
00017 }
00018 
00019 
00020 // Flag: All done, close prefs window
00021 static bool done, result;
00022 
00023 // Pointer to preferences being edited
00024 static Prefs *prefs;
00025 
00026 // Pointer to prefs file name
00027 static char *path;
00028 
00029 // File requesters
00030 struct FileRequester *open_req, *save_req, *drive_req;
00031 
00032 // Prototypes
00033 static void set_values(void);
00034 static void get_values(void);
00035 static void ghost_gadgets(void);
00036 static void get_drive(int i);
00037 
00038 
00039 /*
00040  *  Show preferences editor (synchronously)
00041  *  prefs_name points to the file name of the preferences (which may be changed)
00042  */
00043 
00044 bool Prefs::ShowEditor(bool startup, char *prefs_name)
00045 {
00046         done = result = FALSE;
00047         prefs = this;
00048         path = prefs_name;
00049         open_req = save_req = NULL;
00050 
00051         // Open prefs window
00052         if (!SetupScreen()) {
00053                 if (!OpenPrefsWindow()) {
00054 
00055                         // Allocate file requesters
00056                         open_req = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
00057                                 ASLFR_Window, (ULONG)PrefsWnd,
00058                                 ASLFR_SleepWindow, TRUE,
00059                                 ASLFR_TitleText, (ULONG)"Frodo: Open preferences...",
00060                                 ASLFR_RejectIcons, TRUE,
00061                                 TAG_DONE);
00062                         save_req = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
00063                                 ASLFR_Window, (ULONG)PrefsWnd,
00064                                 ASLFR_SleepWindow, TRUE,
00065                                 ASLFR_TitleText, (ULONG)"Frodo: Save preferences as...",
00066                                 ASLFR_DoSaveMode, TRUE,
00067                                 ASLFR_RejectIcons, TRUE,
00068                                 TAG_DONE);
00069                         drive_req = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
00070                                 ASLFR_Window, (ULONG)PrefsWnd,
00071                                 ASLFR_SleepWindow, TRUE,
00072                                 ASLFR_RejectIcons, TRUE,
00073                                 TAG_DONE);
00074 
00075                         // Handle prefs window
00076                         set_values();
00077                         while (!done) {
00078                                 WaitPort(PrefsWnd->UserPort);
00079                                 HandlePrefsIDCMP();
00080                         }
00081 
00082                         // Free file requesters
00083                         FreeAslRequest(open_req);
00084                         FreeAslRequest(save_req);
00085                         FreeAslRequest(drive_req);
00086                 }
00087                 ClosePrefsWindow();
00088         }
00089         CloseDownScreen();
00090 
00091         return result;
00092 }
00093 
00094 
00095 /*
00096  *  Set the values of the gadgets
00097  */
00098 
00099 static void set_values(void)
00100 {
00101         prefs->Check();
00102 
00103         GT_SetGadgetAttrs(PrefsGadgets[GDX_NormalCycles], PrefsWnd, NULL, GTIN_Number, prefs->NormalCycles, TAG_DONE);
00104         GT_SetGadgetAttrs(PrefsGadgets[GDX_BadLineCycles], PrefsWnd, NULL, GTIN_Number, prefs->BadLineCycles, TAG_DONE);
00105         GT_SetGadgetAttrs(PrefsGadgets[GDX_CIACycles], PrefsWnd, NULL, GTIN_Number, prefs->CIACycles, TAG_DONE);
00106         GT_SetGadgetAttrs(PrefsGadgets[GDX_FloppyCycles], PrefsWnd, NULL, GTIN_Number, prefs->FloppyCycles, TAG_DONE);
00107         GT_SetGadgetAttrs(PrefsGadgets[GDX_SkipFrames], PrefsWnd, NULL, GTIN_Number, prefs->SkipFrames, TAG_DONE);
00108 
00109         GT_SetGadgetAttrs(PrefsGadgets[GDX_SIDType], PrefsWnd, NULL, GTCY_Active, prefs->SIDType, TAG_DONE);
00110         GT_SetGadgetAttrs(PrefsGadgets[GDX_REUSize], PrefsWnd, NULL, GTCY_Active, prefs->REUSize, TAG_DONE);
00111 
00112         GT_SetGadgetAttrs(PrefsGadgets[GDX_SpritesOn], PrefsWnd, NULL, GTCB_Checked, prefs->SpritesOn, TAG_DONE);
00113         GT_SetGadgetAttrs(PrefsGadgets[GDX_SpriteCollisions], PrefsWnd, NULL, GTCB_Checked, prefs->SpriteCollisions, TAG_DONE);
00114         GT_SetGadgetAttrs(PrefsGadgets[GDX_Joystick2On], PrefsWnd, NULL, GTCB_Checked, prefs->Joystick2On, TAG_DONE);
00115         GT_SetGadgetAttrs(PrefsGadgets[GDX_JoystickSwap], PrefsWnd, NULL, GTCB_Checked, prefs->JoystickSwap, TAG_DONE);
00116         GT_SetGadgetAttrs(PrefsGadgets[GDX_LimitSpeed], PrefsWnd, NULL, GTCB_Checked, prefs->LimitSpeed, TAG_DONE);
00117         GT_SetGadgetAttrs(PrefsGadgets[GDX_FastReset], PrefsWnd, NULL, GTCB_Checked, prefs->FastReset, TAG_DONE);
00118         GT_SetGadgetAttrs(PrefsGadgets[GDX_CIAIRQHack], PrefsWnd, NULL, GTCB_Checked, prefs->CIAIRQHack, TAG_DONE);
00119         GT_SetGadgetAttrs(PrefsGadgets[GDX_SIDFilters], PrefsWnd, NULL, GTCB_Checked, prefs->SIDFilters, TAG_DONE);
00120 
00121         GT_SetGadgetAttrs(PrefsGadgets[GDX_DrivePath8], PrefsWnd, NULL, GTST_String, (ULONG)prefs->DrivePath[0], TAG_DONE);
00122         GT_SetGadgetAttrs(PrefsGadgets[GDX_DrivePath9], PrefsWnd, NULL, GTST_String, (ULONG)prefs->DrivePath[1], TAG_DONE);
00123         GT_SetGadgetAttrs(PrefsGadgets[GDX_DrivePath10], PrefsWnd, NULL, GTST_String, (ULONG)prefs->DrivePath[2], TAG_DONE);
00124         GT_SetGadgetAttrs(PrefsGadgets[GDX_DrivePath11], PrefsWnd, NULL, GTST_String, (ULONG)prefs->DrivePath[3], TAG_DONE);
00125 
00126         GT_SetGadgetAttrs(PrefsGadgets[GDX_DriveType8], PrefsWnd, NULL, GTCY_Active, prefs->DriveType[0], TAG_DONE);
00127         GT_SetGadgetAttrs(PrefsGadgets[GDX_DriveType9], PrefsWnd, NULL, GTCY_Active, prefs->DriveType[1], TAG_DONE);
00128         GT_SetGadgetAttrs(PrefsGadgets[GDX_DriveType10], PrefsWnd, NULL, GTCY_Active, prefs->DriveType[2], TAG_DONE);
00129         GT_SetGadgetAttrs(PrefsGadgets[GDX_DriveType11], PrefsWnd, NULL, GTCY_Active, prefs->DriveType[3], TAG_DONE);
00130 
00131         GT_SetGadgetAttrs(PrefsGadgets[GDX_MapSlash], PrefsWnd, NULL, GTCB_Checked, prefs->MapSlash, TAG_DONE);
00132         GT_SetGadgetAttrs(PrefsGadgets[GDX_Emul1541Proc], PrefsWnd, NULL, GTCB_Checked, prefs->Emul1541Proc, TAG_DONE);
00133 
00134         ghost_gadgets();
00135 }
00136 
00137 
00138 /*
00139  *  Get the values of the gadgets
00140  */
00141 
00142 static void get_values(void)
00143 {
00144         prefs->NormalCycles = GetNumber(PrefsGadgets[GDX_NormalCycles]);
00145         prefs->BadLineCycles = GetNumber(PrefsGadgets[GDX_BadLineCycles]);
00146         prefs->CIACycles = GetNumber(PrefsGadgets[GDX_CIACycles]);
00147         prefs->FloppyCycles = GetNumber(PrefsGadgets[GDX_FloppyCycles]);
00148         prefs->SkipFrames = GetNumber(PrefsGadgets[GDX_SkipFrames]);
00149 
00150         strcpy(prefs->DrivePath[0], GetString(PrefsGadgets[GDX_DrivePath8]));
00151         strcpy(prefs->DrivePath[1], GetString(PrefsGadgets[GDX_DrivePath9]));
00152         strcpy(prefs->DrivePath[2], GetString(PrefsGadgets[GDX_DrivePath10]));
00153         strcpy(prefs->DrivePath[3], GetString(PrefsGadgets[GDX_DrivePath11]));
00154 
00155         prefs->Check();
00156 }
00157 
00158 
00159 /*
00160  *  Enable/disable certain gadgets
00161  */
00162 
00163 static void ghost_gadgets(void)
00164 {
00165         GT_SetGadgetAttrs(PrefsGadgets[GDX_NormalCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
00166         GT_SetGadgetAttrs(PrefsGadgets[GDX_BadLineCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
00167         GT_SetGadgetAttrs(PrefsGadgets[GDX_CIACycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
00168         GT_SetGadgetAttrs(PrefsGadgets[GDX_FloppyCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
00169         GT_SetGadgetAttrs(PrefsGadgets[GDX_CIAIRQHack], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
00170 }
00171 
00172 
00173 /*
00174  *  Handle gadgets
00175  */
00176 
00177 int SpritesOnClicked(void)
00178 {
00179         prefs->SpritesOn = !prefs->SpritesOn;
00180 }
00181 
00182 int SpriteCollisionsClicked(void)
00183 {
00184         prefs->SpriteCollisions = !prefs->SpriteCollisions;
00185 }
00186 
00187 int Joystick2OnClicked(void)
00188 {
00189         prefs->Joystick2On = !prefs->Joystick2On;
00190 }
00191 
00192 int JoystickSwapClicked(void)
00193 {
00194         prefs->JoystickSwap = !prefs->JoystickSwap;
00195 }
00196 
00197 int LimitSpeedClicked(void)
00198 {
00199         prefs->LimitSpeed = !prefs->LimitSpeed;
00200 }
00201 
00202 int FastResetClicked(void)
00203 {
00204         prefs->FastReset = !prefs->FastReset;
00205 }
00206 
00207 int CIAIRQHackClicked(void)
00208 {
00209         prefs->CIAIRQHack = !prefs->CIAIRQHack;
00210 }
00211 
00212 int SIDFiltersClicked(void)
00213 {
00214         prefs->SIDFilters = !prefs->SIDFilters;
00215 }
00216 
00217 int NormalCyclesClicked(void) {}
00218 int BadLineCyclesClicked(void) {}
00219 int CIACyclesClicked(void) {}
00220 int FloppyCyclesClicked(void) {}
00221 int SkipFramesClicked(void) {}
00222 int DrivePath8Clicked(void) {}
00223 int DrivePath9Clicked(void) {}
00224 int DrivePath10Clicked(void) {}
00225 int DrivePath11Clicked(void) {}
00226 
00227 int SIDTypeClicked(void)
00228 {
00229         prefs->SIDType = PrefsMsg.Code;
00230 }
00231 
00232 int REUSizeClicked(void)
00233 {
00234         prefs->REUSize = PrefsMsg.Code;
00235 }
00236 
00237 int DriveType8Clicked(void)
00238 {
00239         prefs->DriveType[0] = PrefsMsg.Code;
00240 }
00241 
00242 int DriveType9Clicked(void)
00243 {
00244         prefs->DriveType[1] = PrefsMsg.Code;
00245 }
00246 
00247 int DriveType10Clicked(void)
00248 {
00249         prefs->DriveType[2] = PrefsMsg.Code;
00250 }
00251 
00252 int DriveType11Clicked(void)
00253 {
00254         prefs->DriveType[3] = PrefsMsg.Code;
00255 }
00256 
00257 void get_drive(int i)
00258 {
00259         bool result = FALSE;
00260 
00261         if (drive_req == NULL)
00262                 return;
00263 
00264         get_values();
00265 
00266         if (prefs->DriveType[i] == DRVTYPE_DIR)
00267                 result = AslRequestTags(drive_req,
00268                         ASLFR_TitleText, (ULONG)"Frodo: Select directory",
00269                         ASLFR_DrawersOnly, TRUE,
00270                         ASLFR_DoPatterns, FALSE,
00271                         ASLFR_InitialPattern, (ULONG)"#?",
00272                         ASLFR_InitialDrawer, (ULONG)prefs->DrivePath[i],
00273                         ASLFR_InitialFile, (ULONG)"",
00274                         TAG_DONE);
00275         else {
00276 
00277                 // Separate path and file
00278                 char dir[256], file[256];
00279                 strncpy(dir, prefs->DrivePath[i], 255);
00280                 char *s = FilePart(dir);
00281                 strncpy(file, s, 255);
00282                 *s = 0;
00283 
00284                 if (prefs->DriveType[i] == DRVTYPE_D64)
00285                         result = AslRequestTags(drive_req,
00286                                 ASLFR_TitleText, (ULONG)"Frodo: Select disk image file",
00287                                 ASLFR_DrawersOnly, FALSE,
00288                                 ASLFR_DoPatterns, TRUE,
00289                                 ASLFR_InitialPattern, (ULONG)"#?.(d64|x64)",
00290                                 ASLFR_InitialDrawer, (ULONG)dir,
00291                                 ASLFR_InitialFile, (ULONG)file,
00292                                 TAG_DONE);
00293                 else
00294                         result = AslRequestTags(drive_req,
00295                                 ASLFR_TitleText, (ULONG)"Frodo: Select archive file",
00296                                 ASLFR_DrawersOnly, FALSE,
00297                                 ASLFR_DoPatterns, TRUE,
00298                                 ASLFR_InitialPattern, (ULONG)"#?.(t64|LNX)",
00299                                 ASLFR_InitialDrawer, (ULONG)dir,
00300                                 ASLFR_InitialFile, (ULONG)file,
00301                                 TAG_DONE);
00302         }
00303 
00304         if (result) {
00305                 strncpy(prefs->DrivePath[i], drive_req->fr_Drawer, 255);
00306                 if (prefs->DriveType[i] != DRVTYPE_DIR)
00307                         AddPart(prefs->DrivePath[i], drive_req->fr_File, 255);
00308                 set_values();
00309         }
00310 }
00311 
00312 int GetDrive8Clicked(void)
00313 {
00314         get_drive(0);
00315 }
00316 
00317 int GetDrive9Clicked(void)
00318 {
00319         get_drive(1);
00320 }
00321 
00322 int GetDrive10Clicked(void)
00323 {
00324         get_drive(2);
00325 }
00326 
00327 int GetDrive11Clicked(void)
00328 {
00329         get_drive(3);
00330 }
00331 
00332 int MapSlashClicked(void)
00333 {
00334         prefs->MapSlash = !prefs->MapSlash;
00335 }
00336 
00337 int Emul1541ProcClicked(void)
00338 {
00339         prefs->Emul1541Proc = !prefs->Emul1541Proc;
00340 }
00341 
00342 int OKClicked(void)
00343 {
00344         get_values();
00345         done = result = TRUE;
00346 }
00347 
00348 int CancelClicked(void)
00349 {
00350         done = TRUE;
00351         result = FALSE;
00352 }
00353 
00354 
00355 /*
00356  *  Handle menus
00357  */
00358 
00359 int PrefsOpen(void)
00360 {
00361         if (open_req != NULL && AslRequest(open_req, NULL)) {
00362                 strncpy(path, open_req->fr_Drawer, 255);
00363                 AddPart(path, open_req->fr_File, 255);
00364 
00365                 get_values();   // Useful if Load() is unsuccessful
00366                 prefs->Load(path);
00367                 set_values();
00368         }
00369 }
00370 
00371 int PrefsRevert(void)
00372 {
00373         get_values();   // Useful if Load() is unsuccessful
00374         prefs->Load(path);
00375         set_values();
00376 }
00377 
00378 int PrefsSaveAs(void)
00379 {
00380         if (save_req != NULL && AslRequest(save_req, NULL)) {
00381                 strncpy(path, save_req->fr_Drawer, 255);
00382                 AddPart(path, save_req->fr_File, 255);
00383 
00384                 get_values();
00385                 prefs->Save(path);
00386         }
00387 }
00388 
00389 int PrefsSave(void)
00390 {
00391         get_values();
00392         prefs->Save(path);
00393 
00394 }
00395 
00396 int PrefsOK(void)
00397 {
00398         return OKClicked();
00399 }
00400 
00401 int PrefsCancel(void)
00402 {
00403         return CancelClicked();
00404 }
00405 
00406 
00407 /*
00408  *  Handle keys
00409  */
00410 
00411 int PrefsVanillaKey(void)
00412 {
00413         switch (PrefsMsg.Code) {
00414                 case 'o': case 'O':
00415                         return OKClicked();
00416                 case 'c': case 'C':
00417                         return CancelClicked();
00418         }
00419 }

Generated on Tue Feb 8 04:08:04 2005 for E32frodo by doxygen 1.3.3