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

Prefs_Be.i

Go to the documentation of this file.
00001 /*
00002  *  Prefs_Be.i - Global preferences, Be specific stuff
00003  *
00004  *  Frodo (C) 1994-1997 Christian Bauer
00005  */
00006 
00007 #include <InterfaceKit.h>
00008 #include <StorageKit.h>
00009 #include <Path.h>
00010 
00011 
00012 // Special colors
00013 const rgb_color light_color = {255, 255, 255, 0};
00014 const rgb_color fill_color = {216, 216, 216, 0};
00015 const rgb_color dark_color = {184, 184, 184, 0};
00016 
00017 
00018 // Window thread messages
00019 const uint32 MSG_OK = 'okok';
00020 const uint32 MSG_CANCEL = 'cncl';
00021 const uint32 MSG_SPRITES_ON = 'spon';
00022 const uint32 MSG_SPRITE_COLLISIONS = 'scol';
00023 const uint32 MSG_JOYSTICK_1_ON = 'joy1';
00024 const uint32 MSG_JOYSTICK_2_ON = 'joy2';
00025 const uint32 MSG_JOYSTICK_SWAP = 'jswp';
00026 const uint32 MSG_LIMIT_SPEED = 'lmit';
00027 const uint32 MSG_FAST_RESET = 'frst';
00028 const uint32 MSG_CIA_IRQ_HACK = 'cirq';
00029 const uint32 MSG_SID_FILTERS = 'filt';
00030 const uint32 MSG_DOUBLE_SCAN = 'dbls';
00031 const uint32 MSG_MAP_SLASH = 'mpsl';
00032 const uint32 MSG_EMUL_1541_PROC = '15pr';
00033 const uint32 MSG_DRVTYPE_8 = 'drt8';
00034 const uint32 MSG_DRVTYPE_9 = 'drt9';
00035 const uint32 MSG_DRVTYPE_10 = 'drt:';
00036 const uint32 MSG_DRVTYPE_11 = 'drt;';
00037 const uint32 MSG_GETDRIVE_8 = 'gtd8';
00038 const uint32 MSG_GETDRIVE_9 = 'gtd9';
00039 const uint32 MSG_GETDRIVE_10 = 'gtd:';
00040 const uint32 MSG_GETDRIVE_11 = 'gtd;';
00041 const uint32 MSG_DRIVE_PANEL_RETURNED = 'gdr8';
00042 const uint32 MSG_SID_TYPE = 'sidt';
00043 const uint32 MSG_REU_SIZE = 'reus';
00044 const uint32 MSG_DISPLAY_TYPE = 'dspt';
00045 
00046 const uint32 MSG_OPEN = 'open';
00047 const uint32 MSG_SAVE = 'save';
00048 const uint32 MSG_SAVE_AS = 'svas';
00049 const uint32 MSG_REVERT = 'rvrt';
00050 const uint32 MSG_OPEN_PANEL_RETURNED = 'oprt';
00051 const uint32 MSG_SAVE_PANEL_RETURNED = 'svrt';
00052 
00053 
00054 /*
00055  *  Preferences window class
00056  */
00057 
00058 class NumberControl;
00059 class PathControl;
00060 
00061 class PrefsWindow : public BWindow {
00062 public:
00063         PrefsWindow(Prefs *p, bool start, char *path);
00064         virtual void MessageReceived(BMessage *msg);
00065         virtual bool QuitRequested(void);
00066         virtual bool FilterKeyDown(uint32 *aChar, BView **target);
00067 
00068 private:
00069         BCheckBox *make_checkbox(BRect frame, char *label, uint32 what, BView *parent);
00070         NumberControl *make_number_entry(BRect frame, char *label_text, BView *parent);
00071         BPopUpMenu *make_drvtype_popup(BRect frame, uint32 what, BView *parent);
00072         PathControl *make_path_entry(BRect frame, char *label, BView *parent);
00073         BPopUpMenu *make_sidtype_popup(BRect frame, char *label_text, uint32 what, BView *parent);
00074         BPopUpMenu *make_reusize_popup(BRect frame, char *label_text, uint32 what, BView *parent);
00075         BPopUpMenu *make_disptype_popup(BRect frame, char *label_text, uint32 what, BView *parent);
00076         void set_values(void);
00077         void get_values(void);
00078         void ghost_controls(void);
00079 
00080         Prefs *prefs;
00081 
00082         BMessenger this_messenger;
00083         BFilePanel *open_panel;         // For opening prefs
00084         BFilePanel *save_panel;         // For saving prefs
00085         BFilePanel *file_panel;         // For D64/T64 drives
00086         BFilePanel *dir_panel;          // For directory drives
00087         int panel_drive_num;            // Drive number (0..3) of the file panel
00088 
00089         BButton *g_ok;
00090         BButton *g_cancel;
00091         NumberControl *g_normal_cycles;
00092         NumberControl *g_bad_line_cycles;
00093         NumberControl *g_cia_cycles;
00094         NumberControl *g_floppy_cycles;
00095         NumberControl *g_skip_frames;
00096         BPopUpMenu *g_drive_type[4];
00097         PathControl *g_drive_path[4];
00098         BPopUpMenu *g_sid_type;
00099         BPopUpMenu *g_reu_size;
00100         BPopUpMenu *g_display_type;
00101         BCheckBox *g_sprites_on;
00102         BCheckBox *g_sprite_collisions;
00103         BCheckBox *g_joystick_1_on;
00104         BCheckBox *g_joystick_2_on;
00105         BCheckBox *g_joystick_swap;
00106         BCheckBox *g_limit_speed;
00107         BCheckBox *g_fast_reset;
00108         BCheckBox *g_cia_irq_hack;
00109         BCheckBox *g_sid_filters;
00110         BCheckBox *g_double_scan;
00111         BCheckBox *g_map_slash;
00112         BCheckBox *g_emul_1541_proc;
00113 
00114         char *prefs_path;
00115         bool startup;
00116 };
00117 
00118 
00119 /*
00120  *  Start preferences editor (asynchronously)
00121  *  startup = false: Send MSG_PREFS_DONE to application on close
00122  *  startup = true : Send MSG_STARTUP to application on close if not canceled,
00123  *                   B_QUIT_REQUESTED otherwise
00124  *  prefs_name points to the file name of the preferences (which may be changed)
00125  */
00126 
00127 bool Prefs::ShowEditor(bool startup, char *prefs_name)
00128 {
00129         PrefsWindow *win = new PrefsWindow(this, startup, prefs_name);
00130         win->Show();
00131         return true;
00132 }
00133 
00134 
00135 /*
00136  *  Number-only BTextControl
00137  */
00138 
00139 // Class definition
00140 class NumberControl : public BTextControl {
00141 public:
00142         NumberControl(BRect frame, float divider, const char *name, const char *label, const char *text, BMessage *message);
00143         void SetValue(long value);
00144         long Value(void);
00145 };
00146 
00147 // Constructor: Allow only digits
00148 NumberControl::NumberControl(BRect frame, float divider, const char *name, const char *label, const char *text, BMessage *message)
00149  : BTextControl(frame, name, label, text, message, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
00150 {
00151         SetDivider(divider);
00152         for (int c=0; c<256; c++)
00153                 if (!isdigit(c) && c != B_BACKSPACE && c != B_LEFT_ARROW && c != B_RIGHT_ARROW) 
00154                         ((BTextView *)ChildAt(0))->DisallowChar(c);
00155 }
00156 
00157 // Set integer value
00158 void NumberControl::SetValue(long value)
00159 {
00160         char str[32];
00161         sprintf(str, "%ld", value);
00162         SetText(str);
00163 }
00164 
00165 // Get integer value
00166 long NumberControl::Value(void)
00167 {
00168         return atol(Text());
00169 }
00170 
00171 
00172 /*
00173  *  Path-entry BTextControl
00174  */
00175 
00176 // Class definition
00177 class PathControl : public BTextControl {
00178 public:
00179         PathControl(BRect frame, float divider, const char *name, const char *label, const char *text, BMessage *message);
00180         virtual void MessageReceived(BMessage *msg);
00181 };
00182 
00183 // Constructor: Disable some keys
00184 PathControl::PathControl(BRect frame, float divider, const char *name, const char *label, const char *text, BMessage *message)
00185  : BTextControl(frame, name, label, text, message, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
00186 {
00187         SetDivider(divider);
00188         for (int c=0; c<' '; c++)
00189                 if (c != B_BACKSPACE && c != B_LEFT_ARROW && c != B_RIGHT_ARROW) 
00190                         ((BTextView *)ChildAt(0))->DisallowChar(c);
00191 }
00192 
00193 // Message received: Look out for dropped refs
00194 void PathControl::MessageReceived(BMessage *msg)
00195 {
00196         if (msg->what == B_SIMPLE_DATA) {
00197                 entry_ref the_ref;
00198                 BEntry the_entry;
00199 
00200                 // First look for refs
00201                 if (msg->FindRef("refs", &the_ref) == B_NO_ERROR) {
00202                         if (the_entry.SetTo(&the_ref) == B_NO_ERROR) {
00203                                 BPath the_path;
00204                                 the_entry.GetPath(&the_path);
00205                                 SetText(the_path.Path());
00206                         }
00207                 } else
00208                         BTextControl::MessageReceived(msg);
00209 
00210                 MakeFocus();
00211         } else
00212                 BTextControl::MessageReceived(msg);
00213 }
00214 
00215 
00216 /*
00217  *  Open preferences window
00218  */
00219 
00220 PrefsWindow::PrefsWindow(Prefs *p, bool start, char *path) : BWindow(BRect(0, 0, 400, 349), "Frodo Preferences", B_TITLED_WINDOW, B_NOT_CLOSABLE | B_NOT_RESIZABLE | B_NOT_ZOOMABLE), this_messenger(this)
00221 {
00222         int i;
00223         prefs = p;
00224         startup = start;
00225         prefs_path = path;
00226 
00227         // Move window to right position
00228         Lock();
00229         MoveTo(80, 80);
00230 
00231         // Set up menus
00232         BMenuBar *bar = new BMenuBar(Bounds(), "");
00233         BMenu *menu = new BMenu("Preferences");
00234         BMenuItem *item;
00235         menu->AddItem(item = new BMenuItem("About Frodo" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED)));
00236         item->SetTarget(be_app);
00237         menu->AddItem(new BSeparatorItem);
00238         menu->AddItem(new BMenuItem("Open" B_UTF8_ELLIPSIS, new BMessage(MSG_OPEN), 'O'));
00239         menu->AddItem(new BMenuItem("Save", new BMessage(MSG_SAVE), 'S'));
00240         menu->AddItem(new BMenuItem("Save As" B_UTF8_ELLIPSIS, new BMessage(MSG_SAVE_AS), 'A'));
00241         menu->AddItem(new BMenuItem("Revert", new BMessage(MSG_REVERT)));
00242         menu->AddItem(new BSeparatorItem);
00243         menu->AddItem(item = new BMenuItem("Quit Frodo", new BMessage(B_QUIT_REQUESTED), 'Q'));
00244         item->SetTarget(be_app);
00245         bar->AddItem(menu);
00246         AddChild(bar);
00247         SetKeyMenuBar(bar);
00248         int mbar_height = bar->Frame().bottom + 1;
00249 
00250         // Resize window to fit menu bar
00251         ResizeBy(0, mbar_height);
00252 
00253         // Light gray background
00254         BRect b = Bounds();
00255         BView *top = new BView(BRect(0, mbar_height, b.right, b.bottom), "top", B_FOLLOW_NONE, B_WILL_DRAW);
00256         AddChild(top);
00257         top->SetViewColor(fill_color);
00258 
00259         // Checkboxes
00260         g_sprites_on = make_checkbox(BRect(10, 10, 160, 21), "Sprite display", MSG_SPRITES_ON, top);
00261         g_sprite_collisions = make_checkbox(BRect(10, 25, 160, 36), "Sprite collisions", MSG_SPRITE_COLLISIONS, top);
00262         g_joystick_1_on = make_checkbox(BRect(10, 40, 160, 51), "Joystick on port 1", MSG_JOYSTICK_1_ON, top);
00263         g_joystick_2_on = make_checkbox(BRect(10, 55, 160, 66), "Joystick on port 2", MSG_JOYSTICK_2_ON, top);
00264         g_joystick_swap = make_checkbox(BRect(10, 70, 160, 81), "Swap joysticks", MSG_JOYSTICK_SWAP, top);
00265         g_limit_speed = make_checkbox(BRect(10, 85, 160, 96), "Limit speed", MSG_LIMIT_SPEED, top);
00266         g_fast_reset = make_checkbox(BRect(10, 100, 160, 111), "Fast reset", MSG_FAST_RESET, top);
00267         g_cia_irq_hack = make_checkbox(BRect(10, 115, 160, 126), "Clear CIA ICR on write", MSG_CIA_IRQ_HACK, top);
00268         g_sid_filters = make_checkbox(BRect(10, 130, 160, 141), "SID filters", MSG_SID_FILTERS, top);
00269         g_double_scan = make_checkbox(BRect(10, 145, 160, 156), "Doublescan lines", MSG_DOUBLE_SCAN, top);
00270 
00271         // Number entry fields
00272         g_normal_cycles = make_number_entry(BRect(160, 10, 390, 26), "Cycles per line (CPU)", top);
00273         g_bad_line_cycles = make_number_entry(BRect(160, 30, 390, 46), "Cycles per Bad Line (CPU)", top);
00274         g_cia_cycles = make_number_entry(BRect(160, 50, 390, 66), "Cycles per line (CIA)", top);
00275         g_floppy_cycles = make_number_entry(BRect(160, 70, 390, 86), "Cycles per line (1541)", top);
00276         g_skip_frames = make_number_entry(BRect(160, 90, 390, 106), "Draw every n-th frame", top);
00277 
00278         // Popup fields
00279         g_display_type = make_disptype_popup(BRect(160, 110, 390, 126), "Display type", MSG_DISPLAY_TYPE, top);
00280         g_sid_type = make_sidtype_popup(BRect(160, 130, 390, 146), "SID emulation type", MSG_SID_TYPE, top);
00281         g_reu_size = make_reusize_popup(BRect(160, 150, 390, 166), "REU size", MSG_REU_SIZE, top);
00282 
00283         // Prepare on/off pictures for file panel buttons
00284         BView *view = new BView(BRect(0, 0, 19, 15), "", B_FOLLOW_NONE, 0);
00285         AddChild(view);
00286         view->SetViewColor(fill_color);
00287 
00288         view->BeginPicture(new BPicture);
00289         view->SetHighColor(fill_color);
00290         view->FillRect(BRect(0, 0, 19, 15));
00291         view->SetHighColor(light_color);
00292         view->StrokeRect(BRect(0, 0, 18, 0));
00293         view->StrokeRect(BRect(0, 0, 0, 14));
00294         view->SetHighColor(dark_color);
00295         view->StrokeRect(BRect(0, 15, 19, 15));
00296         view->StrokeRect(BRect(19, 0, 19, 15));
00297         view->SetFont(be_plain_font);
00298         view->SetHighColor(0, 0, 0);
00299         view->SetLowColor(fill_color);
00300         view->MovePenTo(7, 11);
00301         view->DrawString("B");
00302         BPicture *on = view->EndPicture();
00303 
00304         view->BeginPicture(new BPicture);
00305         view->SetHighColor(dark_color);
00306         view->FillRect(BRect(0, 0, 19, 15));
00307         view->SetHighColor(128, 128, 128);
00308         view->StrokeRect(BRect(0, 0, 18, 0));
00309         view->StrokeRect(BRect(0, 0, 0, 14));
00310         view->SetHighColor(light_color);
00311         view->StrokeRect(BRect(0, 15, 19, 15));
00312         view->StrokeRect(BRect(19, 0, 19, 15));
00313         view->SetFont(be_plain_font);
00314         view->SetHighColor(0, 0, 0);
00315         view->SetLowColor(dark_color);
00316         view->MovePenTo(7, 11);
00317         view->DrawString("B");
00318         BPicture *off = view->EndPicture();
00319 
00320         RemoveChild(view);
00321         delete view;
00322 
00323         // Drive settings
00324         BBox *drvbox = new BBox(BRect(10, 173, 390, 304));
00325         top->AddChild(drvbox);
00326         drvbox->SetViewColor(fill_color);
00327         drvbox->SetLowColor(fill_color);
00328         drvbox->SetLabel("Drives");
00329 
00330         for (i=0; i<4; i++) {
00331                 char str[4];
00332                 sprintf(str, "%d", i+8);
00333                 g_drive_path[i] = make_path_entry(BRect(10, 14+i*20, 299, 30+i*20), str, drvbox);
00334                 drvbox->AddChild(new BPictureButton(BRect(304, 16+i*20, 323, 31+i*20), "", new BPicture(*on), new BPicture(*off), new BMessage(MSG_GETDRIVE_8 + i)));
00335                 g_drive_type[i] = make_drvtype_popup(BRect(329, 14+i*20, 373, 30+i*20), MSG_DRVTYPE_8 + i, drvbox);
00336         }
00337 
00338         g_map_slash = make_checkbox(BRect(10, 94, 300, 110), "Map '/'<->'\\' in filenames", MSG_MAP_SLASH, drvbox);
00339         g_emul_1541_proc = make_checkbox(BRect(10, 109, 300, 125), "Enable 1541 processor emulation", MSG_EMUL_1541_PROC, drvbox);
00340 
00341         // "OK" button
00342         top->AddChild(g_ok = new BButton(BRect(20, 315, 90, 340), "", startup ? "Start" : "OK", new BMessage(MSG_OK)));
00343         SetDefaultButton(g_ok);
00344 
00345         // "Cancel" button
00346         top->AddChild(g_cancel = new BButton(BRect(b.right-90, 315, b.right-20, 340), "", startup ? "Quit" : "Cancel", new BMessage(MSG_CANCEL)));
00347 
00348         // Set the values of all controls to reflect the preferences
00349         set_values();
00350         g_normal_cycles->MakeFocus();
00351 
00352         // Create file panels
00353         open_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_OPEN_PANEL_RETURNED));
00354         open_panel->Window()->SetTitle("Frodo: Open preferences");
00355         save_panel = new BFilePanel(B_SAVE_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_SAVE_PANEL_RETURNED));
00356         save_panel->Window()->SetTitle("Frodo: Save preferences");
00357         file_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_DRIVE_PANEL_RETURNED));
00358         file_panel->SetPanelDirectory(&AppDirectory);
00359         dir_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, B_DIRECTORY_NODE, false, new BMessage(MSG_DRIVE_PANEL_RETURNED));
00360         dir_panel->SetPanelDirectory(&AppDirectory);
00361         dir_panel->Window()->SetTitle("Frodo: Select directory");
00362         dir_panel->SetButtonLabel(B_DEFAULT_BUTTON, "Select");
00363 
00364         Unlock();
00365 }
00366 
00367 
00368 /*
00369  *  Create checkbox
00370  */
00371 
00372 BCheckBox *PrefsWindow::make_checkbox(BRect frame, char *label, uint32 what, BView *parent)
00373 {
00374         BCheckBox *checkbox = new BCheckBox(frame, "", label, new BMessage(what));
00375         parent->AddChild(checkbox);
00376         return checkbox;
00377 }
00378 
00379 
00380 /*
00381  *  Create number entry field
00382  */
00383 
00384 NumberControl *PrefsWindow::make_number_entry(BRect frame, char *label_text, BView *parent)
00385 {
00386         NumberControl *num = new NumberControl(frame, frame.right-frame.left-55, "", label_text, NULL, NULL);
00387         parent->AddChild(num);
00388 
00389         num->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_RIGHT);
00390         num->SetFont(be_plain_font);
00391         num->ChildAt(0)->SetFont(be_plain_font);
00392 
00393         return num;
00394 }
00395 
00396 
00397 /*
00398  *  Create drive type popup menu
00399  */
00400 
00401 BPopUpMenu *PrefsWindow::make_drvtype_popup(BRect frame, uint32 what, BView *parent)
00402 {
00403         BPopUpMenu *popup = new BPopUpMenu("drive_type popup", true, true);
00404         popup->AddItem(new BMenuItem("Dir", new BMessage(what)));
00405         popup->AddItem(new BMenuItem("D64", new BMessage(what)));
00406         popup->AddItem(new BMenuItem("T64", new BMessage(what)));
00407         popup->SetTargetForItems(this);
00408         BMenuField *menu_field = new BMenuField(frame, "drive_type", NULL, popup);
00409         menu_field->SetDivider(0);
00410         parent->AddChild(menu_field);
00411         return popup;
00412 }
00413 
00414 
00415 /*
00416  *  Create path entry field
00417  */
00418 
00419 PathControl *PrefsWindow::make_path_entry(BRect frame, char *label, BView *parent)
00420 {
00421         PathControl *path = new PathControl(frame, 16, "", label, NULL, NULL);
00422         parent->AddChild(path);
00423 
00424         path->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
00425         path->SetFont(be_plain_font);
00426         path->ChildAt(0)->SetFont(be_plain_font);
00427         ((BTextView *)(path->ChildAt(0)))->SetMaxBytes(255);
00428 
00429         return path;
00430 }
00431 
00432 
00433 /*
00434  *  Create display type popup
00435  */
00436 
00437 BPopUpMenu *PrefsWindow::make_disptype_popup(BRect frame, char *label_text, uint32 what, BView *parent)
00438 {
00439         BPopUpMenu *popup = new BPopUpMenu("display_type popup", true, true);
00440         popup->AddItem(new BMenuItem("Window", new BMessage(what)));
00441         popup->AddItem(new BMenuItem("Screen", new BMessage(what)));
00442         popup->SetTargetForItems(this);
00443         BMenuField *menu_field = new BMenuField(frame, "display_type", label_text, popup);
00444         menu_field->SetDivider(frame.Width()-55);
00445         menu_field->SetAlignment(B_ALIGN_RIGHT);
00446         parent->AddChild(menu_field);
00447         return popup;
00448 }
00449 
00450 
00451 /*
00452  *  Create SID type popup
00453  */
00454 
00455 BPopUpMenu *PrefsWindow::make_sidtype_popup(BRect frame, char *label_text, uint32 what, BView *parent)
00456 {
00457         BPopUpMenu *popup = new BPopUpMenu("sid_type popup", true, true);
00458         popup->AddItem(new BMenuItem("None", new BMessage(what)));
00459         popup->AddItem(new BMenuItem("Digital", new BMessage(what)));
00460         popup->SetTargetForItems(this);
00461         BMenuField *menu_field = new BMenuField(frame, "sid_type", label_text, popup);
00462         menu_field->SetDivider(frame.Width()-55);
00463         menu_field->SetAlignment(B_ALIGN_RIGHT);
00464         parent->AddChild(menu_field);
00465         return popup;
00466 }
00467 
00468 
00469 /*
00470  *  Create REU size popup
00471  */
00472 
00473 BPopUpMenu *PrefsWindow::make_reusize_popup(BRect frame, char *label_text, uint32 what, BView *parent)
00474 {
00475         BPopUpMenu *popup = new BPopUpMenu("reu_size popup", true, true);
00476         popup->AddItem(new BMenuItem("None", new BMessage(what)));
00477         popup->AddItem(new BMenuItem("128K", new BMessage(what)));
00478         popup->AddItem(new BMenuItem("256K", new BMessage(what)));
00479         popup->AddItem(new BMenuItem("512K", new BMessage(what)));
00480         popup->SetTargetForItems(this);
00481         BMenuField *menu_field = new BMenuField(frame, "reu_size", label_text, popup);
00482         menu_field->SetDivider(frame.Width()-55);
00483         menu_field->SetAlignment(B_ALIGN_RIGHT);
00484         parent->AddChild(menu_field);
00485         return popup;
00486 }
00487 
00488 
00489 /*
00490  *  Set the values of the controls
00491  */
00492 
00493 void PrefsWindow::set_values(void)
00494 {
00495         prefs->Check();
00496 
00497         g_normal_cycles->SetValue(prefs->NormalCycles);
00498         g_bad_line_cycles->SetValue(prefs->BadLineCycles);
00499         g_cia_cycles->SetValue(prefs->CIACycles);
00500         g_floppy_cycles->SetValue(prefs->FloppyCycles);
00501         g_skip_frames->SetValue(prefs->SkipFrames);
00502 
00503         for (int i=0; i<4; i++) {
00504                 g_drive_type[i]->ItemAt(prefs->DriveType[i])->SetMarked(true);
00505                 g_drive_path[i]->SetText(prefs->DrivePath[i]);
00506         }
00507 
00508         g_sid_type->ItemAt(prefs->SIDType)->SetMarked(true);
00509         g_reu_size->ItemAt(prefs->REUSize)->SetMarked(true);
00510         g_display_type->ItemAt(prefs->DisplayType)->SetMarked(true);
00511 
00512         g_sprites_on->SetValue(prefs->SpritesOn ? B_CONTROL_ON : B_CONTROL_OFF);
00513         g_sprite_collisions->SetValue(prefs->SpriteCollisions ? B_CONTROL_ON : B_CONTROL_OFF);
00514         g_joystick_1_on->SetValue(prefs->Joystick1On ? B_CONTROL_ON : B_CONTROL_OFF);
00515         g_joystick_2_on->SetValue(prefs->Joystick2On ? B_CONTROL_ON : B_CONTROL_OFF);
00516         g_joystick_swap->SetValue(prefs->JoystickSwap ? B_CONTROL_ON : B_CONTROL_OFF);
00517         g_limit_speed->SetValue(prefs->LimitSpeed ? B_CONTROL_ON : B_CONTROL_OFF);
00518         g_fast_reset->SetValue(prefs->FastReset ? B_CONTROL_ON : B_CONTROL_OFF);
00519         g_cia_irq_hack->SetValue(prefs->CIAIRQHack ? B_CONTROL_ON : B_CONTROL_OFF);
00520         g_sid_filters->SetValue(prefs->SIDFilters ? B_CONTROL_ON : B_CONTROL_OFF);
00521         g_double_scan->SetValue(prefs->DoubleScan ? B_CONTROL_ON : B_CONTROL_OFF);
00522 
00523         g_map_slash->SetValue(prefs->MapSlash ? B_CONTROL_ON : B_CONTROL_OFF);
00524         g_emul_1541_proc->SetValue(prefs->Emul1541Proc ? B_CONTROL_ON : B_CONTROL_OFF);
00525 
00526         ghost_controls();
00527 }
00528 
00529 
00530 /*
00531  *  Get the values of the controls
00532  */
00533 
00534 void PrefsWindow::get_values(void)
00535 {
00536         prefs->NormalCycles = g_normal_cycles->Value();
00537         prefs->BadLineCycles = g_bad_line_cycles->Value();
00538         prefs->CIACycles = g_cia_cycles->Value();
00539         prefs->FloppyCycles = g_floppy_cycles->Value();
00540         prefs->SkipFrames = g_skip_frames->Value();
00541 
00542         for (int i=0; i<4; i++)
00543                 strcpy(prefs->DrivePath[i], g_drive_path[i]->Text());
00544 
00545         prefs->Check();
00546 }
00547 
00548 
00549 /*
00550  *  Enable/disable certain controls
00551  */
00552 
00553 void PrefsWindow::ghost_controls(void)
00554 {
00555         g_normal_cycles->SetEnabled(!IsFrodoSC);
00556         g_bad_line_cycles->SetEnabled(!IsFrodoSC);
00557         g_cia_cycles->SetEnabled(!IsFrodoSC);
00558         g_floppy_cycles->SetEnabled(!IsFrodoSC);
00559         g_cia_irq_hack->SetEnabled(!IsFrodoSC);
00560         g_double_scan->SetEnabled(prefs->DisplayType == DISPTYPE_SCREEN);
00561 }
00562 
00563 
00564 /*
00565  *  Message from controls/menus received
00566  */
00567 
00568 void PrefsWindow::MessageReceived(BMessage *msg)
00569 {
00570         switch (msg->what) {
00571                 case MSG_OK:
00572                         get_values();
00573                         if (startup)
00574                                 be_app->PostMessage(MSG_STARTUP);
00575                         else {
00576                                 BMessage msg(MSG_PREFS_DONE);
00577                                 msg.AddBool("canceled", false);
00578                                 msg.AddPointer("prefs", prefs);
00579                                 be_app->PostMessage(&msg);
00580                         }
00581                         PostMessage(B_QUIT_REQUESTED);
00582                         break;
00583 
00584                 case MSG_CANCEL:
00585                         if (startup)
00586                                 be_app->PostMessage(B_QUIT_REQUESTED);
00587                         else {
00588                                 BMessage msg(MSG_PREFS_DONE);
00589                                 msg.AddBool("canceled", true);
00590                                 msg.AddPointer("prefs", prefs);
00591                                 be_app->PostMessage(&msg);
00592                         }
00593                         PostMessage(B_QUIT_REQUESTED);
00594                         break;
00595 
00596                 case MSG_SPRITES_ON:
00597                         prefs->SpritesOn = !prefs->SpritesOn;
00598                         break;
00599 
00600                 case MSG_SPRITE_COLLISIONS:
00601                         prefs->SpriteCollisions = !prefs->SpriteCollisions;
00602                         break;
00603 
00604                 case MSG_JOYSTICK_1_ON:
00605                         prefs->Joystick1On = !prefs->Joystick1On;
00606                         break;
00607 
00608                 case MSG_JOYSTICK_2_ON:
00609                         prefs->Joystick2On = !prefs->Joystick2On;
00610                         break;
00611 
00612                 case MSG_JOYSTICK_SWAP:
00613                         prefs->JoystickSwap = !prefs->JoystickSwap;
00614                         break;
00615 
00616                 case MSG_LIMIT_SPEED:
00617                         prefs->LimitSpeed = !prefs->LimitSpeed;
00618                         break;
00619 
00620                 case MSG_FAST_RESET:
00621                         prefs->FastReset = !prefs->FastReset;
00622                         break;
00623 
00624                 case MSG_CIA_IRQ_HACK:
00625                         prefs->CIAIRQHack = !prefs->CIAIRQHack;
00626                         break;
00627 
00628                 case MSG_SID_FILTERS:
00629                         prefs->SIDFilters = !prefs->SIDFilters;
00630                         break;
00631 
00632                 case MSG_DOUBLE_SCAN:
00633                         prefs->DoubleScan = !prefs->DoubleScan;
00634                         break;
00635 
00636                 case MSG_SID_TYPE:
00637                         prefs->SIDType = msg->FindInt32("index");
00638                         break;
00639 
00640                 case MSG_REU_SIZE:
00641                         prefs->REUSize = msg->FindInt32("index");
00642                         break;
00643 
00644                 case MSG_DISPLAY_TYPE:
00645                         prefs->DisplayType = msg->FindInt32("index");
00646                         g_double_scan->SetEnabled(prefs->DisplayType == DISPTYPE_SCREEN);
00647                         break;
00648 
00649                 case MSG_MAP_SLASH:
00650                         prefs->MapSlash = !prefs->MapSlash;
00651                         break;
00652 
00653                 case MSG_EMUL_1541_PROC:
00654                         prefs->Emul1541Proc = !prefs->Emul1541Proc;
00655                         break;
00656 
00657                 case MSG_DRVTYPE_8:
00658                 case MSG_DRVTYPE_9:
00659                 case MSG_DRVTYPE_10:
00660                 case MSG_DRVTYPE_11:
00661                         prefs->DriveType[msg->what & 3] = msg->FindInt32("index");
00662                         break;
00663 
00664                 case MSG_GETDRIVE_8:
00665                 case MSG_GETDRIVE_9:
00666                 case MSG_GETDRIVE_10:
00667                 case MSG_GETDRIVE_11:
00668                         panel_drive_num = msg->what & 3;
00669                         file_panel->Hide();
00670                         dir_panel->Hide();
00671                         if (prefs->DriveType[panel_drive_num] == DRVTYPE_D64) {
00672                                 file_panel->Window()->SetTitle("Frodo: Select disk image file");
00673                                 file_panel->Show();
00674                         } else if (prefs->DriveType[panel_drive_num] == DRVTYPE_T64) {
00675                                 file_panel->Window()->SetTitle("Frodo: Select archive file");
00676                                 file_panel->Show();
00677                         } else
00678                                 dir_panel->Show();
00679                         break;
00680 
00681                 case MSG_DRIVE_PANEL_RETURNED:  {       // Drive path file panel returned
00682                         entry_ref the_ref;
00683                         BEntry the_entry;
00684                         if (msg->FindRef("refs", &the_ref) == B_NO_ERROR)
00685                                 if (the_entry.SetTo(&the_ref) == B_NO_ERROR) {
00686                                         BPath the_path;
00687                                         the_entry.GetPath(&the_path);
00688                                         strncpy(prefs->DrivePath[panel_drive_num], the_path.Path(), 255);
00689                                         prefs->DrivePath[panel_drive_num][255] = 0;
00690                                         set_values();
00691                                 }
00692                         break;
00693                 }
00694 
00695                 case MSG_OPEN:
00696                         open_panel->Show();
00697                         break;
00698 
00699                 case MSG_OPEN_PANEL_RETURNED: { // Open file panel returned
00700                         get_values();   // Useful if Load() is unsuccessful
00701 
00702                         entry_ref the_ref;
00703                         BEntry the_entry;
00704                         if (msg->FindRef("refs", &the_ref) == B_NO_ERROR)
00705                                 if (the_entry.SetTo(&the_ref) == B_NO_ERROR)
00706                                         if (the_entry.IsFile()) {
00707                                                 BPath the_path;
00708                                                 the_entry.GetPath(&the_path);
00709                                                 strncpy(prefs_path, the_path.Path(), 1023);
00710                                                 prefs_path[1023] = 0;
00711                                                 prefs->Load(prefs_path);
00712                                                 set_values();
00713                                         }
00714                 }
00715 
00716                 case MSG_SAVE:
00717                         get_values();
00718                         prefs->Save(prefs_path);
00719                         break;
00720 
00721                 case MSG_SAVE_AS:
00722                         save_panel->Show();
00723                         break;
00724 
00725                 case MSG_SAVE_PANEL_RETURNED: { // Save file panel returned
00726                         entry_ref the_ref;
00727                         BEntry the_entry;
00728                         if (msg->FindRef("directory", &the_ref) == B_NO_ERROR)
00729                                 if (the_entry.SetTo(&the_ref) == B_NO_ERROR) {
00730                                         BPath the_path;
00731                                         the_entry.GetPath(&the_path);
00732                                         strncpy(prefs_path, the_path.Path(), 1023);
00733                                         strncat(prefs_path, "/", 1023);
00734                                         strncat(prefs_path, msg->FindString("name"), 1023);
00735                                         prefs_path[1023] = 0;
00736                                         get_values();
00737                                         if (!prefs->Save(prefs_path))
00738                                                 ShowRequester("Couldn't save preferences.", "Too bad");
00739                                 }
00740                         break;
00741                 }
00742 
00743                 case MSG_REVERT:
00744                         get_values();   // Useful if Load() is unsuccessful
00745                         prefs->Load(prefs_path);
00746                         set_values();
00747                         break;
00748 
00749                 default:
00750                         BWindow::MessageReceived(msg);
00751         }
00752 }
00753 
00754 
00755 /*
00756  *  Intercept ESC key (works as clicking the Cancel button)
00757  */
00758 
00759 bool PrefsWindow::FilterKeyDown(uint32 *aChar, BView **target)
00760 {
00761         if (*aChar == B_ESCAPE) {
00762                 // Flash Cancel button
00763                 g_cancel->SetValue(B_CONTROL_ON);
00764                 snooze(100000.0);
00765                 PostMessage(MSG_CANCEL);
00766         }
00767         return true;
00768 }
00769 
00770 
00771 /*
00772  *  Quit requested
00773  */
00774 
00775 bool PrefsWindow::QuitRequested(void)
00776 {
00777         delete open_panel;
00778         delete save_panel;
00779         delete file_panel;
00780         delete dir_panel;
00781         return true;
00782 }

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