From e0cbe1aa5dec6398e142a8015e1320c389667379 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 14 Aug 2013 02:53:38 -0400 Subject: [PATCH] Refactor BeDecorator --- .../decorators/BeDecorator/BeDecorator.cpp | 94 ++++++++++--------- .../decorators/BeDecorator/BeDecorator.h | 7 +- src/add-ons/decorators/BeDecorator/Jamfile | 2 +- .../decorators/BeDecorator/resources.rdef | 16 ++-- 4 files changed, 65 insertions(+), 54 deletions(-) diff --git a/src/add-ons/decorators/BeDecorator/BeDecorator.cpp b/src/add-ons/decorators/BeDecorator/BeDecorator.cpp index 6ccbff6af9..8a11437ffb 100644 --- a/src/add-ons/decorators/BeDecorator/BeDecorator.cpp +++ b/src/add-ons/decorators/BeDecorator/BeDecorator.cpp @@ -93,39 +93,6 @@ BeDecorator::~BeDecorator() // #pragma mark - Public methods -/*! \brief Updates the decorator in the rectangular area \a updateRect. - - The default version updates all areas which intersect the frame and tab. - - \param updateRect The rectangular area to update. -*/ -void -BeDecorator::Draw(BRect updateRect) -{ - STRACE(("BeDecorator::Draw(BRect updateRect): ")); - updateRect.PrintToStream(); - - // We need to draw a few things: the tab, the resize knob, the borders, - // and the buttons - fDrawingEngine->SetDrawState(&fDrawState); - - _DrawFrame(updateRect); - _DrawTabs(updateRect & fTitleBarRect); -} - - -void -BeDecorator::Draw() -{ - // Easy way to draw everything - no worries about drawing only certain - // things - fDrawingEngine->SetDrawState(&fDrawState); - - _DrawFrame(BRect(fTopBorder.LeftTop(), fBottomBorder.RightBottom())); - _DrawTabs(fTitleBarRect); -} - - /*! Returns the frame colors for the specified decorator component. The meaning of the color array elements depends on the specified component. @@ -139,7 +106,7 @@ void BeDecorator::GetComponentColors(Component component, uint8 highlight, ComponentColors _colors, Decorator::Tab* _tab) { - TabDecorator::Tab* tab = static_cast(_tab); + Decorator::Tab* tab = static_cast(_tab); switch (component) { case COMPONENT_TAB: if (tab && tab->buttonFocus) { @@ -286,7 +253,7 @@ BeDecorator::_DrawFrame(BRect invalid) } } // left - if (invalid.Intersects(fLeftBorder.InsetByCopy(0, -BorderWidth()))) { + if (invalid.Intersects(fLeftBorder.InsetByCopy(0, -fBorderWidth))) { ComponentColors colors; _GetComponentColors(COMPONENT_LEFT_BORDER, colors, fTopTab); @@ -307,7 +274,7 @@ BeDecorator::_DrawFrame(BRect invalid) } } // right - if (invalid.Intersects(fRightBorder.InsetByCopy(0, -BorderWidth()))) { + if (invalid.Intersects(fRightBorder.InsetByCopy(0, -fBorderWidth))) { ComponentColors colors; _GetComponentColors(COMPONENT_RIGHT_BORDER, colors, fTopTab); @@ -343,7 +310,7 @@ BeDecorator::_DrawFrame(BRect invalid) } } // left - if (invalid.Intersects(fLeftBorder.InsetByCopy(0, -BorderWidth()))) { + if (invalid.Intersects(fLeftBorder.InsetByCopy(0, -fBorderWidth))) { ComponentColors colors; _GetComponentColors(COMPONENT_LEFT_BORDER, colors, fTopTab); @@ -374,7 +341,7 @@ BeDecorator::_DrawFrame(BRect invalid) } } // right - if (invalid.Intersects(fRightBorder.InsetByCopy(0, -BorderWidth()))) { + if (invalid.Intersects(fRightBorder.InsetByCopy(0, -fBorderWidth))) { ComponentColors colors; _GetComponentColors(COMPONENT_RIGHT_BORDER, colors, fTopTab); @@ -482,6 +449,14 @@ BeDecorator::_DrawFrame(BRect invalid) } +/*! \brief Actually draws the tab + + This function is called when the tab itself needs drawn. Other items, + like the window title or buttons, should not be drawn here. + + \param tab The \a tab to update. + \param invalid The area of the \a tab to update. +*/ void BeDecorator::_DrawTab(Decorator::Tab* tab, BRect invalid) { @@ -545,16 +520,26 @@ BeDecorator::_DrawTab(Decorator::Tab* tab, BRect invalid) _DrawTitle(tab, tabRect); - DrawButtons(tab, invalid); + _DrawButtons(tab, invalid); } +/*! \brief Actually draws the title + + The main tasks for this function are to ensure that the decorator draws + the title only in its own area and drawing the title itself. + Using B_OP_COPY for drawing the title is recommended because of the marked + performance hit of the other drawing modes, but it is not a requirement. + + \param _tab The \a tab to update. + \param r area of the title to update. +*/ void BeDecorator::_DrawTitle(Decorator::Tab* _tab, BRect r) { STRACE(("_DrawTitle(%f, %f, %f, %f)\n", r.left, r.top, r.right, r.bottom)); - TabDecorator::Tab* tab = static_cast(_tab); + Decorator::Tab* tab = static_cast(_tab); const BRect& tabRect = tab->tabRect; const BRect& closeRect = tab->closeRect; @@ -596,13 +581,22 @@ BeDecorator::_DrawTitle(Decorator::Tab* _tab, BRect r) } +/*! \brief Actually draws the close button + + Unless a subclass has a particularly large button, it is probably + unnecessary to check the update rectangle. + + \param _tab The \a tab to update. + \param direct Draw without double buffering. + \param rect The area of the button to update. +*/ void BeDecorator::_DrawClose(Decorator::Tab* _tab, bool direct, BRect rect) { STRACE(("_DrawClose(%f,%f,%f,%f)\n", rect.left, rect.top, rect.right, rect.bottom)); - TabDecorator::Tab* tab = static_cast(_tab); + Decorator::Tab* tab = static_cast(_tab); int32 index = (tab->buttonFocus ? 0 : 1) + (tab->closePressed ? 0 : 2); ServerBitmap* bitmap = tab->closeBitmaps[index]; @@ -616,13 +610,22 @@ BeDecorator::_DrawClose(Decorator::Tab* _tab, bool direct, BRect rect) } +/*! \brief Actually draws the zoom button + + Unless a subclass has a particularly large button, it is probably + unnecessary to check the update rectangle. + + \param _tab The \a tab to update. + \param direct Draw without double buffering. + \param rect The area of the button to update. +*/ void BeDecorator::_DrawZoom(Decorator::Tab* _tab, bool direct, BRect rect) { STRACE(("_DrawZoom(%f,%f,%f,%f)\n", rect.left, rect.top, rect.right, rect.bottom)); - TabDecorator::Tab* tab = static_cast(_tab); + Decorator::Tab* tab = static_cast(_tab); int32 index = (tab->buttonFocus ? 0 : 1) + (tab->zoomPressed ? 0 : 2); ServerBitmap* bitmap = tab->zoomBitmaps[index]; if (bitmap == NULL) { @@ -635,6 +638,13 @@ BeDecorator::_DrawZoom(Decorator::Tab* _tab, bool direct, BRect rect) } +void +BeDecorator::_DrawMinimize(Decorator::Tab* tab, bool direct, BRect rect) +{ + // This decorator doesn't have this button +} + + void BeDecorator::_GetButtonSizeAndOffset(const BRect& tabRect, float* _offset, float* _size, float* _inset) const diff --git a/src/add-ons/decorators/BeDecorator/BeDecorator.h b/src/add-ons/decorators/BeDecorator/BeDecorator.h index 51f35c0e50..08e8378961 100644 --- a/src/add-ons/decorators/BeDecorator/BeDecorator.h +++ b/src/add-ons/decorators/BeDecorator/BeDecorator.h @@ -35,21 +35,22 @@ public: BeDecorator(DesktopSettings& settings, BRect frame); virtual ~BeDecorator(); - virtual void Draw(BRect updateRect); - virtual void Draw(); - virtual void GetComponentColors(Component component, uint8 highlight, ComponentColors _colors, Decorator::Tab* tab = NULL); protected: virtual void _DrawFrame(BRect rect); + virtual void _DrawTab(Decorator::Tab* tab, BRect rect); virtual void _DrawTitle(Decorator::Tab* tab, BRect rect); virtual void _DrawClose(Decorator::Tab* tab, bool direct, BRect rect); virtual void _DrawZoom(Decorator::Tab* tab, bool direct, BRect rect); + virtual void _DrawMinimize(Decorator::Tab* tab, bool direct, + BRect rect); + virtual void _GetButtonSizeAndOffset(const BRect& tabRect, float* offset, float* size, float* inset) const; diff --git a/src/add-ons/decorators/BeDecorator/Jamfile b/src/add-ons/decorators/BeDecorator/Jamfile index 32a462632b..11b58b7153 100644 --- a/src/add-ons/decorators/BeDecorator/Jamfile +++ b/src/add-ons/decorators/BeDecorator/Jamfile @@ -19,4 +19,4 @@ Addon BeDecorator : BeDecorator.cpp : be app_server $(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++) : resources.rdef -; + ; diff --git a/src/add-ons/decorators/BeDecorator/resources.rdef b/src/add-ons/decorators/BeDecorator/resources.rdef index 6174acddd4..dbab5016f8 100644 --- a/src/add-ons/decorators/BeDecorator/resources.rdef +++ b/src/add-ons/decorators/BeDecorator/resources.rdef @@ -1,10 +1,10 @@ resource("be:decor:info") message('deco') { - "name" = "Classic BeOS", - "authors" = "DarkWyrm, Stephan Aßmus, Clemens Zeidler", - "short_descr" = "Basic appearance of the classic BeOS.", - "long_descr" = "", - "lic_url" = "", - "lic_name" = "MIT", - "support_url" = "http://www.haiku-os.org/", - float "version" = 1.0 + "name" = "Classic BeOS", + "authors" = "DarkWyrm, Stephan Aßmus, Clemens Zeidler", + "short_descr" = "Classic appearance of the BeOS", + "long_descr" = "", + "lic_url" = "", + "lic_name" = "MIT", + "support_url" = "http://www.haiku-os.org/", + float "version" = 1.1 };