ui/wpf/UIwrapper/UIwrapper/graphics.cpp

Thu, 14 Nov 2024 22:28:36 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 14 Nov 2024 22:28:36 +0100
changeset 84
57a359c52617
parent 0
2483f517c562
permissions
-rw-r--r--

load properties after resource creation

#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