From c4e211feb65c3656c3ad7dba1b8b60e983ca1e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 23 Jan 2010 12:48:18 +0000 Subject: [PATCH] * Refactored a method to draw a label when the location is already known. (This one takes care of setting up the correct color.) * Added TODO about using either B_CONTROL_TEXT_COLOR, or elliminating that constant (which I am in favor of...). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35260 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/ControlLook.h | 8 +++++ src/kits/interface/ControlLook.cpp | 47 +++++++++++++++++++----------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/headers/os/interface/ControlLook.h b/headers/os/interface/ControlLook.h index 4aa5e7eccc..7bb834c65e 100644 --- a/headers/os/interface/ControlLook.h +++ b/headers/os/interface/ControlLook.h @@ -257,6 +257,14 @@ public: const rgb_color& base, uint32 flags, const BAlignment& alignment); + // TODO: This should also be virtual + // TODO: Would be nice to have a (non-virtual) version of this method + // which takes an array of labels and locations. That would save some + // setup with the view graphics state. + void DrawLabel(BView* view, const char* label, + const rgb_color& base, uint32 flags, + const BPoint& where); + protected: void _DrawButtonFrame(BView* view, BRect& rect, const BRect& updateRect, diff --git a/src/kits/interface/ControlLook.cpp b/src/kits/interface/ControlLook.cpp index c3a9b28d2d..e9c9fdaf07 100644 --- a/src/kits/interface/ControlLook.cpp +++ b/src/kits/interface/ControlLook.cpp @@ -1743,22 +1743,6 @@ BControlLook::DrawLabel(BView* view, const char* label, BRect rect, if (!rect.Intersects(updateRect)) return; - // setup the text color - rgb_color color; - if (base.red + base.green + base.blue > 128 * 3) - color = tint_color(base, B_DARKEN_MAX_TINT); - else - color = tint_color(base, B_LIGHTEN_MAX_TINT); - - if (flags & B_DISABLED) { - color.red = (uint8)(((int32)base.red + color.red + 1) / 2); - color.green = (uint8)(((int32)base.green + color.green + 1) / 2); - color.blue = (uint8)(((int32)base.blue + color.blue + 1) / 2); - } - - view->SetHighColor(color); - view->SetDrawingMode(B_OP_OVER); - // truncate the label if necessary and get the width and height BString truncatedLabel(label); @@ -1803,7 +1787,36 @@ BControlLook::DrawLabel(BView* view, const char* label, BRect rect, break; } - view->DrawString(truncatedLabel.String(), location); + DrawLabel(view, truncatedLabel.String(), base, flags, location); +} + + +void +BControlLook::DrawLabel(BView* view, const char* label, const rgb_color& base, + uint32 flags, const BPoint& where) +{ + // setup the text color + // TODO: Should either use the ui_color(B_CONTROL_TEXT_COLOR) here, + // or elliminate that constant alltogether (stippi: +1). + rgb_color color; + if (base.red + base.green + base.blue > 128 * 3) + color = tint_color(base, B_DARKEN_MAX_TINT); + else + color = tint_color(base, B_LIGHTEN_MAX_TINT); + + if (flags & B_DISABLED) { + color.red = (uint8)(((int32)base.red + color.red + 1) / 2); + color.green = (uint8)(((int32)base.green + color.green + 1) / 2); + color.blue = (uint8)(((int32)base.blue + color.blue + 1) / 2); + } + + view->SetHighColor(color); + drawing_mode oldMode = view->DrawingMode(); + view->SetDrawingMode(B_OP_OVER); + + view->DrawString(label, where); + + view->SetDrawingMode(oldMode); }