ui/gtk/draw_cairo.c

branch
newapi
changeset 299
48763a9d19a7
parent 293
736c962f1011
child 300
2f924f7ca901
equal deleted inserted replaced
298:c5e207d01ff2 299:48763a9d19a7
31 31
32 #include "container.h" 32 #include "container.h"
33 33
34 #include "draw_cairo.h" 34 #include "draw_cairo.h"
35 35
36 #if UI_GTK3 || UI_GTK4 36
37 gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) { 37 #if GTK_MAJOR_VERSION >= 3
38 static void ui_drawingarea_draw(
39 GtkDrawingArea *area,
40 cairo_t *cr,
41 int width,
42 int height,
43 gpointer data)
44 {
38 UiCairoGraphics g; 45 UiCairoGraphics g;
39 #ifdef UI_GTK4 46 g.g.width = width;
40 g.g.width = gtk_widget_get_width(w); 47 g.g.height = height;
41 g.g.height = gtk_widget_get_height(w); 48 g.widget = GTK_WIDGET(area);
42 #else
43 g.g.width = gtk_widget_get_allocated_width(w);
44 g.g.height = gtk_widget_get_allocated_height(w);
45 #endif
46 g.widget = w;
47 g.cr = cr; 49 g.cr = cr;
48 50
49 UiDrawEvent *event = data; 51 UiDrawEvent *event = data;
50 UiEvent ev; 52 UiEvent ev;
51 ev.obj = event->obj; 53 ev.obj = event->obj;
52 ev.window = event->obj->window; 54 ev.window = event->obj->window;
53 ev.document = event->obj->ctx->document; 55 ev.document = event->obj->ctx->document;
54 56
55 event->callback(&ev, &g.g, event->userdata); 57 event->callback(&ev, &g.g, event->userdata);
56 58 }
59 #endif
60
61 #if UI_GTK3
62 gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) {
63 int width = gtk_widget_get_allocated_width(w);
64 int height = gtk_widget_get_allocated_height(w);
65 ui_drawingarea_draw(w, cr, width, height, data);
57 return FALSE; 66 return FALSE;
58 } 67 }
59 #endif 68 #endif
60 #ifdef UI_GTK2 69 #ifdef UI_GTK2
61 gboolean ui_canvas_expose(GtkWidget *w, GdkEventExpose *e, void *data) { 70 gboolean ui_canvas_expose(GtkWidget *w, GdkEventExpose *e, void *data) {
78 #endif 87 #endif
79 88
80 // function from graphics.h 89 // function from graphics.h
81 90
82 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) { 91 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) {
83 #if UI_GTK3 || UI_GTK4 92 #if GTK_MAJOR_VERSION >= 4
93 gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), ui_drawingarea_draw, event, NULL);
94 #elif GTK_MAJOR_VERSION == 3
84 g_signal_connect(G_OBJECT(widget), 95 g_signal_connect(G_OBJECT(widget),
85 "draw", 96 "draw",
86 G_CALLBACK(ui_drawingarea_expose), 97 G_CALLBACK(ui_drawingarea_expose),
87 event); 98 event);
88 #else 99 #else

mercurial