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 #ifdef UI_GTK3 |
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 g.g.width = gtk_widget_get_allocated_width(w); |
46 g.g.width = width; |
40 g.g.height = gtk_widget_get_allocated_height(w); |
47 g.g.height = height; |
41 g.widget = w; |
48 g.widget = GTK_WIDGET(area); |
42 g.cr = cr; |
49 g.cr = cr; |
43 |
50 |
44 UiDrawEvent *event = data; |
51 UiDrawEvent *event = data; |
45 UiEvent ev; |
52 UiEvent ev; |
46 ev.obj = event->obj; |
53 ev.obj = event->obj; |
47 ev.window = event->obj->window; |
54 ev.window = event->obj->window; |
48 ev.document = event->obj->ctx->document; |
55 ev.document = event->obj->ctx->document; |
49 |
56 |
50 event->callback(&ev, &g.g, event->userdata); |
57 event->callback(&ev, &g.g, event->userdata); |
51 |
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(GTK_DRAWING_AREA(w), cr, width, height, data); |
52 return FALSE; |
66 return FALSE; |
53 } |
67 } |
54 #else |
68 #endif |
|
69 #ifdef UI_GTK2 |
55 gboolean ui_canvas_expose(GtkWidget *w, GdkEventExpose *e, void *data) { |
70 gboolean ui_canvas_expose(GtkWidget *w, GdkEventExpose *e, void *data) { |
56 UiCairoGraphics g; |
71 UiCairoGraphics g; |
57 g.g.width = w->allocation.width; |
72 g.g.width = w->allocation.width; |
58 g.g.height = w->allocation.height; |
73 g.g.height = w->allocation.height; |
59 g.widget = w; |
74 g.widget = w; |
72 #endif |
87 #endif |
73 |
88 |
74 // function from graphics.h |
89 // function from graphics.h |
75 |
90 |
76 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) { |
91 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) { |
77 #ifdef UI_GTK3 |
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 |
78 g_signal_connect(G_OBJECT(widget), |
95 g_signal_connect(G_OBJECT(widget), |
79 "draw", |
96 "draw", |
80 G_CALLBACK(ui_drawingarea_expose), |
97 G_CALLBACK(ui_drawingarea_expose), |
81 event); |
98 event); |
82 #else |
99 #else |