1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 16:40:07 +02:00

Merge branch 'master' into overlays

This commit is contained in:
Paul Licameli 2016-05-12 16:44:41 -04:00
commit 7584decfa0
2 changed files with 88 additions and 59 deletions

View File

@ -2339,13 +2339,30 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
return; return;
} }
const bool overButtons = GetButtonAreaRect(true).Contains(evt.GetPosition()); const auto position = evt.GetPosition();
auto button = FindButton(evt).button; const bool overButtons = GetButtonAreaRect(true).Contains(position);
StatusChoice button;
{
auto mouseState = FindButton(evt);
button = mouseState.button;
if (IsButton(button)) {
TabState newState{ button, mouseState.state == PointerState::InArrow };
if (mTabState != newState) {
// Change the button highlight
mTabState = newState;
Refresh(false);
}
}
else if(evt.Leaving() && !HasFocus())
// erase the button highlight
Refresh(false);
}
const bool inScrubZone = !overButtons && const bool inScrubZone = !overButtons &&
// only if scrubbing is allowed now // only if scrubbing is allowed now
mProject->GetScrubber().CanScrub() && mProject->GetScrubber().CanScrub() &&
mShowScrubbing && mShowScrubbing &&
mScrubZone.Contains(evt.GetPosition()); mScrubZone.Contains(position);
const StatusChoice zone = const StatusChoice zone =
evt.Leaving() evt.Leaving()
? StatusChoice::Leaving ? StatusChoice::Leaving
@ -2353,7 +2370,7 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
? button ? button
: inScrubZone : inScrubZone
? StatusChoice::EnteringScrubZone ? StatusChoice::EnteringScrubZone
: mInner.Contains(evt.GetPosition()) : mInner.Contains(position)
? StatusChoice::EnteringQP ? StatusChoice::EnteringQP
: StatusChoice::NoChange; : StatusChoice::NoChange;
const bool changeInZone = (zone != mPrevZone); const bool changeInZone = (zone != mPrevZone);
@ -2457,16 +2474,9 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
HandlePushbuttonClick(evt); HandlePushbuttonClick(evt);
// Handle popup menus // Handle popup menus
else if (!HasCapture() && evt.RightDown() && !(evt.LeftIsDown())) { else if (!HasCapture() && evt.RightDown() && !(evt.LeftIsDown())) {
if(inScrubZone) ShowButtonMenu
ShowScrubMenu(evt.GetPosition()); (inScrubZone ? StatusChoice::ScrubBarButton : StatusChoice::QuickPlayButton,
else &position);
ShowMenu(evt.GetPosition());
// dismiss and clear Quick-Play indicator
HideQuickPlayIndicator();
if (HasCapture())
ReleaseMouse();
return; return;
} }
else if (!HasCapture() && inScrubZone) { else if (!HasCapture() && inScrubZone) {
@ -3250,8 +3260,11 @@ void AdornedRulerPanel::ToggleButtonState( StatusChoice button )
UpdateStatusBarAndTooltips(mCaptureState.button); UpdateStatusBarAndTooltips(mCaptureState.button);
} }
void AdornedRulerPanel::ShowButtonMenu( StatusChoice button, wxPoint *pPosition) void AdornedRulerPanel::ShowButtonMenu( StatusChoice button, const wxPoint *pPosition)
{ {
if (!IsButton(button))
return;
wxPoint position; wxPoint position;
if(pPosition) if(pPosition)
position = *pPosition; position = *pPosition;
@ -3261,6 +3274,13 @@ void AdornedRulerPanel::ShowButtonMenu( StatusChoice button, wxPoint *pPosition)
position = { rect.GetLeft() + 1, rect.GetBottom() + 1 }; position = { rect.GetLeft() + 1, rect.GetBottom() + 1 };
} }
// Be sure the arrow button appears pressed
mTabState = { button, true };
mShowingMenu = true;
Refresh();
// Do the rest after Refresh() takes effect
CallAfter([=]{
switch (button) { switch (button) {
case StatusChoice::QuickPlayButton: case StatusChoice::QuickPlayButton:
ShowMenu(position); break; ShowMenu(position); break;
@ -3272,6 +3292,13 @@ void AdornedRulerPanel::ShowButtonMenu( StatusChoice button, wxPoint *pPosition)
// dismiss and clear Quick-Play indicator // dismiss and clear Quick-Play indicator
HideQuickPlayIndicator(); HideQuickPlayIndicator();
if (HasCapture())
ReleaseMouse();
mShowingMenu = false;
Refresh();
});
} }
const AdornedRulerPanel::ButtonStrings AdornedRulerPanel::PushbuttonLabels const AdornedRulerPanel::ButtonStrings AdornedRulerPanel::PushbuttonLabels
@ -3310,8 +3337,7 @@ namespace {
} }
void AdornedRulerPanel::DoDrawPushbutton void AdornedRulerPanel::DoDrawPushbutton
(wxDC *dc, StatusChoice button, PointerState down, PointerState pointerState, (wxDC *dc, StatusChoice button, bool buttonState, bool arrowState) const
bool inSomeButton) const
{ {
// Adapted from TrackInfo::DrawMuteSolo() // Adapted from TrackInfo::DrawMuteSolo()
ADCChanger changer(dc); ADCChanger changer(dc);
@ -3325,21 +3351,20 @@ void AdornedRulerPanel::DoDrawPushbutton
// Draw borders, bevels, and backgrounds of the split sections // Draw borders, bevels, and backgrounds of the split sections
const bool tabHighlight = const bool tabHighlight =
!inSomeButton &&
mTabState.mButton == button && mTabState.mButton == button &&
HasFocus(); (HasFocus() || rect.Contains( ScreenToClient(::wxGetMousePosition()) ));
if (tabHighlight)
arrowState = arrowState || mShowingMenu;
if (pointerState == PointerState::InArrow || (tabHighlight && mTabState.mMenu)) { if (tabHighlight && mTabState.mMenu) {
// Draw highlighted arrow after // Draw highlighted arrow after
DrawButtonBackground(dc, textRect, (down == PointerState::In), false); DrawButtonBackground(dc, textRect, buttonState, false);
DrawButtonBackground(dc, arrowRect, (down == PointerState::InArrow), true); DrawButtonBackground(dc, arrowRect, arrowState, true);
} }
else { else {
// Draw maybe highlighted text after // Draw maybe highlighted text after
DrawButtonBackground(dc, arrowRect, (down == PointerState::InArrow), false); DrawButtonBackground(dc, arrowRect, arrowState, false);
DrawButtonBackground( DrawButtonBackground(dc, textRect, buttonState, (tabHighlight && !mTabState.mMenu));
dc, textRect, (down == PointerState::In),
(pointerState == PointerState::In || (tabHighlight && !mTabState.mMenu)));
} }
// Draw the menu triangle // Draw the menu triangle
@ -3375,7 +3400,7 @@ void AdornedRulerPanel::DoDrawPushbutton
dc->GetTextExtent(str, &textWidth, &textHeight); dc->GetTextExtent(str, &textWidth, &textHeight);
auto xx = textBev.x + (textBev.width - textWidth) / 2; auto xx = textBev.x + (textBev.width - textWidth) / 2;
auto yy = textBev.y + (textBev.height - textHeight) / 2; auto yy = textBev.y + (textBev.height - textHeight) / 2;
if (down == PointerState::In) if (buttonState)
// Shift the text a bit for "down" appearance // Shift the text a bit for "down" appearance
++xx, ++yy; ++xx, ++yy;
dc->DrawText(str, xx, yy); dc->DrawText(str, xx, yy);
@ -3429,28 +3454,23 @@ void AdornedRulerPanel::DoDrawPushbuttons(wxDC *dc) const
AColor::MediumTrackInfo(dc, false); AColor::MediumTrackInfo(dc, false);
dc->DrawRectangle(background); dc->DrawRectangle(background);
bool inSomeButton = false;
for (auto button = StatusChoice::FirstButton; !inSomeButton && IsButton(button); ++button) {
inSomeButton = InButtonRect(button, nullptr) != PointerState::Out;
}
for (auto button = StatusChoice::FirstButton; IsButton(button); ++button) { for (auto button = StatusChoice::FirstButton; IsButton(button); ++button) {
bool state = GetButtonState(button); bool buttonState = GetButtonState(button);
bool arrowState = false;
if (button == mCaptureState.button) {
auto in = InButtonRect(button, nullptr); auto in = InButtonRect(button, nullptr);
auto down = PointerState::Out; if (in == mCaptureState.state) {
if (button == mCaptureState.button && in == mCaptureState.state) {
if (in == PointerState::In) { if (in == PointerState::In) {
// Toggle button's apparent state for mouseover // Toggle button's apparent state for mouseover
down = state ? PointerState::Out : in; buttonState = !buttonState;
} }
else if (in == PointerState::InArrow) { else if (in == PointerState::InArrow) {
// Menu arrow is not sticky // Menu arrow is not sticky
down = in; arrowState = true;
} }
} }
else if (state) }
down = PointerState::In; DoDrawPushbutton(dc, button, buttonState, arrowState);
DoDrawPushbutton(dc, button, down, in, inSomeButton);
} }
} }

