[GTK3] Add function to draw grids in VRAM viewer

This commit is contained in:
Maximilian Mader 2019-10-02 23:53:18 +02:00
parent 0a412f9d95
commit cbace7cb09
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
2 changed files with 68 additions and 23 deletions

View File

@ -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_format_stride_for_width(CAIRO_FORMAT_RGB24, 256)
); );
cairo_scale(cr, 2.0, 2.0);
cairo_set_source_surface(cr, surface, 0, 0); cairo_set_source_surface(cr, surface, 0, 0);
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
cairo_paint(cr); 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; 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_format_stride_for_width(CAIRO_FORMAT_RGB24, 256)
); );
cairo_scale(cr, 2.0, 2.0);
cairo_set_source_surface(cr, surface, 0, 0); cairo_set_source_surface(cr, surface, 0, 0);
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
cairo_paint(cr); 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; return FALSE;
} }

View File

@ -318,7 +318,6 @@ Maximilian Mader https://github.com/max-m</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="margin_top">5</property> <property name="margin_top">5</property>
<property name="margin_bottom">10</property> <property name="margin_bottom">10</property>
<items></items>
<signal name="changed" handler="on_boot_rom_location_changed" swapped="no"/> <signal name="changed" handler="on_boot_rom_location_changed" swapped="no"/>
</object> </object>
<packing> <packing>
@ -596,23 +595,6 @@ Maximilian Mader https://github.com/max-m</property>
<property name="position">3</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkCheckButton" id="aspect_ratio_toggle">
<property name="label" translatable="yes">Keep Aspect Ratio</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="margin_top">5</property>
<property name="margin_bottom">10</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_keep_aspect_ratio_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child> <child>
<object class="GtkCheckButton" id="integer_scaling_toggle"> <object class="GtkCheckButton" id="integer_scaling_toggle">
<property name="label" translatable="yes">Use Integer Scaling</property> <property name="label" translatable="yes">Use Integer Scaling</property>
@ -630,9 +612,25 @@ Maximilian Mader https://github.com/max-m</property>
<property name="position">4</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkCheckButton" id="aspect_ratio_toggle">
<property name="label" translatable="yes">Keep Aspect Ratio</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="margin_top">5</property>
<property name="margin_bottom">10</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_keep_aspect_ratio_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child> <child>
<object class="GtkLabel" id="menubar_override_selector_label"> <object class="GtkLabel" id="menubar_override_selector_label">
<property name="visible">False</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Main Menu Override</property> <property name="label" translatable="yes">Main Menu Override</property>
</object> </object>
@ -644,7 +642,6 @@ Maximilian Mader https://github.com/max-m</property>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="menubar_override_selector"> <object class="GtkComboBoxText" id="menubar_override_selector">
<property name="visible">False</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<items> <items>
<item id="auto" translatable="yes">Automatic</item> <item id="auto" translatable="yes">Automatic</item>
@ -1155,8 +1152,6 @@ Maximilian Mader https://github.com/max-m</property>
<object class="GtkWindow" id="vram_viewer"> <object class="GtkWindow" id="vram_viewer">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="title" translatable="yes">VRAM Viewer</property> <property name="title" translatable="yes">VRAM Viewer</property>
<property name="default_width">512</property>
<property name="default_height">384</property>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
@ -1259,6 +1254,8 @@ Maximilian Mader https://github.com/max-m</property>
</child> </child>
<child> <child>
<object class="GtkDrawingArea" id="vram_viewer_tileset_canvas"> <object class="GtkDrawingArea" id="vram_viewer_tileset_canvas">
<property name="width_request">512</property>
<property name="height_request">384</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="app_paintable">True</property> <property name="app_paintable">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -1341,7 +1338,7 @@ Maximilian Mader https://github.com/max-m</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkToggleButton" id="vram_viewer_tilemap_toggle_grid"> <object class="GtkToggleButton" id="vram_viewer_tilemap_toggle_grid_button">
<property name="label" translatable="yes">Grid</property> <property name="label" translatable="yes">Grid</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@ -1399,6 +1396,8 @@ Maximilian Mader https://github.com/max-m</property>
</child> </child>
<child> <child>
<object class="GtkDrawingArea" id="vram_viewer_tilemap_canvas"> <object class="GtkDrawingArea" id="vram_viewer_tilemap_canvas">
<property name="width_request">512</property>
<property name="height_request">512</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="app_paintable">True</property> <property name="app_paintable">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>