Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ZoomHandle Class Referencefinal

#include <ZoomHandle.h>

Inheritance diagram for ZoomHandle:
[legend]
Collaboration diagram for ZoomHandle:
[legend]

Public Member Functions

 ZoomHandle ()
 
ZoomHandleoperator= (const ZoomHandle &)=default
 
virtual ~ZoomHandle ()
 
std::shared_ptr< const TrackFindTrack () const override
 
bool HandlesRightClick () override
 Whether the handle has any special right-button handling. More...
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual void Enter (bool forward, AudacityProject *pProject)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool HandlesRightClick ()
 Whether the handle has any special right-button handling. More...
 
virtual Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject)=0
 
virtual Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
 
virtual Result Cancel (AudacityProject *pProject)=0
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
virtual std::shared_ptr< const TrackFindTrack () const =0
 
virtual bool IsDragging () const
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

Static Public Member Functions

static UIHandlePtr HitAnywhere (std::weak_ptr< ZoomHandle > &holder)
 
static UIHandlePtr HitTest (std::weak_ptr< ZoomHandle > &holder, const wxMouseState &state)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
static std::shared_ptr< const TrackTrackFromChannel (const std::shared_ptr< const Channel > &pChannel)
 A frequent convenience in the definition of UIHandles. More...
 
- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 