View File

@ -410,9 +410,9 @@ private:
CaptureState FindButton( wxMouseEvent &mouseEvent ) const; CaptureState FindButton( wxMouseEvent &mouseEvent ) const;
bool GetButtonState( StatusChoice button ) const; bool GetButtonState( StatusChoice button ) const;
void ToggleButtonState( StatusChoice button ); void ToggleButtonState( StatusChoice button );
void ShowButtonMenu( StatusChoice button, wxPoint *pPosition); void ShowButtonMenu( StatusChoice button, const wxPoint *pPosition);
void DoDrawPushbutton(wxDC *dc, StatusChoice button, PointerState down, void DoDrawPushbutton
PointerState pointerState, bool inSomeButton) const; (wxDC *dc, StatusChoice button, bool buttonState, bool arrowState) const;
void DoDrawPushbuttons(wxDC *dc) const; void DoDrawPushbuttons(wxDC *dc) const;
void HandlePushbuttonClick(wxMouseEvent &evt); void HandlePushbuttonClick(wxMouseEvent &evt);
void HandlePushbuttonEvent(wxMouseEvent &evt); void HandlePushbuttonEvent(wxMouseEvent &evt);
@ -505,6 +505,14 @@ private:
StatusChoice mButton { StatusChoice::FirstButton }; StatusChoice mButton { StatusChoice::FirstButton };
bool mMenu { false }; bool mMenu { false };
TabState() {}
TabState(StatusChoice button, bool menu)
: mButton{ button }, mMenu{ menu } {}
bool operator == (const TabState &rhs) const
{ return mButton == rhs.mButton && mMenu == rhs.mMenu; }
bool operator != (const TabState &rhs) const { return !(*this == rhs); }
TabState &operator ++ () { TabState &operator ++ () {
if (!mMenu) if (!mMenu)
mMenu = true; mMenu = true;
@ -535,6 +543,7 @@ private:
mutable wxFont mButtonFont; mutable wxFont mButtonFont;
bool mDoubleClick {}; bool mDoubleClick {};
bool mShowingMenu {};
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()