ui/wpf/UIwrapper/UIwrapper/graphics.cpp

Wed, 13 Nov 2024 22:02:50 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 13 Nov 2024 22:02:50 +0100
branch
newapi
changeset 381
b47bda6666ce
parent 137
c9b8b9e0cfe8
permissions
-rw-r--r--

fix gtk3 image loading

#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