From a7aa50ae2c538be59e684f0568bec5a7a21f5a56 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 23 Nov 2015 18:08:34 -0500 Subject: [PATCH] Started implementing uiArea on Haiku. --- haiku/area.cpp | 57 +++++++++++++++++++++++++++++++++++++++--- haiku/combobox.cpp | 3 ++- haiku/draw.cpp | 6 +++-- haiku/uipriv_haiku.hpp | 2 +- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/haiku/area.cpp b/haiku/area.cpp index 2b8f9083..e8d82bbf 100644 --- a/haiku/area.cpp +++ b/haiku/area.cpp @@ -1,17 +1,53 @@ // 18 november 2015 #include "uipriv_haiku.hpp" +// TODO scrollbars + +class areaView : public BView { +public: + // C++11! Inherit constructors. + using BView::BView; + + uiArea *a; + virtual void Draw(BRect updateRect); +}; + struct uiArea { uiHaikuControl c; - BStringView *dummy; + areaView *area; + uiAreaHandler *ah; }; uiHaikuDefineControl( uiArea, // type name uiAreaType, // type function - dummy // handle + area // handle ) +void areaView::Draw(BRect updateRect) +{ + uiAreaHandler *ah = this->a->ah; + uiAreaDrawParams dp; + BRect bounds; + + dp.Context = newContext(this); + + bounds = this->Bounds(); + dp.ClientWidth = bounds.right - bounds.left; + dp.ClientHeight = bounds.bottom - bounds.top; + + dp.ClipX = updateRect.left; + dp.ClipY = updateRect.top; + dp.ClipWidth = updateRect.right - updateRect.left; + dp.ClipHeight = updateRect.bottom - updateRect.top; + + // TODO scroll positions + + (*(ah->Draw))(ah, this->a, &dp); + + freeContext(dp.Context); +} + void uiAreaUpdateScroll(uiArea *a) { // TODO @@ -19,7 +55,8 @@ void uiAreaUpdateScroll(uiArea *a) void uiAreaQueueRedrawAll(uiArea *a) { - // TODO + // TODO does this really /queue/ a redraw? or does it redraw right away, regardless of the drawing machinery? + a->area->Invalidate(); } uiArea *uiNewArea(uiAreaHandler *ah) @@ -28,7 +65,19 @@ uiArea *uiNewArea(uiAreaHandler *ah) a = (uiArea *) uiNewControl(uiAreaType()); - a->dummy = new BStringView(NULL, "TODO uiArea not implemented"); + a->ah = ah; + + // TODO: + // - B_FULL_UPDATE_ON_RESIZE? + // - B_FRAME_EVENTS? + // - B_NAVIGABLE? + // - B_SUBPIXEL_PRECISE? + // - B_INVALIDATE_AFTER_LAYOUT? + a->area = new areaView(NULL, + B_WILL_DRAW | B_SUPPORTS_LAYOUT, + NULL); + a->area->a = a; + // TODO background color uiHaikuFinishNewControl(a, uiArea); diff --git a/haiku/combobox.cpp b/haiku/combobox.cpp index c43587da..6232d041 100644 --- a/haiku/combobox.cpp +++ b/haiku/combobox.cpp @@ -20,7 +20,8 @@ void uiComboboxAppend(uiCombobox *c, const char *text) intmax_t uiComboboxSelected(uiCombobox *c) { // TODO - return -1; + // return 0 so the area test can work + return 0; } void uiComboboxSetSelected(uiCombobox *c, intmax_t n) diff --git a/haiku/draw.cpp b/haiku/draw.cpp index 1fd7bb9f..f957fd86 100644 --- a/haiku/draw.cpp +++ b/haiku/draw.cpp @@ -3,6 +3,8 @@ #include "uipriv_haiku.hpp" using namespace std; +// TODO alpha doesn't work + struct uiDrawPath { BShape *shape; uiDrawFillMode fillMode; @@ -15,7 +17,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode fillMode) p = uiNew(uiDrawPath); p->shape = new BShape(); - p->fillMode = mode; + p->fillMode = fillMode; return p; } @@ -106,7 +108,7 @@ static void drawArc(uiDrawPath *p, struct arc *a, void (*startFunction)(uiDrawPa if (a->negative) counterclockwise = true; else - counterclockwise = false + counterclockwise = false; // TODO explain the outer if if (!a->negative) if (a->sweep > M_PI) diff --git a/haiku/uipriv_haiku.hpp b/haiku/uipriv_haiku.hpp index 37004189..8fcd192d 100644 --- a/haiku/uipriv_haiku.hpp +++ b/haiku/uipriv_haiku.hpp @@ -24,5 +24,5 @@ extern void singleChildSetMargined(struct singleChild *s, float inset); // TODO write helper functions? // draw.cpp -extern uiDrawContext *newContext(BView *view) +extern uiDrawContext *newContext(BView *view); extern void freeContext(uiDrawContext *c);