Private Member Functions

 ZoomHandle (const ZoomHandle &)=delete
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
wxRect DrawingArea (TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
 
bool IsDragZooming () const
 

Static Private Member Functions

static HitTestPreview HitPreview (const wxMouseState &state, const AudacityProject *pProject)
 

Private Attributes

int mZoomStart {}
 
int mZoomEnd {}
 
wxRect mRect {}
 

Additional Inherited Members

- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 19 of file ZoomHandle.h.

Constructor & Destructor Documentation

◆ ZoomHandle() [1/2]

ZoomHandle::ZoomHandle ( const ZoomHandle )
privatedelete

◆ ZoomHandle() [2/2]

ZoomHandle::ZoomHandle ( )

This class takes care of our different zoom possibilities. It is possible for a user to just "zoom in" or "zoom out," but it is also possible for a user to drag and select an area that he or she wants to be zoomed in on. We use mZoomStart and mZoomEnd to track the beginning and end of such a zoom area. Note that the ViewInfo actually keeps track of our zoom constant, so we achieve zooming by altering the zoom constant and forcing a refresh.

Definition at line 39 of file ZoomHandle.cpp.

40{}

◆ ~ZoomHandle()

ZoomHandle::~ZoomHandle ( )
virtual

Definition at line 82 of file ZoomHandle.cpp.

83{
84}

Member Function Documentation

◆ Cancel()

UIHandle::Result ZoomHandle::Cancel ( AudacityProject pProject)
overridevirtual

Implements UIHandle.

Definition at line 191 of file ZoomHandle.cpp.

192{
193 // Cancel is implemented! And there is no initial state to restore,
194 // so just return a code.
196}

References RefreshCode::RefreshAll.

◆ Click()

UIHandle::Result ZoomHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Zoom button down, record the position.

Implements UIHandle.

Definition at line 96 of file ZoomHandle.cpp.

98{
99 const wxMouseEvent &event = evt.event;
100 if (event.ButtonDown() || event.LeftDClick()) {
102 mZoomStart = event.m_x;
103 mZoomEnd = event.m_x;
104 mRect = evt.rect;
105 }
107}
int mZoomStart
Definition: ZoomHandle.h:70
int mZoomEnd
Definition: ZoomHandle.h:70
wxRect mRect
Definition: ZoomHandle.h:71

References TrackPanelMouseEvent::event, mRect, mZoomEnd, mZoomStart, TrackPanelMouseEvent::rect, and RefreshCode::RefreshNone.

◆ Drag()

UIHandle::Result ZoomHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 109 of file ZoomHandle.cpp.

111{
112 const wxMouseEvent &event = evt.event;
113 const int left = mRect.GetLeft();
114 const int right = mRect.GetRight();
115
116 mZoomEnd = event.m_x;
117
118 if (event.m_x < left) {
119 mZoomEnd = left;
120 }
121 else if (event.m_x > right) {
122 mZoomEnd = right;
123 }
124
125 // Refresh tracks ALWAYS. Even if IsDragZooming() becomes false, make the
126 // dashed lines disappear. -- PRL
127 return RefreshCode::RefreshAll; // (IsDragZooming() ? RefreshAllTracks : RefreshNone),
128}

References TrackPanelMouseEvent::event, mRect, mZoomEnd, and RefreshCode::RefreshAll.

◆ Draw()

void ZoomHandle::Draw ( TrackPanelDrawingContext context,
const wxRect &  rect,
unsigned  iPass 
)
overrideprivatevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 198 of file ZoomHandle.cpp.

201{
202 if ( iPass == TrackArtist::PassZooming &&
203 // PRL: Draw dashed lines only if we would zoom in
204 // for button up.
205 IsDragZooming() ) {
206 auto &dc = context.dc;
207 dc.SetBrush(*wxTRANSPARENT_BRUSH);
208 dc.SetPen(*wxBLACK_DASHED_PEN);
209 // Make the top and bottom of the dashed rectangle disappear out of
210 // bounds, so that you only see vertical dashed lines.
211 dc.DrawRectangle( {
213 rect.y - 1,
214 1 + abs(mZoomEnd - mZoomStart),
215 rect.height + 2
216 } );
217 }
218}
int min(int a, int b)
bool IsDragZooming() const
Definition: ZoomHandle.cpp:230

References TrackPanelDrawingContext::dc, IsDragZooming(), min(), mZoomEnd, mZoomStart, and TrackArtist::PassZooming.

Here is the call graph for this function:

◆ DrawingArea()

wxRect ZoomHandle::DrawingArea ( TrackPanelDrawingContext ,
const wxRect &  rect,
const wxRect &  panelRect,
unsigned  iPass 
)
overrideprivatevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 220 of file ZoomHandle.cpp.

223{
224 if ( iPass == TrackArtist::PassZooming )
225 return MaximizeHeight( rect, panelRect );
226 else
227 return rect;
228}
static wxRect MaximizeHeight(const wxRect &rect, const wxRect &panelRect)

References TrackPanelDrawable::MaximizeHeight(), and TrackArtist::PassZooming.

Here is the call graph for this function:

◆ FindTrack()

std::shared_ptr< const Track > ZoomHandle::FindTrack ( ) const
overridevirtual
Returns
pointer to associated track, if any

Implements UIHandle.

Definition at line 86 of file ZoomHandle.cpp.

87{
88 return nullptr;
89}

◆ HandlesRightClick()

bool ZoomHandle::HandlesRightClick ( )
overridevirtual

Whether the handle has any special right-button handling.

If not, then Click() will not be called for right click. Default is always false

Reimplemented from UIHandle.

Definition at line 91 of file ZoomHandle.cpp.

92{
93 return true;
94}

◆ HitAnywhere()

UIHandlePtr ZoomHandle::HitAnywhere ( std::weak_ptr< ZoomHandle > &  holder)
static

Definition at line 64 of file ZoomHandle.cpp.

66{
67 auto result = std::make_shared<ZoomHandle>();
68 result = AssignUIHandlePtr(holder, result);
69 return result;
70}
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164

References AssignUIHandlePtr().

Referenced by HitTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HitPreview()

HitTestPreview ZoomHandle::HitPreview ( const wxMouseState &  state,
const AudacityProject pProject 
)
staticprivate

Definition at line 42 of file ZoomHandle.cpp.

44{
45 static auto zoomInCursor =
46 ::MakeCursor(wxCURSOR_MAGNIFIER, ZoomInCursorXpm, 19, 15);
47 static auto zoomOutCursor =
48 ::MakeCursor(wxCURSOR_MAGNIFIER, ZoomOutCursorXpm, 19, 15);
49 TranslatableString message;
50 // TODO: Why not mention middle click to zoom normal on Windows too?
51#if defined( __WXMAC__ )
52 message = XO("Click to Zoom In, Shift-Click to Zoom Out");
53#elif defined( __WXMSW__ )
54 message = XO("Drag to Zoom Into Region, Right-Click to Zoom Out");
55#elif defined( __WXGTK__ )
56 message = XO("Left=Zoom In, Right=Zoom Out, Middle=Normal");
57#endif
58 return {
59 message,
60 (state.ShiftDown() ? &*zoomOutCursor : &*zoomInCursor)
61 };
62}
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:189
Holds a msgid for the translation catalog; may also bind format arguments.

References MakeCursor(), and XO().

Referenced by Preview().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HitTest()

UIHandlePtr ZoomHandle::HitTest ( std::weak_ptr< ZoomHandle > &  holder,
const wxMouseState &  state 
)
static

Definition at line 72 of file ZoomHandle.cpp.

75{
76 if (state.ButtonIsDown(wxMOUSE_BTN_RIGHT))
77 return HitAnywhere(holder);
78 else
79 return {};
80}
static UIHandlePtr HitAnywhere(std::weak_ptr< ZoomHandle > &holder)
Definition: ZoomHandle.cpp:65

References HitAnywhere().

Referenced by CommonChannelView::HitTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsDragZooming()

bool ZoomHandle::IsDragZooming ( ) const
private

Definition at line 230 of file ZoomHandle.cpp.

231{
232 const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
233 return (abs(mZoomEnd - mZoomStart) > DragThreshold);
234}
const int DragThreshold
Definition: TrackPanel.h:57

References DragThreshold, mZoomEnd, and mZoomStart.

Referenced by Draw(), and Release().

Here is the caller graph for this function:

◆ operator=()

ZoomHandle & ZoomHandle::operator= ( const ZoomHandle )
default

◆ Preview()

HitTestPreview ZoomHandle::Preview ( const TrackPanelMouseState state,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 130 of file ZoomHandle.cpp.

132{
133 return HitPreview(st.state, pProject);
134}
static HitTestPreview HitPreview(const wxMouseState &state, const AudacityProject *pProject)
Definition: ZoomHandle.cpp:43

References HitPreview(), and TrackPanelMouseState::state.

Here is the call graph for this function:

◆ Release()

UIHandle::Result ZoomHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

This actually sets the Zoom value when you're done doing a drag zoom.

This handles normal Zoom In/Out, if you just clicked; IOW, if you were NOT dragging to zoom an area.

Todo:
MAGIC NUMBER: We've got several in this method.

Implements UIHandle.

Definition at line 136 of file ZoomHandle.cpp.

139{
140 const wxMouseEvent &event = evt.event;
141 auto &viewInfo = ViewInfo::Get( *pProject );
142 if (mZoomEnd < mZoomStart)
144
145 const int trackLeftEdge = mRect.x;
146 if (IsDragZooming())
147 {
150 double left = viewInfo.PositionToTime(mZoomStart, trackLeftEdge);
151 double right = viewInfo.PositionToTime(mZoomEnd, trackLeftEdge);
152
153 double multiplier =
154 (viewInfo.PositionToTime(mRect.width) - viewInfo.PositionToTime(0)) /
155 (right - left);
156 if (event.ShiftDown())
157 multiplier = 1.0 / multiplier;
158
159 viewInfo.ZoomBy(multiplier);
160
161 viewInfo.hpos = left;
162 }
163 else
164 {
168 const double center_h =
169 viewInfo.PositionToTime(event.m_x, trackLeftEdge);
170
171 const double multiplier =
172 (event.RightUp() || event.RightDClick() || event.ShiftDown())
173 ? 0.5 : 2.0;
174 viewInfo.ZoomBy(multiplier);
175
176 if (event.MiddleUp() || event.MiddleDClick())
177 viewInfo.SetZoom(ZoomInfo::GetDefaultZoom()); // AS: Reset zoom.
178
179 const double new_center_h =
180 viewInfo.PositionToTime(event.m_x, trackLeftEdge);
181
182 viewInfo.hpos += (center_h - new_center_h);
183 }
184
185 mZoomEnd = mZoomStart = 0;
186
187 using namespace RefreshCode;
188 return RefreshAll | FixScrollbars;
189}
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static double GetDefaultZoom()
Definition: ZoomInfo.h:116
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634

References TrackPanelMouseEvent::event, RefreshCode::FixScrollbars, ViewInfo::Get(), ZoomInfo::GetDefaultZoom(), IsDragZooming(), mRect, mZoomEnd, mZoomStart, RefreshCode::RefreshAll, and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

Member Data Documentation

◆ mRect

wxRect ZoomHandle::mRect {}
private

Definition at line 71 of file ZoomHandle.h.

Referenced by Click(), Drag(), and Release().

◆ mZoomEnd

int ZoomHandle::mZoomEnd {}
private

Definition at line 70 of file ZoomHandle.h.

Referenced by Click(), Drag(), Draw(), IsDragZooming(), and Release().

◆ mZoomStart

int ZoomHandle::mZoomStart {}
private

Definition at line 70 of file ZoomHandle.h.

Referenced by Click(), Draw(), IsDragZooming(), and Release().


The documentation for this class was generated from the following files: