[GTK3] Add vram_viewer_finalize(), fix scroll rect, fix no-gl fallback

This commit is contained in:
Maximilian Mader 2020-05-18 01:26:01 +02:00
parent 6a15ff582e
commit 7ce7c8c404
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
2 changed files with 29 additions and 24 deletions

View File

@ -693,18 +693,17 @@ 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);
gui_data.viewport = (Rect){
(win_width - new_width) / 2,
(win_height - new_height) / 2,
new_width,
new_height
};
if (gui_data.gl_area) {
unsigned new_width = x_factor * GB_get_screen_width(&gb);
unsigned new_height = y_factor * GB_get_screen_height(&gb);
gui_data.viewport = (Rect){
(win_width - new_width) / 2,
(win_height - new_height) / 2,
new_width,
new_height
};
glViewport(gui_data.viewport.x, gui_data.viewport.y, gui_data.viewport.width, gui_data.viewport.height);
}
}

View File

@ -51,12 +51,9 @@ static void visible_tab_changed(GObject *stack, GParamSpec *pspec, VramViewerWin
}
static gboolean draw_tileset_canvas(GtkWidget *widget, cairo_t *cr, VramViewerWindow *window) {
guint width, height;
GtkStyleContext *context;
context = gtk_widget_get_style_context(widget);
width = gtk_widget_get_allocated_width(widget);
height = gtk_widget_get_allocated_height(widget);
GtkStyleContext *context = gtk_widget_get_style_context(widget);
guint width = gtk_widget_get_allocated_width(widget);
guint height = gtk_widget_get_allocated_height(widget);
gtk_render_background(context, cr, 0, 0, width, height);
gtk_render_frame(context, cr, 0, 0, width, height);
@ -102,12 +99,9 @@ static gboolean draw_tileset_canvas(GtkWidget *widget, cairo_t *cr, VramViewerWi
}
static gboolean draw_tilemap_canvas(GtkWidget *widget, cairo_t *cr, VramViewerWindow *window) {
guint width, height;
GtkStyleContext *context;
context = gtk_widget_get_style_context(widget);
width = gtk_widget_get_allocated_width(widget);
height = gtk_widget_get_allocated_height(widget);
GtkStyleContext *context = gtk_widget_get_style_context(widget);
guint width = gtk_widget_get_allocated_width(widget);
guint height = gtk_widget_get_allocated_height(widget);
gtk_render_background(context, cr, 0, 0, width, height);
gtk_render_frame(context, cr, 0, 0, width, height);
@ -150,7 +144,7 @@ static gboolean draw_tilemap_canvas(GtkWidget *widget, cairo_t *cr, VramViewerWi
for (unsigned y = 0; y < 2; y++) {
Rect rect = window->scroll_rect;
rect.x -= 256 * x;
rect.y += 256 * y;
rect.y -= 256 * y;
cairo_rectangle(cr, rect.x, rect.y, rect.width, rect.height);
}
@ -317,6 +311,16 @@ static void vram_viewer_window_init(VramViewerWindow *window) {
gtk_widget_add_events(GTK_WIDGET(window->tilemap_canvas), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
}
static void vram_viewer_finalize(GObject *object) {
VramViewerWindow *window = (VramViewerWindow *) object;
g_free(window->tilemap_buffer);
g_free(window->tileset_buffer);
window->gb_vram = NULL;
G_OBJECT_CLASS(vram_viewer_window_parent_class)->finalize(object);
}
static void vram_viewer_window_class_init(VramViewerWindowClass *class) {
gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(class), RESOURCE_PREFIX "ui/vram_viewer.ui");
@ -343,6 +347,8 @@ static void vram_viewer_window_class_init(VramViewerWindowClass *class) {
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), draw_tilemap_canvas);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), tileset_canvas_motion);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), tilemap_canvas_motion);
G_OBJECT_CLASS(class)->finalize = vram_viewer_finalize;
}
VramViewerWindow *vram_viewer_new(void) {