This commit is contained in:
parent
c095fb97a8
commit
76f03c2019
4 changed files with 46 additions and 53 deletions
|
|
@ -23,7 +23,7 @@ class MwApplication : public BApplication {
|
||||||
public:
|
public:
|
||||||
MwWindow* window;
|
MwWindow* window;
|
||||||
|
|
||||||
MwApplication(BRect rc, MwLL handle);
|
MwApplication(MwRect rc, MwLL handle);
|
||||||
~MwApplication();
|
~MwApplication();
|
||||||
|
|
||||||
void MessageReceived(BMessage* message);
|
void MessageReceived(BMessage* message);
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,26 @@
|
||||||
|
|
||||||
#include "../../external/stb_ds.h"
|
#include "../../external/stb_ds.h"
|
||||||
|
|
||||||
static void fix_point(BPoint* p, MwView* v) {
|
MwApplication::MwApplication(MwRect rc, MwLL handle) : BApplication("application/milsko-generic") {
|
||||||
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(BRect rc, MwLL handle) : BApplication("application/milsko-generic") {
|
|
||||||
BScreen* scr = new BScreen();
|
BScreen* scr = new BScreen();
|
||||||
float left = rc.left;
|
float x = (scr->Frame().Width() - rc.width) / 2;
|
||||||
float top = rc.top;
|
float y = (scr->Frame().Height() - rc.height) / 2;
|
||||||
|
BRect rc2;
|
||||||
|
int dx = rc.x == MwDEFAULT;
|
||||||
|
int dy = rc.y == MwDEFAULT;
|
||||||
|
|
||||||
if(rc.left == MwDEFAULT) left = (scr->Frame().Width() - rc.Width()) / 2;
|
rc.x += dx ? -rc.x : 0;
|
||||||
if(rc.top == MwDEFAULT) top = (scr->Frame().Height() - rc.Height()) / 2;
|
rc.y += dy ? -rc.y : 0;
|
||||||
rc = BRect(BPoint(left, top), BSize(rc.Width(), rc.Height()));
|
|
||||||
|
|
||||||
this->window = new MwWindow(rc, B_TITLED_WINDOW, 0);
|
if(dx) rc.x += x;
|
||||||
|
if(dy) rc.y += y;
|
||||||
|
|
||||||
|
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();
|
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);
|
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(message->FindInt32("view-height", &height) != B_OK) break;
|
||||||
|
|
||||||
if(this->handle->haiku.app == NULL) {
|
if(this->handle->haiku.app == NULL) {
|
||||||
this->ResizeTo(width, height);
|
this->ResizeTo(width - 1, height - 1);
|
||||||
} else {
|
} else {
|
||||||
this->Window()->ResizeTo(width, height);
|
this->Window()->ResizeTo(width - 1, height - 1);
|
||||||
|
this->ResizeTo(width - 1, height - 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -322,7 +325,7 @@ void MwWindow::MessageReceived(BMessage* message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct app_param {
|
struct app_param {
|
||||||
BRect rc;
|
MwRect rc;
|
||||||
MwLL handle;
|
MwLL handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -339,7 +342,13 @@ static int32 app_thread(void* data) {
|
||||||
|
|
||||||
MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
MwLL r = (MwLL)malloc(sizeof(*r));
|
MwLL r = (MwLL)malloc(sizeof(*r));
|
||||||
BRect rc = BRect(BPoint(x, y), BSize(width, height));
|
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);
|
MwLLCreateCommon(r);
|
||||||
|
|
||||||
|
|
@ -355,7 +364,7 @@ MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
|
|
||||||
r->haiku.app = NULL;
|
r->haiku.app = NULL;
|
||||||
|
|
||||||
p->rc = rc;
|
p->rc = mrc;
|
||||||
p->handle = r;
|
p->handle = r;
|
||||||
|
|
||||||
r->haiku.app = NULL;
|
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++) {
|
for(i = 0; i < points_count; i++) {
|
||||||
BPoint p(points[i].x, points[i].y);
|
BPoint p(points[i].x, points[i].y);
|
||||||
|
|
||||||
fix_point(&p, handle->haiku.view);
|
|
||||||
|
|
||||||
msg.AddPoint("view-point", p);
|
msg.AddPoint("view-point", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -425,8 +432,6 @@ void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
|
||||||
for(i = 0; i < 2; i++) {
|
for(i = 0; i < 2; i++) {
|
||||||
BPoint p(points[i].x, points[i].y);
|
BPoint p(points[i].x, points[i].y);
|
||||||
|
|
||||||
fix_point(&p, handle->haiku.view);
|
|
||||||
|
|
||||||
msg.AddPoint("view-point", p);
|
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) {
|
void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
|
||||||
BRect rc;
|
*x = handle->haiku.x;
|
||||||
int m = 0;
|
*y = handle->haiku.y;
|
||||||
|
*w = handle->haiku.width;
|
||||||
if(handle->haiku.app == NULL) {
|
*h = handle->haiku.height;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwLLSetXYImpl(MwLL handle, int x, int y) {
|
void MwLLSetXYImpl(MwLL handle, int x, int y) {
|
||||||
|
|
@ -589,13 +585,10 @@ void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
|
void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
|
||||||
BPoint p;
|
|
||||||
BRect rc;
|
BRect rc;
|
||||||
BMessage msg(BVIEW_MW_BITMAP);
|
BMessage msg(BVIEW_MW_BITMAP);
|
||||||
|
|
||||||
p = BPoint(rect->x, rect->y);
|
rc = BRect(rect->x, rect->y, rect->x + rect->width - 1, rect->y + rect->height - 1);
|
||||||
fix_point(&p, handle->haiku.view);
|
|
||||||
rc = BRect(p, BSize(rect->width, rect->height));
|
|
||||||
|
|
||||||
msg.AddRect("view-rect", rc);
|
msg.AddRect("view-rect", rc);
|
||||||
msg.AddPointer("view-bitmap", pixmap->haiku.bitmap);
|
msg.AddPointer("view-bitmap", pixmap->haiku.bitmap);
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text,
|
||||||
int cp;
|
int cp;
|
||||||
|
|
||||||
#ifdef TTF
|
#ifdef TTF
|
||||||
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
|
if(!MwGetInteger(handle, MwNbitmapFont) && ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
p.y -= MwTextHeight(handle, ttf, text) / 2 - (MwTextHeight(handle, ttf, text) / count_nl(text)) / 2;
|
p.y -= MwTextHeight(handle, ttf, text) / 2 - (MwTextHeight(handle, ttf, text) / count_nl(text)) / 2;
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ static void destroy(MwWidget handle) {
|
||||||
int in_area;
|
int in_area;
|
||||||
|
|
||||||
#define MENU_LOOP_INIT \
|
#define MENU_LOOP_INIT \
|
||||||
p.x = 5; \
|
p.x = 0; \
|
||||||
p.y = (MwGetInteger(handle, MwNheight) - MwDefaultBorderWidth(handle)) / 2 + MwDefaultBorderWidth(handle); \
|
p.y = (MwGetInteger(handle, MwNheight) - MwDefaultBorderWidth(handle)) / 2 + MwDefaultBorderWidth(handle); \
|
||||||
\
|
\
|
||||||
r.x = 0; \
|
r.x = 0; \
|
||||||
|
|
@ -67,28 +67,28 @@ static void destroy(MwWidget handle) {
|
||||||
r.width = MwGetInteger(handle, MwNwidth); \
|
r.width = MwGetInteger(handle, MwNwidth); \
|
||||||
r.height = MwGetInteger(handle, MwNheight); \
|
r.height = MwGetInteger(handle, MwNheight); \
|
||||||
\
|
\
|
||||||
rx = r.width - 5;
|
rx = r.width;
|
||||||
|
|
||||||
#define BEGIN_MENU_LOOP \
|
#define BEGIN_MENU_LOOP \
|
||||||
for(i = 0; i < arrlen(m->sub); i++) { \
|
for(i = 0; i < arrlen(m->sub); i++) { \
|
||||||
int incr = m->sub[i]->name[0] == '?' ? 1 : 0; \
|
int incr = m->sub[i]->name[0] == '?' ? 1 : 0; \
|
||||||
int tw = MwTextWidth(handle, NULL, m->sub[i]->name + incr); \
|
int tw = MwTextWidth(handle, MwFLBuildFont(MwFLFlagBold), m->sub[i]->name + incr); \
|
||||||
int th = MwTextHeight(handle, NULL, m->sub[i]->name + incr); \
|
int th = MwTextHeight(handle, MwFLBuildFont(MwFLFlagBold), m->sub[i]->name + incr); \
|
||||||
\
|
\
|
||||||
if(incr) { \
|
if(incr) { \
|
||||||
p.x = rx -= tw; \
|
p.x = rx -= 10 + tw; \
|
||||||
rx -= 10; \
|
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
r.x = p.x - 5; \
|
r.x = p.x; \
|
||||||
r.y = p.y + ((MwGetInteger(handle, MwNheight) - p.y * 2) - (th + 10)) / 2; \
|
r.y = p.y + ((MwGetInteger(handle, MwNheight) - p.y * 2) - (th + 10)) / 2; \
|
||||||
r.width = tw + 10; \
|
r.width = tw + 10; \
|
||||||
r.height = th + 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 \
|
#define END_MENU_LOOP \
|
||||||
p.x += tw + 20; \
|
p.x += tw / 2 + 5; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NEW_SUBMENU \
|
#define NEW_SUBMENU \
|
||||||
|
|
@ -115,7 +115,7 @@ static void draw(MwWidget handle) {
|
||||||
MwDrawWidgetBack(handle, &r, base, 0, MwFALSE);
|
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;
|
END_MENU_LOOP;
|
||||||
|
|
||||||
MwLLFreeColor(text);
|
MwLLFreeColor(text);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue