Sun, 29 Sep 2024 15:55:56 +0200
implement file dialog for gtk4
#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); }