ui/wpf/UIwrapper/UIwrapper/graphics.cpp

changeset 137
c9b8b9e0cfe8
equal deleted inserted replaced
136:1df2fb3d079c 137:c9b8b9e0cfe8
1 #include "stdafx.h"
2 #include <stdio.h>
3
4 #include "graphics.h"
5
6 #using "UIcore.dll"
7
8
9 DrawEventWrapper::DrawEventWrapper(void *gc, UIdrawfunc callback, void *eventdata) {
10 this->callback = callback;
11 this->eventdata = eventdata;
12 this->gc = gc;
13 action = gcnew Action<int,int>(this, &DrawEventWrapper::Callback);
14 }
15
16
17 void DrawEventWrapper::Callback(int width, int height)
18 {
19 if (callback)
20 {
21 UI::DrawingArea ^d = (UI::DrawingArea^)PtrToObject(gc);
22 callback(gc, eventdata, width, height);
23 }
24 }
25
26
27 UI_EXPORT void* __stdcall UIdrawingarea(gcroot<UI::Container^> *container, UIdrawfunc f, void *data)
28 {
29 gcroot<UI::DrawingArea^> *canvas = new gcroot<UI::DrawingArea^>();
30 *canvas = gcnew UI::DrawingArea(*container);
31
32 DrawEventWrapper ^ev = gcnew DrawEventWrapper(ObjectToPtr(*canvas), f, data);
33 (*canvas)->resizeCallback = ev->action;
34
35 return canvas;
36 }
37
38
39 UI_EXPORT void __stdcall UIdrawingarea_redraw(gcroot<UI::DrawingArea^> *drawingarea)
40 {
41 (*drawingarea)->Redraw();
42 }
43
44
45 /* ------------------------- drawing functions ------------------------- */
46
47 UI_EXPORT void __stdcall UIgraphics_color(void *g, int red, int green, int blue)
48 {
49 UI::DrawingArea ^d = (UI::DrawingArea^)PtrToObject(g);
50 d->SetColor(red, green, blue);
51 }
52
53 UI_EXPORT void __stdcall UIdraw_line(void *g, int x1, int y1, int x2, int y2)
54 {
55 UI::DrawingArea ^d = (UI::DrawingArea^)PtrToObject(g);
56 d->DrawLine(x1, y1, x2, y2);
57 }
58
59 UI_EXPORT void __stdcall UIdraw_rect(void *g, int x, int y, int w, int h, int fill)
60 {
61 UI::DrawingArea ^d = (UI::DrawingArea^)PtrToObject(g);
62 d->DrawRect(x, y, w, h, fill ? true : false);
63 }

mercurial