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 <Bitmap.h>
#include <ControlLook.h>
#include <Debug.h>
#include <NodeInfo.h>
#include "icons.h"
#include "BarMenuTitle.h"
#include "BarView.h"
#include "BarWindow.h"
#include "DeskbarMenu.h"
#include "DeskbarUtils.h"
@@ -51,21 +54,62 @@ All rights reserved.
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),
fBarView(bar),
// #pragma mark - TSeparatorItem
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),
fSeparatorItem(NULL)
{
SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f);
TDeskbarMenu* beMenu = new TDeskbarMenu(bar);
TDeskbarMenu* beMenu = new TDeskbarMenu(barView);
TBarWindow::SetDeskbarMenu(beMenu);
const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE,
R_LeafLogoBitmap);
fDeskbarMenuItem = new TBarMenuTitle(frame.Width(), frame.Height(),
logoBitmap, beMenu);
fDeskbarMenuItem = new TBarMenuTitle(0.0f, 0.0f,
AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_LeafLogoBitmap), beMenu);
AddItem(fDeskbarMenuItem);
}
@@ -144,7 +188,7 @@ TBarMenuBar::RemoveTeamMenu()
bool
TBarMenuBar::AddSeperatorItem()
TBarMenuBar::AddSeparatorItem()
{
if (CountItems() > 1)
return false;
@@ -152,9 +196,7 @@ TBarMenuBar::AddSeperatorItem()
BRect frame(Frame());
delete fSeparatorItem;
fSeparatorItem = new TTeamMenuItem(kSepItemWidth,
frame.Height() - 2, false);
fSeparatorItem->SetEnabled(false);
fSeparatorItem = new TSeparatorItem();
bool added = AddItem(fSeparatorItem);
@@ -189,7 +231,7 @@ TBarMenuBar::RemoveSeperatorItem()
void
TBarMenuBar::Draw(BRect updateRect)
{
// want to skip the fancy BMenuBar drawing code.
// skip the fancy BMenuBar drawing code
BMenu::Draw(updateRect);
}
+38 -29
View File
@@ -42,39 +42,48 @@ All rights reserved.
#include <MenuBar.h>
#include "BarView.h"
#include "BarMenuTitle.h"
#include "TimeView.h"
#include <SeparatorItem.h>
class TBarMenuBar : public BMenuBar {
public:
TBarMenuBar(TBarView* bar, BRect frame, const char* name);
virtual ~TBarMenuBar();
class TBarMenuTitle;
class TBarView;
virtual void MouseMoved(BPoint where, uint32 code,
const BMessage* message);
virtual void Draw(BRect);
class TSeparatorItem : public BSeparatorItem {
public:
TSeparatorItem();
void DrawBackground(BRect);
void SmartResize(float width = -1.0f, float height = -1.0f);
bool AddTeamMenu();
bool RemoveTeamMenu();
bool AddSeperatorItem();
bool RemoveSeperatorItem();
void InitTrackingHook(bool (* hookfunction)(BMenu*, void*), void* state,
bool both = false);
private:
TBarView* fBarView;
TBarMenuTitle* fDeskbarMenuItem;
TBarMenuTitle* fAppListMenuItem;
TTeamMenuItem* fSeparatorItem;
virtual void Draw();
};
class TBarMenuBar : public BMenuBar {
public:
TBarMenuBar(BRect frame, const char* name,
TBarView* barView);
virtual ~TBarMenuBar();
#endif /* BARMENUBAR_H */
virtual void MouseMoved(BPoint where, uint32 code,
const BMessage* message);
virtual void Draw(BRect);
void DrawBackground(BRect);
void SmartResize(float width = -1.0f,
float height = -1.0f);
bool AddTeamMenu();
bool RemoveTeamMenu();
bool AddSeparatorItem();
bool RemoveSeperatorItem();
void InitTrackingHook(
bool (* hookfunction)(BMenu*, void*),
void* state, bool both = false);
private:
TBarView* fBarView;
TBarMenuTitle* fDeskbarMenuItem;
TBarMenuTitle* fAppListMenuItem;
TSeparatorItem* fSeparatorItem;
};
#endif // BARMENUBAR_H
+24 -93
View File
@@ -82,120 +82,51 @@ TBarMenuTitle::GetContentSize(float* width, float* height)
void
TBarMenuTitle::Draw()
{
if (be_control_look == NULL) {
BMenuItem::Draw();
BMenu* menu = Menu();
if (menu == NULL)
return;
}
// fill background if selected
rgb_color base = Menu()->LowColor();
BRect rect = Frame();
BRect frame(Frame());
rgb_color base = menu->LowColor();
BRect windowBounds = Menu()->Window()->Bounds();
if (rect.right > windowBounds.right)
rect.right = windowBounds.right;
menu->PushState();
BRect windowBounds = menu->Window()->Bounds();
if (frame.right > windowBounds.right)
frame.right = windowBounds.right;
// fill in background
if (IsSelected()) {
be_control_look->DrawMenuItemBackground(Menu(), rect, rect, base,
be_control_look->DrawMenuItemBackground(menu, frame, frame, base,
BControlLook::B_ACTIVATED);
} else {
be_control_look->DrawButtonBackground(Menu(), rect, rect, base);
}
} else
be_control_look->DrawButtonBackground(menu, frame, frame, base);
// draw content
menu->MovePenTo(ContentLocation());
DrawContent();
// make sure we restore state
Menu()->SetLowColor(base);
menu->PopState();
}
void
TBarMenuTitle::DrawContent()
{
if (fIcon == NULL)
return;
BMenu* menu = Menu();
BRect frame(Frame());
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));
}
BRect iconRect(fIcon->Bounds());
menu->SetDrawingMode(B_OP_ALPHA);
iconRect.OffsetTo(frame.LeftTop());
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) - 0.0f));
float widthOffset = rintf((frame.Width() - iconRect.Width()) / 2);
float heightOffset = rintf((frame.Height() - iconRect.Height()) / 2);
iconRect.OffsetBy(widthOffset - 1.0f, heightOffset + 2.0f);
menu->DrawBitmapAsync(fIcon, dstRect);
}
menu->DrawBitmapAsync(fIcon, iconRect);
}
+1 -1
View File
@@ -50,7 +50,7 @@ class BMenu;
class TBarMenuTitle : public BMenuItem {
public:
TBarMenuTitle(float width, float height, const BBitmap* icon,
BMenu* menu, bool inexpando = false);
BMenu* menu, bool expando = false);
virtual ~TBarMenuTitle();
void SetContentSize(float width, float height);
+1 -1
View File
@@ -395,7 +395,7 @@ TBarView::PlaceDeskbarMenu()
width += 1;
} else {
// shows apps to the right of bemenu
fBarMenuBar->AddSeperatorItem();
fBarMenuBar->AddSeparatorItem();
width = floorf(width) / 2 + kSepItemWidth;
}
loc = Bounds().LeftTop();
+1
View File
@@ -44,6 +44,7 @@ All rights reserved.
#include "BarApp.h"
#include "BarMenuBar.h"
#include "BarView.h"
#include "DeskbarUtils.h"
#include "TeamMenuItem.h"
+1
View File
@@ -50,6 +50,7 @@ All rights reserved.
#include "BarApp.h"
#include "BarMenuBar.h"
#include "BarView.h"
#include "ExpandoMenuBar.h"
#include "ResourceSet.h"
#include "ShowHideMenuItem.h"
+1
View File
@@ -44,6 +44,7 @@ All rights reserved.
#include "BarApp.h"
#include "BarMenuBar.h"
#include "BarView.h"
#include "ExpandoMenuBar.h"
#include "icons.h"
#include "ResourceSet.h"