Make the decorators not crash

This commit is contained in:
John Scipione 2013-07-29 19:56:42 -04:00
parent 6b585e268a
commit 78a987cc9b
5 changed files with 49 additions and 48 deletions

View File

@ -128,25 +128,23 @@ BeDecorator::BeDecorator(DesktopSettings& settings, BRect rect)
fTabOffset(0),
fWasDoubleClick(false)
{
_UpdateFont(settings);
//SetLook(settings, look);
fFrameColors = new RGBColor[6];
fFrameColors[0].SetColor(152, 152, 152);
fFrameColors[1].SetColor(255, 255, 255);
fFrameColors[2].SetColor(216, 216, 216);
fFrameColors[2].SetColor(ui_color(B_MENU_BACKGROUND_COLOR));
fFrameColors[3].SetColor(136, 136, 136);
fFrameColors[4].SetColor(152, 152, 152);
fFrameColors[5].SetColor(96, 96, 96);
fTabList.AddItem(_AllocateNewTab());
fTabColor.SetColor(ui_color(B_WINDOW_TAB_COLOR));
fTextColor.SetColor(ui_color(B_WINDOW_TEXT_COLOR));
// Set appropriate colors based on the current focus value. In this case,
// each decorator defaults to not having the focus.
_SetFocus(_TabAt(0));
fButtonHighColor.SetColor(tint_color(fTabColor.GetColor32(),
B_LIGHTEN_2_TINT));
fButtonLowColor.SetColor(tint_color(fTabColor.GetColor32(),
B_DARKEN_2_TINT));
// Do initial decorator setup
_DoLayout();
//_UpdateFont(settings);
// TODO: If the decorator was created with a frame too small, it should
// resize itself!
@ -214,9 +212,11 @@ BeDecorator::Draw(BRect updateRect)
STRACE(("BeDecorator::Draw(BRect updateRect): "));
updateRect.PrintToStream();
// We need to draw a few things: the tab, the resize knob, the borders,
// and the buttons
fDrawingEngine->SetDrawState(&fDrawState);
_DrawFrame(updateRect & fFrame);
_DrawFrame(updateRect);
_DrawTabs(updateRect & fTitleBarRect);
}
@ -228,7 +228,7 @@ BeDecorator::Draw()
// things
fDrawingEngine->SetDrawState(&fDrawState);
_DrawFrame(fFrame);
_DrawFrame(BRect(fTopBorder.LeftTop(), fBottomBorder.RightBottom()));
_DrawTabs(fTitleBarRect);
}
@ -837,10 +837,16 @@ BeDecorator::_DrawTab(Decorator::Tab* tab, BRect invalid)
void
BeDecorator::_DrawTitle(Decorator::Tab* tab, BRect r)
BeDecorator::_DrawTitle(Decorator::Tab* _tab, BRect r)
{
STRACE(("_DrawTitle(%f, %f, %f, %f)\n", r.left, r.top, r.right, r.bottom));
BeDecorator::Tab* tab = static_cast<BeDecorator::Tab*>(_tab);
const BRect& tabRect = tab->tabRect;
const BRect& closeRect = tab->closeRect;
const BRect& zoomRect = tab->zoomRect;
fDrawingEngine->SetDrawingMode(B_OP_OVER);
fDrawingEngine->SetHighColor(fTextColor);
fDrawingEngine->SetLowColor(fTabColor);
@ -852,20 +858,22 @@ BeDecorator::_DrawTitle(Decorator::Tab* tab, BRect r)
BPoint titlePos;
if (fTopTab->look != kLeftTitledWindowLook) {
titlePos.x = tab->closeRect.IsValid() ? tab->closeRect.right + fTextOffset
: tab->tabRect.left + fTextOffset;
titlePos.y = floorf(((tab->tabRect.top + 2.0) + tab->tabRect.bottom
titlePos.x = closeRect.IsValid() ? closeRect.right + tab->textOffset
: tabRect.left + tab->textOffset;
titlePos.y = floorf(((tabRect.top + 2.0) + tabRect.bottom
+ fontHeight.ascent + fontHeight.descent) / 2.0
- fontHeight.descent + 0.5);
} else {
titlePos.x = floorf(((tab->tabRect.left + 2.0) + tab->tabRect.right
titlePos.x = floorf(((tabRect.left + 2.0) + tabRect.right
+ fontHeight.ascent + fontHeight.descent) / 2.0
- fontHeight.descent + 0.5);
titlePos.y = tab->zoomRect.IsValid() ? tab->zoomRect.top - fTextOffset
: tab->tabRect.bottom - fTextOffset;
titlePos.y = zoomRect.IsValid() ? zoomRect.top - tab->textOffset
: tabRect.bottom - tab->textOffset;
}
fDrawingEngine->DrawString(fTruncatedTitle.String(), fTruncatedTitleLength,
fDrawingEngine->SetFont(fDrawState.Font());
fDrawingEngine->DrawString(tab->truncatedTitle.String(), tab->truncatedTitleLength,
titlePos);
fDrawingEngine->SetDrawingMode(B_OP_COPY);

View File

@ -189,12 +189,9 @@ private:
uint32 fTabOffset;
float fTabLocation;
float fTextOffset;
float fMinTabSize;
float fMaxTabSize;
BString fTruncatedTitle;
int32 fTruncatedTitleLength;
bool fWasDoubleClick;
};

View File

@ -48,8 +48,6 @@ WinDecorator::WinDecorator(DesktopSettings& settings, BRect rect)
:
Decorator(settings, rect)
{
_UpdateFont(settings);
// common colors to both focus and non focus state
frame_highcol = (rgb_color){ 255, 255, 255, 255 };
frame_midcol = (rgb_color){ 216, 216, 216, 255 };
@ -62,18 +60,11 @@ WinDecorator::WinDecorator(DesktopSettings& settings, BRect rect)
fNonFocusTabColor = settings.UIColor(B_WINDOW_INACTIVE_TAB_COLOR);
fNonFocusTextColor = settings.UIColor(B_WINDOW_INACTIVE_TEXT_COLOR);
fTabList.AddItem(_AllocateNewTab());
//_UpdateFont(settings);
// Set appropriate colors based on the current focus value. In this case,
// each decorator defaults to not having the focus.
_SetFocus(_TabAt(0));
// Do initial decorator setup
_DoLayout();
textoffset = 5;
STRACE(("WinDecorator()\n"));
STRACE(("WinDecorator:\n"));
STRACE(("\tFrame (%.1f,%.1f,%.1f,%.1f)\n",
rect.left, rect.top, rect.right, rect.bottom));
}
@ -98,17 +89,20 @@ WinDecorator::Draw(BRect updateRect)
STRACE(("WinDecorator::Draw(BRect updateRect): "));
updateRect.PrintToStream();
// We need to draw a few things: the tab, the resize knob, the borders,
// and the buttons
fDrawingEngine->SetDrawState(&fDrawState);
_DrawFrame(updateRect & fFrame);
_DrawTabs(updateRect & fTitleBarRect);
_DrawFrame(fFrame & updateRect);
_DrawTabs(fTitleBarRect & updateRect);
}
void
WinDecorator::Draw()
{
STRACE(("WinDecorator::Draw()\n"));
// Easy way to draw everything - no worries about drawing only certain
// things
fDrawingEngine->SetDrawState(&fDrawState);
_DrawFrame(fFrame);
@ -301,26 +295,28 @@ void
WinDecorator::_DrawTitle(Decorator::Tab* tab, BRect rect)
{
const BRect& tabRect = tab->tabRect;
const BRect& closeRect = tab->closeRect;
const BRect& minimizeRect = tab->minimizeRect;
const BRect& zoomRect = tab->zoomRect;
const BRect& closeRect = tab->closeRect;
//fDrawingEngine->SetDrawingMode(B_OP_OVER);
fDrawingEngine->SetHighColor(textcol);
fDrawingEngine->SetLowColor(IsFocus(_TabAt(0))
fDrawingEngine->SetLowColor(IsFocus(tab)
? fFocusTabColor : fNonFocusTabColor);
fTruncatedTitle = Title(_TabAt(0));
fTruncatedTitle = Title(tab);
fDrawState.Font().TruncateString(&fTruncatedTitle, B_TRUNCATE_END,
((zoomRect.IsValid() ? zoomRect.left :
((minimizeRect.IsValid() ? minimizeRect.left :
zoomRect.IsValid() ? zoomRect.left :
closeRect.IsValid() ? closeRect.left : tabRect.right) - 5)
- (tabRect.left + textoffset));
- (tabRect.left + 5));
fTruncatedTitleLength = fTruncatedTitle.Length();
fDrawingEngine->SetFont(fDrawState.Font());
fDrawingEngine->DrawString(fTruncatedTitle, fTruncatedTitleLength,
BPoint(tabRect.left + textoffset,closeRect.bottom - 1));
BPoint(tabRect.left + 5, closeRect.bottom - 1));
//fDrawingEngine->SetDrawingMode(B_OP_COPY);
fDrawingEngine->SetDrawingMode(B_OP_COPY);
}
@ -480,7 +476,7 @@ WinDecorator::_SetFocus(Decorator::Tab* tab)
// SetFocus() performs necessary duties for color swapping and
// other things when a window is deactivated or activated.
if (IsFocus(_TabAt(0))) {
if (IsFocus(tab)) {
// tab_highcol.SetColor(100, 100, 255);
// tab_lowcol.SetColor(40, 0, 255);
tab_highcol = fFocusTabColor;

View File

@ -103,7 +103,6 @@ private:
int32 fTruncatedTitleLength;
bool slidetab;
int textoffset;
};

View File

@ -433,6 +433,7 @@ Decorator::IsFocus(int32 tab) const
Decorator::Tab* decoratorTab = fTabList.ItemAt(tab);
if (decoratorTab == NULL)
return false;
return decoratorTab->isFocused;
};