[haiku-commits] r34756 - haiku/trunk/src/add-ons/decorators/MacDecorator

  • From: pulkomandy@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 23 Dec 2009 16:18:41 +0100 (CET)

Author: pulkomandy
Date: 2009-12-23 16:18:40 +0100 (Wed, 23 Dec 2009)
New Revision: 34756
Changeset: http://dev.haiku-os.org/changeset/34756/haiku

Modified:
   haiku/trunk/src/add-ons/decorators/MacDecorator/MacDecorator.cpp
   haiku/trunk/src/add-ons/decorators/MacDecorator/MacDecorator.h
Log:
MacDecorator:
- Style cleanup and sync with DefaultDecorator to some extent
- Don't draw a titlebar and border around menus
- Allow the client to draw something inside the window by returning the correct 
BRegion. (still not perfect, but it is useable, at least)


Modified: haiku/trunk/src/add-ons/decorators/MacDecorator/MacDecorator.cpp
===================================================================
--- haiku/trunk/src/add-ons/decorators/MacDecorator/MacDecorator.cpp    
2009-12-23 11:39:04 UTC (rev 34755)
+++ haiku/trunk/src/add-ons/decorators/MacDecorator/MacDecorator.cpp    
2009-12-23 15:18:40 UTC (rev 34756)
@@ -1,210 +1,85 @@
-#include <Point.h>
-#include "DrawingEngine.h"
-#include <View.h>
-#include "MacDecorator.h"
-#include "RGBColor.h"
-#include "PatternHandler.h"
+/*
+ Copyright 2009, Haiku.
+ Distributed under the terms of the MIT License.
+*/
 
-//#define DEBUG_DECOR
+/*! Decorator looking like Mac OS 9 */
 
-#ifdef DEBUG_DECOR
-#include <stdio.h>
-#endif
 
+#include <GradientLinear.h>
+#include <Point.h>
+#include <View.h>
 
-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;
+#include "DesktopSettings.h"
+#include "DrawingEngine.h"
+#include "PatternHandler.h"
+#include "RGBColor.h"
 
-       return (uint8)value;
-}
+#include "MacDecorator.h"
 
 
-/*!
-       \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.
-*/
-static rgb_color
-make_blend_color(rgb_color colorA, rgb_color colorB, float position)
-{
-       if (position < 0)
-               return colorA;
-       if (position > 1)
-               return colorB;
+//#define DEBUG_DECORATOR
+#ifdef DEBUG_DECORATOR
+#      include <stdio.h>
+#      define STRACE(x) printf x ;
+#else
+#      define STRACE(x) ;
+#endif
 
-       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;
-}
-
-
-
-MacDecorator::MacDecorator(DesktopSettings& settings, BRect frame, window_look 
look, uint32 flags)
- : Decorator(settings, frame, look, flags)
+MacDecorator::MacDecorator(DesktopSettings& settings, BRect rect,
+               window_look look, uint32 flags)
+       : Decorator(settings, rect, look, flags)
 {
-#ifdef DEBUG_DECOR
-printf("MacDecorator()\n");
-#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);
+       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;
-}
 
-MacDecorator::~MacDecorator(void)
-{
-#ifdef DEBUG_DECOR
-printf("~MacDecorator()\n");
-#endif
+       STRACE(("MacDecorator()\n"));
 }
 
-click_type MacDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers)
-{
-       if(fCloseRect.Contains(pt))
-       {
 
-#ifdef DEBUG_DECOR
-printf("MacDecorator():Clicked() - Close\n");
-#endif
-
-               return DEC_CLOSE;
-       }
-
-       if(fZoomRect.Contains(pt))
-       {
-
-#ifdef DEBUG_DECOR
-printf("MacDecorator():Clicked() - Zoom\n");
-#endif
-
-               return DEC_ZOOM;
-       }
-       
-       // Clicking in the tab?
-       if(fTabRect.Contains(pt))
-       {
-               // Here's part of our window management stuff
-               /* TODO This is missing DEC_MOVETOFRONT
-               if(buttons==B_PRIMARY_MOUSE_BUTTON && !IsFocus())
-                       return DEC_MOVETOFRONT;
-               */
-               return DEC_DRAG;
-       }
-
-       // We got this far, so user is clicking on the border?
-       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         
-               return DEC_RESIZE;
-       }
-
-       // Guess user didn't click anything
-#ifdef DEBUG_DECOR
-printf("MacDecorator():Clicked()\n");
-#endif
-       return DEC_NONE;
+MacDecorator::~MacDecorator()
+{
+       STRACE("~MacDecorator()\n");
 }
 
-void MacDecorator::_DoLayout(void)
-{
-#ifdef DEBUG_DECOR
-printf("MacDecorator()::_DoLayout()\n");
-#endif
-       fBorderRect=fFrame;
-       fBorderRect.top+=19;
-       fTabRect=fFrame;
+// settitle
+// fontschanged
+// setlook
+// setflags
 
-       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)
+void
+MacDecorator::MoveBy(BPoint offset)
 {
-       // 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);
+       Decorator::MoveBy(offset);
 }
 
 
 void
