Don't call DrawExpanderArrow() directly, set a variable and Invalidate()

This commit is contained in:
John Scipione
2013-04-07 14:46:23 -04:00
parent 3d1492487d
commit 1dccb7aaaf
3 changed files with 67 additions and 96 deletions
+10 -9
View File
@@ -335,7 +335,8 @@ TExpandoMenuBar::MouseDown(BPoint where)
// start the animation here, finish on mouse up // start the animation here, finish on mouse up
fLastClickedItem = item; fLastClickedItem = item;
fClickedExpander = true; fClickedExpander = true;
item->DrawExpanderArrow(BControlLook::B_RIGHT_DOWN_ARROW); item->SetArrowDirection(BControlLook::B_RIGHT_DOWN_ARROW);
Invalidate(item->ExpanderBounds());
return; return;
// absorb the message // absorb the message
} }
@@ -378,8 +379,8 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
&& lastItem != NULL && buttons == B_PRIMARY_MOUSE_BUTTON) { && lastItem != NULL && buttons == B_PRIMARY_MOUSE_BUTTON) {
// Started expander animation, exited view then entered // Started expander animation, exited view then entered
// again, redraw the expanded arrow // again, redraw the expanded arrow
int32 arrowDirection = BControlLook::B_RIGHT_DOWN_ARROW; lastItem->SetArrowDirection(BControlLook::B_RIGHT_DOWN_ARROW);
lastItem->DrawExpanderArrow(arrowDirection); Invalidate(lastItem->ExpanderBounds());
} }
break; break;
} }
@@ -444,10 +445,10 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
// Started expander animation, then exited view, // Started expander animation, then exited view,
// since we can't track outside mouse movements // since we can't track outside mouse movements
// redraw the original expander arrow // redraw the original expander arrow
int32 arrowDirection = lastItem->IsExpanded() lastItem->SetArrowDirection(lastItem->IsExpanded()
? BControlLook::B_DOWN_ARROW ? BControlLook::B_DOWN_ARROW
: BControlLook::B_RIGHT_ARROW; : BControlLook::B_RIGHT_ARROW);
lastItem->DrawExpanderArrow(arrowDirection); Invalidate(lastItem->ExpanderBounds());
} }
break; break;
} }
@@ -527,9 +528,9 @@ TExpandoMenuBar::MouseUp(BPoint where)
// absorb the message // absorb the message
} else if (lastItem != NULL) { } else if (lastItem != NULL) {
// User changed their mind, redraw the original expander arrow // User changed their mind, redraw the original expander arrow
int32 arrowDirection = lastItem->IsExpanded() lastItem->SetArrowDirection(lastItem->IsExpanded()
? BControlLook::B_DOWN_ARROW : BControlLook::B_RIGHT_ARROW; ? BControlLook::B_DOWN_ARROW : BControlLook::B_RIGHT_ARROW);
lastItem->DrawExpanderArrow(arrowDirection); Invalidate(lastItem->ExpanderBounds());
} }
} }
+33 -69
View File
@@ -92,16 +92,16 @@ TTeamMenuItem::~TTeamMenuItem()
status_t status_t
TTeamMenuItem::Invoke(BMessage* message) TTeamMenuItem::Invoke(BMessage* message)
{ {
if ((static_cast<TBarApp*>(be_app))->BarView()->InvokeItem(Signature())) if (fBarView->InvokeItem(Signature())) {
// handles drop on application // handles drop on application
return B_OK; return B_OK;
}
// if the app could not handle the drag message // if the app could not handle the drag message
// and we were dragging, then kill the drag // and we were dragging, then kill the drag
// should never get here, disabled item will not invoke // should never get here, disabled item will not invoke
TBarView* barView = (static_cast<TBarApp*>(be_app))->BarView(); if (fBarView != NULL && fBarView->Dragging())
if (barView && barView->Dragging()) fBarView->DragStop();
barView->DragStop();
// bring to front or minimize shortcuts // bring to front or minimize shortcuts
uint32 mods = modifiers(); uint32 mods = modifiers();
@@ -136,10 +136,10 @@ TTeamMenuItem::SetOverrideSelected(bool selected)
} }
bool void
TTeamMenuItem::HasLabel() const TTeamMenuItem::SetArrowDirection(int32 direction)
{ {
return fDrawLabel; fArrowDirection = direction;
} }
@@ -150,34 +150,6 @@ TTeamMenuItem::SetHasLabel(bool drawLabel)
} }
float
TTeamMenuItem::LabelWidth() const
{
return fLabelWidth;
}
BList*
TTeamMenuItem::Teams() const
{
return fTeam;
}
const char*
TTeamMenuItem::Signature() const
{
return fSig;
}
const char*
TTeamMenuItem::Name() const
{
return fName;
}
void void
TTeamMenuItem::GetContentSize(float* width, float* height) TTeamMenuItem::GetContentSize(float* width, float* height)
{ {
@@ -221,9 +193,8 @@ TTeamMenuItem::Draw()
menu->PushState(); menu->PushState();
rgb_color menuColor = menu->LowColor(); rgb_color menuColor = menu->LowColor();
TBarView* barView = (static_cast<TBarApp*>(be_app))->BarView(); bool canHandle = !fBarView->Dragging()
bool canHandle = !barView->Dragging() || fBarView->AppCanHandleTypes(Signature());
|| barView->AppCanHandleTypes(Signature());
uint32 flags = 0; uint32 flags = 0;
if (_IsSelected() && canHandle) if (_IsSelected() && canHandle)
flags |= BControlLook::B_ACTIVATED; flags |= BControlLook::B_ACTIVATED;
@@ -311,9 +282,10 @@ TTeamMenuItem::DrawContent()
DrawContentLabel(); DrawContentLabel();
} }
int32 arrowDirection = fExpanded ? BControlLook::B_DOWN_ARROW if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando
: BControlLook::B_RIGHT_ARROW; && fBarView->ExpandoState()) {
DrawExpanderArrow(arrowDirection); DrawExpanderArrow();
}
} }
@@ -352,9 +324,8 @@ TTeamMenuItem::DrawContentLabel()
if (!label) if (!label)
label = Label(); label = Label();
TBarView* barview = (static_cast<TBarApp*>(be_app))->BarView(); bool canHandle = !fBarView->Dragging()
bool canHandle = !barview->Dragging() || fBarView->AppCanHandleTypes(Signature());
|| barview->AppCanHandleTypes(Signature());
if (_IsSelected() && IsEnabled() && canHandle) if (_IsSelected() && IsEnabled() && canHandle)
menu->SetLowColor(tint_color(menu->LowColor(), menu->SetLowColor(tint_color(menu->LowColor(),
B_HIGHLIGHT_BACKGROUND_TINT)); B_HIGHLIGHT_BACKGROUND_TINT));
@@ -373,37 +344,28 @@ TTeamMenuItem::DrawContentLabel()
void void
TTeamMenuItem::DrawExpanderArrow(int32 arrowDirection) TTeamMenuItem::DrawExpanderArrow()
{ {
TBarView* barView = (static_cast<TBarApp*>(be_app))->BarView();
bool canHandle = !barView->Dragging()
|| barView->AppCanHandleTypes(Signature());
uint32 flags = 0;
if (_IsSelected() && canHandle)
flags |= BControlLook::B_ACTIVATED;
if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando
&& barView->ExpandoState()) {
BMenu* menu = Menu(); BMenu* menu = Menu();
BRect frame(Frame()); BRect frame(Frame());
BRect rect(0, 0, kSwitchWidth, 10); BRect rect(0, 0, kSwitchWidth, 10);
rect.OffsetTo(BPoint(frame.right - rect.Width(), rect.OffsetTo(BPoint(frame.right - rect.Width(),
ContentLocation().y + ((frame.Height() - rect.Height()) / 2))); ContentLocation().y + ((frame.Height() - rect.Height()) / 2)));
#if 0
bool canHandle = !fBarView->Dragging()
|| fBarView->AppCanHandleTypes(Signature());
uint32 flags = 0;
if (_IsSelected() && canHandle)
flags |= BControlLook::B_ACTIVATED;
if (flags == 0) { if (flags == 0) {
menu->SetHighColor(menu->LowColor()); menu->SetHighColor(menu->LowColor());
menu->FillRect(rect); menu->FillRect(rect);
} }
#endif
be_control_look->DrawArrowShape(menu, rect, rect, menu->LowColor(), be_control_look->DrawArrowShape(menu, rect, rect, menu->LowColor(),
arrowDirection, 0, B_DARKEN_3_TINT); fArrowDirection, 0, B_DARKEN_3_TINT);
}
}
bool
TTeamMenuItem::IsExpanded()
{
return fExpanded;
} }
@@ -411,6 +373,8 @@ void
TTeamMenuItem::ToggleExpandState(bool resizeWindow) TTeamMenuItem::ToggleExpandState(bool resizeWindow)
{ {
fExpanded = !fExpanded; fExpanded = !fExpanded;
fArrowDirection = fExpanded ? BControlLook::B_DOWN_ARROW
: BControlLook::B_RIGHT_ARROW;
if (fExpanded) { if (fExpanded) {
// Populate Menu() with the stuff from SubMenu(). // Populate Menu() with the stuff from SubMenu().
@@ -516,9 +480,13 @@ TTeamMenuItem::_InitData(BList* team, BBitmap* icon, char* name, char* sig,
snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0)); snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0));
fName = strdup(temp); fName = strdup(temp);
} }
SetLabel(fName); SetLabel(fName);
fOverrideWidth = width;
fOverrideHeight = height;
fDrawLabel = drawLabel;
fVertical = vertical;
fBarView = static_cast<TBarApp*>(be_app)->BarView();
BFont font(be_plain_font); BFont font(be_plain_font);
fLabelWidth = ceilf(font.StringWidth(fName)); fLabelWidth = ceilf(font.StringWidth(fName));
font_height fontHeight; font_height fontHeight;
@@ -526,14 +494,10 @@ TTeamMenuItem::_InitData(BList* team, BBitmap* icon, char* name, char* sig,
fLabelAscent = ceilf(fontHeight.ascent); fLabelAscent = ceilf(fontHeight.ascent);
fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading); fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading);
fOverrideWidth = width;
fOverrideHeight = height;
fOverriddenSelected = false; fOverriddenSelected = false;
fVertical = vertical;
fDrawLabel = drawLabel;
fExpanded = false; fExpanded = false;
fArrowDirection = BControlLook::B_RIGHT_ARROW;
} }
+18 -12
View File
@@ -67,25 +67,28 @@ public:
void SetOverrideHeight(float height); void SetOverrideHeight(float height);
void SetOverrideSelected(bool selected); void SetOverrideSelected(bool selected);
bool HasLabel() const; int32 ArrowDirection() const { return fArrowDirection; };
void SetArrowDirection(int32 direction);
bool HasLabel() const { return fDrawLabel; };
void SetHasLabel(bool drawLabel); void SetHasLabel(bool drawLabel);
bool IsExpanded(); bool IsExpanded() const { return fExpanded; };
void ToggleExpandState(bool resizeWindow); void ToggleExpandState(bool resizeWindow);
BRect ExpanderBounds() const; BRect ExpanderBounds() const;
TWindowMenuItem* ExpandedWindowItem(int32 id); TWindowMenuItem* ExpandedWindowItem(int32 id);
float LabelWidth() const; float LabelWidth() const { return fLabelWidth; };
BList* Teams() const; BList* Teams() const { return fTeam; };
const char* Signature() const; const char* Signature() const { return fSig; };
const char* Name() const; const char* Name() const { return fName; };
protected: protected:
void GetContentSize(float* width, float* height); void GetContentSize(float* width, float* height);
void Draw(); void Draw();
void DrawContent(); void DrawContent();
void DrawContentLabel(); void DrawContentLabel();
void DrawExpanderArrow(int32 arrowDirection); void DrawExpanderArrow();
private: private:
friend class TExpandoMenuBar; friend class TExpandoMenuBar;
@@ -102,17 +105,20 @@ private:
BBitmap* fIcon; BBitmap* fIcon;
char* fName; char* fName;
char* fSig; char* fSig;
float fLabelWidth;
float fLabelAscent;
float fLabelDescent;
float fOverrideWidth; float fOverrideWidth;
float fOverrideHeight; float fOverrideHeight;
bool fDrawLabel; bool fDrawLabel;
bool fVertical; bool fVertical;
bool fExpanded; TBarView* fBarView;
float fLabelWidth;
float fLabelAscent;
float fLabelDescent;
bool fOverriddenSelected; bool fOverriddenSelected;
bool fExpanded;
int32 fArrowDirection;
}; };