mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-08 08:01:19 +02:00
Event handling for the new pushbuttons, and remove the interim pop-up menu
This commit is contained in:
parent
49693fa6b6
commit
f014e0400c
@ -1774,9 +1774,6 @@ BEGIN_EVENT_TABLE(AdornedRulerPanel, wxPanel)
|
||||
EVT_MENU(OnAutoScrollID, AdornedRulerPanel::OnAutoScroll)
|
||||
EVT_MENU(OnLockPlayRegionID, AdornedRulerPanel::OnLockPlayRegion)
|
||||
|
||||
// Main menu commands
|
||||
EVT_MENU(OnShowHideScrubbingID, AdornedRulerPanel::OnShowHideScrubbing)
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
AdornedRulerPanel::AdornedRulerPanel(AudacityProject* parent,
|
||||
@ -2156,15 +2153,6 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
|
||||
: StatusChoice::NoChange
|
||||
);
|
||||
|
||||
if (overButtons && evt.Button(wxMOUSE_BTN_ANY)) {
|
||||
if(evt.ButtonDown())
|
||||
DoMainMenu();
|
||||
|
||||
if (HasCapture())
|
||||
ReleaseMouse();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle popup menus
|
||||
if (evt.RightDown() && !(evt.LeftIsDown())) {
|
||||
if(inScrubZone)
|
||||
@ -2239,18 +2227,32 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
|
||||
return;
|
||||
}
|
||||
|
||||
if (inScrubZone) {
|
||||
if (evt.LeftDown())
|
||||
if (HasCapture() && mCaptureState != Button::NoButton)
|
||||
HandlePushbuttonEvent(evt);
|
||||
else if (!HasCapture() && overButtons) {
|
||||
if (evt.LeftDown()) {
|
||||
auto position = evt.GetPosition();
|
||||
for (unsigned ii = 0; ii < static_cast<unsigned>(Button::NumButtons); ++ii) {
|
||||
auto button = static_cast<Button>(ii);
|
||||
if(GetButtonRect(button).Contains(position)) {
|
||||
CaptureMouse();
|
||||
mCaptureState = button;
|
||||
Refresh();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!HasCapture() && inScrubZone) {
|
||||
if (evt.LeftDown()) {
|
||||
scrubber.MarkScrubStart(evt.m_x, false, false);
|
||||
UpdateStatusBar(StatusChoice::EnteringScrubZone);
|
||||
}
|
||||
wxClientDC dc(this);
|
||||
DrawQuickPlayIndicator(&dc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mQuickPlayEnabled)
|
||||
return;
|
||||
|
||||
else if ( mQuickPlayEnabled) {
|
||||
bool isWithinStart = IsWithinMarker(mousePosX, mOldPlayRegionStart);
|
||||
bool isWithinEnd = IsWithinMarker(mousePosX, mOldPlayRegionEnd);
|
||||
|
||||
@ -2279,6 +2281,7 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
|
||||
mQuickPlayInd = true;
|
||||
wxClientDC dc(this);
|
||||
DrawQuickPlayIndicator(&dc);
|
||||
}
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::HandleQPClick(wxMouseEvent &evt, wxCoord mousePosX)
|
||||
@ -2419,6 +2422,8 @@ void AdornedRulerPanel::HandleQPRelease(wxMouseEvent &evt)
|
||||
if (HasCapture())
|
||||
ReleaseMouse();
|
||||
|
||||
mCaptureState = Button::NoButton;
|
||||
|
||||
if (mPlayRegionEnd < mPlayRegionStart) {
|
||||
// Swap values to ensure mPlayRegionStart < mPlayRegionEnd
|
||||
double tmp = mPlayRegionStart;
|
||||
@ -2560,22 +2565,7 @@ void AdornedRulerPanel::UpdateStatusBar(StatusChoice choice)
|
||||
mProject->TP_DisplayStatusMessage(message);
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::DoMainMenu()
|
||||
{
|
||||
wxMenu menu;
|
||||
|
||||
menu.AppendCheckItem(OnShowHideScrubbingID, _("Scrub Bar"));
|
||||
menu.Check(OnShowHideScrubbingID, mShowScrubbing);
|
||||
|
||||
// Position the popup similarly to the track control panel menus
|
||||
wxPoint pos {
|
||||
kLeftInset + kTrackInfoBtnSize + 1,
|
||||
GetSize().GetHeight() + 1
|
||||
};
|
||||
PopupMenu(&menu, pos);
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::OnShowHideScrubbing(wxCommandEvent&)
|
||||
void AdornedRulerPanel::OnToggleScrubbing()
|
||||
{
|
||||
mShowScrubbing = !mShowScrubbing;
|
||||
WriteScrubEnabledPref(mShowScrubbing);
|
||||
@ -2820,6 +2810,11 @@ wxRect AdornedRulerPanel::GetButtonRect( Button button ) const
|
||||
return rect;
|
||||
}
|
||||
|
||||
bool AdornedRulerPanel::InButtonRect( Button button ) const
|
||||
{
|
||||
return GetButtonRect(button).Contains(ScreenToClient(::wxGetMousePosition()));
|
||||
}
|
||||
|
||||
bool AdornedRulerPanel::GetButtonState( Button button ) const
|
||||
{
|
||||
switch(button) {
|
||||
@ -2833,6 +2828,22 @@ bool AdornedRulerPanel::GetButtonState( Button button ) const
|
||||
}
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::ToggleButtonState( Button button )
|
||||
{
|
||||
switch(button) {
|
||||
case Button::QuickPlay: {
|
||||
wxCommandEvent dummy;
|
||||
OnToggleQuickPlay(dummy);
|
||||
}
|
||||
break;
|
||||
case Button::ScrubBar:
|
||||
OnToggleScrubbing();
|
||||
break;
|
||||
default:
|
||||
wxASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::DoDrawPushbutton(wxDC *dc, Button button, bool down) const
|
||||
{
|
||||
// Adapted from TrackInfo::DrawMuteSolo()
|
||||
@ -2862,6 +2873,19 @@ void AdornedRulerPanel::DoDrawPushbutton(wxDC *dc, Button button, bool down) con
|
||||
AColor::BevelTrackInfo(*dc, !down, bev);
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::HandlePushbuttonEvent(wxMouseEvent &evt)
|
||||
{
|
||||
if(evt.LeftUp()) {
|
||||
if(HasCapture())
|
||||
ReleaseMouse();
|
||||
if(InButtonRect(mCaptureState))
|
||||
ToggleButtonState(mCaptureState);
|
||||
mCaptureState = Button::NoButton;
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::DoDrawPushbuttons(wxDC *dc) const
|
||||
{
|
||||
// Paint the area behind the buttons
|
||||
@ -2871,7 +2895,10 @@ void AdornedRulerPanel::DoDrawPushbuttons(wxDC *dc) const
|
||||
|
||||
for (unsigned ii = 0; ii < static_cast<unsigned>(Button::NumButtons); ++ii) {
|
||||
auto button = static_cast<Button>(ii);
|
||||
DoDrawPushbutton(dc, button, GetButtonState(button));
|
||||
auto state = GetButtonState(button);
|
||||
auto toggle = (button == mCaptureState && InButtonRect(button));
|
||||
auto down = (state != toggle);
|
||||
DoDrawPushbutton(dc, button, down);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,8 +336,6 @@ private:
|
||||
};
|
||||
void UpdateStatusBar(StatusChoice choice);
|
||||
|
||||
void DoMainMenu();
|
||||
|
||||
void OnCaptureLost(wxMouseCaptureLostEvent &evt);
|
||||
|
||||
void DoDrawBorder(wxDC * dc);
|
||||
@ -359,9 +357,12 @@ private:
|
||||
NoButton = -1
|
||||
};
|
||||
wxRect GetButtonRect( Button button ) const;
|
||||
bool InButtonRect( Button button ) const;
|
||||
bool GetButtonState( Button button ) const;
|
||||
void ToggleButtonState( Button button );
|
||||
void DoDrawPushbutton(wxDC *dc, Button button, bool down) const;
|
||||
void DoDrawPushbuttons(wxDC *dc) const;
|
||||
void HandlePushbuttonEvent(wxMouseEvent &evt);
|
||||
|
||||
double Pos2Time(int p, bool ignoreFisheye = false);
|
||||
int Time2Pos(double t, bool ignoreFisheye = false);
|
||||
@ -423,16 +424,15 @@ private:
|
||||
void OnAutoScroll(wxCommandEvent &evt);
|
||||
void OnLockPlayRegion(wxCommandEvent &evt);
|
||||
|
||||
//
|
||||
// Main menu
|
||||
//
|
||||
void OnShowHideScrubbing(wxCommandEvent &evt);
|
||||
void OnToggleScrubbing();
|
||||
|
||||
bool mPlayRegionDragsSelection;
|
||||
bool mTimelineToolTip;
|
||||
bool mQuickPlayEnabled;
|
||||
|
||||
|
||||
Button mCaptureState { Button::NoButton };
|
||||
|
||||
enum MouseEventState {
|
||||
mesNone,
|
||||
mesDraggingPlayRegionStart,
|
||||
|
Loading…
x
Reference in New Issue
Block a user