ui/gtk/draw_cairo.c

changeset 44
473954dc6b74
parent 42
9af327d0e0e4
--- a/ui/gtk/draw_cairo.c	Mon Jun 17 21:20:58 2024 +0200
+++ b/ui/gtk/draw_cairo.c	Sun Sep 29 13:32:51 2024 +0200
@@ -33,17 +33,19 @@
 
 #include "draw_cairo.h"
 
-#if UI_GTK3 || UI_GTK4
-gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) {
+
+#if GTK_MAJOR_VERSION >= 3
+static void ui_drawingarea_draw(
+        GtkDrawingArea *area,
+        cairo_t *cr,
+        int width,
+        int height,
+        gpointer data)
+{
     UiCairoGraphics g;
-#ifdef UI_GTK4
-    g.g.width = gtk_widget_get_width(w);
-    g.g.height = gtk_widget_get_height(w);
-#else
-    g.g.width = gtk_widget_get_allocated_width(w);
-    g.g.height = gtk_widget_get_allocated_height(w);
-#endif
-    g.widget = w;
+    g.g.width = width;
+    g.g.height = height;
+    g.widget = GTK_WIDGET(area);
     g.cr = cr;
     
     UiDrawEvent *event = data;
@@ -53,7 +55,14 @@
     ev.document = event->obj->ctx->document;
     
     event->callback(&ev, &g.g, event->userdata);
-    
+}
+#endif
+
+#if UI_GTK3
+gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) {
+    int width = gtk_widget_get_allocated_width(w);
+    int height = gtk_widget_get_allocated_height(w);
+    ui_drawingarea_draw(GTK_DRAWING_AREA(w), cr, width, height, data);
     return FALSE;
 }
 #endif
@@ -80,7 +89,9 @@
 // function from graphics.h
 
 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) {
-#if UI_GTK3 || UI_GTK4
+#if GTK_MAJOR_VERSION >= 4
+    gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), ui_drawingarea_draw, event, NULL);
+#elif GTK_MAJOR_VERSION == 3
     g_signal_connect(G_OBJECT(widget),
             "draw",
             G_CALLBACK(ui_drawingarea_expose),

mercurial