From 76f03c201981d541a9409ef201935ebfbb9b89d9 Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 29 Apr 2026 05:20:06 +0900 Subject: [PATCH] stuff --- include/Mw/LowLevel/Haiku.h | 2 +- src/backend/haiku.cc | 75 +++++++++++++++++-------------------- src/text/text.c | 2 +- src/widget/menu.c | 20 +++++----- 4 files changed, 46 insertions(+), 53 deletions(-) diff --git a/include/Mw/LowLevel/Haiku.h b/include/Mw/LowLevel/Haiku.h index 8e6026a..2849e5f 100644 --- a/include/Mw/LowLevel/Haiku.h +++ b/include/Mw/LowLevel/Haiku.h @@ -23,7 +23,7 @@ class MwApplication : public BApplication { public: MwWindow* window; - MwApplication(BRect rc, MwLL handle); + MwApplication(MwRect rc, MwLL handle); ~MwApplication(); void MessageReceived(BMessage* message); diff --git a/src/backend/haiku.cc b/src/backend/haiku.cc index c431374..e04915e 100644 --- a/src/backend/haiku.cc +++ b/src/backend/haiku.cc @@ -2,24 +2,26 @@ #include "../../external/stb_ds.h" -static void fix_point(BPoint* p, MwView* v) { - 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; -} +MwApplication::MwApplication(MwRect rc, MwLL handle) : BApplication("application/milsko-generic") { + BScreen* scr = new BScreen(); + float x = (scr->Frame().Width() - rc.width) / 2; + float y = (scr->Frame().Height() - rc.height) / 2; + BRect rc2; + int dx = rc.x == MwDEFAULT; + int dy = rc.y == MwDEFAULT; -MwApplication::MwApplication(BRect rc, MwLL handle) : BApplication("application/milsko-generic") { - BScreen* scr = new BScreen(); - float left = rc.left; - float top = rc.top; + rc.x += dx ? -rc.x : 0; + rc.y += dy ? -rc.y : 0; - 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())); + if(dx) rc.x += x; + if(dy) rc.y += y; - this->window = new MwWindow(rc, B_TITLED_WINDOW, 0); + rc2 = BRect(rc.x, rc.y, rc.x + rc.width - 1, rc.y + rc.height - 1); + + this->window = new MwWindow(rc2, B_TITLED_WINDOW, 0); this->window->Show(); - handle->haiku.view = new MwView(handle, this->window->Bounds(), B_FOLLOW_ALL_SIDES, B_WILL_DRAW); + handle->haiku.view = new MwView(handle, this->window->Bounds(), B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); this->window->AddChild(handle->haiku.view); @@ -83,9 +85,10 @@ void MwView::MessageReceived(BMessage* message) { if(message->FindInt32("view-height", &height) != B_OK) break; if(this->handle->haiku.app == NULL) { - this->ResizeTo(width, height); + this->ResizeTo(width - 1, height - 1); } else { - this->Window()->ResizeTo(width, height); + this->Window()->ResizeTo(width - 1, height - 1); + this->ResizeTo(width - 1, height - 1); } break; } @@ -322,8 +325,8 @@ void MwWindow::MessageReceived(BMessage* message) { } struct app_param { - BRect rc; - MwLL handle; + MwRect rc; + MwLL handle; }; static int32 app_thread(void* data) { @@ -338,8 +341,14 @@ static int32 app_thread(void* data) { } MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { - MwLL r = (MwLL)malloc(sizeof(*r)); - BRect rc = BRect(BPoint(x, y), BSize(width, height)); + MwLL r = (MwLL)malloc(sizeof(*r)); + MwRect mrc; + BRect rc = BRect(x, y, x + width - 1, x + height - 1); + + mrc.x = x; + mrc.y = y; + mrc.width = width; + mrc.height = height; MwLLCreateCommon(r); @@ -355,7 +364,7 @@ MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { r->haiku.app = NULL; - p->rc = rc; + p->rc = mrc; p->handle = r; r->haiku.app = NULL; @@ -409,8 +418,6 @@ void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor c for(i = 0; i < points_count; i++) { BPoint p(points[i].x, points[i].y); - fix_point(&p, handle->haiku.view); - msg.AddPoint("view-point", p); } @@ -425,8 +432,6 @@ void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { for(i = 0; i < 2; i++) { BPoint p(points[i].x, points[i].y); - fix_point(&p, handle->haiku.view); - msg.AddPoint("view-point", p); } @@ -459,19 +464,10 @@ void MwLLFreeColorImpl(MwLLColor color) { } void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) { - BRect rc; - int m = 0; - - if(handle->haiku.app == NULL) { - rc = BRect(BPoint(handle->haiku.x, handle->haiku.y), BSize(handle->haiku.width, handle->haiku.height)); - } else { - rc = handle->haiku.app->window->Frame(); - } - - *x = rc.left; - *y = rc.top; - *w = rc.Width(); - *h = rc.Height(); + *x = handle->haiku.x; + *y = handle->haiku.y; + *w = handle->haiku.width; + *h = handle->haiku.height; } void MwLLSetXYImpl(MwLL handle, int x, int y) { @@ -589,13 +585,10 @@ void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { } void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { - BPoint p; BRect rc; 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)); + rc = BRect(rect->x, rect->y, rect->x + rect->width - 1, rect->y + rect->height - 1); msg.AddRect("view-rect", rc); msg.AddPointer("view-bitmap", pixmap->haiku.bitmap); diff --git a/src/text/text.c b/src/text/text.c index 9ad6435..cf7bf64 100644 --- a/src/text/text.c +++ b/src/text/text.c @@ -71,7 +71,7 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, int cp; #ifdef TTF - if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf); + if(!MwGetInteger(handle, MwNbitmapFont) && ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf); #endif p.y -= MwTextHeight(handle, ttf, text) / 2 - (MwTextHeight(handle, ttf, text) / count_nl(text)) / 2; diff --git a/src/widget/menu.c b/src/widget/menu.c index edadf40..e242cda 100644 --- a/src/widget/menu.c +++ b/src/widget/menu.c @@ -59,7 +59,7 @@ static void destroy(MwWidget handle) { int in_area; #define MENU_LOOP_INIT \ - p.x = 5; \ + p.x = 0; \ p.y = (MwGetInteger(handle, MwNheight) - MwDefaultBorderWidth(handle)) / 2 + MwDefaultBorderWidth(handle); \ \ r.x = 0; \ @@ -67,28 +67,28 @@ static void destroy(MwWidget handle) { r.width = MwGetInteger(handle, MwNwidth); \ r.height = MwGetInteger(handle, MwNheight); \ \ - rx = r.width - 5; + rx = r.width; #define BEGIN_MENU_LOOP \ for(i = 0; i < arrlen(m->sub); i++) { \ int incr = m->sub[i]->name[0] == '?' ? 1 : 0; \ - int tw = MwTextWidth(handle, NULL, m->sub[i]->name + incr); \ - int th = MwTextHeight(handle, NULL, m->sub[i]->name + incr); \ + int tw = MwTextWidth(handle, MwFLBuildFont(MwFLFlagBold), m->sub[i]->name + incr); \ + int th = MwTextHeight(handle, MwFLBuildFont(MwFLFlagBold), m->sub[i]->name + incr); \ \ if(incr) { \ - p.x = rx -= tw; \ - rx -= 10; \ + p.x = rx -= 10 + tw; \ } \ \ - r.x = p.x - 5; \ + r.x = p.x; \ r.y = p.y + ((MwGetInteger(handle, MwNheight) - p.y * 2) - (th + 10)) / 2; \ r.width = tw + 10; \ r.height = th + 10; \ \ - in_area = (r.x <= handle->mouse_point.x && r.y <= handle->mouse_point.y && handle->mouse_point.x <= (int)(r.x + r.width) && handle->mouse_point.y <= (int)(r.y + r.height)) ? 1 : 0; + in_area = (r.x <= handle->mouse_point.x && r.y <= handle->mouse_point.y && handle->mouse_point.x <= (int)(r.x + r.width) && handle->mouse_point.y <= (int)(r.y + r.height)) ? 1 : 0; \ + p.x += 5 + tw / 2; #define END_MENU_LOOP \ - p.x += tw + 20; \ + p.x += tw / 2 + 5; \ } #define NEW_SUBMENU \ @@ -115,7 +115,7 @@ static void draw(MwWidget handle) { MwDrawWidgetBack(handle, &r, base, 0, MwFALSE); } - MwDrawText(handle, MwFLBuildFont((m->sub[i]->wsub != NULL || (in_area && handle->pressed)) ? MwFLFlagBold : 0), &p, m->sub[i]->name + incr, MwALIGNMENT_BEGINNING, text); + MwDrawText(handle, MwFLBuildFont((m->sub[i]->wsub != NULL || (in_area && handle->pressed)) ? MwFLFlagBold : 0), &p, m->sub[i]->name + incr, MwALIGNMENT_CENTER, text); END_MENU_LOOP; MwLLFreeColor(text);