forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASlider.cpp
More file actions
2016 lines (1702 loc) · 49.3 KB
/
Copy pathASlider.cpp
File metadata and controls
2016 lines (1702 loc) · 49.3 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
Audacity: A Digital Audio Editor
ASlider.cpp
Dominic Mazzoni
*******************************************************************//**
\class ASlider
\brief ASlider is a custom slider, allowing for a slicker look and
feel.
It allows you to use images for the slider background and
the thumb.
\class LWSlider
\brief Lightweight version of ASlider. In other words it does not
have a window permanently associated with it.
\class SliderDialog
\brief Pop up dialog used with an LWSlider.
\class TipWindow
\brief A wxPopupWindow used to give the numerical value of an LWSlider
or ASlider.
*//*******************************************************************/
#include "../Audacity.h"
#include "ASlider.h"
#include <math.h>
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/defs.h>
#include <wx/dcbuffer.h>
#include <wx/frame.h>
#include <wx/graphics.h>
#include <wx/image.h>
#include <wx/panel.h>
#include <wx/tooltip.h>
#include <wx/debug.h>
#include <wx/textctrl.h>
#include <wx/valtext.h>
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/statline.h>
#include <wx/sizer.h>
#include <wx/settings.h>
#include <wx/popupwin.h>
#include <wx/window.h>
#include "../AColor.h"
#include "../ImageManipulation.h"
#include "../Project.h"
#include "../ProjectStatus.h"
#include "../ProjectWindowBase.h"
#include "../ShuttleGui.h"
#include "../Theme.h"
#include "valnum.h"
#include "../AllThemeResources.h"
#if wxUSE_ACCESSIBILITY
#include "WindowAccessible.h"
class ASliderAx final : public WindowAccessible
{
public:
ASliderAx(wxWindow * window);
virtual ~ ASliderAx();
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
wxAccStatus GetChild(int childId, wxAccessible** child) override;
// Gets the number of children.
wxAccStatus GetChildCount(int* childCount) override;
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
wxAccStatus GetDefaultAction(int childId, wxString *actionName) override;
// Returns the description for this object or a child.
wxAccStatus GetDescription(int childId, wxString *description) override;
// Gets the window with the keyboard focus.
// If childId is 0 and child is NULL, no object in
// this subhierarchy has the focus.
// If this object has the focus, child should be 'this'.
wxAccStatus GetFocus(int *childId, wxAccessible **child) override;
// Returns help text for this object or a child, similar to tooltip text.
wxAccStatus GetHelpText(int childId, wxString *helpText) override;
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut) override;
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
wxAccStatus GetLocation(wxRect& rect, int elementId) override;
// Gets the name of the specified object.
wxAccStatus GetName(int childId, wxString *name) override;
// Returns a role constant.
wxAccStatus GetRole(int childId, wxAccRole *role) override;
// Gets a variant representing the selected children
// of this object.
// Acceptable values:
// - a null variant (IsNull() returns TRUE)
// - a list variant (GetType() == wxT("list"))
// - an integer representing the selected child element,
// or 0 if this object is selected (GetType() == wxT("long"))
// - a "void*" pointer to a wxAccessible child object
wxAccStatus GetSelections(wxVariant *selections) override;
// Returns a state constant.
wxAccStatus GetState(int childId, long* state) override;
// Returns a localized string representing the value for the object
// or child.
wxAccStatus GetValue(int childId, wxString* strValue) override;
};
#endif // wxUSE_ACCESSIBILITY
#if defined __WXMSW__
const int sliderFontSize = 10;
#else
const int sliderFontSize = 12;
#endif
#ifndef EXPERIMENTAL_DA
#define OPTIONAL_SLIDER_TICKS
#endif
//
// TipWindow
//
class TipWindow final : public wxFrame
{
public:
TipWindow(wxWindow *parent, const TranslatableStrings & labels);
virtual ~TipWindow() {}
wxSize GetSize() const;
void SetPos(const wxPoint & pos);
void SetLabel(const TranslatableString & label);
private:
void OnPaint(wxPaintEvent & event);
private:
TranslatableString mLabel;
int mWidth;
int mHeight;
wxFont mFont;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(TipWindow, wxFrame)
EVT_PAINT(TipWindow::OnPaint)
END_EVENT_TABLE()
TipWindow::TipWindow(wxWindow *parent, const TranslatableStrings & labels)
: wxFrame(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxFRAME_SHAPED | wxNO_BORDER | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT )
{
SetBackgroundStyle(wxBG_STYLE_PAINT);
SetBackgroundColour(wxTransparentColour);
mFont.SetPointSize(sliderFontSize);
mFont.SetFamily(wxFONTFAMILY_SWISS);
mFont.SetStyle(wxFONTSTYLE_NORMAL);
mFont.SetWeight(wxFONTWEIGHT_NORMAL);
mWidth = mHeight = 0;
for ( const auto &label : labels ) {
int width, height;
GetTextExtent(label.Translation(), &width, &height, NULL, NULL, &mFont);
mWidth = std::max( mWidth, width );
mHeight = std::max( mHeight, height );
}
// Pad to allow for curved corners
mWidth += 8;
mHeight += 8;
#if defined(__WXMAC__)
// Use a bitmap region to set the shape since just adding an unfilled path
// will make the window transparent
wxBitmap shape(mWidth, mHeight);
wxMemoryDC dc(shape);
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxBLACK_BRUSH);
dc.DrawRoundedRectangle(0, 0, mWidth, mHeight, 5);
dc.SelectObject(wxNullBitmap);
SetShape(wxRegion(shape, *wxWHITE));
#else
wxGraphicsPath path = wxGraphicsRenderer::GetDefaultRenderer()->CreatePath();
path.AddRoundedRectangle(0, 0, mWidth, mHeight, 5);
SetShape(path);
#endif
}
wxSize TipWindow::GetSize() const
{
return wxSize(mWidth, mHeight);
}
void TipWindow::SetPos(const wxPoint & pos)
{
SetSize(pos.x, pos.y, mWidth, mHeight);
}
void TipWindow::SetLabel(const TranslatableString & label)
{
mLabel = label;
}
void TipWindow::OnPaint(wxPaintEvent & WXUNUSED(event))
{
wxAutoBufferedPaintDC dc(this);
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(AColor::tooltipBrush);
dc.DrawRoundedRectangle(0, 0, mWidth, mHeight, 5);
dc.SetFont(mFont);
dc.SetTextForeground(AColor::tooltipPen.GetColour());
int textWidth, textHeight;
const auto visibleLabel = mLabel.Translation();
dc.GetTextExtent(visibleLabel, &textWidth, &textHeight);
dc.DrawText(visibleLabel, (mWidth - textWidth) / 2, (mHeight - textHeight) / 2);
}
//
// SliderDialog
//
BEGIN_EVENT_TABLE(SliderDialog, wxDialogWrapper)
EVT_TEXT( wxID_ANY, SliderDialog::OnTextChange )
EVT_SLIDER(wxID_ANY,SliderDialog::OnSlider)
END_EVENT_TABLE();
SliderDialog::SliderDialog(wxWindow * parent, wxWindowID id,
const TranslatableString & title,
wxPoint position,
wxSize size,
int style,
float value,
float line,
float page,
LWSlider * pSource):
wxDialogWrapper(parent,id,title,position),
mStyle(style)
{
SetName();
mpOrigin = pSource;
mValue = mpOrigin->Get(false);
auto prec = 2;
auto trailing = NumValidatorStyle::TWO_TRAILING_ZEROES;
if (style == DB_SLIDER)
{
prec = 1;
trailing = NumValidatorStyle::ONE_TRAILING_ZERO;
}
ShuttleGui S(this, eIsCreating);
S.StartVerticalLay();
{
if (style == PAN_SLIDER)
{
mTextCtrl = S
.Validator<IntegerValidator<float>>(
&mValue, NumValidatorStyle::DEFAULT, -100.0, 100.0)
.AddTextBox({}, wxEmptyString, 15);
}
else if (style == VEL_SLIDER)
{
mTextCtrl = S
.Validator<IntegerValidator<float>>(
&mValue, NumValidatorStyle::DEFAULT, -50.0, 50.0)
.AddTextBox({}, wxEmptyString, 15);
}
else
{
mTextCtrl = S
.Validator<FloatingPointValidator<float>>(
prec, &mValue, trailing, mpOrigin->GetMinValue(), mpOrigin->GetMaxValue())
.AddTextBox({}, wxEmptyString, 15);
}
mSlider = safenew ASlider(S.GetParent(),
wxID_ANY,
title,
wxDefaultPosition,
size,
ASlider::Options{}
.Style( style ).Line( line ).Page( page ).Popup( false) );
S.Position(wxEXPAND)
.AddWindow(mSlider);
}
S.EndVerticalLay();
S.AddStandardButtons(eOkButton | eCancelButton);
Fit();
mSlider->Set(value);
}
SliderDialog::~SliderDialog()
{
}
bool SliderDialog::TransferDataToWindow()
{
float value = mSlider->Get(false);
mValue = mStyle == PAN_SLIDER
? value * 100.0
: value;
mTextCtrl->GetValidator()->TransferToWindow();
mTextCtrl->SetSelection(-1, -1);
if (mpOrigin) {
mpOrigin->Set(value);
mpOrigin->SendUpdate(value);
}
return true;
}
bool SliderDialog::TransferDataFromWindow()
{
if (mTextCtrl->GetValidator()->TransferFromWindow())
{
float value = mValue;
if (mStyle == DB_SLIDER)
value = DB_TO_LINEAR(value);
else if (mStyle == PAN_SLIDER)
value /= 100.0;
mSlider->Set(value);
if (mpOrigin) {
mpOrigin->Set(value);
mpOrigin->SendUpdate(value);
}
}
return true;
}
void SliderDialog::OnSlider(wxCommandEvent & event)
{
TransferDataToWindow();
event.Skip(false);
}
void SliderDialog::OnTextChange(wxCommandEvent & event)
{
if (mTextCtrl->GetValidator()->TransferFromWindow())
{
TransferDataFromWindow();
}
event.Skip(false);
}
float SliderDialog::Get()
{
return mSlider->Get(false);
}
//
// LWSlider
//
// Define the thumb outline
static const wxPoint2DDouble outer[] =
{
wxPoint2DDouble( 2, 0 ),
wxPoint2DDouble( 8, 0 ),
wxPoint2DDouble( 10, 2 ),
wxPoint2DDouble( 10, 8 ),
wxPoint2DDouble( 5, 13 ),
wxPoint2DDouble( 0, 8 ),
wxPoint2DDouble( 0, 2 ),
wxPoint2DDouble( 2, 0 )
};
// Define the left and top interior components when enabled
static const wxPoint2DDouble enabledLeftBegin[] =
{
wxPoint2DDouble( 2, 1 ),
wxPoint2DDouble( 1, 2 ),
wxPoint2DDouble( 1, 8 ),
wxPoint2DDouble( 4, 4 ),
wxPoint2DDouble( 4, 7 )
};
static const wxPoint2DDouble enabledLeftEnd[] =
{
wxPoint2DDouble( 8, 1 ),
wxPoint2DDouble( 1, 8 ),
wxPoint2DDouble( 5, 12 ),
wxPoint2DDouble( 6, 4 ),
wxPoint2DDouble( 6, 7 )
};
// Define right and bottom interior components when enabled
static const wxPoint2DDouble enabledRightBegin[] =
{
wxPoint2DDouble( 9, 2 ),
wxPoint2DDouble( 9, 8 ),
wxPoint2DDouble( 4, 5 ),
wxPoint2DDouble( 4, 8 ),
};
static const wxPoint2DDouble enabledRightEnd[] =
{
wxPoint2DDouble( 9, 8 ),
wxPoint2DDouble( 6, 11 ),
wxPoint2DDouble( 6, 5 ),
wxPoint2DDouble( 6, 8 )
};
// Define the interior stripes when disabled
static const wxPoint2DDouble disabledStripesBegin[] =
{
wxPoint2DDouble( 3, 2 ),
wxPoint2DDouble( 5, 2 ),
wxPoint2DDouble( 7, 2 ),
wxPoint2DDouble( 2, 3 ),
wxPoint2DDouble( 2, 5 ),
wxPoint2DDouble( 2, 7 ),
};
static const wxPoint2DDouble disabledStripesEnd[] =
{
wxPoint2DDouble( 8, 7 ),
wxPoint2DDouble( 8, 5 ),
wxPoint2DDouble( 8, 3 ),
wxPoint2DDouble( 7, 8 ),
wxPoint2DDouble( 6, 9 ),
wxPoint2DDouble( 5, 10 ),
};
// Define the right and bottom interior components when disabled
static const wxPoint2DDouble disabledRightBegin[] =
{
wxPoint2DDouble( 9, 2 ),
wxPoint2DDouble( 9, 8 ),
};
static const wxPoint2DDouble disabledRightEnd[] =
{
wxPoint2DDouble( 9, 8 ),
wxPoint2DDouble( 6, 11 ),
};
// Construct customizable slider
LWSlider::LWSlider(wxWindow * parent,
const TranslatableString &name,
const wxPoint &pos,
const wxSize &size,
float minValue,
float maxValue,
float stepValue,
bool canUseShift,
int style,
bool heavyweight /* = false */,
bool popup /* = true */,
int orientation /* = wxHORIZONTAL */) // wxHORIZONTAL or wxVERTICAL. wxVERTICAL is currently only for DB_SLIDER.
{
Init(parent, name, pos, size, minValue, maxValue,
stepValue, canUseShift, style, heavyweight, popup, 1.0, orientation);
}
// Construct predefined slider
LWSlider::LWSlider(wxWindow *parent,
const TranslatableString &name,
const wxPoint &pos,
const wxSize &size,
int style,
bool heavyweight /* = false */,
bool popup /* = true */,
int orientation /* = wxHORIZONTAL */) // wxHORIZONTAL or wxVERTICAL. wxVERTICAL is currently only for DB_SLIDER.
{
wxString leftLabel, rightLabel;
float minValue, maxValue, stepValue;
float speed = 1.0;
switch(style)
{
case PAN_SLIDER:
minValue = -1.0f;
maxValue = +1.0f;
stepValue = 0.1f;
orientation = wxHORIZONTAL; //v Vertical PAN_SLIDER currently not handled, forced to horizontal.
break;
case DB_SLIDER:
minValue = -36.0f;
//if (orientation == wxHORIZONTAL)
maxValue = 36.0f;
//else
//maxValue = 36.0f; // for MixerBoard //v Previously was 6dB for MixerBoard, but identical for now.
stepValue = 1.0f;
speed = 0.5;
break;
case FRAC_SLIDER:
minValue = 0.0f;
maxValue = 1.0f;
stepValue = STEP_CONTINUOUS;
break;
case SPEED_SLIDER:
minValue = 0.01f;
maxValue = 3.0f;
stepValue = STEP_CONTINUOUS;
break;
#ifdef EXPERIMENTAL_MIDI_OUT
case VEL_SLIDER:
minValue = VEL_MIN;
maxValue = VEL_MAX;
stepValue = 1.0f;
speed = 0.5;
break;
#endif
default:
minValue = 0.0f;
maxValue = 1.0f;
stepValue = 0.0f;
wxASSERT(false); // undefined style
}
Init(parent, name, pos, size, minValue, maxValue, stepValue,
true, style, heavyweight, popup, speed, orientation);
}
void LWSlider::Init(wxWindow * parent,
const TranslatableString &name,
const wxPoint &pos,
const wxSize &size,
float minValue,
float maxValue,
float stepValue,
bool canUseShift,
int style,
bool heavyweight,
bool popup,
float speed,
int orientation /* = wxHORIZONTAL */) // wxHORIZONTAL or wxVERTICAL. wxVERTICAL is currently only for DB_SLIDER.
{
mEnabled = true;
mName = name;
mStyle = style;
mOrientation = orientation;
mIsDragging = false;
mParent = parent;
mHW = heavyweight;
mPopup = popup;
mSpeed = speed;
mID = wxID_ANY;
mMinValue = minValue;
mMaxValue = maxValue;
mStepValue = stepValue;
mCanUseShift = canUseShift;
mCurrentValue = 0.0f;
mDefaultValue = 0.0f;
mDefaultShortcut = false;
mBitmap = nullptr;
mThumbBitmap = nullptr;
mThumbBitmapHilited = nullptr;
mScrollLine = 1.0f;
mScrollPage = 5.0f;
mTipPanel = NULL;
AdjustSize(size);
Move(pos);
}
LWSlider::~LWSlider()
{
}
wxWindowID LWSlider::GetId()
{
return mID;
}
void LWSlider::SetId(wxWindowID id)
{
mID = id;
}
void LWSlider::SetDefaultValue(float value)
{
SetDefaultShortcut(true);
mDefaultValue = value;
}
void LWSlider::SetDefaultShortcut(bool value)
{
mDefaultShortcut = value;
}
void LWSlider::GetScroll(float & line, float & page)
{
line = mScrollLine;
page = mScrollPage;
}
void LWSlider::SetScroll(float line, float page)
{
mScrollLine = line;
mScrollPage = page;
}
void LWSlider::Move(const wxPoint &newpos)
{
mLeft = newpos.x;
mTop = newpos.y;
}
void LWSlider::AdjustSize(const wxSize & sz)
{
mWidth = sz.GetWidth();
mHeight = sz.GetHeight();
if( mBitmap ){
mBitmap.reset();
}
mThumbWidth = 11;
mThumbHeight = 20;
if (mOrientation == wxHORIZONTAL)
{
mCenterY = mHeight - 9;
}
else
{
mCenterX = mWidth - 9;
}
if (mOrientation == wxHORIZONTAL)
{
mLeftX = mThumbWidth/2;
mRightX = mWidth - mThumbWidth/2 - 1;
mWidthX = mRightX - mLeftX;
}
else
{
mTopY = mThumbWidth/2;
mBottomY = mHeight - mThumbWidth/2 - 1;
mHeightY = mBottomY - mTopY;
}
Refresh();
}
void LWSlider::OnPaint(wxDC &dc, bool highlight)
{
// The dc will be a paint DC
if (!mBitmap || !mThumbBitmap || !mThumbBitmapHilited)
{
DrawToBitmap(dc);
}
//thumbPos should be in pixels
int thumbPos = ValueToPosition(mCurrentValue);
int thumbOrtho; // position in axis orthogonal to mOrientation
if (mOrientation == wxHORIZONTAL){
thumbOrtho = mCenterY - (mThumbHeight/2);
thumbPos += 1-mThumbWidth/2;
}
else{
thumbOrtho = mCenterX - (mThumbWidth/2);
thumbPos += 8-mThumbHeight/2;
}
// Draw the background.
// If we are lightweight, this has already been done for us.
if( mHW ){
dc.SetBackground( *wxTRANSPARENT_BRUSH );
dc.Clear();
}
dc.DrawBitmap(*mBitmap, mLeft, mTop, true);
const auto &thumbBitmap =
highlight ? *mThumbBitmapHilited : *mThumbBitmap;
if (mOrientation == wxHORIZONTAL)
{
dc.DrawBitmap(thumbBitmap, mLeft+thumbPos, mTop+thumbOrtho, true);
}
else
{
// TODO: Don't use pixel-count hack in positioning.
dc.DrawBitmap(thumbBitmap, mLeft+thumbOrtho-5, mTop+thumbPos, true);
}
if (mTipPanel)
{
mTipPanel->Update();
}
}
void LWSlider::OnSize( wxSizeEvent & event )
{
AdjustSize(event.GetSize());
Refresh();
}
// This function only uses the paintDC to determine what kind of bitmap
// to draw to and nothing else. It does not draw to the paintDC.
void LWSlider::DrawToBitmap(wxDC & paintDC)
{
// Get correctly oriented thumb.
if (mOrientation == wxVERTICAL){
mThumbBitmap = std::make_unique<wxBitmap>(wxBitmap( theTheme.Bitmap( bmpSliderThumbRotated )));
mThumbBitmapHilited = std::make_unique<wxBitmap>(wxBitmap( theTheme.Bitmap( bmpSliderThumbRotatedHilited )));
}
else {
mThumbBitmap = std::make_unique<wxBitmap>(wxBitmap( theTheme.Bitmap( bmpSliderThumb )));
mThumbBitmapHilited = std::make_unique<wxBitmap>(wxBitmap( theTheme.Bitmap( bmpSliderThumbHilited )));
}
// Now the background bitmap
mBitmap = std::make_unique<wxBitmap>();
mBitmap->Create(mWidth, mHeight, paintDC);
#if defined(__WXMAC__)
mBitmap->UseAlpha();
#endif
// Set up the memory DC
// We draw to it, not the paintDC.
wxMemoryDC dc;
dc.SelectObject(*mBitmap);
dc.SetBackground(wxBrush(mParent->GetBackgroundColour()));
dc.Clear();
// Draw the line along which the thumb moves.
AColor::UseThemeColour(&dc, clrSliderMain );
if (mOrientation == wxHORIZONTAL)
{
AColor::Line(dc, mLeftX, mCenterY, mRightX+2, mCenterY);
AColor::Line(dc, mLeftX, mCenterY+1, mRightX+2, mCenterY+1);
}
else
{
AColor::Line(dc, mCenterX, mTopY, mCenterX, mBottomY+2);
AColor::Line(dc, mCenterX+1, mTopY, mCenterX+1, mBottomY+2);
}
// Draw +/- or L/R first. We need to draw these before the tick marks.
if (mStyle == PAN_SLIDER)
{
//VJ Vertical PAN_SLIDER currently not handled, forced to horizontal.
// sliderFontSize is for the tooltip.
// we need something smaller here...
wxFont labelFont(7, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
dc.SetFont(labelFont);
// Color
dc.SetTextForeground( theTheme.Colour( clrTrackPanelText ));
/* i18n-hint: One-letter abbreviation for Left, in the Pan slider */
dc.DrawText(_("L"), mLeftX, 0);
/* i18n-hint: One-letter abbreviation for Right, in the Pan slider */
dc.DrawText(_("R"), mRightX - dc.GetTextExtent(_("R")).GetWidth(), 0);
}
else
{
// draw the '-' and the '+'
// These are drawn with lines, rather tha nwith a font.
AColor::UseThemeColour(&dc, clrTrackPanelText );
if (mOrientation == wxHORIZONTAL)
{
AColor::Line(dc, mLeftX, mCenterY-10, mLeftX+4, mCenterY-10);
AColor::Line(dc, mRightX-5, mCenterY-10, mRightX-1, mCenterY-10);
AColor::Line(dc, mRightX-3, mCenterY-12, mRightX-3, mCenterY-8);
}
else
{
// Vertical DB_SLIDER is for gain slider in MixerBoard.
// We use a Ruler instead of marks & ticks.
// Draw '+' and '-' only for other vertical sliders.
if (mStyle != DB_SLIDER)
{
AColor::Line(dc, mCenterX-12, mBottomY-3, mCenterX-8, mBottomY-3);
AColor::Line(dc, mCenterX-12, mTopY+3, mCenterX-8, mTopY+3);
AColor::Line(dc, mCenterX-10, mTopY, mCenterX-10, mTopY+5);
}
}
}
// Use special colour to indicate no ticks.
wxColour TickColour = theTheme.Colour( clrSliderLight );
bool bTicks = TickColour != wxColour(60,60,60);
if( bTicks ) {
// tick marks
int divs = 10;
double upp;
if (mOrientation == wxHORIZONTAL)
{
// Bug #2446 - A bit of a hack, but it should suffice.
divs = (mWidth - 1) / 10;
upp = divs / (double)(mWidthX-1);
}
else
{
if (mStyle == DB_SLIDER)
divs = mMaxValue - mMinValue + 1;
upp = divs / (double)(mHeightY-1);
}
#ifdef OPTIONAL_SLIDER_TICKS
double d = 0.0;
int int_d = -1;
const int kMax = (mOrientation == wxHORIZONTAL) ? mWidthX : mHeightY;
for(int p = 0; p <= kMax; p++)
{
if (((int)d) > int_d)
{
int_d = (int)d;
int tickLength = ((int_d == 0) || (int_d == divs)) ? 5: 3; // longer ticks at extremes
AColor::UseThemeColour(&dc, clrSliderLight );
if (mOrientation == wxHORIZONTAL)
{
AColor::Line(dc, mLeftX+p, mCenterY-tickLength, mLeftX+p, mCenterY-1); // ticks above
}
else
{
AColor::Line(dc, mCenterX-tickLength, mTopY+p, mCenterX-1, mTopY+p); // ticks at left
}
AColor::UseThemeColour(&dc, clrSliderDark );
if (mOrientation == wxHORIZONTAL)
{
AColor::Line(dc, mLeftX+p+1, mCenterY-tickLength+1, mLeftX+p+1, mCenterY-1); // ticks above
}
else
{
AColor::Line(dc, mCenterX-tickLength+1, mTopY+p+1, mCenterX-1, mTopY+p+1); // ticks at left
}
}
d += upp;
}
#endif
}
dc.SelectObject(wxNullBitmap);
// safenew, because SetMask takes ownership
// We always mask. If we are HeavyWeight, the ASlider draws the
// background.
if( !mHW )
{
mBitmap->SetMask(safenew wxMask(*mBitmap, dc.GetBackground().GetColour()));
}
}
void LWSlider::SetToolTipTemplate(const TranslatableString & tip)
{
mTipTemplate = tip;
}
void LWSlider::ShowTip(bool show)
{
if (show)
{
if (mTipPanel)
{
if (mTipPanel->IsShownOnScreen())
{
return;
}
mTipPanel.reset();
}
CreatePopWin();
FormatPopWin();
SetPopWinPosition();
mTipPanel->ShowWithoutActivating();
}
else
{
if (mTipPanel)
{
mTipPanel->Hide();
mTipPanel.reset();
}
}
}
void LWSlider::CreatePopWin()
{
mTipPanel = std::make_unique<TipWindow>(mParent, GetWidestTips());
}
void LWSlider::SetPopWinPosition()
{
if (mTipPanel)
{
wxSize sz = mTipPanel->GetSize();
wxPoint pt;
if (mOrientation == wxHORIZONTAL)
{
pt.x = mLeft + ((mWidth - sz.x) / 2);
pt.y = mTop + mHeight + 1;
}
else
{
pt.x = mLeft + mWidth + 1;
pt.y = mTop + ((mHeight - sz.y) / 2);
}
mTipPanel->SetPos(mParent->ClientToScreen(pt));
}
}
void LWSlider::FormatPopWin()
{
if (!mTipPanel)
{
return;
}
mTipPanel->SetLabel(GetTip(mCurrentValue));
mTipPanel->Refresh();
}
TranslatableString LWSlider::GetTip(float value) const
{
TranslatableString label;
if (mTipTemplate.empty())
{
TranslatableString val;
switch(mStyle)
{
case FRAC_SLIDER:
val = Verbatim("%.2f").Format( value );
break;
case DB_SLIDER:
/* i18n-hint dB abbreviates decibels */
val = XO("%+.1f dB").Format( value );
break;
case PAN_SLIDER:
if (value == 0.0)
{
val = XO("Center");
}
else
{
const auto v = 100.0f * fabsf(value);
if (value < 0.0)
/* i18n-hint: Stereo pan setting */
val = XO("%.0f%% Left").Format( v );
else
/* i18n-hint: Stereo pan setting */
val = XO("%.0f%% Right").Format( v );
}
break;
case SPEED_SLIDER:
/* i18n-hint: "x" suggests a multiplicative factor */
val = XO("%.2fx").Format( value );
break;
#ifdef EXPERIMENTAL_MIDI_OUT
case VEL_SLIDER:
if (value > 0.0f)
// Signed