From cbace7cb099ef44e2177b3969443f23cde53442d Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Wed, 2 Oct 2019 23:53:18 +0200 Subject: [PATCH] [GTK3] Add function to draw grids in VRAM viewer --- gtk3/main.c | 46 +++++++++++++++++++++++++++++++++++++ gtk3/resources/ui/window.ui | 45 ++++++++++++++++++------------------ 2 files changed, 68 insertions(+), 23 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index d8b2209..8ca119d 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -716,9 +716,35 @@ static gboolean on_draw_vram_viewer_tileset(GtkWidget *widget, cairo_t *cr, gpoi cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, 256) ); + cairo_scale(cr, 2.0, 2.0); cairo_set_source_surface(cr, surface, 0, 0); + cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST); cairo_paint(cr); + if (gtk_toggle_button_get_active(gtkget(GTK_TOGGLE_BUTTON, "vram_viewer_tileset_toggle_grid_button"))) { + cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.25); + cairo_set_line_width(cr, 1); + + const int divisions_x = 256 / 8; + const int divisions_y = 192 / 8; + + for (int i = 0; i < divisions_x; i++) { + const int j = 256 * i; + + cairo_move_to(cr, j / divisions_x, 0); + cairo_line_to(cr, j / divisions_x, 192); + } + + for (int i = 0; i < divisions_y; i++) { + const int j = 192 * i; + + cairo_move_to(cr, 0, j / divisions_y); + cairo_line_to(cr, 256, j / divisions_y); + } + + cairo_stroke(cr); + } + return FALSE; } @@ -741,9 +767,29 @@ static gboolean on_draw_vram_viewer_tilemap(GtkWidget *widget, cairo_t *cr, gpoi cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, 256) ); + cairo_scale(cr, 2.0, 2.0); cairo_set_source_surface(cr, surface, 0, 0); + cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST); cairo_paint(cr); + if (gtk_toggle_button_get_active(gtkget(GTK_TOGGLE_BUTTON, "vram_viewer_tilemap_toggle_grid_button"))) { + cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.25); + cairo_set_line_width(cr, 1); + + const int divisions = 256 / 8; + + for (int i = 0; i < divisions; i++) { + const int j = 256 * i; + + cairo_move_to(cr, j / divisions, 0); + cairo_line_to(cr, j / divisions, 256); + cairo_move_to(cr, 0, j / divisions); + cairo_line_to(cr, 256, j / divisions); + } + + cairo_stroke(cr); + } + return FALSE; } diff --git a/gtk3/resources/ui/window.ui b/gtk3/resources/ui/window.ui index 9a09146..dc36a65 100644 --- a/gtk3/resources/ui/window.ui +++ b/gtk3/resources/ui/window.ui @@ -318,7 +318,6 @@ Maximilian Mader https://github.com/max-m False 5 10 - @@ -596,23 +595,6 @@ Maximilian Mader https://github.com/max-m 3 - - - Keep Aspect Ratio - True - True - False - 5 - 10 - True - - - - False - True - 4 - - Use Integer Scaling @@ -630,9 +612,25 @@ Maximilian Mader https://github.com/max-m 4 + + + Keep Aspect Ratio + True + True + False + 5 + 10 + True + + + + False + True + 4 + + - False False Main Menu Override @@ -644,7 +642,6 @@ Maximilian Mader https://github.com/max-m - False False Automatic @@ -1155,8 +1152,6 @@ Maximilian Mader https://github.com/max-m False VRAM Viewer - 512 - 384 @@ -1259,6 +1254,8 @@ Maximilian Mader https://github.com/max-m + 512 + 384 True True False @@ -1341,7 +1338,7 @@ Maximilian Mader https://github.com/max-m - + Grid True True @@ -1399,6 +1396,8 @@ Maximilian Mader https://github.com/max-m + 512 + 512 True True False