Audacity 3.2.0
WaveChannelVZoomHandle.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5WaveChannelVZoomHandle.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
13
14#include "../../../ui/ChannelVRulerControls.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 WaveChannelVZoomHandle::IsDragZooming(int zoomStart, int zoomEnd, bool hasDragZoom)
25{
26 const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
27 return hasDragZoom && (abs(zoomEnd - zoomStart) > DragThreshold);
28}
29
31// Table class
32
34{
35 mpData = static_cast<InitMenuData*>(pUserData);
36}
37
38
41{
44 iZoomCode, mpData->rect, mpData->yy, mpData->yy, false
45 );
46
47 using namespace RefreshCode;
49}
50
52{
53 // Because labels depend on advanced vertical zoom setting
55}
56
58
60{
61 static wxCursor crossCursor{wxCURSOR_CROSS};
62 static wxCursor arrowCursor{ wxCURSOR_ARROW };
63 const auto message = bVZoom ?
64 XO("Drag to specify a zoom region. Right-click for menu. Ctrl+scroll to zoom.") :
65 XO("Right-click for menu. Ctrl+scroll to zoom.");
66
67 return {
68 message,
69 bVZoom ? &crossCursor : &arrowCursor
70 // , message
71 };
72}
73
75 const TrackPanelMouseEvent &evt, AudacityProject *pProject,
76 const int zoomStart, int &zoomEnd, bool hasDragZooming)
77{
78 using namespace RefreshCode;
79
80 const wxMouseEvent &event = evt.event;
81 if ( event.RightIsDown() )
82 return RefreshNone;
83 zoomEnd = event.m_y;
84 if (IsDragZooming( zoomStart, zoomEnd, hasDragZooming))
85 return RefreshAll;
86 return RefreshNone;
87}
88
90 const TrackPanelMouseEvent &evt, AudacityProject *pProject,
91 wxWindow *pParent, WaveChannel &wc, const wxRect &rect,
92 DoZoomFunction doZoom, PopupMenuTable &table,
93 int zoomStart, int zoomEnd)
94{
95 using namespace RefreshCode;
96 const wxMouseEvent &event = evt.event;
97 const bool shiftDown = event.ShiftDown();
98 const bool rightUp = event.RightUp();
99
100
101 // Popup menu...
102 using namespace WaveChannelViewConstants;
103 if (
104 rightUp &&
105 !(event.ShiftDown() || event.CmdDown()))
106 {
108 *pProject,
109 wc, rect, RefreshCode::RefreshNone, event.m_y, doZoom };
110
111 auto pMenu = PopupMenuTable::BuildMenu( &table, &data );
112 pMenu->Popup( *pParent, { event.m_x, event.m_y } );
113
114 return data.result;
115 }
116 else {
117 // Ignore Capture Lost event
118 bool notLost = event.GetId() != kCaptureLostEventId;
119 // Shift+rightclick to reset zoom
120 if( shiftDown && notLost)
121 zoomStart = zoomEnd;
122 doZoom(pProject, wc, kZoom1to1,
123 rect, zoomStart, zoomEnd, !shiftDown);
124
125 }
126
127 return UpdateVRuler | RefreshAll;
128}
129
132 const wxRect &rect, unsigned iPass, const int zoomStart, const int zoomEnd, bool hasDragZoom)
133{
134 if (iPass == TrackArtist::PassZooming) {
135 if (IsDragZooming(zoomStart, zoomEnd, hasDragZoom))
136 ChannelVRulerControls::DrawZooming(context, rect, zoomStart, zoomEnd);
137 }
138}
139
141 const wxRect &rect, const wxRect &panelRect, unsigned iPass)
142{
143 if (iPass == TrackArtist::PassZooming)
144 return ChannelVRulerControls::ZoomingArea(rect, panelRect);
145 else
146 return rect;
147}
XO("Cut/Copy/Paste")
bool bVZoom
const int DragThreshold
Definition: TrackPanel.h:57
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 wxRect ZoomingArea(const wxRect &rect, const wxRect &panelRect)
static void DrawZooming(TrackPanelDrawingContext &context, const wxRect &rect, int zoomStart, int zoomEnd)
static std::unique_ptr< PopupMenu > BuildMenu(PopupMenuTable *pTable, void *pUserData=NULL)
unsigned Result
Definition: UIHandle.h:40
void InitUserData(void *pUserData) override
Called before the menu items are appended.
void OnZoom(WaveChannelViewConstants::ZoomActions iZoomCode)
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
AUDACITY_DLL_API Result DoRelease(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent, WaveChannel &wc, const wxRect &mRect, DoZoomFunction doZoom, PopupMenuTable &table, int zoomStart, int zoomEnd)
AUDACITY_DLL_API bool IsDragZooming(int zoomStart, int zoomEnd, bool hasDragZoom)
AUDACITY_DLL_API HitTestPreview HitPreview(const bool bVZoom)
AUDACITY_DLL_API void DoDraw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass, int zoomStart, int zoomEnd, bool hasDragZoom)
void(*)(AudacityProject *pProject, WaveChannel &wc, WaveChannelViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint) DoZoomFunction
AUDACITY_DLL_API wxRect DoDrawingArea(const wxRect &rect, const wxRect &panelRect, unsigned iPass)
AUDACITY_DLL_API Result DoDrag(const TrackPanelMouseEvent &event, AudacityProject *pProject, int zoomStart, int &zoomEnd, bool hasDragZoom)
bool IsDragZooming(int zoomStart, int zoomEnd)
WaveChannelVZoomHandle::DoZoomFunction doZoom