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