Audacity  3.0.3
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 ()
 
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 () const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 

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 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 186 of file ZoomHandle.cpp.

187 {
188  // Cancel is implemented! And there is no initial state to restore,
189  // so just return a code.
191 }

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 91 of file ZoomHandle.cpp.

93 {
94  const wxMouseEvent &event = evt.event;
95  if (event.ButtonDown() || event.LeftDClick()) {
97  mZoomStart = event.m_x;
98  mZoomEnd = event.m_x;
99  mRect = evt.rect;
100  }
102 }

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 104 of file ZoomHandle.cpp.

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

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 193 of file ZoomHandle.cpp.

196 {
197  if ( iPass == TrackArtist::PassZooming &&
198  // PRL: Draw dashed lines only if we would zoom in
199  // for button up.
200  IsDragZooming() ) {
201  auto &dc = context.dc;
202  dc.SetBrush(*wxTRANSPARENT_BRUSH);
203  dc.SetPen(*wxBLACK_DASHED_PEN);
204  // Make the top and bottom of the dashed rectangle disappear out of
205  // bounds, so that you only see vertical dashed lines.
206  dc.DrawRectangle( {
208  rect.y - 1,
209  1 + abs(mZoomEnd - mZoomStart),
210  rect.height + 2
211  } );
212  }
213 }

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 215 of file ZoomHandle.cpp.

218 {
219  if ( iPass == TrackArtist::PassZooming )
220  return MaximizeHeight( rect, panelRect );
221  else
222  return rect;
223 }

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

Here is the call graph for this function:

◆ 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 86 of file ZoomHandle.cpp.

87 {
88  return true;
89 }

◆ 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 }

References AssignUIHandlePtr().

Referenced by CommonTrackView::HitTest(), and 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 }

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 }

References HitAnywhere().

Referenced by CommonTrackView::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 225 of file ZoomHandle.cpp.

226 {
227  const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
228  return (abs(mZoomEnd - mZoomStart) > DragThreshold);
229 }

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 125 of file ZoomHandle.cpp.

127 {
128  return HitPreview(st.state, pProject);
129 }

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 131 of file ZoomHandle.cpp.

134 {
135  const wxMouseEvent &event = evt.event;
136  auto &viewInfo = ViewInfo::Get( *pProject );
137  if (mZoomEnd < mZoomStart)
139 
140  const int trackLeftEdge = mRect.x;
141  if (IsDragZooming())
142  {
145  double left = viewInfo.PositionToTime(mZoomStart, trackLeftEdge);
146  double right = viewInfo.PositionToTime(mZoomEnd, trackLeftEdge);
147 
148  double multiplier =
149  (viewInfo.PositionToTime(mRect.width) - viewInfo.PositionToTime(0)) /
150  (right - left);
151  if (event.ShiftDown())
152  multiplier = 1.0 / multiplier;
153 
154  viewInfo.ZoomBy(multiplier);
155 
156  viewInfo.h = left;
157  }
158  else
159  {
163  const double center_h =
164  viewInfo.PositionToTime(event.m_x, trackLeftEdge);
165 
166  const double multiplier =
167  (event.RightUp() || event.RightDClick() || event.ShiftDown())
168  ? 0.5 : 2.0;
169  viewInfo.ZoomBy(multiplier);
170 
171  if (event.MiddleUp() || event.MiddleDClick())
172  viewInfo.SetZoom(ZoomInfo::GetDefaultZoom()); // AS: Reset zoom.
173 
174  const double new_center_h =
175  viewInfo.PositionToTime(event.m_x, trackLeftEdge);
176 
177  viewInfo.h += (center_h - new_center_h);
178  }
179 
180  mZoomEnd = mZoomStart = 0;
181 
182  using namespace RefreshCode;
183  return RefreshAll | FixScrollbars;
184 }

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 69 of file ZoomHandle.h.

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

◆ mZoomEnd

int ZoomHandle::mZoomEnd {}
private

Definition at line 68 of file ZoomHandle.h.

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

◆ mZoomStart

int ZoomHandle::mZoomStart {}
private

Definition at line 68 of file ZoomHandle.h.

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


The documentation for this class was generated from the following files:
ZoomHandle::IsDragZooming
bool IsDragZooming() const
Definition: ZoomHandle.cpp:225
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
RefreshCode::FixScrollbars
@ FixScrollbars
Definition: RefreshCode.h:27
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:241
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
ZoomInfo::GetDefaultZoom
static double GetDefaultZoom()
Definition: ZoomInfo.h:123
ZoomHandle::mZoomEnd
int mZoomEnd
Definition: ZoomHandle.h:68
MakeCursor
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:182
XO
#define XO(s)
Definition: Internat.h:31
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
ZoomHandle::HitAnywhere
static UIHandlePtr HitAnywhere(std::weak_ptr< ZoomHandle > &holder)
Definition: ZoomHandle.cpp:65
ZoomHandle::HitPreview
static HitTestPreview HitPreview(const wxMouseState &state, const AudacityProject *pProject)
Definition: ZoomHandle.cpp:43
DragThreshold
const int DragThreshold
Definition: TrackPanel.h:60
ZoomHandle::mZoomStart
int mZoomStart
Definition: ZoomHandle.h:68
TrackPanelDrawable::MaximizeHeight
static wxRect MaximizeHeight(const wxRect &rect, const wxRect &panelRect)
Definition: TrackPanelDrawable.h:52
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:735
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
ZoomHandle::mRect
wxRect mRect
Definition: ZoomHandle.h:69
TrackArtist::PassZooming
@ PassZooming
Definition: TrackArtist.h:85
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16