-MacDecorator::ResizeBy(BPoint pt, BRegion* dirty)
+MacDecorator::ResizeBy(BPoint offset, BRegion* dirty)
 {
        // Move all internal rectangles the appropriate amount
-       fFrame.right += pt.x;
-       fFrame.bottom += pt.y;
+       fFrame.right += offset.x;
+       fFrame.bottom += offset.y;
 
-       fTabRect.right += pt.x;
-       fBorderRect.right += pt.x;
-       fBorderRect.bottom += pt.y;
-       fZoomRect.OffsetBy(pt.x,0);
-       fMinimizeRect.OffsetBy(pt.x,0);
+       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)) {
@@ -214,7 +89,7 @@
                                realResizeRect = fResizeRect;
                                // resize rect at old location
                                dirty->Include(realResizeRect);
-                               realResizeRect.OffsetBy(pt);
+                               realResizeRect.OffsetBy(offset);
                                // resize rect at new location
                                dirty->Include(realResizeRect);
                                break;
@@ -223,7 +98,7 @@
                        case B_MODAL_WINDOW_LOOK:
                                // resize rect at old location
                                dirty->Include(fBorderRect);
-                               fBorderRect.OffsetBy(pt);
+                               fBorderRect.OffsetBy(offset);
                                // resize rect at new location
                                dirty->Include(fBorderRect);
                                break;
@@ -235,207 +110,320 @@
        // TODO probably some other layouting stuff here
 }
 
+// settablocation
+// setsettings
+// getsettings
 
-void MacDecorator::_DrawTitle(BRect r)
+void
+MacDecorator::Draw(BRect update)
 {
-       if(IsFocus())
-               fDrawState.SetHighColor(textcol);
-       else
-               fDrawState.SetHighColor(inactive_textcol);
-               
-       fDrawState.SetLowColor(frame_midcol);
+       STRACE(("MacDecorator: Draw(%.1f,%.1f,%.1f,%.1f)\n",
+               update.left, update.top, update.right, update.bottom));
 
-       fTruncatedTitle = Title();
-       fDrawState.Font().TruncateString(&fTruncatedTitle, B_TRUNCATE_END,
-               (fZoomRect.left - 5) - (fCloseRect.right + 5));
-       fTruncatedTitleLength = fTruncatedTitle.Length();
+       fDrawingEngine->SetDrawState(&fDrawState);
+       _DrawFrame(update);
+       _DrawTab(update);
+}
 
-       fDrawingEngine->DrawString(fTruncatedTitle,fTruncatedTitleLength,
-               
BPoint(fTabRect.left+textoffset,fCloseRect.bottom-1)/*,&fDrawState*/);
+
+void
+MacDecorator::Draw()
+{
+       STRACE("MacDecorator::Draw()\n");
+       fDrawingEngine->SetDrawState(&fDrawState);
+
+       _DrawFrame(fBorderRect);
+       _DrawTab(fTabRect);
 }
 
-void MacDecorator::GetFootprint(BRegion *region)
+
+// getsizelimits
+
+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
+       // relative to the view. This is most often used to set a Window
        // object's visible region.
-       if(!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);
 }
 
-void MacDecorator::Draw(BRect update)
+
+click_type
+MacDecorator::Clicked(BPoint point, int32 buttons, int32 modifiers)
 {
-#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 (!(fFlags & B_NOT_CLOSABLE) && fCloseRect.Contains(point)) {
+               STRACE(("MacDecorator():Clicked() - Close\n"));
+               return DEC_CLOSE;
+       }
 
-       if(fBorderRect.Intersects(update))
-               
fDrawingEngine->FillRect(fBorderRect,_colors->document_background);
-*/     
-       _DrawFrame(update);
-       _DrawTab(update);
+       if (!(fFlags & B_NOT_ZOOMABLE) && fZoomRect.Contains(point)) {
+               STRACE("MacDecorator():Clicked() - Zoom\n");
+               return DEC_ZOOM;
+       }
+       
+       // Clicking in the tab?
+       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())
+                       return DEC_MOVETOFRONT;
+               */
+               return DEC_DRAG;
+       }
+
+       // We got this far, so user is clicking on the border?
+       BRect srect(fFrame);
+       srect.top+=19;
+       BRect clientrect(srect.InsetByCopy(3,3));
+       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
+       STRACE(("MacDecorator():Clicked()\n"));
+       return DEC_NONE;
 }
 
-void MacDecorator::Draw(void)
+
+void
+MacDecorator::_DoLayout(void)
 {
-#ifdef DEBUG_DECOR
-printf("MacDecorator::Draw()\n");
-#endif
+       STRACE(("MacDecorator: Do Layout\n"));
 
-       // Draw the top view's client area - just a hack :)
-//     RGBColor blue(100,100,255);
-//     fDrawState.SetHighColor(blue);
+       bool hasTab = false;
 
-//     fDrawingEngine->FillRect(fBorderRect,_colors->document_background);
-//     fDrawingEngine->FillRect(fBorderRect,_colors->document_background);
-       DrawFrame();
+       switch (Look()) {
+               case B_MODAL_WINDOW_LOOK:
+                       fBorderWidth = 5;
+                       break;
 
-       DrawTab();
-}
+               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;
 
-void MacDecorator::_DrawZoom(BRect r)
-{
-       bool down=GetClose();
-       
-       // Just like DrawZoom, but for a close button
-       BRect rect(r);
+               case B_BORDERED_WINDOW_LOOK:
+                       fBorderWidth = 1;
+                       break;
 
-       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());
+               default:
+                       fBorderWidth = 0;
+       }
+       fBorderRect=fFrame;
 
