mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-08 16:11:14 +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(OnAutoScrollID, AdornedRulerPanel::OnAutoScroll)
|
||||||
EVT_MENU(OnLockPlayRegionID, AdornedRulerPanel::OnLockPlayRegion)
|
EVT_MENU(OnLockPlayRegionID, AdornedRulerPanel::OnLockPlayRegion)
|
||||||
|
|
||||||
// Main menu commands
|
|
||||||
EVT_MENU(OnShowHideScrubbingID, AdornedRulerPanel::OnShowHideScrubbing)
|
|
||||||
|
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
AdornedRulerPanel::AdornedRulerPanel(AudacityProject* parent,
|
AdornedRulerPanel::AdornedRulerPanel(AudacityProject* parent,
|
||||||
@ -2156,15 +2153,6 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
|
|||||||
: StatusChoice::NoChange
|
: StatusChoice::NoChange
|
||||||
);
|
);
|
||||||
|
|
||||||
if (overButtons && evt.Button(wxMOUSE_BTN_ANY)) {
|
|
||||||
if(evt.ButtonDown())
|
|
||||||
DoMainMenu();
|
|
||||||
|
|
||||||
if (HasCapture())
|
|
||||||
ReleaseMouse();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle popup menus
|
// Handle popup menus
|
||||||
if (evt.RightDown() && !(evt.LeftIsDown())) {
|
if (evt.RightDown() && !(evt.LeftIsDown())) {
|
||||||
if(inScrubZone)
|
if(inScrubZone)
|
||||||
@ -2239,46 +2227,61 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inScrubZone) {
|
if (HasCapture() && mCaptureState != Button::NoButton)
|
||||||
if (evt.LeftDown())
|
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);
|
scrubber.MarkScrubStart(evt.m_x, false, false);
|
||||||
UpdateStatusBar(StatusChoice::EnteringScrubZone);
|
UpdateStatusBar(StatusChoice::EnteringScrubZone);
|
||||||
|
}
|
||||||
wxClientDC dc(this);
|
wxClientDC dc(this);
|
||||||
DrawQuickPlayIndicator(&dc);
|
DrawQuickPlayIndicator(&dc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if ( mQuickPlayEnabled) {
|
||||||
|
bool isWithinStart = IsWithinMarker(mousePosX, mOldPlayRegionStart);
|
||||||
|
bool isWithinEnd = IsWithinMarker(mousePosX, mOldPlayRegionEnd);
|
||||||
|
|
||||||
if (!mQuickPlayEnabled)
|
if (isWithinStart || isWithinEnd) {
|
||||||
return;
|
if (!mIsWE) {
|
||||||
|
SetCursor(mCursorSizeWE);
|
||||||
bool isWithinStart = IsWithinMarker(mousePosX, mOldPlayRegionStart);
|
mIsWE = true;
|
||||||
bool isWithinEnd = IsWithinMarker(mousePosX, mOldPlayRegionEnd);
|
}
|
||||||
|
|
||||||
if (isWithinStart || isWithinEnd) {
|
|
||||||
if (!mIsWE) {
|
|
||||||
SetCursor(mCursorSizeWE);
|
|
||||||
mIsWE = true;
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else {
|
if (mIsWE) {
|
||||||
if (mIsWE) {
|
SetCursor(mCursorHand);
|
||||||
SetCursor(mCursorHand);
|
mIsWE = false;
|
||||||
mIsWE = false;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.LeftDown()) {
|
if (evt.LeftDown()) {
|
||||||
HandleQPClick(evt, mousePosX);
|
HandleQPClick(evt, mousePosX);
|
||||||
HandleQPDrag(evt, mousePosX);
|
HandleQPDrag(evt, mousePosX);
|
||||||
}
|
}
|
||||||
else if (evt.LeftIsDown())
|
else if (evt.LeftIsDown())
|
||||||
HandleQPDrag(evt, mousePosX);
|
HandleQPDrag(evt, mousePosX);
|
||||||
else if (evt.LeftUp())
|
else if (evt.LeftUp())
|
||||||
HandleQPRelease(evt);
|
HandleQPRelease(evt);
|
||||||
|
|
||||||
mQuickPlayInd = true;
|
mQuickPlayInd = true;
|
||||||
wxClientDC dc(this);
|
wxClientDC dc(this);
|
||||||
DrawQuickPlayIndicator(&dc);
|
DrawQuickPlayIndicator(&dc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdornedRulerPanel::HandleQPClick(wxMouseEvent &evt, wxCoord mousePosX)
|
void AdornedRulerPanel::HandleQPClick(wxMouseEvent &evt, wxCoord mousePosX)
|
||||||
@ -2419,6 +2422,8 @@ void AdornedRulerPanel::HandleQPRelease(wxMouseEvent &evt)
|
|||||||
if (HasCapture())
|
if (HasCapture())
|
||||||
ReleaseMouse();
|
ReleaseMouse();
|
||||||
|
|
||||||
|
mCaptureState = Button::NoButton;
|
||||||
|
|
||||||
if (mPlayRegionEnd < mPlayRegionStart) {
|
if (mPlayRegionEnd < mPlayRegionStart) {
|
||||||
// Swap values to ensure mPlayRegionStart < mPlayRegionEnd
|
// Swap values to ensure mPlayRegionStart < mPlayRegionEnd
|
||||||
double tmp = mPlayRegionStart;
|
double tmp = mPlayRegionStart;
|
||||||
@ -2560,22 +2565,7 @@ void AdornedRulerPanel::UpdateStatusBar(StatusChoice choice)
|
|||||||
mProject->TP_DisplayStatusMessage(message);
|
mProject->TP_DisplayStatusMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdornedRulerPanel::DoMainMenu()
|
void AdornedRulerPanel::OnToggleScrubbing()
|
||||||
{
|
|
||||||
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&)
|
|
||||||
{
|
{
|
||||||
mShowScrubbing = !mShowScrubbing;
|
mShowScrubbing = !mShowScrubbing;
|
||||||
WriteScrubEnabledPref(mShowScrubbing);
|
WriteScrubEnabledPref(mShowScrubbing);
|
||||||
@ -2820,6 +2810,11 @@ wxRect AdornedRulerPanel::GetButtonRect( Button button ) const
|
|||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AdornedRulerPanel::InButtonRect( Button button ) const
|
||||||
|
{
|
||||||
|
return GetButtonRect(button).Contains(ScreenToClient(::wxGetMousePosition()));
|
||||||
|
}
|
||||||
|
|
||||||
bool AdornedRulerPanel::GetButtonState( Button button ) const
|
bool AdornedRulerPanel::GetButtonState( Button button ) const
|
||||||
{
|
{
|
||||||
switch(button) {
|
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
|
void AdornedRulerPanel::DoDrawPushbutton(wxDC *dc, Button button, bool down) const
|
||||||
{
|
{
|
||||||
// Adapted from TrackInfo::DrawMuteSolo()
|
// Adapted from TrackInfo::DrawMuteSolo()
|
||||||
@ -2862,6 +2873,19 @@ void AdornedRulerPanel::DoDrawPushbutton(wxDC *dc, Button button, bool down) con
|
|||||||
AColor::BevelTrackInfo(*dc, !down, bev);
|
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
|
void AdornedRulerPanel::DoDrawPushbuttons(wxDC *dc) const
|
||||||
{
|
{
|
||||||
// Paint the area behind the buttons
|
// 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) {
|
for (unsigned ii = 0; ii < static_cast<unsigned>(Button::NumButtons); ++ii) {
|
||||||
auto button = static_cast<Button>(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 UpdateStatusBar(StatusChoice choice);
|
||||||
|
|
||||||
void DoMainMenu();
|
|
||||||
|
|
||||||
void OnCaptureLost(wxMouseCaptureLostEvent &evt);
|
void OnCaptureLost(wxMouseCaptureLostEvent &evt);
|
||||||
|
|
||||||
void DoDrawBorder(wxDC * dc);
|
void DoDrawBorder(wxDC * dc);
|
||||||
@ -359,9 +357,12 @@ private:
|
|||||||
NoButton = -1
|
NoButton = -1
|
||||||
};
|
};
|
||||||
wxRect GetButtonRect( Button button ) const;
|
wxRect GetButtonRect( Button button ) const;
|
||||||
|
bool InButtonRect( Button button ) const;
|
||||||
bool GetButtonState( Button button ) const;
|
bool GetButtonState( Button button ) const;
|
||||||
|
void ToggleButtonState( Button button );
|
||||||
void DoDrawPushbutton(wxDC *dc, Button button, bool down) const;
|
void DoDrawPushbutton(wxDC *dc, Button button, bool down) const;
|
||||||
void DoDrawPushbuttons(wxDC *dc) const;
|
void DoDrawPushbuttons(wxDC *dc) const;
|
||||||
|
void HandlePushbuttonEvent(wxMouseEvent &evt);
|
||||||
|
|
||||||
double Pos2Time(int p, bool ignoreFisheye = false);
|
double Pos2Time(int p, bool ignoreFisheye = false);
|
||||||
int Time2Pos(double t, bool ignoreFisheye = false);
|
int Time2Pos(double t, bool ignoreFisheye = false);
|
||||||
@ -423,16 +424,15 @@ private:
|
|||||||
void OnAutoScroll(wxCommandEvent &evt);
|
void OnAutoScroll(wxCommandEvent &evt);
|
||||||
void OnLockPlayRegion(wxCommandEvent &evt);
|
void OnLockPlayRegion(wxCommandEvent &evt);
|
||||||
|
|
||||||
//
|
void OnToggleScrubbing();
|
||||||
// Main menu
|
|
||||||
//
|
|
||||||
void OnShowHideScrubbing(wxCommandEvent &evt);
|
|
||||||
|
|
||||||
bool mPlayRegionDragsSelection;
|
bool mPlayRegionDragsSelection;
|
||||||
bool mTimelineToolTip;
|
bool mTimelineToolTip;
|
||||||
bool mQuickPlayEnabled;
|
bool mQuickPlayEnabled;
|
||||||
|
|
||||||
|
|
||||||
|
Button mCaptureState { Button::NoButton };
|
||||||
|
|
||||||
enum MouseEventState {
|
enum MouseEventState {
|
||||||
mesNone,
|
mesNone,
|
||||||
mesDraggingPlayRegionStart,
|
mesDraggingPlayRegionStart,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user