Audacity  3.0.3
WaveTrackVZoomHandle.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 WaveTrackVZoomHandle.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 
12 #include "WaveTrackVZoomHandle.h"
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 
24 bool 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 {
44  mpData->doZoom(
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(pParent, &table, &data);
123  pParent->PopupMenu(pMenu.get(), 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 
151  TrackPanelDrawingContext &context,
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 }
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
WaveTrackVRulerMenuTable::InitMenuData::project
AudacityProject & project
Definition: WaveTrackVZoomHandle.h:70
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
PopupMenuTable
Definition: PopupMenuTable.h:104
WaveTrackVZoomHandle::DoRelease
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)
Definition: WaveTrackVZoomHandle.cpp:97
WaveTrackViewConstants
Definition: WaveTrackView.h:17
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
MakeCursor
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:176
WaveTrackVZoomHandle::DoDrawingArea
AUDACITY_DLL_API wxRect DoDrawingArea(const wxRect &rect, const wxRect &panelRect, unsigned iPass)
Definition: WaveTrackVZoomHandle.cpp:161
bVZoom
bool bVZoom
Definition: NoteTrackVZoomHandle.cpp:258
WaveTrackViewConstants::kZoom1to1
@ kZoom1to1
Definition: WaveTrackViewConstants.h:72
WaveTrackVZoomHandle::DoDrag
AUDACITY_DLL_API Result DoDrag(const TrackPanelMouseEvent &event, AudacityProject *pProject, int zoomStart, int &zoomEnd)
Definition: WaveTrackVZoomHandle.cpp:82
XO
#define XO(s)
Definition: Internat.h:31
WaveTrackViewConstants::ZoomActions
ZoomActions
Definition: WaveTrackViewConstants.h:69
WaveTrackVZoomHandle::DoDraw
AUDACITY_DLL_API void DoDraw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass, int zoomStart, int zoomEnd)
Definition: WaveTrackVZoomHandle.cpp:150
WaveTrackVZoomHandle::HitPreview
AUDACITY_DLL_API HitTestPreview HitPreview(const wxMouseState &state)
Definition: WaveTrackVZoomHandle.cpp:61
WaveTrackVRulerMenuTable::InitUserData
void InitUserData(void *pUserData) override
Definition: WaveTrackVZoomHandle.cpp:35
WaveTrackVZoomHandle::DoZoomFunction
void(*)(AudacityProject *pProject, WaveTrack *pTrack, WaveTrackViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint) DoZoomFunction
Definition: WaveTrackVZoomHandle.h:36
WaveTrackVZoomHandle::IsDragZooming
AUDACITY_DLL_API bool IsDragZooming(int zoomStart, int zoomEnd)
Definition: WaveTrackVZoomHandle.cpp:24
DragThreshold
const int DragThreshold
Definition: TrackPanel.h:58
WaveTrackVRulerMenuTable::UpdatePrefs
void UpdatePrefs() override
Definition: WaveTrackVZoomHandle.cpp:53
TrackVRulerControls::ZoomingArea
static wxRect ZoomingArea(const wxRect &rect, const wxRect &panelRect)
Definition: TrackVRulerControls.cpp:81
UIHandle::Result
unsigned Result
Definition: UIHandle.h:37
anonymous_namespace{NoteTrackVZoomHandle.cpp}::IsDragZooming
bool IsDragZooming(int zoomStart, int zoomEnd)
Definition: NoteTrackVZoomHandle.cpp:43
HitTestPreview
Definition: HitTestResult.h:20
WaveTrackVRulerMenuTable::InitMenuData::rect
wxRect rect
Definition: WaveTrackVZoomHandle.h:72
RefreshCode::UpdateVRuler
@ UpdateVRuler
Definition: RefreshCode.h:30
WaveTrackViewConstants::kZoomIn
@ kZoomIn
Definition: WaveTrackViewConstants.h:77
WaveTrackVRulerMenuTable::InitMenuData::pTrack
WaveTrack * pTrack
Definition: WaveTrackVZoomHandle.h:71
PopupMenuTable::Clear
void Clear()
Definition: PopupMenuTable.h:144
WaveTrackVRulerMenuTable::OnZoom
void OnZoom(WaveTrackViewConstants::ZoomActions iZoomCode)
Definition: WaveTrackVZoomHandle.cpp:41
WaveTrackVRulerMenuTable::InitMenuData::yy
int yy
Definition: WaveTrackVZoomHandle.h:74
TrackVRulerControls::DrawZooming
static void DrawZooming(TrackPanelDrawingContext &context, const wxRect &rect, int zoomStart, int zoomEnd)
Definition: TrackVRulerControls.cpp:61
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:113
WaveTrackVRulerMenuTable::mpData
InitMenuData * mpData
Definition: WaveTrackVZoomHandle.h:92
TrackPanelMouseEvent
Definition: TrackPanelMouseEvent.h:46
WaveTrackViewConstants::kZoomOut
@ kZoomOut
Definition: WaveTrackViewConstants.h:78
TrackArtist::PassZooming
@ PassZooming
Definition: TrackArtist.h:79
kCaptureLostEventId
const int kCaptureLostEventId
Definition: TrackPanelMouseEvent.h:23
WaveTrackVRulerMenuTable::InitMenuData::doZoom
WaveTrackVZoomHandle::DoZoomFunction doZoom
Definition: WaveTrackVZoomHandle.h:75
WaveTrackVRulerMenuTable::InitMenuData
Definition: WaveTrackVZoomHandle.h:68
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
WaveTrackVRulerMenuTable::InitMenuData::result
unsigned result
Definition: WaveTrackVZoomHandle.h:73
TrackPanelMouseEvent::event
wxMouseEvent & event
Definition: TrackPanelMouseEvent.h:58
PopupMenuTable::BuildMenu
static std::unique_ptr< wxMenu > BuildMenu(wxEvtHandler *pParent, PopupMenuTable *pTable, void *pUserData=NULL)
Definition: PopupMenuTable.cpp:218
WaveTrackVZoomHandle.h