milsko/src/backend/haiku.cc

672 lines
14 KiB
C++
Raw Normal View History

2026-04-28 15:06:38 +00:00
#include <Mw/Milsko.h>
2026-04-28 23:21:32 +09:00
#include "../../external/stb_ds.h"
2026-04-28 17:44:59 +00:00
2026-04-29 04:24:01 +09:00
static void fix_point(BPoint* p, MwView* v) {
2026-04-29 01:03:50 +09:00
p->x = p->x * (v->handle->haiku.width + 1) / v->handle->haiku.width;
p->y = p->y * (v->handle->haiku.height + 1) / v->handle->haiku.height;
}
2026-04-28 17:44:59 +00:00
MwApplication::MwApplication(BRect rc, MwLL handle) : BApplication("application/milsko-generic") {
2026-04-28 12:59:25 +00:00
BScreen* scr = new BScreen();
float left = rc.left;
float top = rc.top;
2026-04-28 17:44:59 +00:00
if(rc.left == MwDEFAULT) left = (scr->Frame().Width() - rc.Width()) / 2;
if(rc.top == MwDEFAULT) top = (scr->Frame().Height() - rc.Height()) / 2;
rc = BRect(BPoint(left, top), BSize(rc.Width(), rc.Height()));
2026-04-28 23:21:32 +09:00
this->window = new MwWindow(rc, B_TITLED_WINDOW, 0);
2026-04-28 17:44:59 +00:00
this->window->Show();
2026-04-28 23:21:32 +09:00
handle->haiku.view = new MwView(handle, this->window->Bounds(), B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
2026-04-28 18:24:29 +00:00
this->window->AddChild(handle->haiku.view);
2026-04-28 17:44:59 +00:00
delete scr;
}
2026-04-28 12:59:25 +00:00
MwApplication::~MwApplication() {
2026-04-28 17:44:59 +00:00
delete this->window;
}
2026-04-28 12:59:25 +00:00
void MwApplication::MessageReceived(BMessage* message) {
switch(message->what) {
2026-04-29 04:24:01 +09:00
case BAPP_MW_DESTROY:
{
2026-04-28 12:59:25 +00:00
this->Quit();
break;
}
2026-04-29 04:24:01 +09:00
default:
{
2026-04-28 12:59:25 +00:00
BLooper::MessageReceived(message);
break;
}
}
}
2026-04-28 23:21:32 +09:00
MwView::MwView(MwLL handle, BRect frame, uint32 resizingMode, uint32 flags) : BView(frame, NULL, resizingMode, flags) {
this->handle = handle;
this->locker = new BLocker();
2026-04-29 01:03:50 +09:00
this->SetDrawingMode(B_OP_OVER);
2026-04-29 03:41:00 +09:00
this->SetLineMode(B_BUTT_CAP, B_BUTT_JOIN);
2026-04-29 01:03:50 +09:00
2026-04-29 04:24:01 +09:00
this->SetViewColor(B_TRANSPARENT_COLOR);
2026-04-29 03:41:00 +09:00
this->buttons = 0;
2026-04-28 23:21:32 +09:00
}
2026-04-29 04:24:01 +09:00
MwView::~MwView() {
2026-04-28 23:21:32 +09:00
delete this->locker;
}
void MwView::MessageReceived(BMessage* message) {
switch(message->what) {
2026-04-29 03:41:00 +09:00
case BVIEW_MW_DESTROY:
{
this->RemoveSelf();
delete this;
break;
}
case BVIEW_MW_DETACH:
{
this->RemoveSelf();
break;
}
2026-04-29 04:24:01 +09:00
case BVIEW_MW_RESIZE:
{
2026-04-28 23:21:32 +09:00
int width, height;
if(message->FindInt32("view-width", &width) != B_OK) break;
if(message->FindInt32("view-height", &height) != B_OK) break;
2026-04-29 04:24:01 +09:00
if(this->handle->haiku.app == NULL) {
2026-04-29 03:41:00 +09:00
this->ResizeTo(width, height);
2026-04-29 04:24:01 +09:00
} else {
2026-04-29 03:41:00 +09:00
this->Window()->ResizeTo(width, height);
}
2026-04-28 23:21:32 +09:00
break;
}
2026-04-29 04:24:01 +09:00
case BVIEW_MW_MOVE:
{
2026-04-28 23:21:32 +09:00
int x, y;
if(message->FindInt32("view-x", &x) != B_OK) break;
if(message->FindInt32("view-y", &y) != B_OK) break;
2026-04-29 04:24:01 +09:00
if(this->handle->haiku.app == NULL) {
2026-04-29 03:41:00 +09:00
this->MoveTo(x, y);
2026-04-29 04:24:01 +09:00
} else {
2026-04-29 03:41:00 +09:00
this->Window()->MoveTo(x, y);
}
break;
}
case BVIEW_MW_SHOW:
{
2026-04-29 04:24:01 +09:00
if(this->Window() == NULL) {
2026-04-29 03:41:00 +09:00
this->handle->haiku.parent->haiku.view->AddChild(this);
}
break;
}
case BVIEW_MW_HIDE:
{
2026-04-29 04:24:01 +09:00
if(this->Window() != NULL) {
2026-04-29 03:41:00 +09:00
this->RemoveSelf();
}
2026-04-28 23:21:32 +09:00
break;
}
2026-04-29 01:03:50 +09:00
case BVIEW_MW_SET_COLOR:
{
int32 rgb[3];
2026-04-29 04:24:01 +09:00
int i;
2026-04-29 01:03:50 +09:00
rgb[0] = rgb[1] = rgb[2] = 0;
for(i = 0; i < 3 && message->FindInt32("view-color", i, &rgb[i]) == B_OK; i++);
this->SetHighColor(rgb[0], rgb[1], rgb[2]);
break;
}
2026-04-28 23:21:32 +09:00
case BVIEW_MW_POLYGON:
{
2026-04-29 04:24:01 +09:00
int i;
2026-04-28 23:21:32 +09:00
BPoint p;
2026-04-29 03:41:00 +09:00
BPoint points[32];
2026-04-28 23:21:32 +09:00
2026-04-29 04:24:01 +09:00
for(i = 0; i < 32 && message->FindPoint("view-point", i, &p) == B_OK; i++) {
2026-04-28 23:21:32 +09:00
points[i] = p;
}
this->FillPolygon(points, i);
break;
}
2026-04-29 03:41:00 +09:00
case BVIEW_MW_LINE:
{
2026-04-29 04:24:01 +09:00
int i;
2026-04-29 03:41:00 +09:00
BPoint p;
BPoint points[2];
2026-04-29 04:24:01 +09:00
for(i = 0; i < 2 && message->FindPoint("view-point", i, &p) == B_OK; i++) {
2026-04-29 03:41:00 +09:00
points[i] = p;
}
this->StrokeLine(points[0], points[1]);
break;
}
2026-04-29 01:03:50 +09:00
case BVIEW_MW_BITMAP:
{
2026-04-29 04:24:01 +09:00
BRect rc;
2026-04-29 01:03:50 +09:00
BBitmap* bitmap;
if(message->FindRect("view-rect", &rc) != B_OK) break;
if(message->FindPointer("view-bitmap", (void**)&bitmap) != B_OK) break;
this->DrawBitmap(bitmap, rc);
break;
}
2026-04-29 03:41:00 +09:00
case BVIEW_MW_RENDER:
{
this->Invalidate();
break;
}
2026-04-29 04:24:01 +09:00
default:
{
2026-04-28 23:21:32 +09:00
BView::MessageReceived(message);
break;
}
}
}
2026-04-29 04:24:01 +09:00
void MwView::PostMessage(BMessage* message) {
2026-04-28 23:21:32 +09:00
BMessage copy = *message;
copy.AddPointer("window-view", this);
this->Window()->PostMessage(&copy);
}
2026-04-29 04:24:01 +09:00
void MwView::PostMessage(uint32 command) {
2026-04-29 03:41:00 +09:00
BMessage msg(command);
this->PostMessage(&msg);
}
2026-04-29 04:24:01 +09:00
void MwView::Invalidate() {
2026-04-29 03:41:00 +09:00
this->Draw(BRect(0, 0, 0, 0));
}
2026-04-29 04:24:01 +09:00
void MwView::AttachedToWindow() {
2026-04-29 03:41:00 +09:00
this->SetOrigin(0, 0);
}
2026-04-29 04:24:01 +09:00
void MwView::Draw(BRect updateRect) {
2026-04-28 23:21:32 +09:00
MwLLHaikuEvent ev;
(void)updateRect;
ev.type = MwLLHAIKU_EVENT_DRAW;
this->locker->Lock();
arrput(this->handle->haiku.events, ev);
this->locker->Unlock();
}
2026-04-29 04:24:01 +09:00
void MwView::MouseDown(BPoint point) {
2026-04-29 03:41:00 +09:00
MwLLHaikuEvent ev;
2026-04-29 04:24:01 +09:00
uint32 btn;
BPoint p;
2026-04-29 03:41:00 +09:00
this->GetMouse(&p, &btn, false);
2026-04-29 04:24:01 +09:00
2026-04-29 03:41:00 +09:00
this->SetMouseEventMask(B_LOCK_WINDOW_FOCUS);
2026-04-29 04:24:01 +09:00
ev.type = MwLLHAIKU_EVENT_MOUSEDOWN;
2026-04-29 03:41:00 +09:00
ev.mouse.point.x = point.x;
ev.mouse.point.y = point.y;
2026-04-29 04:24:01 +09:00
if((btn & B_PRIMARY_MOUSE_BUTTON) && !(this->buttons & B_PRIMARY_MOUSE_BUTTON)) {
2026-04-29 03:41:00 +09:00
ev.mouse.button = MwMOUSE_LEFT;
2026-04-29 04:24:01 +09:00
} else if((btn & B_SECONDARY_MOUSE_BUTTON) && !(this->buttons & B_SECONDARY_MOUSE_BUTTON)) {
2026-04-29 03:41:00 +09:00
ev.mouse.button = MwMOUSE_RIGHT;
2026-04-29 04:24:01 +09:00
} else if((btn & B_TERTIARY_MOUSE_BUTTON) && !(this->buttons & B_TERTIARY_MOUSE_BUTTON)) {
2026-04-29 03:41:00 +09:00
ev.mouse.button = MwMOUSE_MIDDLE;
}
this->buttons = btn;
this->locker->Lock();
arrput(this->handle->haiku.events, ev);
this->locker->Unlock();
}
2026-04-29 04:24:01 +09:00
void MwView::MouseUp(BPoint point) {
2026-04-29 03:41:00 +09:00
MwLLHaikuEvent ev;
2026-04-29 04:24:01 +09:00
uint32 btn;
BPoint p;
2026-04-29 03:41:00 +09:00
this->GetMouse(&p, &btn, false);
2026-04-29 04:24:01 +09:00
ev.type = MwLLHAIKU_EVENT_MOUSEUP;
2026-04-29 03:41:00 +09:00
ev.mouse.point.x = point.x;
ev.mouse.point.y = point.y;
2026-04-29 04:24:01 +09:00
if(!(btn & B_PRIMARY_MOUSE_BUTTON) && (this->buttons & B_PRIMARY_MOUSE_BUTTON)) {
2026-04-29 03:41:00 +09:00
ev.mouse.button = MwMOUSE_LEFT;
2026-04-29 04:24:01 +09:00
} else if(!(btn & B_SECONDARY_MOUSE_BUTTON) && (this->buttons & B_SECONDARY_MOUSE_BUTTON)) {
2026-04-29 03:41:00 +09:00
ev.mouse.button = MwMOUSE_RIGHT;
2026-04-29 04:24:01 +09:00
} else if(!(btn & B_TERTIARY_MOUSE_BUTTON) && (this->buttons & B_TERTIARY_MOUSE_BUTTON)) {
2026-04-29 03:41:00 +09:00
ev.mouse.button = MwMOUSE_MIDDLE;
}
this->buttons = btn;
this->locker->Lock();
arrput(this->handle->haiku.events, ev);
this->locker->Unlock();
}
2026-04-29 04:24:01 +09:00
void MwView::MouseMoved(BPoint point, uint32 transit, const BMessage* message) {
2026-04-29 03:41:00 +09:00
MwLLHaikuEvent ev;
2026-04-29 04:24:01 +09:00
ev.type = MwLLHAIKU_EVENT_MOUSEMOVED;
2026-04-29 03:41:00 +09:00
ev.mouse.point.x = point.x;
ev.mouse.point.y = point.y;
2026-04-29 04:24:01 +09:00
ev.mouse.button = 0;
2026-04-29 03:41:00 +09:00
this->locker->Lock();
arrput(this->handle->haiku.events, ev);
this->locker->Unlock();
}
2026-04-29 04:24:01 +09:00
void MwView::SetColor(MwLLColor color) {
2026-04-29 01:03:50 +09:00
BMessage msg(BVIEW_MW_SET_COLOR);
msg.AddInt32("view-color", color->common.red);
msg.AddInt32("view-color", color->common.green);
msg.AddInt32("view-color", color->common.blue);
this->PostMessage(&msg);
}
2026-04-28 23:21:32 +09:00
MwWindow::MwWindow(BRect frame, window_type type, uint32 flags) : BWindow(frame, "Milsko", type, flags) {
}
void MwWindow::MessageReceived(BMessage* message) {
void* ptr;
2026-04-29 04:24:01 +09:00
if(message->FindPointer("window-view", &ptr) == B_OK) {
2026-04-28 23:21:32 +09:00
MwView* v = (MwView*)ptr;
v->MessageReceived(message);
return;
}
switch(message->what) {
2026-04-29 04:24:01 +09:00
case BWIN_MW_SET_TITLE:
{
2026-04-28 23:21:32 +09:00
const char* title;
if(message->FindString("window-title", &title) != B_OK) break;
this->SetTitle(title);
break;
}
2026-04-29 04:24:01 +09:00
default:
{
2026-04-28 23:21:32 +09:00
BWindow::MessageReceived(message);
break;
}
}
}
2026-04-28 12:59:25 +00:00
struct app_param {
BRect rc;
MwLL handle;
};
static int32 app_thread(void* data) {
struct app_param* r = (struct app_param*)data;
r->handle->haiku.app = new MwApplication(r->rc, r->handle);
r->handle->haiku.app->Run();
free(r);
return 0;
}
2026-04-28 16:30:01 +00:00
MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
2026-04-29 04:24:01 +09:00
MwLL r = (MwLL)malloc(sizeof(*r));
2026-04-29 01:03:50 +09:00
BRect rc = BRect(BPoint(x, y), BSize(width, height));
2026-04-28 15:18:09 +09:00
2026-04-28 16:30:01 +00:00
MwLLCreateCommon(r);
r->common.copy_buffer = 1;
r->common.type = MwLLBackendHaiku;
2026-04-28 18:24:29 +00:00
r->haiku.parent = parent;
2026-04-28 23:21:32 +09:00
r->haiku.events = NULL;
2026-04-28 12:59:25 +00:00
if(parent == NULL) {
struct app_param* p = (struct app_param*)malloc(sizeof(*p));
r->haiku.app = NULL;
2026-04-28 17:44:59 +00:00
2026-04-28 12:59:25 +00:00
p->rc = rc;
p->handle = r;
2026-04-29 04:24:01 +09:00
r->haiku.app = NULL;
2026-04-28 23:21:32 +09:00
r->haiku.view = NULL;
2026-04-28 12:59:25 +00:00
r->haiku.app_thread = spawn_thread(app_thread, NULL, B_NORMAL_PRIORITY, p);
resume_thread(r->haiku.app_thread);
while(r->haiku.app == NULL) MwTimeSleep(10);
} else {
2026-04-28 18:24:29 +00:00
MwLL top = r;
2026-04-28 12:59:25 +00:00
while(top->haiku.parent != NULL) {
2026-04-28 18:24:29 +00:00
top = top->haiku.parent;
}
2026-04-28 12:59:25 +00:00
r->haiku.app = NULL;
2026-04-28 23:21:32 +09:00
r->haiku.view = new MwView(r, rc, B_FOLLOW_NONE, B_WILL_DRAW);
2026-04-28 18:24:29 +00:00
2026-04-28 17:44:59 +00:00
parent->haiku.view->AddChild(r->haiku.view);
}
2026-04-29 04:24:01 +09:00
r->haiku.x = x;
r->haiku.y = y;
r->haiku.width = width;
2026-04-28 23:21:32 +09:00
r->haiku.height = height;
2026-04-28 16:30:01 +00:00
return r;
}
void MwLLDestroyImpl(MwLL handle) {
MwLLDestroyCommon(handle);
2026-04-29 03:41:00 +09:00
handle->haiku.view->PostMessage(BVIEW_MW_DESTROY);
2026-04-28 12:59:25 +00:00
if(handle->haiku.app != NULL) {
status_t exit_value;
2026-04-28 23:21:32 +09:00
handle->haiku.app->PostMessage(BAPP_MW_DESTROY);
2026-04-28 12:59:25 +00:00
wait_for_thread(handle->haiku.app_thread, &exit_value);
delete handle->haiku.app;
}
2026-04-28 16:30:01 +00:00
free(handle);
}
2026-04-28 15:18:09 +09:00
2026-04-28 17:44:59 +00:00
void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
2026-04-29 04:24:01 +09:00
int i;
2026-04-28 23:21:32 +09:00
BMessage msg(BVIEW_MW_POLYGON);
2026-04-28 17:44:59 +00:00
2026-04-28 12:59:25 +00:00
for(i = 0; i < points_count; i++) {
2026-04-29 01:03:50 +09:00
BPoint p(points[i].x, points[i].y);
fix_point(&p, handle->haiku.view);
msg.AddPoint("view-point", p);
2026-04-28 17:44:59 +00:00
}
2026-04-29 01:03:50 +09:00
handle->haiku.view->SetColor(color);
2026-04-28 23:21:32 +09:00
handle->haiku.view->PostMessage(&msg);
2026-04-28 17:44:59 +00:00
}
2026-04-28 15:18:09 +09:00
2026-04-29 03:41:00 +09:00
void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
2026-04-29 04:24:01 +09:00
int i;
2026-04-29 03:41:00 +09:00
BMessage msg(BVIEW_MW_LINE);
2026-04-29 04:24:01 +09:00
for(i = 0; i < 2; i++) {
2026-04-29 03:41:00 +09:00
BPoint p(points[i].x, points[i].y);
fix_point(&p, handle->haiku.view);
msg.AddPoint("view-point", p);
}
handle->haiku.view->SetColor(color);
handle->haiku.view->PostMessage(&msg);
}
2026-04-28 15:18:09 +09:00
2026-04-29 04:24:01 +09:00
void MwLLBeginDrawImpl(MwLL handle) {
}
2026-04-28 15:18:09 +09:00
2026-04-29 04:24:01 +09:00
void MwLLEndDrawImpl(MwLL handle) {
}
2026-04-28 15:18:09 +09:00
2026-04-28 16:30:01 +00:00
MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
MwLLColor c = (MwLLColor)malloc(sizeof(*c));
2026-04-28 23:21:32 +09:00
2026-04-28 16:30:01 +00:00
MwLLColorUpdate(handle, c, r, g, b);
2026-04-28 23:21:32 +09:00
2026-04-28 16:30:01 +00:00
return c;
}
2026-04-28 15:18:09 +09:00
2026-04-28 16:30:01 +00:00
void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
c->common.red = r;
c->common.green = g;
c->common.blue = b;
}
2026-04-28 15:18:09 +09:00
2026-04-29 01:03:50 +09:00
void MwLLFreeColorImpl(MwLLColor color) {
free(color);
}
2026-04-28 15:18:09 +09:00
2026-04-28 23:21:32 +09:00
void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
BRect rc;
2026-04-29 04:24:01 +09:00
int m = 0;
2026-04-28 15:18:09 +09:00
2026-04-29 04:24:01 +09:00
if(handle->haiku.app == NULL) {
2026-04-28 23:21:32 +09:00
rc = BRect(BPoint(handle->haiku.x, handle->haiku.y), BSize(handle->haiku.width, handle->haiku.height));
2026-04-29 04:24:01 +09:00
} else {
2026-04-28 23:21:32 +09:00
rc = handle->haiku.app->window->Frame();
}
*x = rc.left;
*y = rc.top;
*w = rc.Width();
*h = rc.Height();
}
2026-04-28 15:18:09 +09:00
2026-04-28 23:21:32 +09:00
void MwLLSetXYImpl(MwLL handle, int x, int y) {
BMessage msg(BVIEW_MW_MOVE);
handle->haiku.x = x;
handle->haiku.y = y;
msg.AddInt32("view-x", x);
msg.AddInt32("view-y", y);
handle->haiku.view->PostMessage(&msg);
}
void MwLLSetWHImpl(MwLL handle, int w, int h) {
BMessage msg(BVIEW_MW_RESIZE);
2026-04-29 04:24:01 +09:00
handle->haiku.width = w;
2026-04-28 23:21:32 +09:00
handle->haiku.height = h;
msg.AddInt32("view-width", w);
msg.AddInt32("view-height", h);
handle->haiku.view->PostMessage(&msg);
2026-04-29 03:41:00 +09:00
MwLLDispatch(handle, resize, NULL);
2026-04-28 23:21:32 +09:00
}
2026-04-28 15:18:09 +09:00
2026-04-28 12:59:25 +00:00
void MwLLSetTitleImpl(MwLL handle, const char* title) {
2026-04-28 23:21:32 +09:00
BMessage msg(BWIN_MW_SET_TITLE);
2026-04-28 12:59:25 +00:00
if(handle->haiku.app == NULL) return;
2026-04-28 23:21:32 +09:00
msg.AddString("window-title", title);
handle->haiku.app->window->PostMessage(&msg);
2026-04-28 12:59:25 +00:00
}
2026-04-28 15:18:09 +09:00
2026-04-28 16:30:01 +00:00
int MwLLPendingImpl(MwLL handle) {
2026-04-28 23:21:32 +09:00
handle->haiku.view->locker->Lock();
2026-04-29 04:24:01 +09:00
if(arrlen(handle->haiku.events) > 0) {
2026-04-28 23:21:32 +09:00
handle->haiku.view->locker->Unlock();
return 1;
}
handle->haiku.view->locker->Unlock();
2026-04-28 16:30:01 +00:00
return 0;
}
2026-04-28 15:18:09 +09:00
2026-04-28 23:21:32 +09:00
void MwLLNextEventImpl(MwLL handle) {
handle->haiku.view->locker->Lock();
2026-04-29 04:24:01 +09:00
while(arrlen(handle->haiku.events) > 0) {
2026-04-28 23:21:32 +09:00
MwLLHaikuEvent* ev = &handle->haiku.events[0];
2026-04-29 04:24:01 +09:00
MwMouse m;
2026-04-29 03:41:00 +09:00
2026-04-29 04:24:01 +09:00
if(ev->type == MwLLHAIKU_EVENT_MOUSEDOWN || ev->type == MwLLHAIKU_EVENT_MOUSEUP) {
m.point = ev->mouse.point;
2026-04-29 03:41:00 +09:00
m.button = ev->mouse.button;
}
2026-04-28 23:21:32 +09:00
2026-04-29 04:24:01 +09:00
if(ev->type == MwLLHAIKU_EVENT_DRAW) {
2026-04-28 23:21:32 +09:00
MwLLDispatch(handle, draw, NULL);
2026-04-29 04:24:01 +09:00
} else if(ev->type == MwLLHAIKU_EVENT_MOUSEDOWN) {
2026-04-29 03:41:00 +09:00
MwLLDispatch(handle, down, &m);
2026-04-29 04:24:01 +09:00
} else if(ev->type == MwLLHAIKU_EVENT_MOUSEUP) {
2026-04-29 03:41:00 +09:00
MwLLDispatch(handle, up, &m);
2026-04-29 04:24:01 +09:00
} else if(ev->type == MwLLHAIKU_EVENT_MOUSEMOVED) {
2026-04-29 03:41:00 +09:00
MwLLDispatch(handle, move, &ev->mouse.point);
2026-04-28 23:21:32 +09:00
}
arrdel(handle->haiku.events, 0);
}
handle->haiku.view->locker->Unlock();
}
2026-04-28 15:18:09 +09:00
2026-04-28 16:30:01 +00:00
MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
2026-04-28 12:59:25 +00:00
MwLLPixmap r = (MwLLPixmap)malloc(sizeof(*r));
2026-04-28 16:30:01 +00:00
r->common.raw = (unsigned char*)malloc(4 * width * height);
memcpy(r->common.raw, data, 4 * width * height);
r->common.width = width;
r->common.height = height;
2026-04-29 01:03:50 +09:00
r->haiku.bitmap = NULL;
2026-04-28 16:30:01 +00:00
MwLLPixmapUpdate(r);
return r;
return r;
}
2026-04-28 15:18:09 +09:00
2026-04-29 01:03:50 +09:00
void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) {
uint32* px = (uint32*)malloc(4 * pixmap->common.width * pixmap->common.height);
2026-04-29 04:24:01 +09:00
int i;
2026-04-29 01:03:50 +09:00
2026-04-29 04:24:01 +09:00
for(i = 0; i < pixmap->common.width * pixmap->common.height; i++) {
2026-04-29 01:03:50 +09:00
unsigned char* ipx = &pixmap->common.raw[4 * i];
px[i] = (ipx[3] << 24) | (ipx[0] << 16) | (ipx[1] << 8) | (ipx[2] << 0);
}
if(pixmap->haiku.bitmap != NULL) delete pixmap->haiku.bitmap;
pixmap->haiku.bitmap = new BBitmap(BRect(0, 0, pixmap->common.width - 1, pixmap->common.height - 1), B_RGBA32);
pixmap->haiku.bitmap->SetBits(px, pixmap->common.width * pixmap->common.height * 4, 0, B_RGBA32);
free(px);
}
2026-04-28 15:18:09 +09:00
2026-04-28 16:30:01 +00:00
void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
free(pixmap->common.raw);
free(pixmap);
}
2026-04-28 15:18:09 +09:00
2026-04-29 01:03:50 +09:00
void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
2026-04-29 04:24:01 +09:00
BPoint p;
BRect rc;
2026-04-29 01:03:50 +09:00
BMessage msg(BVIEW_MW_BITMAP);
p = BPoint(rect->x, rect->y);
fix_point(&p, handle->haiku.view);
rc = BRect(p, BSize(rect->width, rect->height));
msg.AddRect("view-rect", rc);
msg.AddPointer("view-bitmap", pixmap->haiku.bitmap);
handle->haiku.view->PostMessage(&msg);
}
2026-04-28 15:18:09 +09:00
void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {}
2026-04-29 03:41:00 +09:00
void MwLLForceRenderImpl(MwLL handle) {
handle->haiku.view->PostMessage(BVIEW_MW_RENDER);
}
2026-04-28 15:18:09 +09:00
void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {}
void MwLLDetachImpl(MwLL handle, MwPoint* point) {}
2026-04-29 03:41:00 +09:00
void MwLLShowImpl(MwLL handle, int show) {
2026-04-29 04:24:01 +09:00
if(show) {
2026-04-29 03:41:00 +09:00
handle->haiku.view->PostMessage(BVIEW_MW_SHOW);
2026-04-29 04:24:01 +09:00
} else {
2026-04-29 03:41:00 +09:00
handle->haiku.view->PostMessage(BVIEW_MW_HIDE);
}
}
2026-04-28 15:18:09 +09:00
void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int maxy) {}
2026-04-28 15:24:45 +09:00
void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLMakeToolWindowImpl(MwLL handle) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLMakePopupImpl(MwLL handle, MwLL parent) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLBeginStateChangeImpl(MwLL handle) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLEndStateChangeImpl(MwLL handle) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLFocusImpl(MwLL handle) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLGrabPointerImpl(MwLL handle, int toggle) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_type) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLGetClipboardImpl(MwLL handle, int clipboard_type) {}
2026-04-28 15:20:14 +09:00
2026-04-28 15:24:45 +09:00
void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) {}
2026-04-28 15:20:14 +09:00
2026-04-29 03:41:00 +09:00
void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
BScreen* screen = new BScreen();
2026-04-29 04:24:01 +09:00
if(screen->IsValid()) {
rect->width = screen->Frame().Width();
2026-04-29 03:41:00 +09:00
rect->height = screen->Frame().Height();
}
delete screen;
}
2026-04-28 15:20:14 +09:00
2026-04-28 16:30:01 +00:00
void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {
(void)handle;
(void)toggle;
}
2026-04-28 15:20:14 +09:00
2026-04-28 16:30:01 +00:00
MwBool MwLLDoModernImpl(MwLL handle) {
(void)handle;
return MwTRUE;
}
2026-04-28 15:20:14 +09:00
2026-04-28 16:30:01 +00:00
int MwLLHaikuCallInitImpl() {
return 0;
}
2026-04-28 15:21:11 +09:00
2026-04-28 15:06:38 +00:00
#include "call.c"
CALL(Haiku);