| 31 |
31 |
| 32 #include "graphics.h" |
32 #include "graphics.h" |
| 33 #include "container.h" |
33 #include "container.h" |
| 34 #include "../common/object.h" |
34 #include "../common/object.h" |
| 35 |
35 |
| 36 UIWIDGET ui_drawingarea(UiObject *obj, ui_drawfunc f, void *userdata) { |
36 #if GTK_CHECK_VERSION(3, 0, 0) |
| |
37 #include "draw_cairo.h" |
| |
38 #endif |
| |
39 |
| |
40 static void destroy_drawingarea(GtkWidget *widget, UiDrawingArea *drawingarea) { |
| |
41 free(drawingarea); |
| |
42 } |
| |
43 |
| |
44 static void drawingarea_draw(UiDrawingArea *drawingarea, cairo_t *cr, int width, int height) { |
| |
45 UiEvent event; |
| |
46 event.obj = drawingarea->obj; |
| |
47 event.window = event.obj->window; |
| |
48 event.document = event.obj->ctx->document; |
| |
49 event.eventdata = NULL; |
| |
50 event.eventdatatype = 0; |
| |
51 event.intval = 0; |
| |
52 event.set = 0; |
| |
53 |
| |
54 |
| |
55 } |
| |
56 |
| |
57 #if GTK_CHECK_VERSION(4, 0, 0) |
| |
58 static void drawfunc( |
| |
59 GtkDrawingArea *area, |
| |
60 cairo_t *cr, |
| |
61 int width, |
| |
62 int height, |
| |
63 gpointer userdata) |
| |
64 { |
| |
65 ui_drawingarea_draw(userdata, cr, width, height); |
| |
66 } |
| |
67 #elif GTK_CHECK_VERSION(3, 0, 0) |
| |
68 gboolean draw_callback(GtkWidget *widget, cairo_t *cr, UiDrawingArea *drawingarea) { |
| |
69 int width = gtk_widget_get_allocated_width(widget); |
| |
70 int height = gtk_widget_get_allocated_height(widget); |
| |
71 ui_drawingarea_draw(drawingarea, cr, width, height); |
| |
72 return FALSE; |
| |
73 } |
| |
74 #endif |
| |
75 |
| |
76 UIWIDGET ui_drawingarea_create(UiObject *obj, UiDrawingAreaArgs *args) { |
| 37 GtkWidget *widget = gtk_drawing_area_new(); |
77 GtkWidget *widget = gtk_drawing_area_new(); |
| 38 |
78 ui_set_name_and_style(widget, args->name, args->style_class); |
| 39 if(f) { |
79 |
| 40 UiDrawEvent *event = malloc(sizeof(UiDrawEvent)); |
80 #if GTK_CHECK_VERSION(4, 0, 0) |
| 41 event->obj = obj; |
81 gtk_drawing_area_set_content_width(GTK_DRAWING_AREA(widget), args->width > 0 ? args->width : 100); |
| 42 event->callback = f; |
82 gtk_drawing_area_set_content_height(GTK_DRAWING_AREA(widget), args->height > 0 ? args->height : 100); |
| 43 event->userdata = userdata; |
83 #else |
| 44 ui_connect_draw_handler(widget, event); |
84 int w = args->width > 0 ? args->width : 100; |
| 45 } |
85 int h = args->height > 0 ? args->height : 100; |
| 46 |
86 gtk_widget_set_size_request(widget, w, h); |
| 47 UiContainer *ct = uic_get_current_container(obj); |
87 #endif |
| 48 ct->add(ct, widget); |
88 |
| |
89 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| |
90 UiLayout layout = UI_ARGS2LAYOUT(args); |
| |
91 ct->add(ct, widget, &layout); |
| |
92 |
| |
93 UiDrawingArea *drawingarea = malloc(sizeof(UiDrawingArea)); |
| |
94 drawingarea->obj = obj; |
| |
95 drawingarea->widget = widget; |
| |
96 drawingarea->draw = args->draw; |
| |
97 drawingarea->drawdata = args->drawdata; |
| |
98 drawingarea->onclick = args->onclick; |
| |
99 drawingarea->onclickdata = args->onclickdata; |
| |
100 drawingarea->onmotion = args->onmotion; |
| |
101 drawingarea->onmotiondata = args->onmotiondata; |
| |
102 |
| |
103 #if GTK_CHECK_VERSION(4, 0, 0) |
| |
104 gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), drawfunc, drawingarea, NULL); |
| |
105 #elif GTK_CHECK_VERSION(3, 0, 0) |
| |
106 g_signal_connect( |
| |
107 widget, |
| |
108 "draw", |
| |
109 G_CALLBACK(draw_callback), |
| |
110 NULL); |
| |
111 #endif |
| |
112 |
| |
113 g_signal_connect( |
| |
114 widget, |
| |
115 "destroy", |
| |
116 G_CALLBACK(destroy_drawingarea), |
| |
117 drawingarea); |
| 49 |
118 |
| 50 return widget; |
119 return widget; |
| 51 } |
120 } |
| 52 |
121 |
| 53 |
122 |
| 140 |
209 |
| 141 void ui_text_setstringl(UiTextLayout *layout, char *str, int len) { |
210 void ui_text_setstringl(UiTextLayout *layout, char *str, int len) { |
| 142 pango_layout_set_text(layout->layout, str, len); |
211 pango_layout_set_text(layout->layout, str, len); |
| 143 } |
212 } |
| 144 |
213 |
| 145 void ui_text_setfont(UiTextLayout *layout, char *font, int size) { |
214 void ui_text_setfont(UiTextLayout *layout, const char *font, int size) { |
| 146 PangoFontDescription *fontDesc; |
215 PangoFontDescription *fontDesc; |
| 147 fontDesc = pango_font_description_from_string(font); |
216 fontDesc = pango_font_description_from_string(font); |
| 148 pango_font_description_set_size(fontDesc, size * PANGO_SCALE); |
217 pango_font_description_set_size(fontDesc, size * PANGO_SCALE); |
| 149 pango_layout_set_font_description(layout->layout, fontDesc); |
218 pango_layout_set_font_description(layout->layout, fontDesc); |
| 150 pango_font_description_free(fontDesc); |
219 pango_font_description_free(fontDesc); |