diff --git a/src/add-ons/decorators/MacDecorator/MacDecorator.cpp b/src/add-ons/decorators/MacDecorator/MacDecorator.cpp index 3bd8693424..019c6a6ed4 100644 --- a/src/add-ons/decorators/MacDecorator/MacDecorator.cpp +++ b/src/add-ons/decorators/MacDecorator/MacDecorator.cpp @@ -1,114 +1,184 @@ -#include -#include "DrawingEngine.h" -#include -#include "MacDecorator.h" -#include "RGBColor.h" -#include "PatternHandler.h" - -//#define DEBUG_DECOR - -#ifdef DEBUG_DECOR -#include -#endif - - -static inline uint8 -blend_color_value(uint8 a, uint8 b, float position) -{ - int16 delta = (int16)b - a; - int32 value = a + (int32)(position * delta); - if (value > 255) - return 255; - if (value < 0) - return 0; - - return (uint8)value; -} - - -/*! - \brief Function mostly for calculating gradient colors - \param col Start color - \param col2 End color - \param position A floating point number such that 0.0 <= position <= 1.0. 0.0 results in the - start color and 1.0 results in the end color. - \return The blended color. If an invalid position was given, {0,0,0,0} is returned. +/* + Copyright 2009, Haiku. + Distributed under the terms of the MIT License. */ -static rgb_color -make_blend_color(rgb_color colorA, rgb_color colorB, float position) -{ - if (position < 0) - return colorA; - if (position > 1) - return colorB; - rgb_color blendColor; - blendColor.red = blend_color_value(colorA.red, colorB.red, position); - blendColor.green = blend_color_value(colorA.green, colorB.green, position); - blendColor.blue = blend_color_value(colorA.blue, colorB.blue, position); - blendColor.alpha = blend_color_value(colorA.alpha, colorB.alpha, position); - - return blendColor; -} +/*! Decorator looking like Mac OS 9 */ +#include +#include +#include -MacDecorator::MacDecorator(DesktopSettings& settings, BRect frame, window_look look, uint32 flags) - : Decorator(settings, frame, look, flags) -{ -#ifdef DEBUG_DECOR -printf("MacDecorator()\n"); +#include "DesktopSettings.h" +#include "DrawingEngine.h" +#include "PatternHandler.h" +#include "RGBColor.h" + +#include "MacDecorator.h" + + +//#define DEBUG_DECORATOR +#ifdef DEBUG_DECORATOR +# include +# define STRACE(x) printf x ; +#else +# define STRACE(x) ; #endif - taboffset=0; - frame_highcol.SetColor(255,255,255); - frame_midcol.SetColor(216,216,216); - frame_lowcol.SetColor(110,110,110); - frame_lowercol.SetColor(0,0,0); + +MacDecorator::MacDecorator(DesktopSettings& settings, BRect rect, + window_look look, uint32 flags) + : Decorator(settings, rect, look, flags) +{ + frame_highcol = (rgb_color){ 255, 255, 255, 255 }; + frame_midcol = (rgb_color){ 216, 216, 216, 255 }; + frame_lowcol = (rgb_color){ 110, 110, 110, 255 }; + frame_lowercol = (rgb_color){ 0, 0, 0, 255 }; - button_highcol.SetColor(232,232,232); - button_lowcol.SetColor(128,128,128); + fButtonHighColor = (rgb_color){ 232, 232, 232, 255 }; + fButtonLowColor = (rgb_color){ 128, 128, 128, 255 }; - textcol.SetColor(0,0,0); - inactive_textcol.SetColor(100,100,100); - + fFocusTextColor = settings.UIColor(B_WINDOW_TEXT_COLOR); + fNonFocusTextColor = settings.UIColor(B_WINDOW_INACTIVE_TEXT_COLOR); + _DoLayout(); textoffset=5; + + STRACE(("MacDecorator()\n")); } -MacDecorator::~MacDecorator(void) + +MacDecorator::~MacDecorator() { -#ifdef DEBUG_DECOR -printf("~MacDecorator()\n"); -#endif + STRACE("~MacDecorator()\n"); } -click_type MacDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers) +// settitle +// fontschanged +// setlook +// setflags + + +void +MacDecorator::MoveBy(BPoint offset) { - if(fCloseRect.Contains(pt)) - { + Decorator::MoveBy(offset); +} -#ifdef DEBUG_DECOR -printf("MacDecorator():Clicked() - Close\n"); -#endif +void +MacDecorator::ResizeBy(BPoint offset, BRegion* dirty) +{ + // Move all internal rectangles the appropriate amount + fFrame.right += offset.x; + fFrame.bottom += offset.y; + + fTabRect.right += offset.x; + fBorderRect.right += offset.x; + fBorderRect.bottom += offset.y; + fZoomRect.OffsetBy(offset.x,0); + fMinimizeRect.OffsetBy(offset.x,0); + + // handle invalidation of resize rect + if (dirty && !(fFlags & B_NOT_RESIZABLE)) { + BRect realResizeRect; + switch (fLook) { + case B_DOCUMENT_WINDOW_LOOK: + realResizeRect = fResizeRect; + // resize rect at old location + dirty->Include(realResizeRect); + realResizeRect.OffsetBy(offset); + // resize rect at new location + dirty->Include(realResizeRect); + break; + case B_TITLED_WINDOW_LOOK: + case B_FLOATING_WINDOW_LOOK: + case B_MODAL_WINDOW_LOOK: + // resize rect at old location + dirty->Include(fBorderRect); + fBorderRect.OffsetBy(offset); + // resize rect at new location + dirty->Include(fBorderRect); + break; + default: + break; + } + } + + // TODO probably some other layouting stuff here +} + +// settablocation +// setsettings +// getsettings + +void +MacDecorator::Draw(BRect update) +{ + STRACE(("MacDecorator: Draw(%.1f,%.1f,%.1f,%.1f)\n", + update.left, update.top, update.right, update.bottom)); + + fDrawingEngine->SetDrawState(&fDrawState); + _DrawFrame(update); + _DrawTab(update); +} + + +void +MacDecorator::Draw() +{ + STRACE("MacDecorator::Draw()\n"); + fDrawingEngine->SetDrawState(&fDrawState); + + _DrawFrame(fBorderRect); + _DrawTab(fTabRect); +} + + +// getsizelimits + +void +MacDecorator::GetFootprint(BRegion *region) +{ + // This function calculates the decorator's footprint in coordinates + // relative to the view. This is most often used to set a Window + // object's visible region. + if (!region) + return; + + region->MakeEmpty(); + + // No border : we don't draw anything. + if (fLook == B_NO_BORDER_WINDOW_LOOK) + return; + + + region->Set(fBorderRect); + region->Exclude(fFrame); + + if (fLook == B_BORDERED_WINDOW_LOOK) + return; + region->Include(fTabRect); +} + + +click_type +MacDecorator::Clicked(BPoint point, int32 buttons, int32 modifiers) +{ + if (!(fFlags & B_NOT_CLOSABLE) && fCloseRect.Contains(point)) { + STRACE(("MacDecorator():Clicked() - Close\n")); return DEC_CLOSE; } - if(fZoomRect.Contains(pt)) - { - -#ifdef DEBUG_DECOR -printf("MacDecorator():Clicked() - Zoom\n"); -#endif - + if (!(fFlags & B_NOT_ZOOMABLE) && fZoomRect.Contains(point)) { + STRACE("MacDecorator():Clicked() - Zoom\n"); return DEC_ZOOM; } // Clicking in the tab? - if(fTabRect.Contains(pt)) - { + if (fTabRect.Contains(point)) { // Here's part of our window management stuff /* TODO This is missing DEC_MOVETOFRONT if(buttons==B_PRIMARY_MOUSE_BUTTON && !IsFocus()) @@ -121,321 +191,239 @@ printf("MacDecorator():Clicked() - Zoom\n"); BRect srect(fFrame); srect.top+=19; BRect clientrect(srect.InsetByCopy(3,3)); - if(srect.Contains(pt) && !clientrect.Contains(pt)) - { -#ifdef DEBUG_DECOR -printf("MacDecorator():Clicked() - Resize\n"); -#endif + if (!(fFlags & B_NOT_RESIZABLE) + && (fLook == B_TITLED_WINDOW_LOOK + || fLook == B_FLOATING_WINDOW_LOOK + || fLook == B_MODAL_WINDOW_LOOK) + && srect.Contains(point) && !clientrect.Contains(point)) { + STRACE(("MacDecorator():Clicked() - Resize\n")); return DEC_RESIZE; } // Guess user didn't click anything -#ifdef DEBUG_DECOR -printf("MacDecorator():Clicked()\n"); -#endif + STRACE(("MacDecorator():Clicked()\n")); return DEC_NONE; } -void MacDecorator::_DoLayout(void) -{ -#ifdef DEBUG_DECOR -printf("MacDecorator()::_DoLayout()\n"); -#endif - fBorderRect=fFrame; - fBorderRect.top+=19; - fTabRect=fFrame; - - fTabRect.bottom=fTabRect.top+19; - - fZoomRect=fTabRect; - fZoomRect.left=fZoomRect.right-12; - fZoomRect.bottom=fZoomRect.top+12; - fZoomRect.OffsetBy(-4,4); - - fCloseRect=fZoomRect; - fMinimizeRect=fZoomRect; - - fCloseRect.OffsetTo(fTabRect.left+4,fTabRect.top+4); - - fZoomRect.OffsetBy(0-(fZoomRect.Width()+4),0); - if(Title() && fDrawingEngine) - { - titlepixelwidth=fDrawingEngine->StringWidth(Title(),strlen(Title())/*,&fDrawState*/); - - if(titlepixelwidth<(fZoomRect.left-fCloseRect.right-10)) - { - // start with offset from closerect.right - textoffset=int(((fZoomRect.left-5)-(fCloseRect.right+5))/2); - textoffset-=int(titlepixelwidth/2); - - // now make it the offset from fTabRect.left - textoffset+=int(fCloseRect.right+5-fTabRect.left); - } - else - textoffset=int(fCloseRect.right)+5; - } - else - { - textoffset=0; - titlepixelwidth=0; - } -} - -void MacDecorator::MoveBy(BPoint pt) -{ - // Move all internal rectangles the appropriate amount - fFrame.OffsetBy(pt); - fCloseRect.OffsetBy(pt); - fTabRect.OffsetBy(pt); - fBorderRect.OffsetBy(pt); - fZoomRect.OffsetBy(pt); - fMinimizeRect.OffsetBy(pt); -} - void -MacDecorator::ResizeBy(BPoint pt, BRegion* dirty) +MacDecorator::_DoLayout(void) { - // Move all internal rectangles the appropriate amount - fFrame.right += pt.x; - fFrame.bottom += pt.y; + STRACE(("MacDecorator: Do Layout\n")); - fTabRect.right += pt.x; - fBorderRect.right += pt.x; - fBorderRect.bottom += pt.y; - fZoomRect.OffsetBy(pt.x,0); - fMinimizeRect.OffsetBy(pt.x,0); + bool hasTab = false; - // handle invalidation of resize rect - if (dirty && !(fFlags & B_NOT_RESIZABLE)) { - BRect realResizeRect; - switch (fLook) { - case B_DOCUMENT_WINDOW_LOOK: - realResizeRect = fResizeRect; - // resize rect at old location - dirty->Include(realResizeRect); - realResizeRect.OffsetBy(pt); - // resize rect at new location - dirty->Include(realResizeRect); - break; - case B_TITLED_WINDOW_LOOK: - case B_FLOATING_WINDOW_LOOK: - case B_MODAL_WINDOW_LOOK: - // resize rect at old location - dirty->Include(fBorderRect); - fBorderRect.OffsetBy(pt); - // resize rect at new location - dirty->Include(fBorderRect); - break; - default: - break; - } + switch (Look()) { + case B_MODAL_WINDOW_LOOK: + fBorderWidth = 5; + break; + + case B_TITLED_WINDOW_LOOK: + case B_DOCUMENT_WINDOW_LOOK: + hasTab = true; + fBorderWidth = 5; + break; + case B_FLOATING_WINDOW_LOOK: + hasTab = true; + fBorderWidth = 3; + break; + + case B_BORDERED_WINDOW_LOOK: + fBorderWidth = 1; + break; + + default: + fBorderWidth = 0; } + fBorderRect=fFrame; - // TODO probably some other layouting stuff here + if (hasTab) { + fBorderRect.top+=19; + + fTabRect=fFrame; + fTabRect.bottom=fTabRect.top+19; + + fZoomRect=fTabRect; + fZoomRect.left=fZoomRect.right-12; + fZoomRect.bottom=fZoomRect.top+12; + fZoomRect.OffsetBy(-4,4); + + fCloseRect=fZoomRect; + fMinimizeRect=fZoomRect; + + fCloseRect.OffsetTo(fTabRect.left+4,fTabRect.top+4); + + fZoomRect.OffsetBy(0-(fZoomRect.Width()+4),0); + if (Title() && fDrawingEngine) { + titlepixelwidth=fDrawingEngine->StringWidth(Title(),strlen(Title())); + + if (titlepixelwidth<(fZoomRect.left-fCloseRect.right-10)) { + // start with offset from closerect.right + textoffset=int(((fZoomRect.left-5)-(fCloseRect.right+5))/2); + textoffset-=int(titlepixelwidth/2); + + // now make it the offset from fTabRect.left + textoffset+=int(fCloseRect.right+5-fTabRect.left); + } else + textoffset=int(fCloseRect.right)+5; + } else { + textoffset=0; + titlepixelwidth=0; + } + } else { + // no tab + fTabRect.Set(0.0, 0.0, -1.0, -1.0); + fCloseRect.Set(0.0, 0.0, -1.0, -1.0); + fZoomRect.Set(0.0, 0.0, -1.0, -1.0); + fMinimizeRect.Set(0.0, 0.0, -1.0, -1.0); + } } -void MacDecorator::_DrawTitle(BRect r) +void +MacDecorator::_DrawFrame(BRect invalid) { - if(IsFocus()) - fDrawState.SetHighColor(textcol); - else - fDrawState.SetHighColor(inactive_textcol); - - fDrawState.SetLowColor(frame_midcol); - - fTruncatedTitle = Title(); - fDrawState.Font().TruncateString(&fTruncatedTitle, B_TRUNCATE_END, - (fZoomRect.left - 5) - (fCloseRect.right + 5)); - fTruncatedTitleLength = fTruncatedTitle.Length(); - - fDrawingEngine->DrawString(fTruncatedTitle,fTruncatedTitleLength, - BPoint(fTabRect.left+textoffset,fCloseRect.bottom-1)/*,&fDrawState*/); -} - -void MacDecorator::GetFootprint(BRegion *region) -{ - // This function calculates the decorator's footprint in coordinates - // relative to the layer. This is most often used to set a WinBorder - // object's visible region. - if(!region) + if (fLook == B_NO_BORDER_WINDOW_LOOK) return; + + if (fBorderWidth <= 0) + return; + + BRect r = fBorderRect; + switch (fLook) { + case B_TITLED_WINDOW_LOOK: + case B_DOCUMENT_WINDOW_LOOK: + case B_MODAL_WINDOW_LOOK: + { + BPoint offset,pt2,topleftpt,toprightpt; + + offset=r.LeftTop(); + pt2=r.LeftBottom(); + + // Draw the left side of the frame + fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); + offset.x++; + pt2.x++; + pt2.y--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_highcol); + offset.x++; + pt2.x++; + pt2.y--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); + offset.x++; + pt2.x++; + fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); + offset.x++; + pt2.x++; + pt2.y--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_lowcol); + offset.x++; + offset.y+=2; + topleftpt=offset; + pt2.x++; + pt2.y--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); + + + offset=r.RightTop(); + pt2=r.RightBottom(); + + // Draw the right side of the frame + fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); + offset.x--; + pt2.x--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_lowcol); + offset.x--; + pt2.x--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); + offset.x--; + pt2.x--; + fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); + offset.x--; + pt2.x--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_highcol); + offset.x--; + offset.y+=2; + toprightpt=offset; + pt2.x--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); + + // Draw the top side of the frame that is not in the tab + fDrawingEngine->StrokeLine(topleftpt,toprightpt,frame_lowercol); + topleftpt.y--; + toprightpt.x++; + toprightpt.y--; + + fDrawingEngine->StrokeLine(topleftpt,toprightpt,frame_lowcol); + + offset=r.RightTop(); + pt2=r.RightBottom(); + + + offset=r.LeftBottom(); + pt2=r.RightBottom(); + + // Draw the bottom side of the frame + fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); + offset.x++; + offset.y--; + pt2.x--; + pt2.y--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_lowcol); + offset.x++; + offset.y--; + pt2.x--; + pt2.y--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); + offset.x++; + offset.y--; + pt2.x--; + pt2.y--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); + offset.x++; + offset.y--; + pt2.x--; + pt2.y--; + + fDrawingEngine->StrokeLine(offset,pt2,frame_highcol); + offset.x+=2; + offset.y--; + pt2.x--; + pt2.y--; - region->Set(fBorderRect); - region->Include(fTabRect); + fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); + offset.y--; + pt2.x--; + pt2.y--; + } + case B_BORDERED_WINDOW_LOOK: + fDrawingEngine->StrokeRect(r, frame_midcol); + break; + + default: + // don't draw a border frame + break; + } } -void MacDecorator::Draw(BRect update) -{ -#ifdef DEBUG_DECOR -printf("MacDecorator::Draw(): "); update.PrintToStream(); -#endif -/* - // Draw the top view's client area - just a hack :) - fDrawingEngine->FillRect(fBorderRect,_colors->document_background); - if(fBorderRect.Intersects(update)) - fDrawingEngine->FillRect(fBorderRect,_colors->document_background); -*/ - _DrawFrame(update); - _DrawTab(update); -} - -void MacDecorator::Draw(void) -{ -#ifdef DEBUG_DECOR -printf("MacDecorator::Draw()\n"); -#endif - - // Draw the top view's client area - just a hack :) -// RGBColor blue(100,100,255); -// fDrawState.SetHighColor(blue); - -// fDrawingEngine->FillRect(fBorderRect,_colors->document_background); -// fDrawingEngine->FillRect(fBorderRect,_colors->document_background); - DrawFrame(); - - DrawTab(); -} - -void MacDecorator::_DrawZoom(BRect r) -{ - bool down=GetClose(); - - // Just like DrawZoom, but for a close button - BRect rect(r); - - BPoint pt(r.LeftTop()),pt2(r.RightTop()); - - pt2.x--; - fDrawState.SetHighColor(RGBColor(136,136,136)); - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt2=r.LeftBottom(); - pt2.y--; - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt=r.RightBottom(); - pt2=r.RightTop(); - pt2.y++; - fDrawState.SetHighColor(RGBColor(255,255,255)); - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt2=r.LeftBottom(); - pt2.x++; - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - rect.InsetBy(1,1); - fDrawState.SetHighColor(RGBColor(0,0,0)); - fDrawingEngine->StrokeRect(rect,fDrawState.HighColor()); - - rect.InsetBy(1,1); - DrawBlendedRect(rect,down); - rect.InsetBy(1,1); - DrawBlendedRect(rect,!down); - - rect.top+=2; - rect.left--; - rect.right++; - - fDrawState.SetHighColor(RGBColor(0,0,0)); - fDrawingEngine->StrokeLine(rect.LeftTop(),rect.RightTop(),fDrawState.HighColor()); -} - -void MacDecorator::_DrawClose(BRect r) -{ - bool down=GetClose(); - - // Just like DrawZoom, but for a close button - BRect rect(r); - - BPoint pt(r.LeftTop()),pt2(r.RightTop()); - - pt2.x--; - fDrawState.SetHighColor(RGBColor(136,136,136)); - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt2=r.LeftBottom(); - pt2.y--; - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt=r.RightBottom(); - pt2=r.RightTop(); - pt2.y++; - fDrawState.SetHighColor(RGBColor(255,255,255)); - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt2=r.LeftBottom(); - pt2.x++; - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - rect.InsetBy(1,1); - fDrawState.SetHighColor(RGBColor(0,0,0)); - fDrawingEngine->StrokeRect(rect,fDrawState.HighColor()); - - rect.InsetBy(1,1); - DrawBlendedRect(rect,down); - rect.InsetBy(1,1); - DrawBlendedRect(rect,!down); - -// rect.top+=4; -// rect.left++; -// rect.right--; - -// fDrawState.SetHighColor(RGBColor(0,0,0)); -// fDrawingEngine->StrokeLine(rect.LeftTop(),rect.RightTop(),&fDrawState,pat_solidhigh); -} - -void MacDecorator::_DrawMinimize(BRect r) -{ - bool down=GetClose(); - - // Just like DrawZoom, but for a close button - BRect rect(r); - - BPoint pt(r.LeftTop()),pt2(r.RightTop()); - - pt2.x--; - fDrawState.SetHighColor(RGBColor(136,136,136)); - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt2=r.LeftBottom(); - pt2.y--; - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt=r.RightBottom(); - pt2=r.RightTop(); - pt2.y++; - fDrawState.SetHighColor(RGBColor(255,255,255)); - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - pt2=r.LeftBottom(); - pt2.x++; - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - - rect.InsetBy(1,1); - fDrawState.SetHighColor(RGBColor(0,0,0)); - fDrawingEngine->StrokeRect(rect,fDrawState.HighColor()); - - rect.InsetBy(1,1); - DrawBlendedRect(rect,down); - rect.InsetBy(1,1); - DrawBlendedRect(rect,!down); - - rect.top+=4; - rect.bottom-=4; - rect.InsetBy(-2,0); - - fDrawState.SetHighColor(RGBColor(0,0,0)); - fDrawingEngine->StrokeRect(rect,fDrawState.HighColor()); -} - -void MacDecorator::_DrawTab(BRect r) +void +MacDecorator::_DrawTab(BRect invalid) { // If a window has a tab, this will draw it and any buttons which are // in it. - if(fLook==B_NO_BORDER_WINDOW_LOOK) + if (!fTabRect.IsValid() || !invalid.Intersects(fTabRect)) return; // fDrawState.SetHighColor(frame_lowcol); @@ -447,7 +435,7 @@ void MacDecorator::_DrawTab(BRect r) fDrawingEngine->FillRect(rect,frame_midcol); - if(IsFocus()) + //if(IsFocus()) { fDrawingEngine->StrokeLine(rect.LeftTop(),rect.RightTop(),frame_lowercol); fDrawingEngine->StrokeLine(rect.LeftTop(),rect.LeftBottom(),frame_lowercol); @@ -465,46 +453,46 @@ void MacDecorator::_DrawTab(BRect r) { // Left side - BPoint pt(fCloseRect.right+5,fCloseRect.top), + BPoint offset(fCloseRect.right+5,fCloseRect.top), pt2(fTabRect.left+textoffset-5,fCloseRect.top); fDrawState.SetHighColor(RGBColor(frame_highcol)); for(int32 i=0;i<6;i++) { - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - pt.y+=2; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + offset.y+=2; pt2.y+=2; } - pt.Set(fCloseRect.right+6,fCloseRect.top+1), + offset.Set(fCloseRect.right+6,fCloseRect.top+1), pt2.Set(fTabRect.left+textoffset-4,fCloseRect.top+1); fDrawState.SetHighColor(RGBColor(frame_lowcol)); for(int32 i=0;i<6;i++) { - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - pt.y+=2; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + offset.y+=2; pt2.y+=2; } // Right side - pt.Set(fTabRect.left+textoffset+titlepixelwidth+6,fZoomRect.top), + offset.Set(fTabRect.left+textoffset+titlepixelwidth+6,fZoomRect.top), pt2.Set(fZoomRect.left-6,fZoomRect.top); - if(pt.xStrokeLine(pt,pt2,fDrawState.HighColor()); - pt.y+=2; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + offset.y+=2; pt2.y+=2; } - pt.Set(fTabRect.left+textoffset+titlepixelwidth+7,fZoomRect.top+1), + offset.Set(fTabRect.left+textoffset+titlepixelwidth+7,fZoomRect.top+1), pt2.Set(fZoomRect.left-5,fZoomRect.top+1); fDrawState.SetHighColor(frame_lowcol); for(int32 i=0;i<6;i++) { - fDrawingEngine->StrokeLine(pt,pt2,fDrawState.HighColor()); - pt.y+=2; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + offset.y+=2; pt2.y+=2; } } @@ -519,190 +507,201 @@ void MacDecorator::_DrawTab(BRect r) } -void MacDecorator::DrawBlendedRect(BRect r, bool down) + +void +MacDecorator::_DrawClose(BRect r) { - BRect r1 = r; - BRect r2 = r; + bool down=GetClose(); + + // Just like DrawZoom, but for a close button + BRect rect(r); - r1.left += 1.0; - r1.top += 1.0; + BPoint offset(r.LeftTop()),pt2(r.RightTop()); + + pt2.x--; + fDrawState.SetHighColor(RGBColor(136,136,136)); + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + pt2=r.LeftBottom(); + pt2.y--; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + offset=r.RightBottom(); + pt2=r.RightTop(); + pt2.y++; + fDrawState.SetHighColor(RGBColor(255,255,255)); + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + pt2=r.LeftBottom(); + pt2.x++; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); - r2.bottom -= 1.0; - r2.right -= 1.0; - - // TODO: replace these with cached versions? does R5 use different colours? - RGBColor tabColorLight = RGBColor(tint_color(tab_col.GetColor32(),B_LIGHTEN_2_TINT)); - RGBColor tabColorShadow = RGBColor(tint_color(tab_col.GetColor32(),B_DARKEN_2_TINT)); - - int32 w = r.IntegerWidth(); - int32 h = r.IntegerHeight(); - - RGBColor temprgbcol; - rgb_color halfColor, startColor, endColor; - float rstep, gstep, bstep; - - int steps = w < h ? w : h; - - if (down) { - startColor = button_lowcol.GetColor32(); - endColor = button_highcol.GetColor32(); - } else { - startColor = button_highcol.GetColor32(); - endColor = button_lowcol.GetColor32(); - } - - halfColor = make_blend_color(startColor, endColor, 0.5); - - rstep = float(startColor.red - halfColor.red) / steps; - gstep = float(startColor.green - halfColor.green) / steps; - bstep = float(startColor.blue - halfColor.blue) / steps; - - for (int32 i = 0; i <= steps; i++) { - temprgbcol.SetColor(uint8(startColor.red - (i * rstep)), - uint8(startColor.green - (i * gstep)), - uint8(startColor.blue - (i * bstep))); - - fDrawingEngine->StrokeLine(BPoint(r.left, r.top + i), - BPoint(r.left + i, r.top), temprgbcol); - - temprgbcol.SetColor(uint8(halfColor.red - (i * rstep)), - uint8(halfColor.green - (i * gstep)), - uint8(halfColor.blue - (i * bstep))); - - fDrawingEngine->StrokeLine(BPoint(r.left + steps, r.top + i), - BPoint(r.left + i, r.top + steps), temprgbcol); - } - - // draw bevelling effect on box - fDrawingEngine->StrokeRect(r2, tabColorShadow); // inner dark box - fDrawingEngine->StrokeRect(r, tabColorShadow); // outer dark box - fDrawingEngine->StrokeRect(r1, tabColorLight); // light box + rect.InsetBy(1,1); + fDrawState.SetHighColor(RGBColor(0,0,0)); + fDrawingEngine->StrokeRect(rect,fDrawState.HighColor()); + + rect.InsetBy(1,1); + _DrawBlendedRect(fDrawingEngine, rect, down); + rect.InsetBy(1,1); + _DrawBlendedRect(fDrawingEngine, rect, !down); + +// rect.top+=4; +// rect.left++; +// rect.right--; + +// fDrawState.SetHighColor(RGBColor(0,0,0)); +// fDrawingEngine->StrokeLine(rect.LeftTop(),rect.RightTop(),&fDrawState,pat_solidhigh); } + +void MacDecorator::_DrawTitle(BRect r) +{ + if(IsFocus()) + fDrawState.SetHighColor(fFocusTextColor); + else + fDrawState.SetHighColor(fNonFocusTextColor); + + fDrawState.SetLowColor(frame_midcol); + + fTruncatedTitle = Title(); + fDrawState.Font().TruncateString(&fTruncatedTitle, B_TRUNCATE_END, + (fZoomRect.left - 5) - (fCloseRect.right + 5)); + fTruncatedTitleLength = fTruncatedTitle.Length(); + + fDrawingEngine->DrawString(fTruncatedTitle,fTruncatedTitleLength, + BPoint(fTabRect.left+textoffset,fCloseRect.bottom-1)/*,&fDrawState*/); +} + + +void MacDecorator::_DrawZoom(BRect r) +{ + bool down=GetClose(); + + // Just like DrawZoom, but for a close button + BRect rect(r); + + BPoint offset(r.LeftTop()),pt2(r.RightTop()); + + pt2.x--; + fDrawState.SetHighColor(RGBColor(136,136,136)); + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + pt2=r.LeftBottom(); + pt2.y--; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + offset=r.RightBottom(); + pt2=r.RightTop(); + pt2.y++; + fDrawState.SetHighColor(RGBColor(255,255,255)); + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + pt2=r.LeftBottom(); + pt2.x++; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + rect.InsetBy(1,1); + fDrawState.SetHighColor(RGBColor(0,0,0)); + fDrawingEngine->StrokeRect(rect,fDrawState.HighColor()); + + rect.InsetBy(1,1); + _DrawBlendedRect(fDrawingEngine, rect, down); + rect.InsetBy(1,1); + _DrawBlendedRect(fDrawingEngine, rect, !down); + + rect.top+=2; + rect.left--; + rect.right++; + + fDrawState.SetHighColor(RGBColor(0,0,0)); + fDrawingEngine->StrokeLine(rect.LeftTop(),rect.RightTop(),fDrawState.HighColor()); +} + + +void MacDecorator::_DrawMinimize(BRect r) +{ + bool down=GetClose(); + + // Just like DrawZoom, but for a close button + BRect rect(r); + + BPoint offset(r.LeftTop()),pt2(r.RightTop()); + + pt2.x--; + fDrawState.SetHighColor(RGBColor(136,136,136)); + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + pt2=r.LeftBottom(); + pt2.y--; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + offset=r.RightBottom(); + pt2=r.RightTop(); + pt2.y++; + fDrawState.SetHighColor(RGBColor(255,255,255)); + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + pt2=r.LeftBottom(); + pt2.x++; + fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor()); + + rect.InsetBy(1,1); + fDrawState.SetHighColor(RGBColor(0,0,0)); + fDrawingEngine->StrokeRect(rect,fDrawState.HighColor()); + + rect.InsetBy(1,1); + _DrawBlendedRect(fDrawingEngine, rect, down); + rect.InsetBy(1,1); + _DrawBlendedRect(fDrawingEngine, rect, !down); + + rect.top+=4; + rect.bottom-=4; + rect.InsetBy(-2,0); + + fDrawState.SetHighColor(RGBColor(0,0,0)); + fDrawingEngine->StrokeRect(rect,fDrawState.HighColor()); +} + + +/*! \brief Draws a framed rectangle with a gradient. + \param down The rectangle should be drawn recessed or not +*/ +void +MacDecorator::_DrawBlendedRect(DrawingEngine* engine, BRect rect, + bool down/*, bool focus*/) +{ + // figure out which colors to use + rgb_color startColor, endColor; + if (down) { + startColor = tint_color(fButtonLowColor, B_DARKEN_1_TINT); + endColor = fButtonLowColor; + } else { + startColor = tint_color(fButtonHighColor, B_LIGHTEN_MAX_TINT); + endColor = fButtonHighColor; + } + + // fill + rect.InsetBy(1, 1); + BGradientLinear gradient; + gradient.SetStart(rect.LeftTop()); + gradient.SetEnd(rect.RightBottom()); + gradient.AddColor(startColor, 0); + gradient.AddColor(endColor, 255); + + engine->FillRect(rect, gradient); + + // outline + rect.InsetBy(-1, -1); + engine->StrokeRect(rect, tint_color(fTabColor, B_DARKEN_2_TINT)); +} + + /* void MacDecorator::_SetColors(void) { _SetFocus(); } */ -void MacDecorator::_DrawFrame(BRect rect) -{ - if(fLook==B_NO_BORDER_WINDOW_LOOK) - return; - - BRect r=fBorderRect; - BPoint pt,pt2,topleftpt,toprightpt; - - pt=r.LeftTop(); - pt2=r.LeftBottom(); - - // Draw the left side of the frame - fDrawingEngine->StrokeLine(pt,pt2,frame_lowercol); - pt.x++; - pt2.x++; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_highcol); - pt.x++; - pt2.x++; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_midcol); - pt.x++; - pt2.x++; - fDrawingEngine->StrokeLine(pt,pt2,frame_midcol); - pt.x++; - pt2.x++; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_lowcol); - pt.x++; - pt.y+=2; - topleftpt=pt; - pt2.x++; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_lowercol); - - - pt=r.RightTop(); - pt2=r.RightBottom(); - - // Draw the right side of the frame - fDrawingEngine->StrokeLine(pt,pt2,frame_lowercol); - pt.x--; - pt2.x--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_lowcol); - pt.x--; - pt2.x--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_midcol); - pt.x--; - pt2.x--; - fDrawingEngine->StrokeLine(pt,pt2,frame_midcol); - pt.x--; - pt2.x--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_highcol); - pt.x--; - pt.y+=2; - toprightpt=pt; - pt2.x--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_lowercol); - - // Draw the top side of the frame that is not in the tab - fDrawingEngine->StrokeLine(topleftpt,toprightpt,frame_lowercol); - topleftpt.y--; - toprightpt.x++; - toprightpt.y--; - - fDrawingEngine->StrokeLine(topleftpt,toprightpt,frame_lowcol); - - pt=r.RightTop(); - pt2=r.RightBottom(); - - - pt=r.LeftBottom(); - pt2=r.RightBottom(); - - // Draw the bottom side of the frame - fDrawingEngine->StrokeLine(pt,pt2,frame_lowercol); - pt.x++; - pt.y--; - pt2.x--; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_lowcol); - pt.x++; - pt.y--; - pt2.x--; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_midcol); - pt.x++; - pt.y--; - pt2.x--; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_midcol); - pt.x++; - pt.y--; - pt2.x--; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_highcol); - pt.x+=2; - pt.y--; - pt2.x--; - pt2.y--; - - fDrawingEngine->StrokeLine(pt,pt2,frame_lowercol); - pt.y--; - pt2.x--; - pt2.y--; -} extern "C" float get_decorator_version(void) { diff --git a/src/add-ons/decorators/MacDecorator/MacDecorator.h b/src/add-ons/decorators/MacDecorator/MacDecorator.h index ca693e7337..682d36ccc1 100644 --- a/src/add-ons/decorators/MacDecorator/MacDecorator.h +++ b/src/add-ons/decorators/MacDecorator/MacDecorator.h @@ -1,63 +1,88 @@ +/* + Copyright 2009, Haiku. + Distributed under the terms of the MIT License. +*/ + + #ifndef _MAC_DECORATOR_H_ #define _MAC_DECORATOR_H_ + #include "Decorator.h" #include "RGBColor.h" - - class MacDecorator: public Decorator { public: - MacDecorator(DesktopSettings& settings, - BRect frame, - window_look look, - uint32 flags); - ~MacDecorator(void); + MacDecorator(DesktopSettings& settings, + BRect frame, window_look look, + uint32 flags); + ~MacDecorator(); - // SetTitle - // SetLook - // SetFlags + // void SetTitle(const char* string, + // BRegion* updateRegion = NULL); + // void FontsChanged(DesktopSettings& settings, + // BRegion* updateRegion); + // void SetLook(DesktopSettings& settings, + // BRegion* updateRegion = NULL); + // void SetFlags(uint32 flags, + // BRegion* updateRegion = NULL); - //void MoveBy(float x, float y); - void MoveBy(BPoint pt); -// void ResizeBy(float x, float y); - void ResizeBy(BPoint pt, BRegion* diirty); + void MoveBy(BPoint offset); + void ResizeBy(BPoint offset, BRegion* dirty); + // SetTabLocation // TabLocation + // // SetSettings // GetSettings - void Draw(BRect r); - void Draw(void); + + void Draw(BRect updateRect); + void Draw(); + //GetSizeLimits - void GetFootprint(BRegion *region); - click_type Clicked(BPoint pt, int32 buttons, int32 modifiers); + + void GetFootprint(BRegion *region); - protected: - void _DoLayout(void); - void _DrawFrame(BRect r); - void _DrawTab(BRect r); - void _DrawClose(BRect r); - void _DrawTitle(BRect r); - void _DrawZoom(BRect r); - void _DrawMinimize(BRect r); - // SetFocus -// void _SetColors(void); - void DrawBlendedRect(BRect r, bool down); - uint32 taboffset; - private: - RGBColor tab_col; - RGBColor button_highcol,button_lowcol; - RGBColor frame_highcol, frame_midcol, frame_lowcol, frame_lowercol; - RGBColor textcol,inactive_textcol; - uint64 solidhigh, solidlow; + click_type Clicked(BPoint pt, int32 buttons, + int32 modifiers); - BString fTruncatedTitle; - int32 fTruncatedTitleLength; +protected: + void _DoLayout(); - bool slidetab; - int textoffset; - float titlepixelwidth; + void _DrawFrame(BRect r); + void _DrawTab(BRect r); + + void _DrawClose(BRect r); + void _DrawTitle(BRect r); + void _DrawZoom(BRect r); + void _DrawMinimize(BRect r); + + // void _SetFocus(); + // void _SetColors(); +private: + void _DrawBlendedRect(DrawingEngine* engine, + BRect r, bool down); + + rgb_color fButtonHighColor; + rgb_color fButtonLowColor; + rgb_color fTabColor; + rgb_color frame_highcol; + rgb_color frame_midcol; + rgb_color frame_lowcol; + rgb_color frame_lowercol; + rgb_color fFocusTextColor; + rgb_color fNonFocusTextColor; + uint64 solidhigh, solidlow; + + BString fTruncatedTitle; + int32 fTruncatedTitleLength; + + int32 fBorderWidth; + + bool slidetab; + int textoffset; + float titlepixelwidth; }; #endif