diff --git a/include/Mw/MachDep.h b/include/Mw/MachDep.h index a9ac37c6d..f00a119ba 100644 --- a/include/Mw/MachDep.h +++ b/include/Mw/MachDep.h @@ -65,6 +65,8 @@ #if defined(__HAIKU__) && defined(__cplusplus) #include #include +#include +#include #endif #ifdef __APPLE__ diff --git a/pl/rules.pl b/pl/rules.pl index a725c6ca7..b117d5f46 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -98,6 +98,7 @@ if (grep(/^cocoa$/, @backends) || param_get("gnustep")) { if (grep(/^haiku$/, @backends)) { add_cflags("-DUSE_HAIKU"); new_object("src/backend/haiku.cxx"); + add_libs("-lbe"); } if (param_get("stb-image")) { diff --git a/src/backend/haiku.cxx b/src/backend/haiku.cxx index db97322d9..948c2d598 100644 --- a/src/backend/haiku.cxx +++ b/src/backend/haiku.cxx @@ -1,13 +1,58 @@ #include +void MwApplication::ReadyToRun(){ + this->ready = 1; +} + +void MwApplication::Pulse(){ +} + +MwApplication::MwApplication(BRect rc, MwLL handle) : BApplication("application/milsko-generic") { + BScreen* scr = new BScreen(); + float left = rc.left; + float top = rc.top; + + 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())); + + this->window = new BWindow(rc, "Milsko", B_TITLED_WINDOW, 0); + this->window->Show(); + + handle->haiku.view = new BView(this->window->Bounds(), NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW); + + this->ready = 0; + + delete scr; +} + +MwApplication::~MwApplication(){ + delete this->window; +} + MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { MwLL r = (MwLL)malloc(sizeof(*r)); + BRect rc(BPoint(x, y), BSize(width, height)); MwLLCreateCommon(r); r->common.copy_buffer = 1; r->common.type = MwLLBackendHaiku; + if(parent == NULL){ + r->haiku.app = new MwApplication(rc, r); + r->haiku.app->window->AddChild(r->haiku.view); + + r->haiku.app->Run(); + + while(!r->haiku.app->ready); + }else{ + r->haiku.app = NULL; + r->haiku.view = new BView(rc, NULL, B_FOLLOW_NONE, B_WILL_DRAW); + + parent->haiku.view->AddChild(r->haiku.view); + } + return r; } @@ -17,7 +62,18 @@ void MwLLDestroyImpl(MwLL handle) { free(handle); } -void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {} +void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { + BPoint* p = (BPoint*)malloc(sizeof(*p) * points_count); + int i; + + for(i = 0; i < points_count; i++){ + p[i] = BPoint(points[i].x, points[i].y); + } + + handle->haiku.view->FillPolygon(p, points_count); + + free(p); +} void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {}