DefaultDecorator(/SATDecorator):

* Use a separate color array for the buttons, instead of using that for the
  tab.
* _DrawBlendedRect(): No longer gets the focus flag, but gets a color array
  instead.
* _GetBitmapForButton(): Made non-static and removed the "focus" and "object"
  parameters.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39637 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-11-25 23:23:08 +00:00
parent 09b19da8c2
commit 06aa76e216
3 changed files with 59 additions and 37 deletions
@@ -470,6 +470,17 @@ SATDecorator::GetComponentColors(Component component, ComponentColors _colors)
_colors[COLOR_TAB_TEXT] = kFocusTextColor; _colors[COLOR_TAB_TEXT] = kFocusTextColor;
break; break;
case COMPONENT_CLOSE_BUTTON:
case COMPONENT_ZOOM_BUTTON:
if (!fTabHighlighted) {
DefaultDecorator::GetComponentColors(component, _colors);
return;
}
_colors[COLOR_BUTTON] = kHighlightTabColor;
_colors[COLOR_BUTTON_LIGHT] = kHighlightTabColorLight;
break;
case COMPONENT_LEFT_BORDER: case COMPONENT_LEFT_BORDER:
case COMPONENT_RIGHT_BORDER: case COMPONENT_RIGHT_BORDER:
case COMPONENT_TOP_BORDER: case COMPONENT_TOP_BORDER:
+39 -33
View File
@@ -726,7 +726,7 @@ DefaultDecorator::_DrawClose(BRect rect)
ServerBitmap* bitmap = fCloseBitmaps[index]; ServerBitmap* bitmap = fCloseBitmaps[index];
if (bitmap == NULL) { if (bitmap == NULL) {
bitmap = _GetBitmapForButton(COMPONENT_CLOSE_BUTTON, GetClose(), bitmap = _GetBitmapForButton(COMPONENT_CLOSE_BUTTON, GetClose(),
fButtonFocus, rect.IntegerWidth(), rect.IntegerHeight(), this); rect.IntegerWidth(), rect.IntegerHeight());
fCloseBitmaps[index] = bitmap; fCloseBitmaps[index] = bitmap;
} }
@@ -782,7 +782,7 @@ DefaultDecorator::_DrawZoom(BRect rect)
ServerBitmap* bitmap = fZoomBitmaps[index]; ServerBitmap* bitmap = fZoomBitmaps[index];
if (bitmap == NULL) { if (bitmap == NULL) {
bitmap = _GetBitmapForButton(COMPONENT_ZOOM_BUTTON, GetZoom(), bitmap = _GetBitmapForButton(COMPONENT_ZOOM_BUTTON, GetZoom(),
fButtonFocus, rect.IntegerWidth(), rect.IntegerHeight(), this); rect.IntegerWidth(), rect.IntegerHeight());
fZoomBitmaps[index] = bitmap; fZoomBitmaps[index] = bitmap;
} }
@@ -1167,6 +1167,17 @@ DefaultDecorator::GetComponentColors(Component component,
} }
break; break;
case COMPONENT_CLOSE_BUTTON:
case COMPONENT_ZOOM_BUTTON:
if (fButtonFocus) {
_colors[COLOR_BUTTON] = kFocusTabColor;
_colors[COLOR_BUTTON_LIGHT] = kFocusTabColorLight;
} else {
_colors[COLOR_BUTTON] = kNonFocusTabColor;
_colors[COLOR_BUTTON_LIGHT] = kNonFocusTabColorLight;
}
break;
case COMPONENT_LEFT_BORDER: case COMPONENT_LEFT_BORDER:
case COMPONENT_RIGHT_BORDER: case COMPONENT_RIGHT_BORDER:
case COMPONENT_TOP_BORDER: case COMPONENT_TOP_BORDER:
@@ -1224,25 +1235,21 @@ DefaultDecorator::_DrawButtonBitmap(ServerBitmap* bitmap, BRect rect)
/*! \brief Draws a framed rectangle with a gradient. /*! \brief Draws a framed rectangle with a gradient.
\param down The rectangle should be drawn recessed or not \param down The rectangle should be drawn recessed or not.
\param colors A button color array with the colors to be used.
*/ */
void void
DefaultDecorator::_DrawBlendedRect(DrawingEngine* engine, BRect rect, DefaultDecorator::_DrawBlendedRect(DrawingEngine* engine, BRect rect,
bool down, bool focus) bool down, const ComponentColors& colors)
{ {
ComponentColors colors;
GetComponentColors(COMPONENT_TAB, colors);
// figure out which colors to use // figure out which colors to use
rgb_color startColor, endColor; rgb_color startColor, endColor;
rgb_color tabColor = focus ? kFocusTabColor : kNonFocusTabColor;
// TODO: Use GetComponentColors() only!
if (down) { if (down) {
startColor = tint_color(tabColor, B_DARKEN_1_TINT); startColor = tint_color(colors[COLOR_BUTTON], B_DARKEN_1_TINT);
endColor = colors[COLOR_TAB_LIGHT]; endColor = colors[COLOR_BUTTON_LIGHT];
} else { } else {
startColor = tint_color(tabColor, B_LIGHTEN_MAX_TINT); startColor = tint_color(colors[COLOR_BUTTON], B_LIGHTEN_MAX_TINT);
endColor = tabColor; endColor = colors[COLOR_BUTTON];
} }
// fill // fill
@@ -1257,7 +1264,7 @@ DefaultDecorator::_DrawBlendedRect(DrawingEngine* engine, BRect rect,
// outline // outline
rect.InsetBy(-1, -1); rect.InsetBy(-1, -1);
engine->StrokeRect(rect, tint_color(tabColor, B_DARKEN_2_TINT)); engine->StrokeRect(rect, tint_color(colors[COLOR_BUTTON], B_DARKEN_2_TINT));
} }
@@ -1343,24 +1350,27 @@ DefaultDecorator::_InvalidateBitmaps()
ServerBitmap* ServerBitmap*
DefaultDecorator::_GetBitmapForButton(Component item, bool down, bool focus, DefaultDecorator::_GetBitmapForButton(Component item, bool down, int32 width,
int32 width, int32 height, DefaultDecorator* object) int32 height)
{ {
// TODO: the list of shared bitmaps is never freed // TODO: the list of shared bitmaps is never freed
struct decorator_bitmap { struct decorator_bitmap {
Component item; Component item;
bool down; bool down;
bool focus;
int32 width; int32 width;
int32 height; int32 height;
rgb_color focusColor; rgb_color baseColor;
rgb_color nonFocusColor; rgb_color lightColor;
UtilityBitmap* bitmap; UtilityBitmap* bitmap;
decorator_bitmap* next; decorator_bitmap* next;
}; };
static BLocker sBitmapListLock("decorator lock", true); static BLocker sBitmapListLock("decorator lock", true);
static decorator_bitmap* sBitmapList = NULL; static decorator_bitmap* sBitmapList = NULL;
ComponentColors colors;
GetComponentColors(item, colors);
BAutolock locker(sBitmapListLock); BAutolock locker(sBitmapListLock);
// search our list for a matching bitmap // search our list for a matching bitmap
@@ -1368,10 +1378,9 @@ DefaultDecorator::_GetBitmapForButton(Component item, bool down, bool focus,
decorator_bitmap* current = sBitmapList; decorator_bitmap* current = sBitmapList;
while (current) { while (current) {
if (current->item == item && current->down == down if (current->item == item && current->down == down
&& current->focus == focus && current->width == width && current->width == width && current->height == height
&& current->height == height && current->baseColor == colors[COLOR_BUTTON]
&& current->focusColor == object->kFocusTabColor && current->lightColor == colors[COLOR_BUTTON_LIGHT]) {
&& current->nonFocusColor == object->kNonFocusTabColor) {
return current->bitmap; return current->bitmap;
} }
@@ -1389,12 +1398,12 @@ DefaultDecorator::_GetBitmapForButton(Component item, bool down, bool focus,
BRect rect(0, 0, width - 1, height - 1); BRect rect(0, 0, width - 1, height - 1);
STRACE(("DefaultDecorator creating bitmap for %s %sfocus %s at size %ldx%ld\n", STRACE(("DefaultDecorator creating bitmap for %s %s at size %ldx%ld\n",
item == COMPONENT_CLOSE_BUTTON ? "close" : "zoom", focus ? "" : "non-", item == COMPONENT_CLOSE_BUTTON ? "close" : "zoom",
down ? "down" : "up", width, height)); down ? "down" : "up", width, height));
switch (item) { switch (item) {
case COMPONENT_CLOSE_BUTTON: case COMPONENT_CLOSE_BUTTON:
object->_DrawBlendedRect(sBitmapDrawingEngine, rect, down, focus); _DrawBlendedRect(sBitmapDrawingEngine, rect, down, colors);
break; break;
case COMPONENT_ZOOM_BUTTON: case COMPONENT_ZOOM_BUTTON:
@@ -1406,15 +1415,13 @@ DefaultDecorator::_GetBitmapForButton(Component item, bool down, bool focus,
BRect zoomRect(rect); BRect zoomRect(rect);
zoomRect.left += inset; zoomRect.left += inset;
zoomRect.top += inset; zoomRect.top += inset;
object->_DrawBlendedRect(sBitmapDrawingEngine, zoomRect, _DrawBlendedRect(sBitmapDrawingEngine, zoomRect, down, colors);
down, focus);
inset = floorf(width / 2.1); inset = floorf(width / 2.1);
zoomRect = rect; zoomRect = rect;
zoomRect.right -= inset; zoomRect.right -= inset;
zoomRect.bottom -= inset; zoomRect.bottom -= inset;
object->_DrawBlendedRect(sBitmapDrawingEngine, zoomRect, _DrawBlendedRect(sBitmapDrawingEngine, zoomRect, down, colors);
down, focus);
break; break;
} }
@@ -1436,12 +1443,11 @@ DefaultDecorator::_GetBitmapForButton(Component item, bool down, bool focus,
entry->item = item; entry->item = item;
entry->down = down; entry->down = down;
entry->focus = focus;
entry->width = width; entry->width = width;
entry->height = height; entry->height = height;
entry->bitmap = bitmap; entry->bitmap = bitmap;
entry->focusColor = object->kFocusTabColor; entry->baseColor = colors[COLOR_BUTTON];
entry->nonFocusColor = object->kNonFocusTabColor; entry->lightColor = colors[COLOR_BUTTON_LIGHT];
entry->next = sBitmapList; entry->next = sBitmapList;
sBitmapList = entry; sBitmapList = entry;
return bitmap; return bitmap;
+9 -4
View File
@@ -68,6 +68,11 @@ protected:
COLOR_TAB_TEXT = 6 COLOR_TAB_TEXT = 6
}; };
enum {
COLOR_BUTTON = 0,
COLOR_BUTTON_LIGHT = 1
};
typedef rgb_color ComponentColors[7]; typedef rgb_color ComponentColors[7];
protected: protected:
@@ -118,12 +123,12 @@ private:
void _DrawButtonBitmap(ServerBitmap* bitmap, void _DrawButtonBitmap(ServerBitmap* bitmap,
BRect rect); BRect rect);
void _DrawBlendedRect(DrawingEngine *engine, void _DrawBlendedRect(DrawingEngine *engine,
BRect rect, bool down, bool focus); BRect rect, bool down,
const ComponentColors& colors);
void _LayoutTabItems(const BRect& tabRect); void _LayoutTabItems(const BRect& tabRect);
void _InvalidateBitmaps(); void _InvalidateBitmaps();
static ServerBitmap* _GetBitmapForButton(Component item, bool down, ServerBitmap* _GetBitmapForButton(Component item, bool down,
bool focus, int32 width, int32 height, int32 width, int32 height);
DefaultDecorator* object);
protected: protected:
static const rgb_color kFrameColors[4]; static const rgb_color kFrameColors[4];