ui/gtk/graphics.c

changeset 44
473954dc6b74
parent 32
e5f4d8af567e
equal deleted inserted replaced
43:ef01d2c90128 44:473954dc6b74
49 49
50 return widget; 50 return widget;
51 } 51 }
52 52
53 53
54 #if GTK_MAJOR_VERSION <= 3
54 static gboolean widget_button_pressed( 55 static gboolean widget_button_pressed(
55 GtkWidget *widget, 56 GtkWidget *widget,
56 GdkEvent *event, 57 GdkEvent *event,
57 gpointer userdata) 58 gpointer userdata)
58 { 59 {
80 e.intval = 0; 81 e.intval = 0;
81 eventdata->callback(&e, eventdata->userdata); 82 eventdata->callback(&e, eventdata->userdata);
82 } 83 }
83 return TRUE; 84 return TRUE;
84 } 85 }
86 #endif
85 87
86 void ui_drawingarea_getsize(UIWIDGET drawingarea, int *width, int *height) { 88 void ui_drawingarea_getsize(UIWIDGET drawingarea, int *width, int *height) {
87 #ifdef UI_GTK3 89 #if GTK_MAJOR_VERSION >= 4
88 *width = gtk_widget_get_allocated_width(drawingarea); 90 *width = gtk_widget_get_width(drawingarea);
89 *height = gtk_widget_get_allocated_height(drawingarea); 91 *height = gtk_widget_get_height(drawingarea);
92 #elif GTK_MAJOR_VERSION == 3
93 *width = gtk_widget_get_allocated_width(drawingarea);
94 *height = gtk_widget_get_allocated_height(drawingarea);
90 #else 95 #else
91 *width = drawingarea->allocation.width; 96 *width = drawingarea->allocation.width;
92 *height = drawingarea->allocation.height; 97 *height = drawingarea->allocation.height;
93 #endif 98 #endif
94 } 99 }
95 100
96 void ui_drawingarea_redraw(UIWIDGET drawingarea) { 101 void ui_drawingarea_redraw(UIWIDGET drawingarea) {
97 gtk_widget_queue_draw(drawingarea); 102 gtk_widget_queue_draw(drawingarea);
98 } 103 }
99 104
100 void ui_drawingarea_mousehandler(UiObject *obj, UIWIDGET widget, ui_callback f, void *u) { 105 void ui_drawingarea_mousehandler(UiObject *obj, UIWIDGET widget, ui_callback f, void *u) {
106 #if GTK_MAJOR_VERSION >= 4
107 // TODO
108 #else
101 gtk_widget_set_events(widget, GDK_BUTTON_PRESS_MASK); 109 gtk_widget_set_events(widget, GDK_BUTTON_PRESS_MASK);
102 if(f) { 110 if(f) {
103 UiEventData *event = malloc(sizeof(UiEventData)); 111 UiEventData *event = malloc(sizeof(UiEventData));
104 event->obj = obj; 112 event->obj = obj;
105 event->callback = f; 113 event->callback = f;
112 G_CALLBACK(widget_button_pressed), 120 G_CALLBACK(widget_button_pressed),
113 event); 121 event);
114 } else { 122 } else {
115 // TODO: warning 123 // TODO: warning
116 } 124 }
125 #endif
117 } 126 }
118 127
119 128
120 // text layout 129 // text layout
121 UiTextLayout* ui_text(UiGraphics *g) { 130 UiTextLayout* ui_text(UiGraphics *g) {

mercurial