Fix a bug where the Deskbar menu was incorrectly sized in horizontal mode

Actually, the Deskbar menu was sized correctly but the separator item was not,
so, I've replaced the separator item with a new TSeparatorItem class that is derived
from BSeparatorItem but does it's own drawing. This neatly avoids the bug since
the TSeperatorItem doesn't need to be resized explicitly.

Also, there were some instances of AddSeperatorItem (with an e) that I renamed to
AddSeparatorItem (with an a). I also eliminated includes in the header which means
I added them in some cpp files where they were needed.
This commit is contained in:
John Scipione
2013-04-14 02:49:36 -04:00
parent e83b2f0b9c
commit 4ae3e5421d
8 changed files with 122 additions and 137 deletions
+55 -13
View File
@@ -37,11 +37,14 @@ All rights reserved.
#include "BarMenuBar.h" #include "BarMenuBar.h"
#include <Bitmap.h> #include <Bitmap.h>
#include <ControlLook.h>
#include <Debug.h> #include <Debug.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include "icons.h" #include "icons.h"
#include "BarMenuTitle.h"
#include "BarView.h"
#include "BarWindow.h" #include "BarWindow.h"
#include "DeskbarMenu.h" #include "DeskbarMenu.h"
#include "DeskbarUtils.h" #include "DeskbarUtils.h"
@@ -51,21 +54,62 @@ All rights reserved.
const float kSepItemWidth = 5.0f; const float kSepItemWidth = 5.0f;
TBarMenuBar::TBarMenuBar(TBarView* bar, BRect frame, const char* name)
: BMenuBar(frame, name, B_FOLLOW_NONE, B_ITEMS_IN_ROW, false), // #pragma mark - TSeparatorItem
fBarView(bar),
TSeparatorItem::TSeparatorItem()
:
BSeparatorItem()
{
}
void
TSeparatorItem::Draw()
{
BMenu* menu = Menu();
if (menu == NULL)
return;
BRect frame(Frame());
frame.right = frame.left + kSepItemWidth;
rgb_color base = menu->LowColor();
menu->PushState();
menu->SetHighColor(tint_color(base, 1.22));
frame.top--;
// need to expand the frame for some reason
// stroke a darker line on the left edge
menu->StrokeLine(frame.LeftTop(), frame.LeftBottom());
frame.left++;
// fill in background
be_control_look->DrawButtonBackground(menu, frame, frame, base);
menu->PopState();
}
// #pragma mark - TBarMenuBar
TBarMenuBar::TBarMenuBar(BRect frame, const char* name, TBarView* barView)
:
BMenuBar(frame, name, B_FOLLOW_NONE, B_ITEMS_IN_ROW, false),
fBarView(barView),
fAppListMenuItem(NULL), fAppListMenuItem(NULL),
fSeparatorItem(NULL) fSeparatorItem(NULL)
{ {
SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f); SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f);
TDeskbarMenu* beMenu = new TDeskbarMenu(bar); TDeskbarMenu* beMenu = new TDeskbarMenu(barView);
TBarWindow::SetDeskbarMenu(beMenu); TBarWindow::SetDeskbarMenu(beMenu);
const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE, fDeskbarMenuItem = new TBarMenuTitle(0.0f, 0.0f,
R_LeafLogoBitmap); AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_LeafLogoBitmap), beMenu);
fDeskbarMenuItem = new TBarMenuTitle(frame.Width(), frame.Height(),
logoBitmap, beMenu);
AddItem(fDeskbarMenuItem); AddItem(fDeskbarMenuItem);
} }
@@ -144,7 +188,7 @@ TBarMenuBar::RemoveTeamMenu()
bool bool
TBarMenuBar::AddSeperatorItem() TBarMenuBar::AddSeparatorItem()
{ {
if (CountItems() > 1) if (CountItems() > 1)
return false; return false;
@@ -152,9 +196,7 @@ TBarMenuBar::AddSeperatorItem()
BRect frame(Frame()); BRect frame(Frame());
delete fSeparatorItem; delete fSeparatorItem;
fSeparatorItem = new TTeamMenuItem(kSepItemWidth, fSeparatorItem = new TSeparatorItem();
frame.Height() - 2, false);
fSeparatorItem->SetEnabled(false);
bool added = AddItem(fSeparatorItem); bool added = AddItem(fSeparatorItem);
@@ -189,7 +231,7 @@ TBarMenuBar::RemoveSeperatorItem()
void void
TBarMenuBar::Draw(BRect updateRect) TBarMenuBar::Draw(BRect updateRect)
{ {
// want to skip the fancy BMenuBar drawing code. // skip the fancy BMenuBar drawing code
BMenu::Draw(updateRect); BMenu::Draw(updateRect);
} }
+20 -11
View File
@@ -42,15 +42,23 @@ All rights reserved.
#include <MenuBar.h> #include <MenuBar.h>
#include <SeparatorItem.h>
#include "BarView.h"
#include "BarMenuTitle.h"
#include "TimeView.h"
class TBarMenuTitle;
class TBarView;
class TSeparatorItem : public BSeparatorItem {
public:
TSeparatorItem();
virtual void Draw();
};
class TBarMenuBar : public BMenuBar { class TBarMenuBar : public BMenuBar {
public: public:
TBarMenuBar(TBarView* bar, BRect frame, const char* name); TBarMenuBar(BRect frame, const char* name,
TBarView* barView);
virtual ~TBarMenuBar(); virtual ~TBarMenuBar();
virtual void MouseMoved(BPoint where, uint32 code, virtual void MouseMoved(BPoint where, uint32 code,
@@ -58,23 +66,24 @@ class TBarMenuBar : public BMenuBar {
virtual void Draw(BRect); virtual void Draw(BRect);
void DrawBackground(BRect); void DrawBackground(BRect);
void SmartResize(float width = -1.0f, float height = -1.0f); void SmartResize(float width = -1.0f,
float height = -1.0f);
bool AddTeamMenu(); bool AddTeamMenu();
bool RemoveTeamMenu(); bool RemoveTeamMenu();
bool AddSeperatorItem(); bool AddSeparatorItem();
bool RemoveSeperatorItem(); bool RemoveSeperatorItem();
void InitTrackingHook(bool (* hookfunction)(BMenu*, void*), void* state, void InitTrackingHook(
bool both = false); bool (* hookfunction)(BMenu*, void*),
void* state, bool both = false);
private: private:
TBarView* fBarView; TBarView* fBarView;
TBarMenuTitle* fDeskbarMenuItem; TBarMenuTitle* fDeskbarMenuItem;
TBarMenuTitle* fAppListMenuItem; TBarMenuTitle* fAppListMenuItem;
TTeamMenuItem* fSeparatorItem; TSeparatorItem* fSeparatorItem;
}; };
#endif // BARMENUBAR_H
#endif /* BARMENUBAR_H */
+24 -93
View File
@@ -82,120 +82,51 @@ TBarMenuTitle::GetContentSize(float* width, float* height)
void void
TBarMenuTitle::Draw() TBarMenuTitle::Draw()
{ {
if (be_control_look == NULL) { BMenu* menu = Menu();
BMenuItem::Draw(); if (menu == NULL)
return; return;
}
// fill background if selected BRect frame(Frame());
rgb_color base = Menu()->LowColor(); rgb_color base = menu->LowColor();
BRect rect = Frame();
BRect windowBounds = Menu()->Window()->Bounds(); menu->PushState();
if (rect.right > windowBounds.right)
rect.right = windowBounds.right;
BRect windowBounds = menu->Window()->Bounds();
if (frame.right > windowBounds.right)
frame.right = windowBounds.right;
// fill in background
if (IsSelected()) { if (IsSelected()) {
be_control_look->DrawMenuItemBackground(Menu(), rect, rect, base, be_control_look->DrawMenuItemBackground(menu, frame, frame, base,
BControlLook::B_ACTIVATED); BControlLook::B_ACTIVATED);
} else { } else
be_control_look->DrawButtonBackground(Menu(), rect, rect, base); be_control_look->DrawButtonBackground(menu, frame, frame, base);
}
// draw content menu->MovePenTo(ContentLocation());
DrawContent(); DrawContent();
// make sure we restore state menu->PopState();
Menu()->SetLowColor(base);
} }
void void
TBarMenuTitle::DrawContent() TBarMenuTitle::DrawContent()
{ {
if (fIcon == NULL)
return;
BMenu* menu = Menu(); BMenu* menu = Menu();
BRect frame(Frame()); BRect frame(Frame());
BRect iconRect(fIcon->Bounds());
if (be_control_look != NULL) {
menu->SetDrawingMode(B_OP_ALPHA);
if (fIcon != NULL) {
BRect dstRect(fIcon->Bounds());
dstRect.OffsetTo(frame.LeftTop());
dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2)
- 1.0f), rintf(((frame.Height() - dstRect.Height()) / 2)
+ 2.0f));
menu->DrawBitmapAsync(fIcon, dstRect);
}
return;
}
rgb_color menuColor = menu->LowColor();
rgb_color dark = tint_color(menuColor, B_DARKEN_1_TINT);
rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT);
bool inExpandoMode = dynamic_cast<TExpandoMenuBar*>(menu) != NULL;
BRect bounds(menu->Window()->Bounds());
if (bounds.right < frame.right)
frame.right = bounds.right;
menu->SetDrawingMode(B_OP_COPY);
if (!IsSelected() && !menu->IsRedrawAfterSticky()) {
menu->BeginLineArray(8);
menu->AddLine(frame.RightTop(), frame.LeftTop(), light);
menu->AddLine(frame.LeftBottom(), frame.RightBottom(), dark);
menu->AddLine(frame.LeftTop(),
frame.LeftBottom()+BPoint(0, inExpandoMode ? 0 : -1), light);
menu->AddLine(frame.RightBottom(), frame.RightTop(), dark);
if (inExpandoMode) {
frame.top += 1;
menu->AddLine(frame.LeftTop(), frame.RightTop() + BPoint(-1, 0),
light);
}
menu->EndLineArray();
frame.InsetBy(1, 1);
menu->SetHighColor(menuColor);
menu->FillRect(frame);
if (IsSelected())
menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
else
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
frame.InsetBy(-1, -1);
if (inExpandoMode)
frame.top -= 1;
}
ASSERT(IsEnabled());
if (IsSelected() && !menu->IsRedrawAfterSticky()) {
menu->SetHighColor(tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT));
menu->FillRect(frame);
if (menu->IndexOf(this) > 0) {
menu->SetHighColor(tint_color(menuColor, B_DARKEN_4_TINT));
menu->StrokeLine(frame.LeftTop(), frame.LeftBottom());
}
if (IsSelected())
menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
else
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
}
menu->SetDrawingMode(B_OP_ALPHA); menu->SetDrawingMode(B_OP_ALPHA);
iconRect.OffsetTo(frame.LeftTop());
if (fIcon != NULL) { float widthOffset = rintf((frame.Width() - iconRect.Width()) / 2);
BRect dstRect(fIcon->Bounds()); float heightOffset = rintf((frame.Height() - iconRect.Height()) / 2);
dstRect.OffsetTo(frame.LeftTop()); iconRect.OffsetBy(widthOffset - 1.0f, heightOffset + 2.0f);
dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2) - 1.0f),
rintf(((frame.Height() - dstRect.Height()) / 2) - 0.0f));
menu->DrawBitmapAsync(fIcon, dstRect); menu->DrawBitmapAsync(fIcon, iconRect);
}
} }
+1 -1
View File
@@ -50,7 +50,7 @@ class BMenu;
class TBarMenuTitle : public BMenuItem { class TBarMenuTitle : public BMenuItem {
public: public:
TBarMenuTitle(float width, float height, const BBitmap* icon, TBarMenuTitle(float width, float height, const BBitmap* icon,
BMenu* menu, bool inexpando = false); BMenu* menu, bool expando = false);
virtual ~TBarMenuTitle(); virtual ~TBarMenuTitle();
void SetContentSize(float width, float height); void SetContentSize(float width, float height);
+1 -1
View File
@@ -395,7 +395,7 @@ TBarView::PlaceDeskbarMenu()
width += 1; width += 1;
} else { } else {
// shows apps to the right of bemenu // shows apps to the right of bemenu
fBarMenuBar->AddSeperatorItem(); fBarMenuBar->AddSeparatorItem();
width = floorf(width) / 2 + kSepItemWidth; width = floorf(width) / 2 + kSepItemWidth;
} }
loc = Bounds().LeftTop(); loc = Bounds().LeftTop();
+1
View File
@@ -44,6 +44,7 @@ All rights reserved.
#include "BarApp.h" #include "BarApp.h"
#include "BarMenuBar.h" #include "BarMenuBar.h"
#include "BarView.h"
#include "DeskbarUtils.h" #include "DeskbarUtils.h"
#include "TeamMenuItem.h" #include "TeamMenuItem.h"
+1
View File
@@ -50,6 +50,7 @@ All rights reserved.
#include "BarApp.h" #include "BarApp.h"
#include "BarMenuBar.h" #include "BarMenuBar.h"
#include "BarView.h"
#include "ExpandoMenuBar.h" #include "ExpandoMenuBar.h"
#include "ResourceSet.h" #include "ResourceSet.h"
#include "ShowHideMenuItem.h" #include "ShowHideMenuItem.h"
+1
View File
@@ -44,6 +44,7 @@ All rights reserved.
#include "BarApp.h" #include "BarApp.h"
#include "BarMenuBar.h" #include "BarMenuBar.h"
#include "BarView.h"
#include "ExpandoMenuBar.h" #include "ExpandoMenuBar.h"
#include "icons.h" #include "icons.h"
#include "ResourceSet.h" #include "ResourceSet.h"