Audacity  2.2.2
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:
UIHandle

Public Member Functions

 ZoomHandle ()
 
ZoomHandleoperator= (const ZoomHandle &)=default
 
virtual ~ZoomHandle ()
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, const AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
void DrawExtras (DrawingPass pass, wxDC *dc, const wxRegion &updateRegion, const wxRect &panelRect) override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual void Enter (bool forward)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape () const
 
virtual bool Escape ()
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 

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 &)
 

Private Member Functions

 ZoomHandle (const ZoomHandle &)=delete
 
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
enum  DrawingPass { Cells, Panel }
 
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 20 of file ZoomHandle.h.

Constructor & Destructor Documentation

ZoomHandle::ZoomHandle ( const ZoomHandle )
privatedelete
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 ( )
virtual

Definition at line 82 of file ZoomHandle.cpp.

83 {
84 }

Member Function Documentation

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

Implements UIHandle.

Definition at line 181 of file ZoomHandle.cpp.

References RefreshCode::RefreshAll.

182 {
183  // Cancel is implemented! And there is no initial state to restore,
184  // so just return a code.
186 }
UIHandle::Result ZoomHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Zoom button down, record the position.

Implements UIHandle.

Definition at line 87 of file ZoomHandle.cpp.

References TrackPanelMouseEvent::event, TrackPanelMouseEvent::rect, and RefreshCode::RefreshNone.

88 {
89  const wxMouseEvent &event = evt.event;
90  if (event.ButtonDown() || event.LeftDClick()) {
92  mZoomStart = event.m_x;
93  mZoomEnd = event.m_x;
94  mRect = evt.rect;
95  }
97 }
wxRect mRect
Definition: ZoomHandle.h:63
int mZoomStart
Definition: ZoomHandle.h:62
int mZoomEnd
Definition: ZoomHandle.h:62
UIHandle::Result ZoomHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 100 of file ZoomHandle.cpp.

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

101 {
102  const wxMouseEvent &event = evt.event;
103  const int left = mRect.GetLeft();
104  const int right = mRect.GetRight();
105 
106  mZoomEnd = event.m_x;
107 
108  if (event.m_x < left) {
109  mZoomEnd = left;
110  }
111  else if (event.m_x > right) {
112  mZoomEnd = right;
113  }
114 
115  // Refresh tracks ALWAYS. Even if IsDragZooming() becomes false, make the
116  // dashed lines disappear. -- PRL
117  return RefreshCode::RefreshAll; // (IsDragZooming() ? RefreshAllTracks : RefreshNone),
118 }
wxRect mRect
Definition: ZoomHandle.h:63
int mZoomEnd
Definition: ZoomHandle.h:62
void ZoomHandle::DrawExtras ( DrawingPass  pass,
wxDC *  dc,
const wxRegion &  updateRegion,
const wxRect &  panelRect 
)
overridevirtual

Reimplemented from UIHandle.

Definition at line 189 of file ZoomHandle.cpp.

References min().

190 {
191  if (pass == Cells) {
192  // PRL: Draw dashed lines only if we would zoom in
193  // for button up.
194  if (!IsDragZooming())
195  return;
196 
197  wxRect rect;
198 
199  dc->SetBrush(*wxTRANSPARENT_BRUSH);
200  dc->SetPen(*wxBLACK_DASHED_PEN);
201 
202  rect.x = std::min(mZoomStart, mZoomEnd);
203  rect.width = 1 + abs(mZoomEnd - mZoomStart);
204  rect.y = -1;
205  rect.height = panelRect.height + 2;
206 
207  dc->DrawRectangle(rect);
208  }
209 }
int min(int a, int b)
bool IsDragZooming() const
Definition: ZoomHandle.cpp:211
int mZoomStart
Definition: ZoomHandle.h:62
int mZoomEnd
Definition: ZoomHandle.h:62
UIHandlePtr ZoomHandle::HitAnywhere ( std::weak_ptr< ZoomHandle > &  holder)
static

Definition at line 65 of file ZoomHandle.cpp.

References AssignUIHandlePtr().

Referenced by HitPreview(), and Track::HitTest().

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:162
HitTestPreview ZoomHandle::HitPreview ( const wxMouseState &  state,
const AudacityProject pProject 
)
staticprivate

Definition at line 43 of file ZoomHandle.cpp.

References _(), HitAnywhere(), and MakeCursor().

44 {
45  static auto zoomInCursor =
46  ::MakeCursor(wxCURSOR_MAGNIFIER, ZoomInCursorXpm, 19, 15);
47  static auto zoomOutCursor =
48  ::MakeCursor(wxCURSOR_MAGNIFIER, ZoomOutCursorXpm, 19, 15);
49  wxString message;
50  // TODO: Why not mention middle click to zoom normal on Windows too?
51 #if defined( __WXMAC__ )
52  message = _("Click to Zoom In, Shift-Click to Zoom Out");
53 #elif defined( __WXMSW__ )
54  message = _("Drag to Zoom Into Region, Right-Click to Zoom Out");
55 #elif defined( __WXGTK__ )
56  message = _("Left=Zoom In, Right=Zoom Out, Middle=Normal");
57 #endif
58  return {
59  message,
60  (state.ShiftDown() ? &*zoomOutCursor : &*zoomInCursor)
61  };
62 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:274
UIHandlePtr ZoomHandle::HitTest ( std::weak_ptr< ZoomHandle > &  holder,
const wxMouseState &  state 
)
static

Definition at line 73 of file ZoomHandle.cpp.

Referenced by Track::HitTest().

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
bool ZoomHandle::IsDragZooming ( ) const
private

Definition at line 211 of file ZoomHandle.cpp.

References DragThreshold, mZoomEnd, and mZoomStart.

212 {
213  const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
214  return (abs(mZoomEnd - mZoomStart) > DragThreshold);
215 }
const int DragThreshold
Definition: TrackPanel.h:242
int mZoomStart
Definition: ZoomHandle.h:62
int mZoomEnd
Definition: ZoomHandle.h:62
ZoomHandle& ZoomHandle::operator= ( const ZoomHandle )
default
HitTestPreview ZoomHandle::Preview ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 121 of file ZoomHandle.cpp.

References TrackPanelMouseState::state.

122 {
123  return HitPreview(st.state, pProject);
124 }
static HitTestPreview HitPreview(const wxMouseState &state, const AudacityProject *pProject)
Definition: ZoomHandle.cpp:43
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 127 of file ZoomHandle.cpp.

References TrackPanelMouseEvent::event, RefreshCode::FixScrollbars, ZoomInfo::GetDefaultZoom(), AudacityProject::GetViewInfo(), ZoomInfo::h, ZoomInfo::PositionToTime(), RefreshCode::RefreshAll, ZoomInfo::SetZoom(), and ZoomInfo::ZoomBy().

129 {
130  const wxMouseEvent &event = evt.event;
131  ViewInfo &viewInfo = pProject->GetViewInfo();
132  if (mZoomEnd < mZoomStart)
133  std::swap(mZoomStart, mZoomEnd);
134 
135  const int trackLeftEdge = mRect.x;
136  if (IsDragZooming())
137  {
140  double left = viewInfo.PositionToTime(mZoomStart, trackLeftEdge);
141  double right = viewInfo.PositionToTime(mZoomEnd, trackLeftEdge);
142 
143  double multiplier =
144  (viewInfo.PositionToTime(mRect.width) - viewInfo.PositionToTime(0)) /
145  (right - left);
146  if (event.ShiftDown())
147  multiplier = 1.0 / multiplier;
148 
149  viewInfo.ZoomBy(multiplier);
150 
151  viewInfo.h = left;
152  }
153  else
154  {
158  const double center_h =
159  viewInfo.PositionToTime(event.m_x, trackLeftEdge);
160 
161  const double multiplier =
162  (event.RightUp() || event.RightDClick() || event.ShiftDown())
163  ? 0.5 : 2.0;
164  viewInfo.ZoomBy(multiplier);
165 
166  if (event.MiddleUp() || event.MiddleDClick())
167  viewInfo.SetZoom(ZoomInfo::GetDefaultZoom()); // AS: Reset zoom.
168 
169  const double new_center_h =
170  viewInfo.PositionToTime(event.m_x, trackLeftEdge);
171 
172  viewInfo.h += (center_h - new_center_h);
173  }
174 
175  mZoomEnd = mZoomStart = 0;
176 
177  using namespace RefreshCode;
178  return RefreshAll | FixScrollbars;
179 }
void SetZoom(double pixelsPerSecond)
Definition: ViewInfo.cpp:94
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ViewInfo.cpp:49
double h
Definition: ViewInfo.h:47
wxRect mRect
Definition: ZoomHandle.h:63
bool IsDragZooming() const
Definition: ZoomHandle.cpp:211
int mZoomStart
Definition: ZoomHandle.h:62
int mZoomEnd
Definition: ZoomHandle.h:62
static double GetDefaultZoom()
Definition: ViewInfo.h:85
void ZoomBy(double multiplier)
Definition: ViewInfo.cpp:112
const ViewInfo & GetViewInfo() const
Definition: Project.h:207

Member Data Documentation

wxRect ZoomHandle::mRect {}
private

Definition at line 63 of file ZoomHandle.h.

int ZoomHandle::mZoomEnd {}
private

Definition at line 62 of file ZoomHandle.h.

Referenced by IsDragZooming().

int ZoomHandle::mZoomStart {}
private

Definition at line 62 of file ZoomHandle.h.

Referenced by IsDragZooming().


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