From ce5d64725d8f4ada1b45675102b02e56c890bc18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 19 Jan 2009 10:31:43 +0000 Subject: [PATCH] * Renamed the drawing functions in DrawingEngine to remove the *Gradient part. In general, there is a lot of code duplication now, also in Painter. I will need to find a way to elliminate this again. Also, all the stroking functions should be gradient enabled as well. * Improved the look of the DefaultDecorater, inspired by the patch from Dennis Washington. I did not adopt the changes which give backwards compatibility problems, though, like changing the window border width or the single border decorator color. But I reckon these changes are overall even a bit smoother. * Fixed a long standing decorator bug, where the resize area of the border was visually different than the click recognition. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28951 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/DefaultDecorator.cpp | 108 ++++++++++++---------- src/servers/app/ServerWindow.cpp | 18 ++-- src/servers/app/drawing/DrawingEngine.cpp | 41 ++++---- src/servers/app/drawing/DrawingEngine.h | 23 +++-- 4 files changed, 102 insertions(+), 88 deletions(-) diff --git a/src/servers/app/DefaultDecorator.cpp b/src/servers/app/DefaultDecorator.cpp index e2754e0598..31ca95c859 100644 --- a/src/servers/app/DefaultDecorator.cpp +++ b/src/servers/app/DefaultDecorator.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -94,15 +95,16 @@ DefaultDecorator::DefaultDecorator(DesktopSettings& settings, BRect rect, // common colors to both focus and non focus state fFrameColors[0] = (rgb_color){ 152, 152, 152, 255 }; - fFrameColors[1] = (rgb_color){ 255, 255, 255, 255 }; + fFrameColors[1] = (rgb_color){ 240, 240, 240, 255 }; fFrameColors[4] = (rgb_color){ 152, 152, 152, 255 }; - fFrameColors[5] = (rgb_color){ 96, 96, 96, 255 }; + fFrameColors[5] = (rgb_color){ 124, 124, 124, 255 }; // state based colors - fFocusFrameColors[0] = (rgb_color){ 216, 216, 216, 255 }; - fFocusFrameColors[1] = (rgb_color){ 136, 136, 136, 255 }; + fFocusFrameColors[0] = (rgb_color){ 224, 224, 224, 255 }; + fFocusFrameColors[1] = (rgb_color){ 208, 208, 208, 255 }; fNonFocusFrameColors[0] = (rgb_color){ 232, 232, 232, 255 }; - fNonFocusFrameColors[1] = (rgb_color){ 148, 148, 148, 255 }; + fNonFocusFrameColors[1] = (rgb_color){ 216, 216, 216, 255 }; + fNonFocusFrameColors[1] = fNonFocusFrameColors[0]; fFocusTabColor = UIColor(B_WINDOW_TAB_COLOR); fFocusTextColor = UIColor(B_WINDOW_TEXT_COLOR); @@ -583,8 +585,8 @@ DefaultDecorator::Clicked(BPoint point, int32 buttons, int32 modifiers) || fLook == B_FLOATING_WINDOW_LOOK || fLook == B_MODAL_WINDOW_LOOK || fLook == kLeftTitledWindowLook)) { - BRect temp(BPoint(fBottomBorder.right - 18, - fBottomBorder.bottom - 18), fBottomBorder.RightBottom()); + BRect temp(BPoint(fBottomBorder.right - 22, + fBottomBorder.bottom - 22), fBottomBorder.RightBottom()); if (temp.Contains(point)) return DEC_RESIZE; } @@ -896,8 +898,16 @@ DefaultDecorator::_DrawFrame(BRect invalid) float x = r.right - 3; float y = r.bottom - 3; - fDrawingEngine->FillRect(BRect(x - 13, y - 13, x, y), - fFrameColors[2]); + BRect bg(x - 13, y - 13, x, y); + + BGradientLinear gradient; + gradient.SetStart(bg.LeftTop()); + gradient.SetEnd(bg.RightBottom()); + gradient.AddColor(fFrameColors[1], 0); + gradient.AddColor(fFrameColors[2], 255); + + fDrawingEngine->FillRect(bg, gradient); + fDrawingEngine->StrokeLine(BPoint(x - 15, y - 15), BPoint(x - 15, y - 2), fFrameColors[0]); fDrawingEngine->StrokeLine(BPoint(x - 14, y - 14), @@ -910,12 +920,14 @@ DefaultDecorator::_DrawFrame(BRect invalid) if (!IsFocus()) break; + static const rgb_color kWhite + = (rgb_color){ 255, 255, 255, 255 }; for (int8 i = 1; i <= 4; i++) { for (int8 j = 1; j <= i; j++) { BPoint pt1(x - (3 * j) + 1, y - (3 * (5 - i)) + 1); BPoint pt2(x - (3 * j) + 2, y - (3 * (5 - i)) + 2); fDrawingEngine->StrokePoint(pt1, fFrameColors[0]); - fDrawingEngine->StrokePoint(pt2, fFrameColors[1]); + fDrawingEngine->StrokePoint(pt2, kWhite); } } break; @@ -993,12 +1005,19 @@ DefaultDecorator::_DrawTab(BRect invalid) } // fill + BGradientLinear gradient; + gradient.SetStart(fTabRect.LeftTop()); + gradient.AddColor(fTabColorLight, 0); + gradient.AddColor(fTabColor, 255); + if (fLook != kLeftTitledWindowLook) { + gradient.SetEnd(fTabRect.LeftBottom()); fDrawingEngine->FillRect(BRect(fTabRect.left + 2, fTabRect.top + 2, - fTabRect.right - 2, fTabRect.bottom), fTabColor); + fTabRect.right - 2, fTabRect.bottom), gradient); } else { + gradient.SetEnd(fTabRect.RightTop()); fDrawingEngine->FillRect(BRect(fTabRect.left + 2, fTabRect.top + 2, - fTabRect.right, fTabRect.bottom - 2), fTabColor); + fTabRect.right, fTabRect.bottom - 2), gradient); } _DrawTitle(fTabRect); @@ -1034,8 +1053,8 @@ DefaultDecorator::_DrawTitle(BRect r) { STRACE(("_DrawTitle(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom)); + fDrawingEngine->SetDrawingMode(B_OP_OVER); fDrawingEngine->SetHighColor(fTextColor); - fDrawingEngine->SetLowColor(fTabColor); fDrawingEngine->SetFont(fDrawState.Font()); // figure out position of text @@ -1059,6 +1078,8 @@ DefaultDecorator::_DrawTitle(BRect r) fDrawingEngine->DrawString(fTruncatedTitle.String(), fTruncatedTitleLength, titlePos); + + fDrawingEngine->SetDrawingMode(B_OP_COPY); } @@ -1102,9 +1123,9 @@ DefaultDecorator::_SetFocus() fButtonFocus = false; } - fTabColorLight = tint_color(fTabColor, + fTabColorLight = tint_color(fTabColor, B_LIGHTEN_2_TINT); + fTabColorShadow = tint_color(fTabColor, (B_LIGHTEN_2_TINT + B_LIGHTEN_MAX_TINT) / 2); - fTabColorShadow = tint_color(fTabColor, B_DARKEN_2_TINT); } @@ -1138,12 +1159,12 @@ DefaultDecorator::_DrawButtonBitmap(ServerBitmap* bitmap, BRect rect) if (bitmap == NULL) return; - // TODO: find out why locking sometimes deadlocks here and re-add locking - // once the problem is fixed (or remove this comment if locking isn't - // necessary at all...) bool copyToFrontEnabled = fDrawingEngine->CopyToFrontEnabled(); fDrawingEngine->SetCopyToFrontEnabled(true); + drawing_mode oldMode; + fDrawingEngine->SetDrawingMode(B_OP_OVER, oldMode); fDrawingEngine->DrawBitmap(bitmap, rect.OffsetToCopy(0, 0), rect); + fDrawingEngine->SetDrawingMode(oldMode); fDrawingEngine->SetCopyToFrontEnabled(copyToFrontEnabled); } @@ -1156,46 +1177,30 @@ void DefaultDecorator::_DrawBlendedRect(DrawingEngine* engine, BRect rect, bool down, bool focus) { - // Actually just draws a blended square - int32 width = rect.IntegerWidth(); - int32 height = rect.IntegerHeight(); - int32 steps = width < height ? width : height; - + // figure out which colors to use rgb_color startColor, endColor; rgb_color tabColor = focus ? fFocusTabColor : fNonFocusTabColor; if (down) { startColor = tint_color(tabColor, B_DARKEN_1_TINT); - endColor = tint_color(tabColor, B_LIGHTEN_2_TINT);; + endColor = tint_color(tabColor, B_LIGHTEN_2_TINT); } else { - startColor = tint_color(tabColor, B_LIGHTEN_2_TINT); - endColor = tint_color(tabColor, B_DARKEN_1_TINT); + startColor = tint_color(tabColor, B_LIGHTEN_MAX_TINT); + endColor = tabColor; } - rgb_color halfColor = make_blend_color(startColor, endColor, 0.5); + // fill + rect.InsetBy(1, 1); + BGradientLinear gradient; + gradient.SetStart(rect.LeftTop()); + gradient.SetEnd(rect.RightBottom()); + gradient.AddColor(startColor, 0); + gradient.AddColor(endColor, 255); - float rstep = float(startColor.red - halfColor.red) / steps; - float gstep = float(startColor.green - halfColor.green) / steps; - float bstep = float(startColor.blue - halfColor.blue) / steps; + engine->FillRect(rect, gradient); - rgb_color tempColor; - for (int32 i = 0; i <= steps; i++) { - tempColor.red = uint8(startColor.red - (i * rstep)); - tempColor.green = uint8(startColor.green - (i * gstep)); - tempColor.blue = uint8(startColor.blue - (i * bstep)); - - engine->StrokeLine(BPoint(rect.left, rect.top + i), - BPoint(rect.left + i, rect.top), tempColor); - - tempColor.red = uint8(halfColor.red - (i * rstep)); - tempColor.green = uint8(halfColor.green - (i * gstep)); - tempColor.blue = uint8(halfColor.blue - (i * bstep)); - - engine->StrokeLine(BPoint(rect.left + steps, rect.top + i), - BPoint(rect.left + i, rect.top + steps), tempColor); - } - - engine->StrokeRect(rect, - focus ? fFocusFrameColors[1] : fNonFocusFrameColors[1]); + // outline + rect.InsetBy(-1, -1); + engine->StrokeRect(rect, tint_color(tabColor, B_DARKEN_2_TINT)); } @@ -1311,8 +1316,6 @@ DefaultDecorator::_GetBitmapForButton(int32 item, bool down, bool focus, return NULL; BRect rect(0, 0, width - 1, height - 1); - sBitmapDrawingEngine->FillRect(rect, - focus ? object->fFocusTabColor : object->fNonFocusTabColor); STRACE(("DefaultDecorator creating bitmap for %s %sfocus %s at size %ldx%ld\n", item == DEC_CLOSE ? "close" : "zoom", focus ? "" : "non-", @@ -1324,6 +1327,9 @@ DefaultDecorator::_GetBitmapForButton(int32 item, bool down, bool focus, case DEC_ZOOM: { + // init the background + sBitmapDrawingEngine->FillRect(rect, B_TRANSPARENT_COLOR); + float inset = floorf(width / 4.0); BRect zoomRect(rect); zoomRect.left += inset; diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index d662e51936..1337c4656d 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -2363,7 +2363,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, fCurrentView->ConvertToScreenForDrawing(&rect); fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillRectGradient(rect, *gradient); + drawingEngine->FillRect(rect, *gradient); break; } case AS_VIEW_DRAW_BITMAP: @@ -2437,7 +2437,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, break; fCurrentView->ConvertToScreenForDrawing(&r); fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillArcGradient(r, angle, span, *gradient); + drawingEngine->FillArc(r, angle, span, *gradient); break; } case AS_STROKE_BEZIER: @@ -2472,7 +2472,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, if (link.ReadGradient(&gradient) != B_OK) break; fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillBezierGradient(pts, *gradient); + drawingEngine->FillBezier(pts, *gradient); break; } case AS_STROKE_ELLIPSE: @@ -2501,7 +2501,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, break; fCurrentView->ConvertToScreenForDrawing(&rect); fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillEllipseGradient(rect, *gradient); + drawingEngine->FillEllipse(rect, *gradient); break; } case AS_STROKE_ROUNDRECT: @@ -2537,7 +2537,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, break; fCurrentView->ConvertToScreenForDrawing(&rect); fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillRoundRectGradient(rect, xrad, yrad, *gradient); + drawingEngine->FillRoundRect(rect, xrad, yrad, *gradient); break; } case AS_STROKE_TRIANGLE: @@ -2578,7 +2578,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, break; fCurrentView->ConvertToScreenForDrawing(&rect); fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillTriangleGradient(pts, rect, *gradient); + drawingEngine->FillTriangle(pts, rect, *gradient); break; } case AS_STROKE_POLYGON: @@ -2628,7 +2628,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, fCurrentView->ConvertToScreenForDrawing(&polyFrame); fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillPolygonGradient(pointList, pointCount, + drawingEngine->FillPolygon(pointList, pointCount, polyFrame, *gradient, isClosed && pointCount > 2); } delete[] pointList; @@ -2699,7 +2699,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, fCurrentView->ConvertToScreenForDrawing(&ptList[i]); } fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillShapeGradient(shapeFrame, opCount, opList, + drawingEngine->FillShape(shapeFrame, opCount, opList, ptCount, ptList, *gradient); } @@ -2734,7 +2734,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, fCurrentView->ConvertToScreenForDrawing(®ion); fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillRegionGradient(region, *gradient); + drawingEngine->FillRegion(region, *gradient); break; } case AS_STROKE_LINEARRAY: diff --git a/src/servers/app/drawing/DrawingEngine.cpp b/src/servers/app/drawing/DrawingEngine.cpp index b125c48bff..d6bd82e759 100644 --- a/src/servers/app/drawing/DrawingEngine.cpp +++ b/src/servers/app/drawing/DrawingEngine.cpp @@ -269,6 +269,14 @@ DrawingEngine::SetDrawingMode(drawing_mode mode) } +void +DrawingEngine::SetDrawingMode(drawing_mode mode, drawing_mode& oldMode) +{ + oldMode = fPainter->DrawingMode(); + fPainter->SetDrawingMode(mode); +} + + void DrawingEngine::SetFont(const ServerFont& font) { @@ -611,9 +619,8 @@ DrawingEngine::DrawArc(BRect r, const float& angle, const float& span, } } -// FillArcGradient void -DrawingEngine::FillArcGradient(BRect r, const float& angle, const float& span, +DrawingEngine::FillArc(BRect r, const float& angle, const float& span, const BGradient& gradient) { CRASH_IF_NOT_LOCKED @@ -639,7 +646,7 @@ DrawingEngine::FillArcGradient(BRect r, const float& angle, const float& span, } } -// DrawBezier + void DrawingEngine::DrawBezier(BPoint* pts, bool filled) { @@ -653,9 +660,9 @@ DrawingEngine::DrawBezier(BPoint* pts, bool filled) _CopyToFront(touched); } -// FillBezierGradient + void -DrawingEngine::FillBezierGradient(BPoint* pts, const BGradient& gradient) +DrawingEngine::FillBezier(BPoint* pts, const BGradient& gradient) { CRASH_IF_NOT_LOCKED @@ -667,7 +674,7 @@ DrawingEngine::FillBezierGradient(BPoint* pts, const BGradient& gradient) _CopyToFront(touched); } -// DrawEllipse + void DrawingEngine::DrawEllipse(BRect r, bool filled) { @@ -696,9 +703,9 @@ DrawingEngine::DrawEllipse(BRect r, bool filled) } } -// FillEllipseGradient + void -DrawingEngine::FillEllipseGradient(BRect r, const BGradient& gradient) +DrawingEngine::FillEllipse(BRect r, const BGradient& gradient) { CRASH_IF_NOT_LOCKED @@ -722,7 +729,7 @@ DrawingEngine::FillEllipseGradient(BRect r, const BGradient& gradient) } } -// DrawPolygon + void DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, BRect bounds, bool filled, bool closed) @@ -742,9 +749,9 @@ DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, BRect bounds, } } -// FillPolygonGradient + void -DrawingEngine::FillPolygonGradient(BPoint* ptlist, int32 numpts, BRect bounds, +DrawingEngine::FillPolygon(BPoint* ptlist, int32 numpts, BRect bounds, const BGradient& gradient, bool closed) { CRASH_IF_NOT_LOCKED @@ -760,8 +767,10 @@ DrawingEngine::FillPolygonGradient(BPoint* ptlist, int32 numpts, BRect bounds, } } + // #pragma mark - rgb_color + void DrawingEngine::StrokePoint(const BPoint& pt, const rgb_color& color) { @@ -959,7 +968,7 @@ DrawingEngine::FillRect(BRect r) void -DrawingEngine::FillRectGradient(BRect r, const BGradient& gradient) +DrawingEngine::FillRect(BRect r, const BGradient& gradient) { CRASH_IF_NOT_LOCKED @@ -1030,7 +1039,7 @@ DrawingEngine::FillRegion(BRegion& r) void -DrawingEngine::FillRegionGradient(BRegion& r, const BGradient& gradient) +DrawingEngine::FillRegion(BRegion& r, const BGradient& gradient) { CRASH_IF_NOT_LOCKED @@ -1077,7 +1086,7 @@ DrawingEngine::DrawRoundRect(BRect r, float xrad, float yrad, bool filled) void -DrawingEngine::FillRoundRectGradient(BRect r, float xrad, float yrad, +DrawingEngine::FillRoundRect(BRect r, float xrad, float yrad, const BGradient& gradient) { CRASH_IF_NOT_LOCKED @@ -1121,7 +1130,7 @@ DrawingEngine::DrawShape(const BRect& bounds, int32 opCount, void -DrawingEngine::FillShapeGradient(const BRect& bounds, int32 opCount, +DrawingEngine::FillShape(const BRect& bounds, int32 opCount, const uint32* opList, int32 ptCount, const BPoint* ptList, const BGradient& gradient) { @@ -1160,7 +1169,7 @@ DrawingEngine::DrawTriangle(BPoint* pts, const BRect& bounds, bool filled) } void -DrawingEngine::FillTriangleGradient(BPoint* pts, const BRect& bounds, +DrawingEngine::FillTriangle(BPoint* pts, const BRect& bounds, const BGradient& gradient) { CRASH_IF_NOT_LOCKED diff --git a/src/servers/app/drawing/DrawingEngine.h b/src/servers/app/drawing/DrawingEngine.h index 2e3114451f..ccbc98d138 100644 --- a/src/servers/app/drawing/DrawingEngine.h +++ b/src/servers/app/drawing/DrawingEngine.h @@ -79,6 +79,8 @@ public: float miterLimit); void SetPattern(const struct pattern& pattern); void SetDrawingMode(drawing_mode mode); + void SetDrawingMode(drawing_mode mode, + drawing_mode& oldMode); void SetBlendingMode(source_alpha srcAlpha, alpha_function alphaFunc); void SetFont(const ServerFont& font); @@ -100,20 +102,18 @@ public: void DrawArc(BRect r, const float& angle, const float& span, bool filled); - void FillArcGradient(BRect r, const float& angle, + void FillArc(BRect r, const float& angle, const float& span, const BGradient& gradient); void DrawBezier(BPoint* pts, bool filled); - void FillBezierGradient(BPoint* pts, - const BGradient& gradient); + void FillBezier(BPoint* pts, const BGradient& gradient); void DrawEllipse(BRect r, bool filled); - void FillEllipseGradient(BRect r, - const BGradient& gradient); + void FillEllipse(BRect r, const BGradient& gradient); void DrawPolygon(BPoint* ptlist, int32 numpts, BRect bounds, bool filled, bool closed); - void FillPolygonGradient(BPoint* ptlist, int32 numpts, + void FillPolygon(BPoint* ptlist, int32 numpts, BRect bounds, const BGradient& gradient, bool closed); @@ -126,29 +126,28 @@ public: void StrokeRect(BRect r); void FillRect(BRect r); - void FillRectGradient(BRect r, const BGradient& gradient); + void FillRect(BRect r, const BGradient& gradient); void FillRegion(BRegion& r); - void FillRegionGradient(BRegion& r, - const BGradient& gradient); + void FillRegion(BRegion& r, const BGradient& gradient); void DrawRoundRect(BRect r, float xrad, float yrad, bool filled); - void FillRoundRectGradient(BRect r, float xrad, + void FillRoundRect(BRect r, float xrad, float yrad, const BGradient& gradient); void DrawShape(const BRect& bounds, int32 opcount, const uint32* oplist, int32 ptcount, const BPoint* ptlist, bool filled); - void FillShapeGradient(const BRect& bounds, + void FillShape(const BRect& bounds, int32 opcount, const uint32* oplist, int32 ptcount, const BPoint* ptlist, const BGradient& gradient); void DrawTriangle(BPoint* pts, const BRect& bounds, bool filled); - void FillTriangleGradient(BPoint* pts, + void FillTriangle(BPoint* pts, const BRect& bounds, const BGradient& gradient); // this version used by Decorator