Audacity 3.2.0
WaveTrackVZoomHandle.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5WaveTrackVZoomHandle.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
13
14#include "../../../ui/TrackVRulerControls.h"
15
16#include "../../../../HitTestResult.h"
17#include "Project.h"
18#include "../../../../RefreshCode.h"
19#include "../../../../TrackArtist.h"
20#include "../../../../TrackPanelMouseEvent.h"
21#include "WaveTrack.h"
22#include "../../../../../images/Cursors.h"
23
24bool WaveTrackVZoomHandle::IsDragZooming(int zoomStart, int zoomEnd)
25{
26 const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
27 bool bVZoom;
28 gPrefs->Read(wxT("/GUI/VerticalZooming"), &bVZoom, false);
29 return bVZoom && (abs(zoomEnd - zoomStart) > DragThreshold);
30}
31
33// Table class
34
36{
37 mpData = static_cast<InitMenuData*>(pUserData);
38}
39
40
43{
46 iZoomCode, mpData->rect, mpData->yy, mpData->yy, false
47 );
48
49 using namespace RefreshCode;
51}
52
54{
55 // Because labels depend on advanced vertical zoom setting
57}
58
60
62{
63 static auto zoomInCursor =
64 ::MakeCursor(wxCURSOR_MAGNIFIER, ZoomInCursorXpm, 19, 15);
65 static auto zoomOutCursor =
66 ::MakeCursor(wxCURSOR_MAGNIFIER, ZoomOutCursorXpm, 19, 15);
67 static wxCursor arrowCursor{ wxCURSOR_ARROW };
68 bool bVZoom;
69 gPrefs->Read(wxT("/GUI/VerticalZooming"), &bVZoom, false);
70 bVZoom &= !state.RightIsDown();
71 const auto message = bVZoom ?
72 XO("Click to vertically zoom in. Shift-click to zoom out. Drag to specify a zoom region.") :
73 XO("Right-click for menu.");
74
75 return {
76 message,
77 bVZoom ? (state.ShiftDown() ? &*zoomOutCursor : &*zoomInCursor) : &arrowCursor
78 // , message
79 };
80}
81
83 const TrackPanelMouseEvent &evt, AudacityProject *pProject,
84 const int zoomStart, int &zoomEnd)
85{
86 using namespace RefreshCode;
87
88 const wxMouseEvent &event = evt.event;
89 if ( event.RightIsDown() )
90 return RefreshNone;
91 zoomEnd = event.m_y;
92 if (IsDragZooming( zoomStart, zoomEnd ))
93 return RefreshAll;
94 return RefreshNone;
95}
96
98 const TrackPanelMouseEvent &evt, AudacityProject *pProject,
99 wxWindow *pParent, WaveTrack *pTrack, const wxRect &rect,
100 DoZoomFunction doZoom, PopupMenuTable &table,
101 int zoomStart, int zoomEnd )
102{
103 using namespace RefreshCode;
104 if (!pTrack)
105 return RefreshNone;
106
107 const wxMouseEvent &event = evt.event;
108 const bool shiftDown = event.ShiftDown();
109 const bool rightUp = event.RightUp();
110
111
112 // Popup menu...
113 using namespace WaveTrackViewConstants;
114 if (
115 rightUp &&
116 !(event.ShiftDown() || event.CmdDown()))
117 {
119 *pProject,
120 pTrack, rect, RefreshCode::RefreshNone, event.m_y, doZoom };
121
122 auto pMenu = PopupMenuTable::BuildMenu( &table, &data );
123 pMenu->Popup( *pParent, { event.m_x, event.m_y } );
124
125 return data.result;
126 }
127 else{
128 bool bVZoom;
129 gPrefs->Read(wxT("/GUI/VerticalZooming"), &bVZoom, false);
130 // Ignore Capture Lost event
131 bVZoom &= event.GetId() != kCaptureLostEventId;
132 // shiftDown | rightUp | ZoomKind
133 // T | T | 1to1
134 // T | F | Out
135 // F | - | In
136 if( bVZoom ) {
137 if( shiftDown )
138 zoomStart = zoomEnd;
139 doZoom(pProject, pTrack,
140 shiftDown
141 ? (rightUp ? kZoom1to1 : kZoomOut)
142 : kZoomIn,
143 rect, zoomStart, zoomEnd, !shiftDown);
144 }
145 }
146
147 return UpdateVRuler | RefreshAll;
148}
149
152 const wxRect &rect, unsigned iPass, const int zoomStart, const int zoomEnd )
153{
154 if ( iPass == TrackArtist::PassZooming ) {
155 if ( IsDragZooming( zoomStart, zoomEnd ) )
157 ( context, rect, zoomStart, zoomEnd );
158 }
159}
160
162 const wxRect &rect, const wxRect &panelRect, unsigned iPass )
163{
164 if ( iPass == TrackArtist::PassZooming )
165 return TrackVRulerControls::ZoomingArea( rect, panelRect );
166 else
167 return rect;
168}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
bool bVZoom
FileConfig * gPrefs
Definition: Prefs.cpp:70
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:186
const int DragThreshold
Definition: TrackPanel.h:59
const int kCaptureLostEventId
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static std::unique_ptr< PopupMenu > BuildMenu(PopupMenuTable *pTable, void *pUserData=NULL)
static void DrawZooming(TrackPanelDrawingContext &context, const wxRect &rect, int zoomStart, int zoomEnd)
static wxRect ZoomingArea(const wxRect &rect, const wxRect &panelRect)
unsigned Result
Definition: UIHandle.h:38
A Track that contains audio waveform data.
Definition: WaveTrack.h:54
void OnZoom(WaveTrackViewConstants::ZoomActions iZoomCode)
void InitUserData(void *pUserData) override
Called before the menu items are appended.
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
AUDACITY_DLL_API HitTestPreview HitPreview(const wxMouseState &state)
AUDACITY_DLL_API void DoDraw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass, int zoomStart, int zoomEnd)
AUDACITY_DLL_API Result DoRelease(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent, WaveTrack *pTrack, const wxRect &mRect, DoZoomFunction doZoom, PopupMenuTable &table, int zoomStart, int zoomEnd)
AUDACITY_DLL_API wxRect DoDrawingArea(const wxRect &rect, const wxRect &panelRect, unsigned iPass)
AUDACITY_DLL_API bool IsDragZooming(int zoomStart, int zoomEnd)
AUDACITY_DLL_API Result DoDrag(const TrackPanelMouseEvent &event, AudacityProject *pProject, int zoomStart, int &zoomEnd)
void(*)(AudacityProject *pProject, WaveTrack *pTrack, WaveTrackViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint) DoZoomFunction
bool IsDragZooming(int zoomStart, int zoomEnd)
WaveTrackVZoomHandle::DoZoomFunction doZoom