ui/gtk/graphics.c

changeset 431
bb7da585debc
parent 299
48763a9d19a7
equal deleted inserted replaced
169:fe49cff3c571 431:bb7da585debc
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;
106 event->userdata = u; 114 event->userdata = u;
115 event->customdata = NULL;
116 event->value = 0;
107 117
108 g_signal_connect(G_OBJECT(widget), 118 g_signal_connect(G_OBJECT(widget),
109 "button-press-event", 119 "button-press-event",
110 G_CALLBACK(widget_button_pressed), 120 G_CALLBACK(widget_button_pressed),
111 event); 121 event);
112 } else { 122 } else {
113 // TODO: warning 123 // TODO: warning
114 } 124 }
125 #endif
115 } 126 }
116 127
117 128
118 // text layout 129 // text layout
119 UiTextLayout* ui_text(UiGraphics *g) { 130 UiTextLayout* ui_text(UiGraphics *g) {

mercurial