From 9b360ef2928bc2eff40f6165ee2aead424f7b901 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 10 Apr 2020 22:19:40 +0200 Subject: [PATCH] [GTK3] Add DMG color palettes --- gtk3/main.c | 11 +++++++- gtk3/main.h | 1 + gtk3/resources/ui/window.ui | 51 ++++++++++++++++++++++++++++++++----- gtk3/settings.c | 41 ++++++++++++++++++++++++++++- gtk3/settings.h | 4 +++ 5 files changed, 100 insertions(+), 8 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index 106541d..7eeb7de 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -1569,6 +1569,13 @@ G_MODULE_EXPORT void on_display_border_changed(GtkWidget *w, gpointer user_data_ border_mode_changed = true; } +G_MODULE_EXPORT void on_monochrome_palette_changed(GtkWidget *w, gpointer user_data_gptr) { + GtkComboBox *box = GTK_COMBO_BOX(w); + config.monochrome_palette_id = (gchar *)gtk_combo_box_get_active_id(box); + + GB_set_palette(&gb, get_monochrome_palette()); +} + G_MODULE_EXPORT void on_color_menubar_override_changed(GtkWidget *w, gpointer user_data_gptr) { config.menubar_override = (gchar *)gtk_combo_box_get_active_id(GTK_COMBO_BOX(w)); } @@ -1994,7 +2001,7 @@ static void vblank(GB_gameboy_t *gb) { if (border_mode_changed) { GB_set_border_mode(gb, get_display_border_mode()); update_window_geometry(); - + border_mode_changed = false; } @@ -2211,6 +2218,8 @@ static void reset(GuiData *gui_data) { GB_switch_model_and_reset(&gb, current_model); } + GB_set_palette(&gb, get_monochrome_palette()); + gui_data->prev_model = get_model(); GtkRequisition minimum_size; diff --git a/gtk3/main.h b/gtk3/main.h index b2b090f..a4250d8 100644 --- a/gtk3/main.h +++ b/gtk3/main.h @@ -142,6 +142,7 @@ G_MODULE_EXPORT void on_cgb_model_changed(GtkWidget *w, gpointer user_data_gptr) G_MODULE_EXPORT void on_color_correction_changed(GtkWidget *w, gpointer user_data_gptr); G_MODULE_EXPORT void on_frame_blending_changed(GtkWidget *w, gpointer user_data_gptr); G_MODULE_EXPORT void on_display_border_changed(GtkWidget *w, gpointer user_data_gptr); +G_MODULE_EXPORT void on_monochrome_palette_changed(GtkWidget *w, gpointer user_data_gptr); G_MODULE_EXPORT void on_color_menubar_override_changed(GtkWidget *w, gpointer user_data_gptr); G_MODULE_EXPORT void on_dmg_model_changed(GtkWidget *w, gpointer user_data_gptr); G_MODULE_EXPORT void on_graphic_filter_changed(GtkWidget *w, gpointer user_data_gptr); diff --git a/gtk3/resources/ui/window.ui b/gtk3/resources/ui/window.ui index 8d2deef..b439be4 100644 --- a/gtk3/resources/ui/window.ui +++ b/gtk3/resources/ui/window.ui @@ -555,6 +555,7 @@ Maximilian Mader https://github.com/max-m 16 16 vertical + True @@ -597,6 +598,7 @@ Maximilian Mader https://github.com/max-m 1 + True @@ -630,6 +632,7 @@ Maximilian Mader https://github.com/max-m 3 + True @@ -666,7 +669,7 @@ Maximilian Mader https://github.com/max-m True False - Display Border: + Color palette for monochrome models: False @@ -674,6 +677,39 @@ Maximilian Mader https://github.com/max-m 6 + + + True + False + 5 + 10 + + Greyscale + Lime (Game Boy) + Olive (Pocket) + Teal (Light) + + + + + False + True + 7 + + + + + + True + False + Display Border: + + + False + True + 8 + + True @@ -690,7 +726,7 @@ Maximilian Mader https://github.com/max-m False True - 7 + 9 @@ -708,9 +744,10 @@ Maximilian Mader https://github.com/max-m False True - 8 + 10 + Keep Aspect Ratio @@ -725,9 +762,10 @@ Maximilian Mader https://github.com/max-m False True - 9 + 11 + False @@ -736,7 +774,7 @@ Maximilian Mader https://github.com/max-m False True - 10 + 12 @@ -753,7 +791,7 @@ Maximilian Mader https://github.com/max-m False True - 11 + 13 @@ -761,6 +799,7 @@ Maximilian Mader https://github.com/max-m 1 + True diff --git a/gtk3/settings.c b/gtk3/settings.c index 641a80f..ab37c2d 100644 --- a/gtk3/settings.c +++ b/gtk3/settings.c @@ -110,6 +110,7 @@ void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) { gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "color_correction_selector"), config.color_correction_id); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "frame_blending_selector"), config.frame_blending_mode); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "display_border_selector"), config.display_border_mode); + gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "monochrome_palette_selector"), config.monochrome_palette_id); gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "integer_scaling_toggle"), config.use_integer_scaling); gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "aspect_ratio_toggle"), config.keep_aspect_ratio); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "highpass_filter_selector"), config.high_pass_filter_id); @@ -326,7 +327,7 @@ GB_border_mode_t get_display_border_mode(void) { } // This should not happen - g_warning("Unknown frame blending mode: %s\nFalling back to “Never”", config.display_border_mode); + g_warning("Unknown SGB border mode: %s\nFalling back to “Never”", config.display_border_mode); default_value: return GB_BORDER_NEVER; } @@ -344,6 +345,44 @@ void set_display_border_mode(GB_border_mode_t mode) { } } +const GB_palette_t* get_monochrome_palette(void) { + if (config.monochrome_palette_id == NULL) goto default_value; + + if (g_strcmp0(config.monochrome_palette_id, "greyscale") == 0) { + return &GB_PALETTE_GREY; + } + else if (g_strcmp0(config.monochrome_palette_id, "lime") == 0) { + return &GB_PALETTE_DMG; + } + else if (g_strcmp0(config.monochrome_palette_id, "olive") == 0) { + return &GB_PALETTE_MGB; + } + else if (g_strcmp0(config.monochrome_palette_id, "teal") == 0) { + return &GB_PALETTE_GBL; + } + + // This should not happen + g_warning("Unknown monochrome palette: %s\nFalling back to “Greyscale”", config.monochrome_palette_id); + default_value: return &GB_PALETTE_GREY; +} + +void set_monochrome_palette(const GB_palette_t *mode) { + g_message("%p | %p | %p | %p | %p", mode, &GB_PALETTE_GREY, &GB_PALETTE_DMG, &GB_PALETTE_MGB, &GB_PALETTE_GBL); + + if (mode == &GB_PALETTE_GREY) { + config.monochrome_palette_id = "greyscale"; + } + else if (mode == &GB_PALETTE_DMG) { + config.monochrome_palette_id = "lime"; + } + else if (mode == &GB_PALETTE_MGB) { + config.monochrome_palette_id = "olive"; + } + else if (mode == &GB_PALETTE_GBL) { + config.monochrome_palette_id = "teal"; + } +} + GB_highpass_mode_t get_highpass_mode(void) { if (config.high_pass_filter_id == NULL) goto default_value; diff --git a/gtk3/settings.h b/gtk3/settings.h index e884b9c..0c34d5b 100644 --- a/gtk3/settings.h +++ b/gtk3/settings.h @@ -42,6 +42,7 @@ EXPAND_GROUP_MEMBER(color_correction_id, string, "emulate_hardware") \ EXPAND_GROUP_MEMBER(frame_blending_mode, string, "disabled") \ EXPAND_GROUP_MEMBER(display_border_mode, string, "never") \ + EXPAND_GROUP_MEMBER(monochrome_palette_id, string, "greyscale") \ EXPAND_GROUP_MEMBER(keep_aspect_ratio, boolean, true) \ EXPAND_GROUP_MEMBER(use_integer_scaling, boolean, true) \ EXPAND_GROUP_MEMBER(menubar_override, string, "auto") \ @@ -100,6 +101,9 @@ void set_display_border_mode(GB_border_mode_t); GB_highpass_mode_t get_highpass_mode(void); void set_highpass_mode(GB_highpass_mode_t); +const GB_palette_t* get_monochrome_palette(void); +void set_monochrome_palette(const GB_palette_t*); + GB_model_t get_dmg_model(void); GB_model_t get_sgb_model(void); GB_model_t get_cgb_model(void);