| 33 |
33 |
| 34 #include "draw_cairo.h" |
34 #include "draw_cairo.h" |
| 35 |
35 |
| 36 |
36 |
| 37 #if GTK_MAJOR_VERSION >= 3 |
37 #if GTK_MAJOR_VERSION >= 3 |
| 38 static void ui_drawingarea_draw( |
38 void ui_drawingarea_draw(UiDrawingArea *drawingarea, cairo_t *cr, int width, int height) { |
| 39 GtkDrawingArea *area, |
|
| 40 cairo_t *cr, |
|
| 41 int width, |
|
| 42 int height, |
|
| 43 gpointer data) |
|
| 44 { |
|
| 45 UiCairoGraphics g; |
39 UiCairoGraphics g; |
| 46 g.g.width = width; |
40 g.g.width = width; |
| 47 g.g.height = height; |
41 g.g.height = height; |
| 48 g.widget = GTK_WIDGET(area); |
42 g.widget = drawingarea->widget;; |
| 49 g.cr = cr; |
43 g.cr = cr; |
| 50 |
44 |
| 51 UiDrawEvent *event = data; |
45 UiEvent event; |
| 52 UiEvent ev; |
46 event.obj = drawingarea->obj; |
| 53 ev.obj = event->obj; |
47 event.window = event.obj->window; |
| 54 ev.window = event->obj->window; |
48 event.document = event.obj->ctx->document; |
| 55 ev.document = event->obj->ctx->document; |
49 event.eventdata = NULL; |
| |
50 event.eventdatatype = 0; |
| |
51 event.intval = 0; |
| |
52 event.set = 0; |
| 56 |
53 |
| 57 event->callback(&ev, &g.g, event->userdata); |
54 if(drawingarea->draw) { |
| |
55 drawingarea->draw(&event, &g.g, drawingarea->drawdata); |
| |
56 } |
| 58 } |
57 } |
| 59 #endif |
58 #endif |
| 60 |
59 |
| |
60 /* |
| 61 #if UI_GTK3 |
61 #if UI_GTK3 |
| 62 gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) { |
62 gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) { |
| 63 int width = gtk_widget_get_allocated_width(w); |
63 int width = gtk_widget_get_allocated_width(w); |
| 64 int height = gtk_widget_get_allocated_height(w); |
64 int height = gtk_widget_get_allocated_height(w); |
| 65 ui_drawingarea_draw(GTK_DRAWING_AREA(w), cr, width, height, data); |
65 ui_drawingarea_draw(GTK_DRAWING_AREA(w), cr, width, height, data); |
| 83 event->callback(&ev, &g.g, event->userdata); |
83 event->callback(&ev, &g.g, event->userdata); |
| 84 |
84 |
| 85 return FALSE; |
85 return FALSE; |
| 86 } |
86 } |
| 87 #endif |
87 #endif |
| |
88 */ |
| 88 |
89 |
| 89 // function from graphics.h |
90 // function from graphics.h |
| 90 |
91 |
| |
92 /* |
| 91 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) { |
93 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) { |
| 92 #if GTK_MAJOR_VERSION >= 4 |
94 #if GTK_MAJOR_VERSION >= 4 |
| 93 gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), ui_drawingarea_draw, event, NULL); |
95 gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), ui_drawingarea_draw, event, NULL); |
| 94 #elif GTK_MAJOR_VERSION == 3 |
96 #elif GTK_MAJOR_VERSION == 3 |
| 95 g_signal_connect(G_OBJECT(widget), |
97 g_signal_connect(G_OBJECT(widget), |
| 101 "expose_event", |
103 "expose_event", |
| 102 G_CALLBACK(ui_canvas_expose), |
104 G_CALLBACK(ui_canvas_expose), |
| 103 event); |
105 event); |
| 104 #endif |
106 #endif |
| 105 } |
107 } |
| 106 |
108 */ |
| 107 |
109 |
| 108 PangoContext *ui_get_pango_context(UiGraphics *g) { |
110 PangoContext *ui_get_pango_context(UiGraphics *g) { |
| 109 UiCairoGraphics *gr = (UiCairoGraphics*)g; |
111 UiCairoGraphics *gr = (UiCairoGraphics*)g; |
| 110 //return gtk_widget_get_pango_context(gr->widget); |
112 //return gtk_widget_get_pango_context(gr->widget); |
| 111 return pango_cairo_create_context(gr->cr); |
113 return pango_cairo_create_context(gr->cr); |
| 128 cairo_move_to(gr->cr, (double)x1 + 0.5, (double)y1 + 0.5); |
130 cairo_move_to(gr->cr, (double)x1 + 0.5, (double)y1 + 0.5); |
| 129 cairo_line_to(gr->cr, (double)x2 + 0.5, (double)y2 + 0.5); |
131 cairo_line_to(gr->cr, (double)x2 + 0.5, (double)y2 + 0.5); |
| 130 cairo_stroke(gr->cr); |
132 cairo_stroke(gr->cr); |
| 131 } |
133 } |
| 132 |
134 |
| 133 void ui_draw_rect(UiGraphics *g, int x, int y, int w, int h, int fill) { |
135 void ui_draw_rect(UiGraphics *g, int x, int y, int w, int h, UiBool fill) { |
| 134 UiCairoGraphics *gr = (UiCairoGraphics*)g; |
136 UiCairoGraphics *gr = (UiCairoGraphics*)g; |
| 135 cairo_set_line_width(gr->cr, 1); |
137 cairo_set_line_width(gr->cr, 1); |
| 136 cairo_rectangle(gr->cr, x + 0.5, y + 0.5 , w, h); |
138 cairo_rectangle(gr->cr, x + 0.5, y + 0.5 , w, h); |
| 137 if(fill) { |
139 if(fill) { |
| 138 cairo_fill(gr->cr); |
140 cairo_fill(gr->cr); |