-       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());
-}
+       if (hasTab) {
+               fBorderRect.top+=19;
 
-void MacDecorator::_DrawClose(BRect r)
-{
-       bool down=GetClose();
-       
-       // Just like DrawZoom, but for a close button
-       BRect rect(r);
+               fTabRect=fFrame;
+               fTabRect.bottom=fTabRect.top+19;
 
-       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());
+               fZoomRect=fTabRect;
+               fZoomRect.left=fZoomRect.right-12;
+               fZoomRect.bottom=fZoomRect.top+12;
+               fZoomRect.OffsetBy(-4,4);
 
-       rect.InsetBy(1,1);
-       fDrawState.SetHighColor(RGBColor(0,0,0));
-       fDrawingEngine->StrokeRect(rect,fDrawState.HighColor());
+               fCloseRect=fZoomRect;
+               fMinimizeRect=fZoomRect;
+
+               fCloseRect.OffsetTo(fTabRect.left+4,fTabRect.top+4);
        
-       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);
+               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::_DrawMinimize(BRect r)
+
+void
+MacDecorator::_DrawFrame(BRect invalid)
 {
-       bool down=GetClose();
-       
-       // Just like DrawZoom, but for a close button
-       BRect rect(r);
+       if (fLook == B_NO_BORDER_WINDOW_LOOK)
+               return;
 
-       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());
+       if (fBorderWidth <= 0)
+               return;
 
-       rect.InsetBy(1,1);
-       fDrawState.SetHighColor(RGBColor(0,0,0));
-       fDrawingEngine->StrokeRect(rect,fDrawState.HighColor());
+       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--;
        
-       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());
+                       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::_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 @@
        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 @@
                {
                        // 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.x<pt2.x)
+                       if(offset.x<pt2.x)
                        {
                                
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(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::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;
+       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);
+}
 
-       // 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();
+void MacDecorator::_DrawTitle(BRect r)
+{
+       if(IsFocus())
+               fDrawState.SetHighColor(fFocusTextColor);
+       else
+               fDrawState.SetHighColor(fNonFocusTextColor);
+               
+       fDrawState.SetLowColor(frame_midcol);
 
-       RGBColor temprgbcol;
-       rgb_color halfColor, startColor, endColor;
-       float rstep, gstep, bstep;
+       fTruncatedTitle = Title();
+       fDrawState.Font().TruncateString(&fTruncatedTitle, B_TRUNCATE_END,
+               (fZoomRect.left - 5) - (fCloseRect.right + 5));
+       fTruncatedTitleLength = fTruncatedTitle.Length();
 
-       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
+       fDrawingEngine->DrawString(fTruncatedTitle,fTruncatedTitleLength,
+               
BPoint(fTabRect.left+textoffset,fCloseRect.bottom-1)/*,&fDrawState*/);
 }
 
-/*
-void MacDecorator::_SetColors(void)
+
+void MacDecorator::_DrawZoom(BRect r)
 {
-       _SetFocus();
-}
-*/
-void MacDecorator::_DrawFrame(BRect rect)
-{
-       if(fLook==B_NO_BORDER_WINDOW_LOOK)
-               return;
+       bool down=GetClose();
+       
+       // Just like DrawZoom, but for a close button
+       BRect rect(r);
 
-       BRect r=fBorderRect;
-       BPoint pt,pt2,topleftpt,toprightpt;
+       BPoint offset(r.LeftTop()),pt2(r.RightTop());
        
-       pt=r.LeftTop();
+       pt2.x--;
+       fDrawState.SetHighColor(RGBColor(136,136,136));
+       fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor());
+       
        pt2=r.LeftBottom();
-
-       // Draw the left side of the frame
-       fDrawingEngine->StrokeLine(pt,pt2,frame_lowercol);
-       pt.x++;
-       pt2.x++;
        pt2.y--;
+       fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor());
        
-       fDrawingEngine->StrokeLine(pt,pt2,frame_highcol);
-       pt.x++;
-       pt2.x++;
-       pt2.y--;
+       offset=r.RightBottom();
+       pt2=r.RightTop();
+       pt2.y++;
+       fDrawState.SetHighColor(RGBColor(255,255,255));
+       fDrawingEngine->StrokeLine(offset,pt2,fDrawState.HighColor());
        
-       fDrawingEngine->StrokeLine(pt,pt2,frame_midcol);

[... truncated: 323 lines follow ...]

Other related posts:

  • » [haiku-commits] r34756 - haiku/trunk/src/add-ons/decorators/MacDecorator - pulkomandy