From b142227577fac96451d552dd9ddd02dc30220f2a Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 10 Apr 2020 21:42:03 +0200 Subject: [PATCH] [GTK3] Implement the new SGB border options --- gtk3/main.c | 26 ++++++++++++++++++++--- gtk3/main.h | 1 + gtk3/resources/ui/window.ui | 41 +++++++++++++++++++++++++++++++++---- gtk3/settings.c | 33 +++++++++++++++++++++++++++++ gtk3/settings.h | 4 ++++ 5 files changed, 98 insertions(+), 7 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index a4b0257..106541d 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -58,6 +58,7 @@ static bool vram_viewer_updating = false; static gchar *vram_viewer_active_tab = ""; static gboolean vram_viewer_is_cgb = false; static uint8_t vram_viewer_palette_data[16][0x40]; +static bool border_mode_changed = false; static volatile bool running = false; static volatile bool stopping = false; @@ -1561,6 +1562,13 @@ G_MODULE_EXPORT void on_frame_blending_changed(GtkWidget *w, gpointer user_data_ config.frame_blending_mode = (gchar *)gtk_combo_box_get_active_id(box); } +G_MODULE_EXPORT void on_display_border_changed(GtkWidget *w, gpointer user_data_gptr) { + GtkComboBox *box = GTK_COMBO_BOX(w); + config.display_border_mode = (gchar *)gtk_combo_box_get_active_id(box); + + border_mode_changed = true; +} + 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)); } @@ -1982,6 +1990,14 @@ static void on_vblank(gpointer data) { static void vblank(GB_gameboy_t *gb) { flip(); + + if (border_mode_changed) { + GB_set_border_mode(gb, get_display_border_mode()); + update_window_geometry(); + + border_mode_changed = false; + } + GB_set_pixels_output(gb, get_pixels()); if (underclock_down && clock_mutliplier > 0.5) { @@ -2083,7 +2099,6 @@ static void init(GuiData *gui_data) { if (GB_is_inited(&gb)) return; GB_init(&gb, get_model()); - update_window_geometry(); GB_set_vblank_callback(&gb, vblank); GB_set_pixels_output(&gb, get_current_buffer()); @@ -2098,6 +2113,12 @@ static void init(GuiData *gui_data) { GB_set_async_input_callback(&gb, async_console_input); GB_set_log_callback(&gb, console_log); GB_set_boot_rom_load_callback(&gb, load_boot_rom); + + if (get_display_border_mode() <= GB_BORDER_ALWAYS) { + GB_set_border_mode(&gb, get_display_border_mode()); + } + + update_window_geometry(); } static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type) { @@ -2143,7 +2164,7 @@ static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type) { else { internal_boot_rom: boot_rom_path = g_build_filename(RESOURCE_PREFIX "bootroms/", boot_rom_name, NULL); boot_rom_f = g_resources_lookup_data(boot_rom_path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error); - + g_message("Loading internal boot ROM: %s", boot_rom_path); g_free(boot_rom_path); @@ -2201,7 +2222,6 @@ static void reset(GuiData *gui_data) { update_window_geometry(); } - char *path = g_file_get_path(gui_data->file); if (GB_load_rom(&gb, path) != 0) { diff --git a/gtk3/main.h b/gtk3/main.h index 385e3bb..b2b090f 100644 --- a/gtk3/main.h +++ b/gtk3/main.h @@ -141,6 +141,7 @@ G_MODULE_EXPORT void on_boot_rom_location_changed(GtkWidget *w, gpointer user_da 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_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 4e23630..c4a53c6 100644 --- a/gtk3/resources/ui/window.ui +++ b/gtk3/resources/ui/window.ui @@ -660,6 +660,39 @@ Maximilian Mader https://github.com/max-m 5 + + + + True + False + Display Border: + + + False + True + 6 + + + + + True + False + 5 + 10 + + Never + Super Game Boy Only + Always + + + + + False + True + 7 + + + Use Integer Scaling @@ -674,7 +707,7 @@ Maximilian Mader https://github.com/max-m False True - 6 + 8 @@ -691,7 +724,7 @@ Maximilian Mader https://github.com/max-m False True - 7 + 9 @@ -702,7 +735,7 @@ Maximilian Mader https://github.com/max-m False True - 8 + 10 @@ -719,7 +752,7 @@ Maximilian Mader https://github.com/max-m False True - 9 + 11 diff --git a/gtk3/settings.c b/gtk3/settings.c index d9784cf..641a80f 100644 --- a/gtk3/settings.c +++ b/gtk3/settings.c @@ -109,6 +109,7 @@ void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) { gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "shader_selector"), config.shader); 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_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); @@ -311,6 +312,38 @@ void set_frame_blending_mode(GB_frame_blending_mode_t mode) { } } +GB_border_mode_t get_display_border_mode(void) { + if (config.display_border_mode == NULL) goto default_value; + + if (g_strcmp0(config.display_border_mode, "never") == 0) { + return GB_BORDER_NEVER; + } + else if (g_strcmp0(config.display_border_mode, "sgb_only") == 0) { + return GB_BORDER_SGB; + } + else if (g_strcmp0(config.display_border_mode, "always") == 0) { + return GB_BORDER_ALWAYS; + } + + // This should not happen + g_warning("Unknown frame blending mode: %s\nFalling back to “Never”", config.display_border_mode); + default_value: return GB_BORDER_NEVER; +} + +void set_display_border_mode(GB_border_mode_t mode) { + switch (mode) { + case GB_BORDER_NEVER: + config.display_border_mode = "never"; + break; + case GB_BORDER_SGB: + config.display_border_mode = "sgb_only"; + break; + case GB_BORDER_ALWAYS: + config.display_border_mode = "always"; + break; + } +} + 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 862905c..e884b9c 100644 --- a/gtk3/settings.h +++ b/gtk3/settings.h @@ -41,6 +41,7 @@ EXPAND_GROUP_MEMBER(shader, string, "NearestNeighbor") \ 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(keep_aspect_ratio, boolean, true) \ EXPAND_GROUP_MEMBER(use_integer_scaling, boolean, true) \ EXPAND_GROUP_MEMBER(menubar_override, string, "auto") \ @@ -93,6 +94,9 @@ void set_color_correction_mode(GB_color_correction_mode_t); GB_frame_blending_mode_t get_frame_blending_mode(void); void set_frame_blending_mode(GB_frame_blending_mode_t); +GB_border_mode_t get_display_border_mode(void); +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);