ui/wpf/UIwrapper/UIwrapper/graphics.cpp

changeset 137
c9b8b9e0cfe8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/UIwrapper/UIwrapper/graphics.cpp	Mon Jan 23 10:50:22 2017 +0100
@@ -0,0 +1,63 @@
+#include "stdafx.h"
+#include <stdio.h>
+
+#include "graphics.h"
+
+#using "UIcore.dll"
+
+
+DrawEventWrapper::DrawEventWrapper(void *gc, UIdrawfunc callback, void *eventdata) {
+	this->callback = callback;
+	this->eventdata = eventdata;
+	this->gc = gc;
+	action = gcnew Action<int,int>(this, &DrawEventWrapper::Callback);
+}
+
+
+void DrawEventWrapper::Callback(int width, int height)
+{
+	if (callback)
+	{
+		UI::DrawingArea ^d = (UI::DrawingArea^)PtrToObject(gc);
+		callback(gc, eventdata, width, height);
+	}
+}
+
+
+UI_EXPORT void* __stdcall UIdrawingarea(gcroot<UI::Container^> *container, UIdrawfunc f, void *data)
+{
+	gcroot<UI::DrawingArea^> *canvas = new gcroot<UI::DrawingArea^>();
+	*canvas = gcnew UI::DrawingArea(*container);
+
+	DrawEventWrapper ^ev = gcnew DrawEventWrapper(ObjectToPtr(*canvas), f, data);
+	(*canvas)->resizeCallback = ev->action;
+
+	return canvas;
+}
+
+
+UI_EXPORT void __stdcall UIdrawingarea_redraw(gcroot<UI::DrawingArea^> *drawingarea)
+{
+	(*drawingarea)->Redraw();
+}
+
+
+/* ------------------------- drawing functions ------------------------- */
+
+UI_EXPORT void __stdcall UIgraphics_color(void *g, int red, int green, int blue)
+{
+	UI::DrawingArea ^d = (UI::DrawingArea^)PtrToObject(g);
+	d->SetColor(red, green, blue);
+}
+
+UI_EXPORT void __stdcall UIdraw_line(void *g, int x1, int y1, int x2, int y2)
+{
+	UI::DrawingArea ^d = (UI::DrawingArea^)PtrToObject(g);
+	d->DrawLine(x1, y1, x2, y2);
+}
+
+UI_EXPORT void __stdcall UIdraw_rect(void *g, int x, int y, int w, int h, int fill)
+{
+	UI::DrawingArea ^d = (UI::DrawingArea^)PtrToObject(g);
+	d->DrawRect(x, y, w, h, fill ? true : false);
+}

mercurial