ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Prefs_Be.h
Revision: 1.6
Committed: 2005-06-27T19:55:48Z (18 years, 9 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: VERSION_4_2, HEAD
Changes since 1.5: +1 -1 lines
Log Message:
updated copyright dates

File Contents

# Content
1 /*
2 * Prefs_Be.h - Global preferences, Be specific stuff
3 *
4 * Frodo (C) 1994-1997,2002-2005 Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <InterfaceKit.h>
22 #include <StorageKit.h>
23 #include <Path.h>
24
25
26 // Special colors
27 const rgb_color light_color = {255, 255, 255, 0};
28 const rgb_color fill_color = {216, 216, 216, 0};
29 const rgb_color dark_color = {184, 184, 184, 0};
30
31
32 // Window thread messages
33 const uint32 MSG_OK = 'okok';
34 const uint32 MSG_CANCEL = 'cncl';
35 const uint32 MSG_SPRITES_ON = 'spon';
36 const uint32 MSG_SPRITE_COLLISIONS = 'scol';
37 const uint32 MSG_JOYSTICK_1_PORT = 'joy1';
38 const uint32 MSG_JOYSTICK_2_PORT = 'joy2';
39 const uint32 MSG_JOYSTICK_SWAP = 'jswp';
40 const uint32 MSG_LIMIT_SPEED = 'lmit';
41 const uint32 MSG_FAST_RESET = 'frst';
42 const uint32 MSG_CIA_IRQ_HACK = 'cirq';
43 const uint32 MSG_SID_FILTERS = 'filt';
44 const uint32 MSG_DOUBLE_SCAN = 'dbls';
45 const uint32 MSG_MAP_SLASH = 'mpsl';
46 const uint32 MSG_EMUL_1541_PROC = '15pr';
47 const uint32 MSG_GETDRIVE_8 = 'gtd8';
48 const uint32 MSG_GETDRIVE_9 = 'gtd9';
49 const uint32 MSG_GETDRIVE_10 = 'gtd:';
50 const uint32 MSG_GETDRIVE_11 = 'gtd;';
51 const uint32 MSG_DRIVE_PANEL_RETURNED = 'gdr8';
52 const uint32 MSG_SID_TYPE = 'sidt';
53 const uint32 MSG_REU_SIZE = 'reus';
54 const uint32 MSG_DISPLAY_TYPE = 'dspt';
55
56 const uint32 MSG_OPEN = 'open';
57 const uint32 MSG_SAVE = 'save';
58 const uint32 MSG_SAVE_AS = 'svas';
59 const uint32 MSG_REVERT = 'rvrt';
60 const uint32 MSG_OPEN_PANEL_RETURNED = 'oprt';
61 const uint32 MSG_SAVE_PANEL_RETURNED = 'svrt';
62
63
64 /*
65 * Preferences window class
66 */
67
68 class NumberControl;
69 class PathControl;
70
71 class PrefsWindow : public BWindow {
72 public:
73 PrefsWindow(Prefs *p, bool start, char *path);
74 virtual void MessageReceived(BMessage *msg);
75 virtual bool QuitRequested(void);
76 virtual bool FilterKeyDown(uint32 *aChar, BView **target);
77
78 private:
79 BCheckBox *make_checkbox(BRect frame, char *label, uint32 what, BView *parent);
80 NumberControl *make_number_entry(BRect frame, char *label_text, BView *parent);
81 PathControl *make_path_entry(BRect frame, char *label, BView *parent);
82 BPopUpMenu *make_sidtype_popup(BRect frame, char *label_text, uint32 what, BView *parent);
83 BPopUpMenu *make_reusize_popup(BRect frame, char *label_text, uint32 what, BView *parent);
84 BPopUpMenu *make_disptype_popup(BRect frame, char *label_text, uint32 what, BView *parent);
85 BPopUpMenu *make_joystick_popup(BRect frame, char *label_text, uint32 what, BView *parent);
86 void set_values(void);
87 void get_values(void);
88 void ghost_controls(void);
89
90 Prefs *prefs;
91
92 BMessenger this_messenger;
93 BFilePanel *open_panel; // For opening prefs
94 BFilePanel *save_panel; // For saving prefs
95 BFilePanel *file_panel; // For D64/T64 drives
96 BFilePanel *dir_panel; // For directory drives
97 int panel_drive_num; // Drive number (0..3) of the file panel
98
99 BButton *g_ok;
100 BButton *g_cancel;
101 NumberControl *g_normal_cycles;
102 NumberControl *g_bad_line_cycles;
103 NumberControl *g_cia_cycles;
104 NumberControl *g_floppy_cycles;
105 NumberControl *g_skip_frames;
106 PathControl *g_drive_path[4];
107 BPopUpMenu *g_sid_type;
108 BPopUpMenu *g_reu_size;
109 BPopUpMenu *g_display_type;
110 BPopUpMenu *g_joystick_1_port;
111 BPopUpMenu *g_joystick_2_port;
112 BCheckBox *g_sprites_on;
113 BCheckBox *g_sprite_collisions;
114 BCheckBox *g_joystick_swap;
115 BCheckBox *g_limit_speed;
116 BCheckBox *g_fast_reset;
117 BCheckBox *g_cia_irq_hack;
118 BCheckBox *g_sid_filters;
119 BCheckBox *g_double_scan;
120 BCheckBox *g_map_slash;
121 BCheckBox *g_emul_1541_proc;
122
123 char *prefs_path;
124 bool startup;
125 };
126
127
128 /*
129 * Start preferences editor (asynchronously)
130 * startup = false: Send MSG_PREFS_DONE to application on close
131 * startup = true : Send MSG_STARTUP to application on close if not canceled,
132 * B_QUIT_REQUESTED otherwise
133 * prefs_name points to the file name of the preferences (which may be changed)
134 */
135
136 bool Prefs::ShowEditor(bool startup, char *prefs_name)
137 {
138 PrefsWindow *win = new PrefsWindow(this, startup, prefs_name);
139 win->Show();
140 return true;
141 }
142
143
144 /*
145 * Number-only BTextControl
146 */
147
148 // Class definition
149 class NumberControl : public BTextControl {
150 public:
151 NumberControl(BRect frame, float divider, const char *name, const char *label, const char *text, BMessage *message);
152 void SetValue(long value);
153 long Value(void);
154 };
155
156 // Constructor: Allow only digits
157 NumberControl::NumberControl(BRect frame, float divider, const char *name, const char *label, const char *text, BMessage *message)
158 : BTextControl(frame, name, label, text, message, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
159 {
160 SetDivider(divider);
161 for (int c=0; c<256; c++)
162 if (!isdigit(c) && c != B_BACKSPACE && c != B_LEFT_ARROW && c != B_RIGHT_ARROW)
163 ((BTextView *)ChildAt(0))->DisallowChar(c);
164 }
165
166 // Set integer value
167 void NumberControl::SetValue(long value)
168 {
169 char str[32];
170 sprintf(str, "%ld", value);
171 SetText(str);
172 }
173
174 // Get integer value
175 long NumberControl::Value(void)
176 {
177 return atol(Text());
178 }
179
180
181 /*
182 * Path-entry BTextControl
183 */
184
185 // Class definition
186 class PathControl : public BTextControl {
187 public:
188 PathControl(BRect frame, float divider, const char *name, const char *label, const char *text, BMessage *message);
189 virtual void MessageReceived(BMessage *msg);
190 };
191
192 // Constructor: Disable some keys
193 PathControl::PathControl(BRect frame, float divider, const char *name, const char *label, const char *text, BMessage *message)
194 : BTextControl(frame, name, label, text, message, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
195 {
196 SetDivider(divider);
197 for (int c=0; c<' '; c++)
198 if (c != B_BACKSPACE && c != B_LEFT_ARROW && c != B_RIGHT_ARROW)
199 ((BTextView *)ChildAt(0))->DisallowChar(c);
200 }
201
202 // Message received: Look out for dropped refs
203 void PathControl::MessageReceived(BMessage *msg)
204 {
205 if (msg->what == B_SIMPLE_DATA) {
206 entry_ref the_ref;
207 BEntry the_entry;
208
209 // First look for refs
210 if (msg->FindRef("refs", &the_ref) == B_NO_ERROR) {
211 if (the_entry.SetTo(&the_ref) == B_NO_ERROR) {
212 BPath the_path;
213 the_entry.GetPath(&the_path);
214 SetText(the_path.Path());
215 }
216 } else
217 BTextControl::MessageReceived(msg);
218
219 MakeFocus();
220 } else
221 BTextControl::MessageReceived(msg);
222 }
223
224
225 /*
226 * Open preferences window
227 */
228
229 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)
230 {
231 int i;
232 prefs = p;
233 startup = start;
234 prefs_path = path;
235
236 // Move window to right position
237 Lock();
238 MoveTo(80, 80);
239
240 // Set up menus
241 BMenuBar *bar = new BMenuBar(Bounds(), "");
242 BMenu *menu = new BMenu("Preferences");
243 BMenuItem *item;
244 menu->AddItem(item = new BMenuItem("About Frodo" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED)));
245 item->SetTarget(be_app);
246 menu->AddItem(new BSeparatorItem);
247 menu->AddItem(new BMenuItem("Open" B_UTF8_ELLIPSIS, new BMessage(MSG_OPEN), 'O'));
248 menu->AddItem(new BMenuItem("Save", new BMessage(MSG_SAVE), 'S'));
249 menu->AddItem(new BMenuItem("Save As" B_UTF8_ELLIPSIS, new BMessage(MSG_SAVE_AS), 'A'));
250 menu->AddItem(new BMenuItem("Revert", new BMessage(MSG_REVERT)));
251 menu->AddItem(new BSeparatorItem);
252 menu->AddItem(item = new BMenuItem("Quit Frodo", new BMessage(B_QUIT_REQUESTED), 'Q'));
253 item->SetTarget(be_app);
254 bar->AddItem(menu);
255 AddChild(bar);
256 SetKeyMenuBar(bar);
257 int mbar_height = int(bar->Frame().bottom) + 1;
258
259 // Resize window to fit menu bar
260 ResizeBy(0, mbar_height);
261
262 // Light gray background
263 BRect b = Bounds();
264 BView *top = new BView(BRect(0, mbar_height, b.right, b.bottom), "top", B_FOLLOW_NONE, B_WILL_DRAW);
265 AddChild(top);
266 top->SetViewColor(fill_color);
267
268 // Checkboxes
269 g_sprites_on = make_checkbox(BRect(10, 10, 180, 21), "Sprite display", MSG_SPRITES_ON, top);
270 g_sprite_collisions = make_checkbox(BRect(10, 25, 180, 36), "Sprite collisions", MSG_SPRITE_COLLISIONS, top);
271 g_limit_speed = make_checkbox(BRect(10, 40, 180, 51), "Limit speed", MSG_LIMIT_SPEED, top);
272 g_fast_reset = make_checkbox(BRect(10, 55, 180, 66), "Fast reset", MSG_FAST_RESET, top);
273 g_cia_irq_hack = make_checkbox(BRect(10, 70, 180, 81), "Clear CIA ICR on write", MSG_CIA_IRQ_HACK, top);
274 g_sid_filters = make_checkbox(BRect(10, 85, 180, 96), "SID filters", MSG_SID_FILTERS, top);
275 g_double_scan = make_checkbox(BRect(10, 100, 180, 111), "Doublescan lines", MSG_DOUBLE_SCAN, top);
276 g_joystick_swap = make_checkbox(BRect(10, 115, 180, 126), "Swap joysticks", MSG_JOYSTICK_SWAP, top);
277 g_joystick_1_port = make_joystick_popup(BRect(10, 130, 180, 145), "Joystick 1", MSG_JOYSTICK_1_PORT, top);
278 g_joystick_2_port = make_joystick_popup(BRect(10, 150, 180, 165), "Joystick 2", MSG_JOYSTICK_2_PORT, top);
279
280 // Number entry fields
281 g_normal_cycles = make_number_entry(BRect(180, 10, 390, 26), "Cycles per line (CPU)", top);
282 g_bad_line_cycles = make_number_entry(BRect(180, 30, 390, 46), "Cycles per Bad Line (CPU)", top);
283 g_cia_cycles = make_number_entry(BRect(180, 50, 390, 66), "Cycles per line (CIA)", top);
284 g_floppy_cycles = make_number_entry(BRect(180, 70, 390, 86), "Cycles per line (1541)", top);
285 g_skip_frames = make_number_entry(BRect(180, 90, 390, 106), "Draw every n-th frame", top);
286
287 // Popup fields
288 g_display_type = make_disptype_popup(BRect(180, 110, 390, 126), "Display type", MSG_DISPLAY_TYPE, top);
289 g_sid_type = make_sidtype_popup(BRect(180, 130, 390, 146), "SID emulation type", MSG_SID_TYPE, top);
290 g_reu_size = make_reusize_popup(BRect(180, 150, 390, 166), "REU size", MSG_REU_SIZE, top);
291
292 // Prepare on/off pictures for file panel buttons
293 BView *view = new BView(BRect(0, 0, 19, 15), "", B_FOLLOW_NONE, 0);
294 AddChild(view);
295 view->SetViewColor(fill_color);
296
297 view->BeginPicture(new BPicture);
298 view->SetHighColor(fill_color);
299 view->FillRect(BRect(0, 0, 19, 15));
300 view->SetHighColor(light_color);
301 view->StrokeRect(BRect(0, 0, 18, 0));
302 view->StrokeRect(BRect(0, 0, 0, 14));
303 view->SetHighColor(dark_color);
304 view->StrokeRect(BRect(0, 15, 19, 15));
305 view->StrokeRect(BRect(19, 0, 19, 15));
306 view->SetFont(be_plain_font);
307 view->SetHighColor(0, 0, 0);
308 view->SetLowColor(fill_color);
309 view->MovePenTo(7, 11);
310 view->DrawString("B");
311 BPicture *on = view->EndPicture();
312
313 view->BeginPicture(new BPicture);
314 view->SetHighColor(dark_color);
315 view->FillRect(BRect(0, 0, 19, 15));
316 view->SetHighColor(128, 128, 128);
317 view->StrokeRect(BRect(0, 0, 18, 0));
318 view->StrokeRect(BRect(0, 0, 0, 14));
319 view->SetHighColor(light_color);
320 view->StrokeRect(BRect(0, 15, 19, 15));
321 view->StrokeRect(BRect(19, 0, 19, 15));
322 view->SetFont(be_plain_font);
323 view->SetHighColor(0, 0, 0);
324 view->SetLowColor(dark_color);
325 view->MovePenTo(7, 11);
326 view->DrawString("B");
327 BPicture *off = view->EndPicture();
328
329 RemoveChild(view);
330 delete view;
331
332 // Drive settings
333 BBox *drvbox = new BBox(BRect(10, 173, 390, 304));
334 top->AddChild(drvbox);
335 drvbox->SetViewColor(fill_color);
336 drvbox->SetLowColor(fill_color);
337 drvbox->SetLabel("Drives");
338
339 for (i=0; i<4; i++) {
340 char str[4];
341 sprintf(str, "%d", i+8);
342 g_drive_path[i] = make_path_entry(BRect(10, 14+i*20, 299, 30+i*20), str, drvbox);
343 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)));
344 }
345
346 g_map_slash = make_checkbox(BRect(10, 94, 300, 110), "Map '/'<->'\\' in filenames", MSG_MAP_SLASH, drvbox);
347 g_emul_1541_proc = make_checkbox(BRect(10, 109, 300, 125), "Enable 1541 processor emulation", MSG_EMUL_1541_PROC, drvbox);
348
349 // "OK" button
350 top->AddChild(g_ok = new BButton(BRect(20, 315, 90, 340), "", startup ? "Start" : "OK", new BMessage(MSG_OK)));
351 SetDefaultButton(g_ok);
352
353 // "Cancel" button
354 top->AddChild(g_cancel = new BButton(BRect(b.right-90, 315, b.right-20, 340), "", startup ? "Quit" : "Cancel", new BMessage(MSG_CANCEL)));
355
356 // Set the values of all controls to reflect the preferences
357 set_values();
358 g_normal_cycles->MakeFocus();
359
360 // Create file panels
361 open_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_OPEN_PANEL_RETURNED));
362 open_panel->Window()->SetTitle("Frodo: Open preferences");
363 save_panel = new BFilePanel(B_SAVE_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_SAVE_PANEL_RETURNED));
364 save_panel->Window()->SetTitle("Frodo: Save preferences");
365 file_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_DRIVE_PANEL_RETURNED));
366 file_panel->SetPanelDirectory(&AppDirectory);
367 file_panel->Window()->SetTitle("Frodo: Select disk image or archive file");
368 dir_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, B_DIRECTORY_NODE, false, new BMessage(MSG_DRIVE_PANEL_RETURNED));
369 dir_panel->SetPanelDirectory(&AppDirectory);
370 dir_panel->Window()->SetTitle("Frodo: Select directory");
371 dir_panel->SetButtonLabel(B_DEFAULT_BUTTON, "Select");
372
373 Unlock();
374 }
375
376
377 /*
378 * Create checkbox
379 */
380
381 BCheckBox *PrefsWindow::make_checkbox(BRect frame, char *label, uint32 what, BView *parent)
382 {
383 BCheckBox *checkbox = new BCheckBox(frame, "", label, new BMessage(what));
384 parent->AddChild(checkbox);
385 return checkbox;
386 }
387
388
389 /*
390 * Create number entry field
391 */
392
393 NumberControl *PrefsWindow::make_number_entry(BRect frame, char *label_text, BView *parent)
394 {
395 NumberControl *num = new NumberControl(frame, frame.right-frame.left-55, "", label_text, NULL, NULL);
396 parent->AddChild(num);
397
398 num->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_RIGHT);
399 num->SetFont(be_plain_font);
400 num->ChildAt(0)->SetFont(be_plain_font);
401
402 return num;
403 }
404
405
406 /*
407 * Create path entry field
408 */
409
410 PathControl *PrefsWindow::make_path_entry(BRect frame, char *label, BView *parent)
411 {
412 PathControl *path = new PathControl(frame, 16, "", label, NULL, NULL);
413 parent->AddChild(path);
414
415 path->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
416 path->SetFont(be_plain_font);
417 path->ChildAt(0)->SetFont(be_plain_font);
418 ((BTextView *)(path->ChildAt(0)))->SetMaxBytes(255);
419
420 return path;
421 }
422
423
424 /*
425 * Create display type popup
426 */
427
428 BPopUpMenu *PrefsWindow::make_disptype_popup(BRect frame, char *label_text, uint32 what, BView *parent)
429 {
430 BPopUpMenu *popup = new BPopUpMenu("display_type popup", true, true);
431 popup->AddItem(new BMenuItem("Window", new BMessage(what)));
432 popup->AddItem(new BMenuItem("Screen", new BMessage(what)));
433 popup->SetTargetForItems(this);
434 BMenuField *menu_field = new BMenuField(frame, "display_type", label_text, popup);
435 menu_field->SetDivider(frame.Width()-75);
436 menu_field->SetAlignment(B_ALIGN_RIGHT);
437 parent->AddChild(menu_field);
438 return popup;
439 }
440
441
442 /*
443 * Create SID type popup
444 */
445
446 BPopUpMenu *PrefsWindow::make_sidtype_popup(BRect frame, char *label_text, uint32 what, BView *parent)
447 {
448 BPopUpMenu *popup = new BPopUpMenu("sid_type popup", true, true);
449 popup->AddItem(new BMenuItem("None", new BMessage(what)));
450 popup->AddItem(new BMenuItem("Digital", new BMessage(what)));
451 popup->SetTargetForItems(this);
452 BMenuField *menu_field = new BMenuField(frame, "sid_type", label_text, popup);
453 menu_field->SetDivider(frame.Width()-75);
454 menu_field->SetAlignment(B_ALIGN_RIGHT);
455 parent->AddChild(menu_field);
456 return popup;
457 }
458
459
460 /*
461 * Create REU size popup
462 */
463
464 BPopUpMenu *PrefsWindow::make_reusize_popup(BRect frame, char *label_text, uint32 what, BView *parent)
465 {
466 BPopUpMenu *popup = new BPopUpMenu("reu_size popup", true, true);
467 popup->AddItem(new BMenuItem("None", new BMessage(what)));
468 popup->AddItem(new BMenuItem("128K", new BMessage(what)));
469 popup->AddItem(new BMenuItem("256K", new BMessage(what)));
470 popup->AddItem(new BMenuItem("512K", new BMessage(what)));
471 popup->SetTargetForItems(this);
472 BMenuField *menu_field = new BMenuField(frame, "reu_size", label_text, popup);
473 menu_field->SetDivider(frame.Width()-75);
474 menu_field->SetAlignment(B_ALIGN_RIGHT);
475 parent->AddChild(menu_field);
476 return popup;
477 }
478
479
480 /*
481 * Create joystick port popup
482 */
483
484 BPopUpMenu *PrefsWindow::make_joystick_popup(BRect frame, char *label_text, uint32 what, BView *parent)
485 {
486 BPopUpMenu *popup = new BPopUpMenu("joystick popup", true, true);
487 popup->AddItem(new BMenuItem("None", new BMessage(what)));
488 popup->AddItem(new BMenuItem("Joystick Port 1", new BMessage(what)));
489 popup->AddItem(new BMenuItem("Joystick Port 2", new BMessage(what)));
490 popup->AddItem(new BMenuItem("GeekPort A", new BMessage(what)));
491 popup->AddItem(new BMenuItem("GeekPort B", new BMessage(what)));
492 popup->SetTargetForItems(this);
493 BMenuField *menu_field = new BMenuField(frame, "joystick", label_text, popup);
494 menu_field->SetDivider(60);
495 menu_field->SetAlignment(B_ALIGN_RIGHT);
496 parent->AddChild(menu_field);
497 return popup;
498 }
499
500
501 /*
502 * Set the values of the controls
503 */
504
505 void PrefsWindow::set_values(void)
506 {
507 prefs->Check();
508
509 g_normal_cycles->SetValue(prefs->NormalCycles);
510 g_bad_line_cycles->SetValue(prefs->BadLineCycles);
511 g_cia_cycles->SetValue(prefs->CIACycles);
512 g_floppy_cycles->SetValue(prefs->FloppyCycles);
513 g_skip_frames->SetValue(prefs->SkipFrames);
514
515 for (int i=0; i<4; i++)
516 g_drive_path[i]->SetText(prefs->DrivePath[i]);
517
518 g_sid_type->ItemAt(prefs->SIDType)->SetMarked(true);
519 g_reu_size->ItemAt(prefs->REUSize)->SetMarked(true);
520 g_display_type->ItemAt(prefs->DisplayType)->SetMarked(true);
521
522 g_sprites_on->SetValue(prefs->SpritesOn ? B_CONTROL_ON : B_CONTROL_OFF);
523 g_sprite_collisions->SetValue(prefs->SpriteCollisions ? B_CONTROL_ON : B_CONTROL_OFF);
524 g_joystick_1_port->ItemAt(prefs->Joystick1Port)->SetMarked(true);
525 g_joystick_2_port->ItemAt(prefs->Joystick2Port)->SetMarked(true);
526 g_joystick_swap->SetValue(prefs->JoystickSwap ? B_CONTROL_ON : B_CONTROL_OFF);
527 g_limit_speed->SetValue(prefs->LimitSpeed ? B_CONTROL_ON : B_CONTROL_OFF);
528 g_fast_reset->SetValue(prefs->FastReset ? B_CONTROL_ON : B_CONTROL_OFF);
529 g_cia_irq_hack->SetValue(prefs->CIAIRQHack ? B_CONTROL_ON : B_CONTROL_OFF);
530 g_sid_filters->SetValue(prefs->SIDFilters ? B_CONTROL_ON : B_CONTROL_OFF);
531 g_double_scan->SetValue(prefs->DoubleScan ? B_CONTROL_ON : B_CONTROL_OFF);
532
533 g_map_slash->SetValue(prefs->MapSlash ? B_CONTROL_ON : B_CONTROL_OFF);
534 g_emul_1541_proc->SetValue(prefs->Emul1541Proc ? B_CONTROL_ON : B_CONTROL_OFF);
535
536 ghost_controls();
537 }
538
539
540 /*
541 * Get the values of the controls
542 */
543
544 void PrefsWindow::get_values(void)
545 {
546 prefs->NormalCycles = g_normal_cycles->Value();
547 prefs->BadLineCycles = g_bad_line_cycles->Value();
548 prefs->CIACycles = g_cia_cycles->Value();
549 prefs->FloppyCycles = g_floppy_cycles->Value();
550 prefs->SkipFrames = g_skip_frames->Value();
551
552 for (int i=0; i<4; i++)
553 strcpy(prefs->DrivePath[i], g_drive_path[i]->Text());
554
555 prefs->Check();
556 }
557
558
559 /*
560 * Enable/disable certain controls
561 */
562
563 void PrefsWindow::ghost_controls(void)
564 {
565 g_normal_cycles->SetEnabled(!IsFrodoSC);
566 g_bad_line_cycles->SetEnabled(!IsFrodoSC);
567 g_cia_cycles->SetEnabled(!IsFrodoSC);
568 g_floppy_cycles->SetEnabled(!IsFrodoSC);
569 g_cia_irq_hack->SetEnabled(!IsFrodoSC);
570 g_double_scan->SetEnabled(prefs->DisplayType == DISPTYPE_SCREEN);
571 }
572
573
574 /*
575 * Message from controls/menus received
576 */
577
578 void PrefsWindow::MessageReceived(BMessage *msg)
579 {
580 switch (msg->what) {
581 case MSG_OK:
582 get_values();
583 if (startup)
584 be_app->PostMessage(MSG_STARTUP);
585 else {
586 BMessage msg(MSG_PREFS_DONE);
587 msg.AddBool("canceled", false);
588 msg.AddPointer("prefs", prefs);
589 be_app->PostMessage(&msg);
590 }
591 PostMessage(B_QUIT_REQUESTED);
592 break;
593
594 case MSG_CANCEL:
595 if (startup)
596 be_app->PostMessage(B_QUIT_REQUESTED);
597 else {
598 BMessage msg(MSG_PREFS_DONE);
599 msg.AddBool("canceled", true);
600 msg.AddPointer("prefs", prefs);
601 be_app->PostMessage(&msg);
602 }
603 PostMessage(B_QUIT_REQUESTED);
604 break;
605
606 case MSG_SPRITES_ON:
607 prefs->SpritesOn = !prefs->SpritesOn;
608 break;
609
610 case MSG_SPRITE_COLLISIONS:
611 prefs->SpriteCollisions = !prefs->SpriteCollisions;
612 break;
613
614 case MSG_JOYSTICK_1_PORT:
615 prefs->Joystick1Port = msg->FindInt32("index");
616 break;
617
618 case MSG_JOYSTICK_2_PORT:
619 prefs->Joystick2Port = msg->FindInt32("index");
620 break;
621
622 case MSG_JOYSTICK_SWAP:
623 prefs->JoystickSwap = !prefs->JoystickSwap;
624 break;
625
626 case MSG_LIMIT_SPEED:
627 prefs->LimitSpeed = !prefs->LimitSpeed;
628 break;
629
630 case MSG_FAST_RESET:
631 prefs->FastReset = !prefs->FastReset;
632 break;
633
634 case MSG_CIA_IRQ_HACK:
635 prefs->CIAIRQHack = !prefs->CIAIRQHack;
636 break;
637
638 case MSG_SID_FILTERS:
639 prefs->SIDFilters = !prefs->SIDFilters;
640 break;
641
642 case MSG_DOUBLE_SCAN:
643 prefs->DoubleScan = !prefs->DoubleScan;
644 break;
645
646 case MSG_SID_TYPE:
647 prefs->SIDType = msg->FindInt32("index");
648 break;
649
650 case MSG_REU_SIZE:
651 prefs->REUSize = msg->FindInt32("index");
652 break;
653
654 case MSG_DISPLAY_TYPE:
655 prefs->DisplayType = msg->FindInt32("index");
656 g_double_scan->SetEnabled(prefs->DisplayType == DISPTYPE_SCREEN);
657 break;
658
659 case MSG_MAP_SLASH:
660 prefs->MapSlash = !prefs->MapSlash;
661 break;
662
663 case MSG_EMUL_1541_PROC:
664 prefs->Emul1541Proc = !prefs->Emul1541Proc;
665 break;
666
667 case MSG_GETDRIVE_8:
668 case MSG_GETDRIVE_9:
669 case MSG_GETDRIVE_10:
670 case MSG_GETDRIVE_11:
671 panel_drive_num = msg->what & 3;
672 // file_panel->Hide();
673 // dir_panel->Hide();
674 file_panel->Show();
675 // dir_panel->Show();
676 break;
677
678 case MSG_DRIVE_PANEL_RETURNED: { // Drive path file panel returned
679 entry_ref the_ref;
680 BEntry the_entry;
681 if (msg->FindRef("refs", &the_ref) == B_NO_ERROR)
682 if (the_entry.SetTo(&the_ref) == B_NO_ERROR) {
683 BPath the_path;
684 the_entry.GetPath(&the_path);
685 strncpy(prefs->DrivePath[panel_drive_num], the_path.Path(), 255);
686 prefs->DrivePath[panel_drive_num][255] = 0;
687 set_values();
688 }
689 break;
690 }
691
692 case MSG_OPEN:
693 open_panel->Show();
694 break;
695
696 case MSG_OPEN_PANEL_RETURNED: { // Open file panel returned
697 get_values(); // Useful if Load() is unsuccessful
698
699 entry_ref the_ref;
700 BEntry the_entry;
701 if (msg->FindRef("refs", &the_ref) == B_NO_ERROR)
702 if (the_entry.SetTo(&the_ref) == B_NO_ERROR)
703 if (the_entry.IsFile()) {
704 BPath the_path;
705 the_entry.GetPath(&the_path);
706 strncpy(prefs_path, the_path.Path(), 1023);
707 prefs_path[1023] = 0;
708 prefs->Load(prefs_path);
709 set_values();
710 }
711 }
712
713 case MSG_SAVE:
714 get_values();
715 prefs->Save(prefs_path);
716 break;
717
718 case MSG_SAVE_AS:
719 save_panel->Show();
720 break;
721
722 case MSG_SAVE_PANEL_RETURNED: { // Save file panel returned
723 entry_ref the_ref;
724 BEntry the_entry;
725 if (msg->FindRef("directory", &the_ref) == B_NO_ERROR)
726 if (the_entry.SetTo(&the_ref) == B_NO_ERROR) {
727 BPath the_path;
728 the_entry.GetPath(&the_path);
729 strncpy(prefs_path, the_path.Path(), 1023);
730 strncat(prefs_path, "/", 1023);
731 strncat(prefs_path, msg->FindString("name"), 1023);
732 prefs_path[1023] = 0;
733 get_values();
734 if (!prefs->Save(prefs_path))
735 ShowRequester("Couldn't save preferences.", "Too bad");
736 }
737 break;
738 }
739
740 case MSG_REVERT:
741 get_values(); // Useful if Load() is unsuccessful
742 prefs->Load(prefs_path);
743 set_values();
744 break;
745
746 default:
747 BWindow::MessageReceived(msg);
748 }
749 }
750
751
752 /*
753 * Intercept ESC key (works as clicking the Cancel button)
754 */
755
756 bool PrefsWindow::FilterKeyDown(uint32 *aChar, BView **target)
757 {
758 if (*aChar == B_ESCAPE) {
759 // Flash Cancel button
760 g_cancel->SetValue(B_CONTROL_ON);
761 snooze(100000);
762 PostMessage(MSG_CANCEL);
763 }
764 return true;
765 }
766
767
768 /*
769 * Quit requested
770 */
771
772 bool PrefsWindow::QuitRequested(void)
773 {
774 delete open_panel;
775 delete save_panel;
776 delete file_panel;
777 delete dir_panel;
778 return true;
779 }