forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdornedRulerPanel.h
237 lines (176 loc) · 6.35 KB
/
AdornedRulerPanel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**********************************************************************
Sneedacity: A Digital Audio Editor
AdornedRulerPanel.h
Dominic Mazzoni
**********************************************************************/
#ifndef __SNEEDACITY_ADORNED_RULER_PANEL__
#define __SNEEDACITY_ADORNED_RULER_PANEL__
#include "CellularPanel.h"
#include "widgets/Ruler.h" // member variable
#include "Prefs.h"
#include "ViewInfo.h" // for PlayRegion
class SneedacityProject;
struct SelectedRegionEvent;
class SnapManager;
class TrackList;
// This is an Sneedacity Specific ruler panel.
class SNEEDACITY_DLL_API AdornedRulerPanel final
: public CellularPanel
, private PrefsListener
{
public:
static AdornedRulerPanel &Get( SneedacityProject &project );
static const AdornedRulerPanel &Get( const SneedacityProject &project );
static void Destroy( SneedacityProject &project );
AdornedRulerPanel(SneedacityProject *project,
wxWindow* parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
ViewInfo *viewinfo = NULL);
~AdornedRulerPanel();
void Refresh
(bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
override;
bool AcceptsFocus() const override { return s_AcceptsFocus; }
bool AcceptsFocusFromKeyboard() const override { return true; }
void SetFocusFromKbd() override;
public:
int GetRulerHeight() { return GetRulerHeight( ShowingScrubRuler() ); }
static int GetRulerHeight(bool showScrubBar);
wxRect GetInnerRect() const { return mInner; }
void SetLeftOffset(int offset);
void DrawSelection();
void SetPlayRegion(double playRegionStart, double playRegionEnd);
void ClearPlayRegion();
void LockPlayRegion();
void UnlockPlayRegion();
void TogglePinnedHead();
void GetMaxSize(wxCoord *width, wxCoord *height);
void InvalidateRuler();
void UpdatePrefs() override;
void ReCreateButtons();
void UpdateQuickPlayPos(wxCoord &mousePosX, bool shiftDown);
bool ShowingScrubRuler() const;
//void OnToggleScrubRulerFromMenu(wxCommandEvent& );
bool SetPanelSize();
void DrawBothOverlays();
private:
void DoIdle();
void OnIdle( wxIdleEvent &evt );
void OnAudioStartStop(wxCommandEvent & evt);
void OnPaint(wxPaintEvent &evt);
void OnSize(wxSizeEvent &evt);
void OnThemeChange(wxCommandEvent& evt);
void OnSelectionChange(SelectedRegionEvent& evt);
void DoSelectionChange( const SelectedRegion &selectedRegion );
bool UpdateRects();
void HandleQPClick(wxMouseEvent &event, wxCoord mousePosX);
void HandleQPDrag(wxMouseEvent &event, wxCoord mousePosX);
void HandleQPRelease(wxMouseEvent &event);
void StartQPPlay(bool looped, bool cutPreview);
void DoDrawBackground(wxDC * dc);
void DoDrawEdge(wxDC *dc);
void DoDrawMarks(wxDC * dc, bool /*text */ );
void DoDrawSelection(wxDC * dc);
public:
std::pair< wxPoint, wxBitmap >
GetIndicatorBitmap(wxCoord xx, bool playing) const;
void DoDrawIndicator(wxDC * dc, wxCoord xx, bool playing, int width, bool scrub, bool seek);
void UpdateButtonStates();
private:
static bool s_AcceptsFocus;
struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
using TempAllowFocus = std::unique_ptr<bool, Resetter>;
public:
static TempAllowFocus TemporarilyAllowFocus();
private:
void DoDrawPlayRegion(wxDC * dc);
enum class MenuChoice { QuickPlay, Scrub };
void ShowContextMenu( MenuChoice choice, const wxPoint *pPosition);
double Pos2Time(int p, bool ignoreFisheye = false);
int Time2Pos(double t, bool ignoreFisheye = false);
bool IsWithinMarker(int mousePosX, double markerTime);
private:
Ruler mRuler;
SneedacityProject *const mProject;
TrackList *mTracks;
wxRect mOuter;
wxRect mScrubZone;
wxRect mInner;
int mLeftOffset; // Number of pixels before we hit the 'zero position'.
double mIndTime;
double mQuickPlayPosUnsnapped;
double mQuickPlayPos;
bool mIsSnapped;
PlayRegion mOldPlayRegion;
bool mIsRecording;
//
// Pop-up menu
//
void ShowMenu(const wxPoint & pos);
void ShowScrubMenu(const wxPoint & pos);
void DragSelection();
void HandleSnapping();
void OnToggleQuickPlay(wxCommandEvent &evt);
void OnSyncSelToQuickPlay(wxCommandEvent &evt);
//void OnTimelineToolTips(wxCommandEvent &evt);
void OnAutoScroll(wxCommandEvent &evt);
void OnLockPlayRegion(wxCommandEvent &evt);
void OnPinnedButton(wxCommandEvent & event);
void OnTogglePinnedState(wxCommandEvent & event);
bool mPlayRegionDragsSelection;
bool mTimelineToolTip;
bool mQuickPlayEnabled;
enum MouseEventState {
mesNone,
mesDraggingPlayRegionStart,
mesDraggingPlayRegionEnd,
mesSelectingPlayRegionClick,
mesSelectingPlayRegionRange
};
MouseEventState mMouseEventState;
double mLeftDownClickUnsnapped; // click position in seconds, before snap
double mLeftDownClick; // click position in seconds
bool mIsDragging;
DECLARE_EVENT_TABLE()
wxWindow *mButtons[3];
bool mNeedButtonUpdate { true };
//
// CellularPanel implementation
//
// Get the root object defining a recursive subdivision of the panel's
// area into cells
std::shared_ptr<TrackPanelNode> Root() override;
public:
SneedacityProject * GetProject() const override;
private:
TrackPanelCell *GetFocusedCell() override;
void SetFocusedCell() override;
void ProcessUIHandleResult
(TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
unsigned refreshResult) override;
void UpdateStatusMessage( const TranslatableString & ) override;
void CreateOverlays();
// Cooperating objects
class QuickPlayIndicatorOverlay;
std::shared_ptr<QuickPlayIndicatorOverlay> mOverlay;
class QuickPlayRulerOverlay;
private:
class CommonRulerHandle;
class QPHandle;
class ScrubbingHandle;
class CommonCell;
class QPCell;
std::shared_ptr<QPCell> mQPCell;
class ScrubbingCell;
std::shared_ptr<ScrubbingCell> mScrubbingCell;
// classes implementing subdivision for CellularPanel
struct Subgroup;
struct MainGroup;
SelectedRegion mLastDrawnSelectedRegion;
double mLastDrawnH{};
double mLastDrawnZoom{};
bool mDirtySelectedRegion{};
};
#endif //define __SNEEDACITY_ADORNED_RULER_PANEL__