ui/wpf/graphics.c

Sun, 29 Sep 2024 13:33:34 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Sep 2024 13:33:34 +0200
branch
newapi
changeset 312
3f2b3d15668b
parent 137
c9b8b9e0cfe8
permissions
-rw-r--r--

fix treeview icons (GTK)

137
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 #include <stdio.h>
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 #include <stdlib.h>
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 #include "graphics.h"
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 #include "container.h"
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 #include "../../ucx/mempool.h"
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 #include "../common/context.h"
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 #include "../common/object.h"
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 UIWIDGET ui_drawingarea(UiObject *obj, ui_drawfunc f, void *userdata) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 UiDrawEvent *eventdata = NULL;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 ui_draw_callback cb = NULL;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 if(f) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 eventdata = malloc(sizeof(UiDrawEvent));
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 eventdata->obj = obj;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 eventdata->draw = f;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 eventdata->userdata = userdata;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 cb = ui_draw_event;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 UiContainer *container = uic_get_current_container(obj);
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 return UIdrawingarea(container, cb, eventdata);
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 void ui_draw_event(void *gc, UiDrawEvent *event, int width, int height) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 UiEvent e;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 e.obj = event->obj;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 e.window = e.obj->window;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 e.document = e.obj->ctx->document;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 e.eventdata = NULL;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 e.intval = 0;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 UiWPFGraphics g;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 g.g.width = width;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 g.g.height = height;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 g.gc = gc;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 event->draw(&e, &g.g, event->userdata);
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 void ui_drawingarea_mousehandler(UiObject *obj, UIWIDGET widget, ui_callback f, void *u) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 void ui_drawingarea_getsize(UIWIDGET drawingarea, int *width, int *height) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 void ui_drawingarea_redraw(UIWIDGET drawingarea) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 UIdrawingarea_redraw(drawingarea);
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 /* ------------------------- drawing functions ------------------------- */
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 void ui_graphics_color(UiGraphics *g, int red, int green, int blue) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 UiWPFGraphics *wg = (UiWPFGraphics*)g;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 UIgraphics_color(wg->gc, red, green, blue);
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 void ui_draw_line(UiGraphics *g, int x1, int y1, int x2, int y2) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 UiWPFGraphics *wg = (UiWPFGraphics*)g;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 UIdraw_line(wg->gc, x1, y1, x2, y2);
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 void ui_draw_rect(UiGraphics *g, int x, int y, int w, int h, int fill) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 UiWPFGraphics *wg = (UiWPFGraphics*)g;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 UIdraw_rect(wg->gc, x, y, w, h, fill);
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 }
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 void ui_draw_text(UiGraphics *g, int x, int y, UiTextLayout *text) {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 }

mercurial