ui/wpf/UIwrapper/UIwrapper/graphics.cpp

Mon, 22 May 2023 21:21:20 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 22 May 2023 21:21:20 +0200
branch
newapi
changeset 176
bc63cb601f6d
parent 137
c9b8b9e0cfe8
permissions
-rw-r--r--

port motif code to ucx 3

#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