Audacity 3.2.0
ASlider.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ASlider.h
6
7 Dominic Mazzoni
8
9 This class is a custom slider.
10
11**********************************************************************/
12
13#ifndef __AUDACITY_SLIDER__
14#define __AUDACITY_SLIDER__
15
16#include <wx/setup.h> // for wxUSE_* macros
17#include <wx/defs.h>
18#include <wx/timer.h> // member variable
19#include "wxPanelWrapper.h" // to inherit
20
21class wxBitmap;
22class wxSize;
23class wxPoint;
24class wxTextCtrl;
25
26class Ruler;
27class TipWindow;
28
29//
30// Predefined slider types (mStyle)
31//
32#define FRAC_SLIDER 1 // 0.0...1.0
33#define DB_SLIDER 2 // -36...36 dB
34#define PAN_SLIDER 3 // -1.0...1.0
35#define SPEED_SLIDER 4 // 0.01 ..3.0
36
37#define VEL_SLIDER 5 // -50..50
38
39#define PERCENT_SLIDER 6 //0% .. 100%
40
41#define DB_MIN -36.0f
42#define DB_MAX 36.0f
43#define FRAC_MIN 0.0f
44#define FRAC_MAX 1.0f
45#define SPEED_MIN 0.01f
46#define SPEED_MAX 3.0f
47#define VEL_MIN -50.0f
48#define VEL_MAX 50.0f
49
50// Customizable slider only: If stepValue is STEP_CONTINUOUS,
51// every value on the slider between minValue and maxValue
52// will be possible
53//
54#define STEP_CONTINUOUS 0.0f
55
56//
57// Lightweight slider - i.e. a slider that doesn't appear in
58// its own window, but rather draws itself inside an existing
59// window (used inside Track Labels). The ASlider class,
60// which uses this class, is below.
61//
62
63class AUDACITY_DLL_API LWSlider
64{
65 friend class ASlider;
66 friend class ASliderAx;
67
68 public:
69
70 // MM: Construct customizable slider
71 LWSlider(wxWindow * parent,
73 const wxPoint &pos,
74 const wxSize &size,
75 float minValue,
76 float maxValue,
77 float stepValue,
78 bool canUseShift,
79 int style,
80 bool showlabels=true,
81 bool drawticks=true,
82 bool drawtrack=true,
83 bool alwayshidetip=false,
84 bool heavyweight=false,
85 bool popup=true,
86 int orientation = wxHORIZONTAL); // wxHORIZONTAL or wxVERTICAL. wxVERTICAL is currently only for DB_SLIDER.
87
88 // Construct predefined slider
89 LWSlider(wxWindow * parent,
91 const wxPoint &pos,
92 const wxSize &size,
93 int style,
94 bool showlabels=true,
95 bool drawticks=true,
96 bool drawtrack=true,
97 bool alwayshidetip=false,
98 bool heavyweight=false,
99 bool popup=true,
100 int orientation = wxHORIZONTAL); // wxHORIZONTAL or wxVERTICAL. wxVERTICAL is currently only for DB_SLIDER.
101
102 void Init(wxWindow * parent,
104 const wxPoint &pos,
105 const wxSize &size,
106 float minValue,
107 float maxValue,
108 float stepValue,
109 bool canUseShift,
110 int style,
111 bool showlabels,
112 bool drawticks,
113 bool drawtrack,
114 bool alwayshidetip,
115 bool heavyweight,
116 bool popup,
117 float speed,
118 int orientation = wxHORIZONTAL); // wxHORIZONTAL or wxVERTICAL. wxVERTICAL is currently only for DB_SLIDER.
119
120 virtual ~LWSlider();
121
122 wxWindowID GetId();
123 void SetId(wxWindowID id);
124
125 void SetName(const TranslatableString& name);
126
127 void SetDefaultValue(float value);
128 void SetDefaultShortcut(bool value);
129
130 void GetScroll(float & line, float & page);
131 void SetScroll(float line, float page);
132
133 void ShowTip(bool show);
134 void SetToolTipTemplate(const TranslatableString & tip);
135
136 float Get(bool convert = true);
137 void Set(float value);
138
139 void Increase(float steps);
140 void Decrease(float steps);
141
142 // If set to less than 1.0, moving the mouse one pixel will move
143 // the slider by less than 1 unit
144 void SetSpeed(float speed);
145
146 void Move(const wxPoint &newpos);
147
148 void AdjustSize(const wxSize & sz);
149
150 void OnPaint(wxDC &dc, bool highlighted);
151 void OnSize(wxSizeEvent & event);
152 void OnMouseEvent(wxMouseEvent & event);
153 void OnKeyDown(wxKeyEvent & event);
154 void Refresh();
155 void Redraw();
156
157 bool ShowDialog();
158 bool ShowDialog(wxPoint pos);
159
160 void SetEnabled(bool enabled);
161 bool GetEnabled() const;
162
163 float GetMinValue() const;
164 float GetMaxValue() const;
165
166 void SetParent(wxWindow *parent);
167 void SendUpdate(float newValue);
168
169 wxString GetStringValue() const;
170
171 void OnKillFocus();
172
173 private:
174
175 TranslatableString GetTip(float value) const;
176 TranslatableStrings GetWidestTips() const;
177 void FormatPopWin();
178 void SetPopWinPosition();
179 void CreatePopWin();
180 void DrawToBitmap(wxDC & dc);
181
182 bool DoShowDialog(wxPoint pos);
183
184
185 int ValueToPosition(float val);
186 float DragPositionToValue(int fromPos, bool shiftDown);
187 float ClickPositionToValue(int fromPos, bool shiftDown);
188
189 wxWindow *mParent;
190
192 int mOrientation; // wxHORIZONTAL or wxVERTICAL. wxVERTICAL is currently only for DB_SLIDER.
193
197
199
200 bool mHW; // is it really heavyweight (in a window)
201 bool mPopup; // should display dialog on double click
202
203 int mLeft;
204 int mTop;
205
206 int mWidth; //In pixels
207 int mHeight; //In pixels
208
209 // for (mOrientation == wxHORIZONTAL)
211
215
216 // for (mOrientation == wxVERTICAL) //v Vertical PAN_SLIDER currently not handled, forced to horizontal.
218
219 int mTopY;
220 int mBottomY; // low values at bottom
222
223
224 int mThumbWidth; //In pixels
225 int mThumbHeight; //In pixels
226
228 int mClickPos; // position in x if (mOrientation == wxHORIZONTAL), else in y
229
233 float mSpeed;
234
237
239
242
244
245 wxWindowID mID;
246
247 wxWeakRef<TipWindow> mTipPanel;
249
251
252 std::unique_ptr<wxBitmap> mBitmap, mThumbBitmap, mThumbBitmapHilited;
253
255
257};
258
259class AUDACITY_DLL_API ASlider /* not final */ : public wxPanel
260{
261 friend class ASliderAx;
262
263 public:
264 struct Options {
266
267 int style{ FRAC_SLIDER };
268 wxOrientation orientation{ wxHORIZONTAL };
269 bool showLabels{ true };
270 bool drawTicks{ true };
271 bool drawTrack{ true };
272 bool alwaysHideTip{ false };
273 bool popup{ true };
274 bool canUseShift{ true };
275 float stepValue{ STEP_CONTINUOUS };
276
277 float line{ 1.0 };
278 float page{ 5.0 };
279
280 Options& Style( int s ) { style = s; return *this; }
281 Options& Orientation( wxOrientation o )
282 { orientation = o; return *this; }
283 Options& ShowLabels( bool l ) { showLabels = l; return *this; }
284 Options& DrawTicks( bool t ) { drawTicks = t; return *this; }
285 Options& DrawTrack( bool t ) { drawTrack = t; return *this; }
286 Options& AlwayHideTip( bool t) { alwaysHideTip = t; return * this; }
287 Options& Popup( bool p ) { popup = p; return *this; }
288 Options& CanUseShift( bool c ) { canUseShift = c; return *this; }
289 Options& StepValue( float v ) { stepValue = v; return *this; }
290
291 Options& Line( float l ) { line = l; return *this; }
292 Options& Page( float p ) { page = p; return *this; }
293 };
294
295 ASlider( wxWindow * parent,
296 wxWindowID id,
298 const wxPoint & pos,
299 const wxSize & size,
300 const Options &options = Options{});
301 virtual ~ASlider();
302
303 bool AcceptsFocus() const override { return s_AcceptsFocus; }
304 bool AcceptsFocusFromKeyboard() const override { return true; }
305
306 void SetFocusFromKbd() override;
307
308 bool SetBackgroundColour(const wxColour& colour) override;
309
310 void GetScroll(float & line, float & page);
311 void SetScroll(float line, float page);
312
313 void SetToolTipTemplate(const TranslatableString & tip);
314
315 float Get( bool convert = true );
316 void Set(float value);
317
318 void Increase(float steps);
319 void Decrease(float steps);
320 bool ShowDialog(wxPoint pos = wxPoint(-1, -1));
321
322 void SetSpeed(float speed);
323
324 void OnErase(wxEraseEvent & event);
325 void OnPaint(wxPaintEvent & event);
326 void OnSize(wxSizeEvent & event);
327 void OnMouseEvent(wxMouseEvent & event);
328 void OnCaptureLost(wxMouseCaptureLostEvent & event);
329 void OnKeyDown(wxKeyEvent &event);
330 void OnSlider(wxCommandEvent &event);
331 void OnSetFocus(wxFocusEvent & event);
332 void OnKillFocus(wxFocusEvent & event);
333 void OnTimer(wxTimerEvent & event);
334
335 // Overrides of the wxWindow functions with the same semantics
336 bool Enable(bool enable = true) override;
337 bool IsEnabled() const;
338
339private:
340 static bool s_AcceptsFocus;
341 struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
342 using TempAllowFocus = std::unique_ptr<bool, Resetter>;
343
344public:
345 static TempAllowFocus TemporarilyAllowFocus();
346
347 private:
348 std::unique_ptr<LWSlider> mLWSlider;
350 wxTimer mTimer;
351
352 protected:
354
355 public:
356 DECLARE_EVENT_TABLE()
357};
358
359
360
361#define SLIDER_DIALOG_TEXTCTRL 100
362
363
364// This is a modal dialog that contains an ASlider
365// and a text-entry box which can be used to set the
366// value of a slider.
367class SliderDialog final : public wxDialogWrapper
368{
369 public:
370 SliderDialog(wxWindow * parent, wxWindowID id,
372 wxPoint position,
373 wxSize size,
374 int style,
375 float value,
376 float line,
377 float page,
378 LWSlider * pSlider=nullptr);
380
381 float Get();
382
383 private:
384 bool TransferDataToWindow() override;
385 bool TransferDataFromWindow() override;
386
387 void OnSlider(wxCommandEvent &event);
388 void OnTextChange(wxCommandEvent &event);
389
391 wxTextCtrl * mTextCtrl;
394 float mValue;
395
396 public:
397 DECLARE_EVENT_TABLE()
398};
399
400#endif
#define FRAC_SLIDER
Definition: ASlider.h:32
#define STEP_CONTINUOUS
Definition: ASlider.h:54
const TranslatableString name
Definition: Distortion.cpp:74
static const auto title
std::vector< TranslatableString > TranslatableStrings
static void OnSize(wxSizeEvent &evt)
Definition: VSTEffect.cpp:2537
ASlider is a custom slider, allowing for a slicker look and feel.
Definition: ASlider.h:260
bool AcceptsFocusFromKeyboard() const override
Definition: ASlider.h:304
int mStyle
Definition: ASlider.h:353
std::unique_ptr< LWSlider > mLWSlider
Definition: ASlider.h:348
bool AcceptsFocus() const override
Definition: ASlider.h:303
std::unique_ptr< bool, Resetter > TempAllowFocus
Definition: ASlider.h:342
static bool s_AcceptsFocus
Definition: ASlider.h:340
bool mSliderIsFocused
Definition: ASlider.h:349
wxTimer mTimer
Definition: ASlider.h:350
Lightweight version of ASlider. In other words it does not have a window permanently associated with ...
Definition: ASlider.h:64
float mCurrentValue
Definition: ASlider.h:238
int mCenterX
Definition: ASlider.h:217
float mDefaultValue
Definition: ASlider.h:241
int mLeft
Definition: ASlider.h:203
float mMinValue
Definition: ASlider.h:230
int mThumbWidth
Definition: ASlider.h:224
bool mCanUseShift
Definition: ASlider.h:243
float mClickValue
Definition: ASlider.h:227
bool mPopup
Definition: ASlider.h:201
int mHeightY
Definition: ASlider.h:221
bool mAlwaysHideTip
Definition: ASlider.h:198
float mMaxValue
Definition: ASlider.h:231
TranslatableString mTipTemplate
Definition: ASlider.h:248
bool mShowLabels
Definition: ASlider.h:194
int mTopY
Definition: ASlider.h:219
TranslatableString mName
Definition: ASlider.h:254
int mBottomY
Definition: ASlider.h:220
int mLeftX
Definition: ASlider.h:212
int mCenterY
Definition: ASlider.h:210
int mStyle
Definition: ASlider.h:191
int mHeight
Definition: ASlider.h:207
bool mEnabled
Definition: ASlider.h:256
wxWindow * mParent
Definition: ASlider.h:189
std::unique_ptr< wxBitmap > mBitmap
Definition: ASlider.h:252
wxWindowID mID
Definition: ASlider.h:245
bool mIsDragging
Definition: ASlider.h:250
int mRightX
Definition: ASlider.h:213
int mOrientation
Definition: ASlider.h:192
int mTop
Definition: ASlider.h:204
bool mDrawTicks
Definition: ASlider.h:195
float mSpeed
Definition: ASlider.h:233
bool mDefaultShortcut
Definition: ASlider.h:240
float mStepValue
Definition: ASlider.h:232
float mScrollPage
Definition: ASlider.h:236
float mScrollLine
Definition: ASlider.h:235
bool mHW
Definition: ASlider.h:200
int mWidth
Definition: ASlider.h:206
int mWidthX
Definition: ASlider.h:214
bool mDrawTrack
Definition: ASlider.h:196
int mThumbHeight
Definition: ASlider.h:225
wxWeakRef< TipWindow > mTipPanel
Definition: ASlider.h:247
int mClickPos
Definition: ASlider.h:228
Used to display a Ruler.
Definition: Ruler.h:26
Pop up dialog used with an LWSlider.
Definition: ASlider.h:368
bool TransferDataFromWindow() override
Definition: ASlider.cpp:353
float mValue
Definition: ASlider.h:394
LWSlider * mpOrigin
Definition: ASlider.h:393
int mStyle
Definition: ASlider.h:392
void OnSlider(wxCommandEvent &event)
Definition: ASlider.cpp:372
float Get()
Definition: ASlider.cpp:387
void OnTextChange(wxCommandEvent &event)
Definition: ASlider.cpp:378
SliderDialog(wxWindow *parent, wxWindowID id, const TranslatableString &title, wxPoint position, wxSize size, int style, float value, float line, float page, LWSlider *pSlider=nullptr)
Definition: ASlider.cpp:258
wxTextCtrl * mTextCtrl
Definition: ASlider.h:391
ASlider * mSlider
Definition: ASlider.h:390
bool TransferDataToWindow() override
Definition: ASlider.cpp:337
A wxPopupWindow used to give the numerical value of an LWSlider or ASlider.
Definition: ASlider.cpp:149
Holds a msgid for the translation catalog; may also bind format arguments.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:194
Options & Orientation(wxOrientation o)
Definition: ASlider.h:281
Options & DrawTrack(bool t)
Definition: ASlider.h:285
Options & Style(int s)
Definition: ASlider.h:280
Options & CanUseShift(bool c)
Definition: ASlider.h:288
Options & DrawTicks(bool t)
Definition: ASlider.h:284
Options & Page(float p)
Definition: ASlider.h:292
Options & Line(float l)
Definition: ASlider.h:291
Options & Popup(bool p)
Definition: ASlider.h:287
Options & AlwayHideTip(bool t)
Definition: ASlider.h:286
Options & ShowLabels(bool l)
Definition: ASlider.h:283
Options & StepValue(float v)
Definition: ASlider.h:289