[GTK3] Implement tilemap scrolling rect
This commit is contained in:
parent
a032722e84
commit
cf0bfc6076
42
gtk3/main.c
42
gtk3/main.c
@ -26,7 +26,8 @@ static bool paused = false;
|
||||
static bool underclock_down = false, rewind_down = false, do_rewind = false, rewind_paused = false, turbo_down = false;
|
||||
static double clock_mutliplier = 1.0;
|
||||
static char *battery_save_path_ptr;
|
||||
static Rect rect;
|
||||
static Rect viewport = {0};
|
||||
static Rect scrollRect = {0};
|
||||
static bool vram_viewer_visible = false;
|
||||
static bool running = true;
|
||||
|
||||
@ -673,8 +674,8 @@ static gboolean on_draw_fallback(GtkWidget *widget, cairo_t *cr, gpointer data)
|
||||
cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, screen_width)
|
||||
);
|
||||
|
||||
cairo_translate(cr, rect.x, rect.y);
|
||||
cairo_scale(cr, rect.w / screen_width, rect.h / screen_height);
|
||||
cairo_translate(cr, viewport.x, viewport.y);
|
||||
cairo_scale(cr, viewport.w / screen_width, viewport.h / screen_height);
|
||||
cairo_set_source_surface(cr, surface, 0, 0);
|
||||
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
|
||||
cairo_paint(cr);
|
||||
@ -790,6 +791,29 @@ static gboolean on_draw_vram_viewer_tilemap(GtkWidget *widget, cairo_t *cr, gpoi
|
||||
cairo_stroke(cr);
|
||||
}
|
||||
|
||||
if (gtk_toggle_button_get_active(gtkget(GTK_TOGGLE_BUTTON, "vram_viewer_tilemap_toggle_scrolling_button"))) {
|
||||
cairo_rectangle(cr, 0, 0, width, height);
|
||||
|
||||
for (unsigned x = 0; x < 2; x++) {
|
||||
for (unsigned y = 0; y < 2; y++) {
|
||||
Rect rect = scrollRect;
|
||||
rect.x -= 256 * x;
|
||||
rect.y += 256 * y;
|
||||
|
||||
cairo_rectangle(cr, rect.x, rect.y, rect.w, rect.h);
|
||||
}
|
||||
}
|
||||
|
||||
cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
|
||||
cairo_set_line_width(cr, 2);
|
||||
cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
|
||||
cairo_set_source_rgba(cr, 0.2, 0.2, 0.2, 0.5);
|
||||
cairo_fill_preserve(cr);
|
||||
cairo_clip_preserve(cr);
|
||||
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.6);
|
||||
cairo_stroke(cr);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -889,7 +913,7 @@ static void render_texture(void *pixels, void *previous) {
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
render_bitmap_with_shader(&shader, _pixels, previous, GB_get_screen_width(&gb), GB_get_screen_height(&gb), rect.x, rect.y, rect.w, rect.h);
|
||||
render_bitmap_with_shader(&shader, _pixels, previous, GB_get_screen_width(&gb), GB_get_screen_height(&gb), viewport.x, viewport.y, viewport.w, viewport.h);
|
||||
}
|
||||
|
||||
static void update_viewport(void) {
|
||||
@ -918,14 +942,14 @@ static void update_viewport(void) {
|
||||
unsigned new_width = x_factor * GB_get_screen_width(&gb);
|
||||
unsigned new_height = y_factor * GB_get_screen_height(&gb);
|
||||
|
||||
rect = (Rect){
|
||||
viewport = (Rect){
|
||||
(win_width - new_width) / 2,
|
||||
(win_height - new_height) / 2,
|
||||
new_width,
|
||||
new_height
|
||||
};
|
||||
|
||||
if (!fallback_canvas) glViewport(rect.x, rect.y, rect.w, rect.h);
|
||||
if (!fallback_canvas) glViewport(viewport.x, viewport.y, viewport.w, viewport.h);
|
||||
}
|
||||
|
||||
static void update_window_geometry() {
|
||||
@ -990,6 +1014,12 @@ static void vblank(GB_gameboy_t *gb) {
|
||||
GB_draw_tileset(gb, tileset_buffer, GB_PALETTE_NONE, 0);
|
||||
GB_draw_tilemap(gb, tilemap_buffer, GB_PALETTE_AUTO, 0, GB_MAP_AUTO, GB_TILESET_AUTO);
|
||||
|
||||
scrollRect = (Rect){
|
||||
GB_read_memory(gb, 0xFF00 | GB_IO_SCX),
|
||||
GB_read_memory(gb, 0xFF00 | GB_IO_SCY),
|
||||
160, 144
|
||||
};
|
||||
|
||||
// Queue a redraw of the VRAM viewer
|
||||
gtk_widget_queue_draw(GTK_WIDGET(vram_viewer));
|
||||
}
|
||||
|
@ -1353,7 +1353,7 @@ Maximilian Mader https://github.com/max-m</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="vram_viewer_tilemap_toggle_scrolling">
|
||||
<object class="GtkToggleButton" id="vram_viewer_tilemap_toggle_scrolling_button">
|
||||
<property name="label" translatable="yes">Scrolling</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
@ -1401,6 +1401,10 @@ Maximilian Mader https://github.com/max-m</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="app_paintable">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="hexpand">False</property>
|
||||
<property name="vexpand">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
|
Loading…
Reference in New Issue
Block a user