| 1 |
/********************************************************************** |
| 2 |
|
| 3 |
Audacity: A Digital Audio Editor |
| 4 |
|
| 5 |
WaveChannelVZoomHandle.cpp |
| 6 |
|
| 7 |
Paul Licameli split from TrackPanel.cpp |
| 8 |
|
| 9 |
**********************************************************************/ |
| 10 |
|
| 11 |
|
| 12 |
#include "WaveChannelVZoomHandle.h" |
| 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 |
|
| 24 |
bool 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 |
|
| 30 |
/////////////////////////////////////////////////////////////////////////////// |
| 31 |
// Table class |
| 32 |
|
| 33 |
void WaveChannelVRulerMenuTable::InitUserData(void *pUserData) |
| 34 |
{ |
| 35 |
mpData = static_cast<InitMenuData*>(pUserData); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
void WaveChannelVRulerMenuTable::OnZoom( |
| 40 |
WaveChannelViewConstants::ZoomActions iZoomCode) |
| 41 |
{ |
| 42 |
mpData->doZoom( |
| 43 |
&mpData->project, mpData->wc, |
| 44 |
iZoomCode, mpData->rect, mpData->yy, mpData->yy, false |
| 45 |
); |
| 46 |
|
| 47 |
using namespace RefreshCode; |
| 48 |
mpData->result = UpdateVRuler | RefreshAll; |
| 49 |
} |
| 50 |
|
| 51 |
void WaveChannelVRulerMenuTable::UpdatePrefs() |
| 52 |
{ |
| 53 |
// Because labels depend on advanced vertical zoom setting |
| 54 |
PopupMenuTable::Clear(); |
| 55 |
} |
| 56 |
|
| 57 |
/////////////////////////////////////////////////////////////////////////////// |
| 58 |
|
| 59 |
HitTestPreview WaveChannelVZoomHandle::HitPreview(const bool bVZoom) |
| 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 |
|
| 74 |
UIHandle::Result WaveChannelVZoomHandle::DoDrag( |
| 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 |
|
| 89 |
UIHandle::Result WaveChannelVZoomHandle::DoRelease( |
| 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 |
{ |
| 107 |
WaveChannelVRulerMenuTable::InitMenuData data { |
| 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 |
|
| 130 |
void WaveChannelVZoomHandle::DoDraw( |
| 131 |
TrackPanelDrawingContext &context, |
| 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 |
|
| 140 |
wxRect WaveChannelVZoomHandle::DoDrawingArea( |
| 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 |
} |