ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/prefs_editor_gtk.cpp
(Generate patch)

Comparing SheepShaver/src/Unix/prefs_editor_gtk.cpp (file contents):
Revision 1.12 by gbeauche, 2005-03-19T09:35:01Z vs.
Revision 1.13 by gbeauche, 2005-03-27T22:32:46Z

# Line 39 | Line 39
39   // Global variables
40   static GtkWidget *win;                          // Preferences window
41   static bool start_clicked = true;       // Return value of PrefsEditor() function
42 + static int screen_width, screen_height; // Screen dimensions
43  
44  
45   // Prototypes
# Line 293 | Line 294 | static GtkItemFactoryEntry menu_items[]
294  
295   bool PrefsEditor(void)
296   {
297 +        // Get screen dimensions
298 +        screen_width = gdk_screen_width();
299 +        screen_height = gdk_screen_height();
300 +
301          // Create window
302          win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
303          gtk_window_set_title(GTK_WINDOW(win), GetString(STR_PREFS_TITLE));
# Line 554 | Line 559 | static void create_jit_pane(GtkWidget *t
559   *  "Graphics/Sound" pane
560   */
561  
562 < static GtkWidget *w_frameskip;
562 > // Display types
563 > enum {
564 >        DISPLAY_WINDOW,
565 >        DISPLAY_SCREEN
566 > };
567 >
568 > static GtkWidget *w_frameskip, *w_display_x, *w_display_y;
569 > static GtkWidget *l_frameskip, *l_display_x, *l_display_y;
570 > static int display_type;
571 > static int dis_width, dis_height;
572  
573   static GtkWidget *w_dspdevice_file, *w_mixerdevice_file;
574  
575 + // Hide/show graphics widgets
576 + static void hide_show_graphics_widgets(void)
577 + {
578 +        switch (display_type) {
579 +                case DISPLAY_WINDOW:
580 +                        gtk_widget_show(w_frameskip); gtk_widget_show(l_frameskip);
581 +                        break;
582 +                case DISPLAY_SCREEN:
583 +                        gtk_widget_hide(w_frameskip); gtk_widget_hide(l_frameskip);
584 +                        break;
585 +        }
586 + }
587 +
588 + // "Window" video type selected
589 + static void mn_window(...)
590 + {
591 +        display_type = DISPLAY_WINDOW;
592 +        hide_show_graphics_widgets();
593 + }
594 +
595 + // "Fullscreen" video type selected
596 + static void mn_fullscreen(...)
597 + {
598 +        display_type = DISPLAY_SCREEN;
599 +        hide_show_graphics_widgets();
600 + }
601 +
602   // "5 Hz".."60Hz" selected
603   static void mn_5hz(...) {PrefsReplaceInt32("frameskip", 12);}
604   static void mn_7hz(...) {PrefsReplaceInt32("frameskip", 8);}
# Line 572 | Line 613 | static void tb_gfxaccel(GtkWidget *widge
613          PrefsReplaceBool("gfxaccel", GTK_TOGGLE_BUTTON(widget)->active);
614   }
615  
575 // Video modes
576 static void tb_w640x480(GtkWidget *widget)
577 {
578        if (GTK_TOGGLE_BUTTON(widget)->active)
579                PrefsReplaceInt32("windowmodes", PrefsFindInt32("windowmodes") | 1);
580        else
581                PrefsReplaceInt32("windowmodes", PrefsFindInt32("windowmodes") & ~1);
582 }
583
584 static void tb_w800x600(GtkWidget *widget)
585 {
586        if (GTK_TOGGLE_BUTTON(widget)->active)
587                PrefsReplaceInt32("windowmodes", PrefsFindInt32("windowmodes") | 2);
588        else
589                PrefsReplaceInt32("windowmodes", PrefsFindInt32("windowmodes") & ~2);
590 }
591
592 static void tb_fs640x480(GtkWidget *widget)
593 {
594        if (GTK_TOGGLE_BUTTON(widget)->active)
595                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 1);
596        else
597                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~1);
598 }
599
600 static void tb_fs800x600(GtkWidget *widget)
601 {
602        if (GTK_TOGGLE_BUTTON(widget)->active)
603                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 2);
604        else
605                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~2);
606 }
607
608 static void tb_fs1024x768(GtkWidget *widget)
609 {
610        if (GTK_TOGGLE_BUTTON(widget)->active)
611                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 4);
612        else
613                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~4);
614 }
615
616 static void tb_fs1152x768(GtkWidget *widget)
617 {
618        if (GTK_TOGGLE_BUTTON(widget)->active)
619                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 64);
620        else
621                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~64);
622 }
623
624 static void tb_fs1152x900(GtkWidget *widget)
625 {
626        if (GTK_TOGGLE_BUTTON(widget)->active)
627                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 8);
628        else
629                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~8);
630 }
631
632 static void tb_fs1280x1024(GtkWidget *widget)
633 {
634        if (GTK_TOGGLE_BUTTON(widget)->active)
635                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 16);
636        else
637                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~16);
638 }
639
640 static void tb_fs1600x1200(GtkWidget *widget)
641 {
642        if (GTK_TOGGLE_BUTTON(widget)->active)
643                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 32);
644        else
645                PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~32);
646 }
647
616   // Set sensitivity of widgets
617   static void set_graphics_sensitive(void)
618   {
# Line 660 | Line 628 | static void tb_nosound(GtkWidget *widget
628          set_graphics_sensitive();
629   }
630  
631 + // Read and convert graphics preferences
632 + static void parse_graphics_prefs(void)
633 + {
634 +        display_type = DISPLAY_WINDOW;
635 +        dis_width = 640;
636 +        dis_height = 480;
637 +
638 +        const char *str = PrefsFindString("screen");
639 +        if (str) {
640 +                if (sscanf(str, "win/%d/%d", &dis_width, &dis_height) == 2)
641 +                        display_type = DISPLAY_WINDOW;
642 +                else if (sscanf(str, "dga/%d/%d", &dis_width, &dis_height) == 2)
643 +                        display_type = DISPLAY_SCREEN;
644 +        }
645 +        else {
646 +                uint32 window_modes = PrefsFindInt32("windowmodes");
647 +                uint32 screen_modes = PrefsFindInt32("screenmodes");
648 +                if (screen_modes) {
649 +                        display_type = DISPLAY_SCREEN;
650 +                        static const struct {
651 +                                int id;
652 +                                int width;
653 +                                int height;
654 +                        }
655 +                        modes[] = {
656 +                                {  1,    640,    480 },
657 +                                {  2,    800,    600 },
658 +                                {  4,   1024,    768 },
659 +                                { 64,   1152,    768 },
660 +                                {  8,   1152,    900 },
661 +                                { 16,   1280,   1024 },
662 +                                { 32,   1600,   1200 },
663 +                                { 0, }
664 +                        };
665 +                        for (int i = 0; modes[i].id != 0; i++) {
666 +                                if (screen_modes & modes[i].id) {
667 +                                        if (modes[i].width <= screen_width && modes[i].height <= screen_height) {
668 +                                                dis_width = modes[i].width;
669 +                                                dis_height = modes[i].height;
670 +                                        }
671 +                                }
672 +                        }
673 +                }
674 +                else if (window_modes) {
675 +                        display_type = DISPLAY_WINDOW;
676 +                        if (window_modes & 1)
677 +                                dis_width = 640, dis_height = 480;
678 +                        if (window_modes & 2)
679 +                                dis_width = 800, dis_height = 600;
680 +                }
681 +        }
682 +        if (dis_width == screen_width)
683 +                dis_width = 0;
684 +        if (dis_height == screen_height)
685 +                dis_height = 0;
686 + }
687 +
688   // Read settings from widgets and set preferences
689   static void read_graphics_settings(void)
690   {
691 +        const char *str;
692 +
693 +        str = gtk_entry_get_text(GTK_ENTRY(w_display_x));
694 +        dis_width = atoi(str);
695 +
696 +        str = gtk_entry_get_text(GTK_ENTRY(w_display_y));
697 +        dis_height = atoi(str);
698 +
699 +        char pref[256];
700 +        switch (display_type) {
701 +                case DISPLAY_WINDOW:
702 +                        sprintf(pref, "win/%d/%d", dis_width, dis_height);
703 +                        break;
704 +                case DISPLAY_SCREEN:
705 +                        sprintf(pref, "dga/%d/%d", dis_width, dis_height);
706 +                        break;
707 +                default:
708 +                        PrefsRemoveItem("screen");
709 +                        return;
710 +        }
711 +        PrefsReplaceString("screen", pref);
712 +
713          PrefsReplaceString("dsp", get_file_entry_path(w_dspdevice_file));
714          PrefsReplaceString("mixer", get_file_entry_path(w_mixerdevice_file));
715   }
# Line 670 | Line 717 | static void read_graphics_settings(void)
717   // Create "Graphics/Sound" pane
718   static void create_graphics_pane(GtkWidget *top)
719   {
720 <        GtkWidget *box, *vbox, *frame;
720 >        GtkWidget *box, *table, *label, *opt, *menu, *combo;
721 >        char str[32];
722 >
723 >        parse_graphics_prefs();
724  
725          box = make_pane(top, STR_GRAPHICS_SOUND_PANE_TITLE);
726 +        table = make_table(box, 2, 4);
727  
728 <        static const opt_desc options[] = {
729 <                {STR_REF_5HZ_LAB, GTK_SIGNAL_FUNC(mn_5hz)},
730 <                {STR_REF_7_5HZ_LAB, GTK_SIGNAL_FUNC(mn_7hz)},
731 <                {STR_REF_10HZ_LAB, GTK_SIGNAL_FUNC(mn_10hz)},
732 <                {STR_REF_15HZ_LAB, GTK_SIGNAL_FUNC(mn_15hz)},
733 <                {STR_REF_30HZ_LAB, GTK_SIGNAL_FUNC(mn_30hz)},
734 <                {STR_REF_60HZ_LAB, GTK_SIGNAL_FUNC(mn_60hz)},
735 <                {0, NULL}
736 <        };
737 <        int frameskip = PrefsFindInt32("frameskip"), active = 0;
738 <        switch (frameskip) {
739 <                case 12: active = 0; break;
740 <                case 8: active = 1; break;
741 <                case 6: active = 2; break;
742 <                case 4: active = 3; break;
743 <                case 2: active = 4; break;
693 <                case 1: active = 5; break;
728 >        label = gtk_label_new(GetString(STR_VIDEO_TYPE_CTRL));
729 >        gtk_widget_show(label);
730 >        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
731 >
732 >        opt = gtk_option_menu_new();
733 >        gtk_widget_show(opt);
734 >        menu = gtk_menu_new();
735 >        add_menu_item(menu, STR_WINDOW_CTRL, GTK_SIGNAL_FUNC(mn_window));
736 >        add_menu_item(menu, STR_FULLSCREEN_CTRL, GTK_SIGNAL_FUNC(mn_fullscreen));
737 >        switch (display_type) {
738 >                case DISPLAY_WINDOW:
739 >                        gtk_menu_set_active(GTK_MENU(menu), 0);
740 >                        break;
741 >                case DISPLAY_SCREEN:
742 >                        gtk_menu_set_active(GTK_MENU(menu), 1);
743 >                        break;
744          }
745 <        w_frameskip = make_option_menu(box, STR_FRAMESKIP_CTRL, options, active);
745 >        gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu);
746 >        gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 0, 1, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
747  
748 <        make_checkbox(box, STR_GFXACCEL_CTRL, PrefsFindBool("gfxaccel"), GTK_SIGNAL_FUNC(tb_gfxaccel));
748 >        l_frameskip = gtk_label_new(GetString(STR_FRAMESKIP_CTRL));
749 >        gtk_widget_show(l_frameskip);
750 >        gtk_table_attach(GTK_TABLE(table), l_frameskip, 0, 1, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
751  
752 <        frame = gtk_frame_new (GetString(STR_VIDEO_MODE_CTRL));
753 <        gtk_widget_show(frame);
754 <        gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 0);
752 >        w_frameskip = gtk_option_menu_new();
753 >        gtk_widget_show(w_frameskip);
754 >        menu = gtk_menu_new();
755 >        add_menu_item(menu, STR_REF_5HZ_LAB, GTK_SIGNAL_FUNC(mn_5hz));
756 >        add_menu_item(menu, STR_REF_7_5HZ_LAB, GTK_SIGNAL_FUNC(mn_7hz));
757 >        add_menu_item(menu, STR_REF_10HZ_LAB, GTK_SIGNAL_FUNC(mn_10hz));
758 >        add_menu_item(menu, STR_REF_15HZ_LAB, GTK_SIGNAL_FUNC(mn_15hz));
759 >        add_menu_item(menu, STR_REF_30HZ_LAB, GTK_SIGNAL_FUNC(mn_30hz));
760 >        add_menu_item(menu, STR_REF_60HZ_LAB, GTK_SIGNAL_FUNC(mn_60hz));
761 >        int frameskip = PrefsFindInt32("frameskip");
762 >        int item = -1;
763 >        switch (frameskip) {
764 >                case 12: item = 0; break;
765 >                case 8: item = 1; break;
766 >                case 6: item = 2; break;
767 >                case 4: item = 3; break;
768 >                case 2: item = 4; break;
769 >                case 1: item = 5; break;
770 >                case 0: item = 5; break;
771 >        }
772 >        if (item >= 0)
773 >                gtk_menu_set_active(GTK_MENU(menu), item);
774 >        gtk_option_menu_set_menu(GTK_OPTION_MENU(w_frameskip), menu);
775 >        gtk_table_attach(GTK_TABLE(table), w_frameskip, 1, 2, 1, 2, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
776 >
777 >        l_display_x = gtk_label_new(GetString(STR_DISPLAY_X_CTRL));
778 >        gtk_widget_show(l_display_x);
779 >        gtk_table_attach(GTK_TABLE(table), l_display_x, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
780 >
781 >        combo = gtk_combo_new();
782 >        gtk_widget_show(combo);
783 >        GList *glist1 = NULL;
784 >        glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_512_LAB));
785 >        glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_640_LAB));
786 >        glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_800_LAB));
787 >        glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_1024_LAB));
788 >        glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_MAX_LAB));
789 >        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist1);
790 >        if (dis_width)
791 >                sprintf(str, "%d", dis_width);
792 >        else
793 >                strcpy(str, GetString(STR_SIZE_MAX_LAB));
794 >        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
795 >        gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 2, 3, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
796 >        w_display_x = GTK_COMBO(combo)->entry;
797 >
798 >        l_display_y = gtk_label_new(GetString(STR_DISPLAY_Y_CTRL));
799 >        gtk_widget_show(l_display_y);
800 >        gtk_table_attach(GTK_TABLE(table), l_display_y, 0, 1, 3, 4, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
801 >
802 >        combo = gtk_combo_new();
803 >        gtk_widget_show(combo);
804 >        GList *glist2 = NULL;
805 >        glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_384_LAB));
806 >        glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_480_LAB));
807 >        glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_600_LAB));
808 >        glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_768_LAB));
809 >        glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_MAX_LAB));
810 >        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist2);
811 >        if (dis_height)
812 >                sprintf(str, "%d", dis_height);
813 >        else
814 >                strcpy(str, GetString(STR_SIZE_MAX_LAB));
815 >        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
816 >        gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 3, 4, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
817 >        w_display_y = GTK_COMBO(combo)->entry;
818  
819 <        vbox = gtk_vbox_new(FALSE, 4);
704 <        gtk_widget_show(vbox);
705 <        gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
706 <        gtk_container_add(GTK_CONTAINER(frame), vbox);
707 <
708 <        make_checkbox(vbox, STR_W_640x480_CTRL, PrefsFindInt32("windowmodes") & 1, GTK_SIGNAL_FUNC(tb_w640x480));
709 <        make_checkbox(vbox, STR_W_800x600_CTRL, PrefsFindInt32("windowmodes") & 2, GTK_SIGNAL_FUNC(tb_w800x600));
710 <        make_checkbox(vbox, STR_640x480_CTRL, PrefsFindInt32("screenmodes") & 1, GTK_SIGNAL_FUNC(tb_fs640x480));
711 <        make_checkbox(vbox, STR_800x600_CTRL, PrefsFindInt32("screenmodes") & 2, GTK_SIGNAL_FUNC(tb_fs800x600));
712 <        make_checkbox(vbox, STR_1024x768_CTRL, PrefsFindInt32("screenmodes") & 4, GTK_SIGNAL_FUNC(tb_fs1024x768));
713 <        make_checkbox(vbox, STR_1152x768_CTRL, PrefsFindInt32("screenmodes") & 64, GTK_SIGNAL_FUNC(tb_fs1152x768));
714 <        make_checkbox(vbox, STR_1152x900_CTRL, PrefsFindInt32("screenmodes") & 8, GTK_SIGNAL_FUNC(tb_fs1152x900));
715 <        make_checkbox(vbox, STR_1280x1024_CTRL, PrefsFindInt32("screenmodes") & 16, GTK_SIGNAL_FUNC(tb_fs1280x1024));
716 <        make_checkbox(vbox, STR_1600x1200_CTRL, PrefsFindInt32("screenmodes") & 32, GTK_SIGNAL_FUNC(tb_fs1600x1200));
819 >        make_checkbox(box, STR_GFXACCEL_CTRL, PrefsFindBool("gfxaccel"), GTK_SIGNAL_FUNC(tb_gfxaccel));
820  
821          make_separator(box);
822          make_checkbox(box, STR_NOSOUND_CTRL, "nosound", GTK_SIGNAL_FUNC(tb_nosound));
# Line 721 | Line 824 | static void create_graphics_pane(GtkWidg
824          w_mixerdevice_file = make_entry(box, STR_MIXERDEVICE_FILE_CTRL, "mixer");
825  
826          set_graphics_sensitive();
827 +
828 +        hide_show_graphics_widgets();
829   }
830  
831  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines