39#include <wx/dcbuffer.h>
41#include <wx/graphics.h>
43#include <wx/tooltip.h>
45#include <wx/textctrl.h>
46#include <wx/valtext.h>
47#include <wx/statline.h>
48#include <wx/settings.h>
49#include <wx/popupwin.h>
56#include "../ProjectWindowBase.h"
63#if wxUSE_ACCESSIBILITY
69 ASliderAx(wxWindow * window);
71 virtual ~ ASliderAx();
75 wxAccStatus GetChild(
int childId, wxAccessible** child)
override;
78 wxAccStatus GetChildCount(
int* childCount)
override;
86 wxAccStatus GetDefaultAction(
int childId, wxString *actionName)
override;
89 wxAccStatus GetDescription(
int childId, wxString *description)
override;
95 wxAccStatus GetFocus(
int *childId, wxAccessible **child)
override;
98 wxAccStatus GetHelpText(
int childId, wxString *helpText)
override;
102 wxAccStatus GetKeyboardShortcut(
int childId, wxString *shortcut)
override;
106 wxAccStatus GetLocation(wxRect& rect,
int elementId)
override;
109 wxAccStatus GetName(
int childId, wxString *
name)
override;
112 wxAccStatus GetRole(
int childId, wxAccRole *role)
override;
122 wxAccStatus GetSelections(wxVariant *selections)
override;
125 wxAccStatus GetState(
int childId,
long* state)
override;
129 wxAccStatus GetValue(
int childId, wxString* strValue)
override;
140#define OPTIONAL_SLIDER_TICKS
153 void SetPos(
const wxPoint & pos);
157 void OnPaint(wxPaintEvent & event);
165 DECLARE_EVENT_TABLE()
173: wxFrame(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
174 wxFRAME_SHAPED | wxNO_BORDER | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT )
176 SetBackgroundStyle(wxBG_STYLE_PAINT);
177 SetBackgroundColour(wxTransparentColour);
180 mFont.SetFamily(wxFONTFAMILY_SWISS);
181 mFont.SetStyle(wxFONTSTYLE_NORMAL);
182 mFont.SetWeight(wxFONTWEIGHT_NORMAL);
184 mWidth = mHeight = 0;
185 for (
const auto &
label : labels ) {
188 mWidth = std::max( mWidth, width );
189 mHeight = std::max( mHeight, height );
196#if defined(__WXMAC__)
199 wxBitmap shape(mWidth, mHeight);
200 wxMemoryDC dc(shape);
202 dc.SetPen(*wxBLACK_PEN);
203 dc.SetBrush(*wxBLACK_BRUSH);
204 dc.DrawRoundedRectangle(0, 0, mWidth, mHeight, 5);
205 dc.SelectObject(wxNullBitmap);
207 SetShape(wxRegion(shape, *wxWHITE));
209 wxGraphicsPath path = wxGraphicsRenderer::GetDefaultRenderer()->CreatePath();
210 path.AddRoundedRectangle(0, 0, mWidth, mHeight, 5);
232 wxAutoBufferedPaintDC dc(
this);
234 dc.SetPen(*wxBLACK_PEN);
241 int textWidth, textHeight;
243 dc.GetTextExtent(visibleLabel, &textWidth, &textHeight);
244 dc.DrawText(visibleLabel, (
mWidth - textWidth) / 2, (
mHeight - textHeight) / 2);
270 mValue = mpOrigin->Get(
false);
273 auto trailing = NumValidatorStyle::TWO_TRAILING_ZEROES;
277 trailing = NumValidatorStyle::ONE_TRAILING_ZERO;
282 trailing = NumValidatorStyle::THREE_TRAILING_ZEROES;
287 S.StartVerticalLay();
292 .Validator<IntegerValidator<float>>(
293 &mValue, NumValidatorStyle::DEFAULT, -100.0, 100.0)
294 .AddTextBox({}, wxEmptyString, 15);
299 .Validator<IntegerValidator<float>>(
300 &mValue, NumValidatorStyle::DEFAULT, -50.0, 50.0)
301 .AddTextBox({}, wxEmptyString, 15);
306 .Validator<IntegerValidator<float>>(
307 &mValue, NumValidatorStyle::DEFAULT, 0.0, 100.0)
308 .AddTextBox({}, wxEmptyString, 15);
313 .Validator<FloatingPointValidator<float>>(
314 prec, &mValue, trailing, mpOrigin->GetMinValue(), mpOrigin->GetMaxValue())
315 .AddTextBox({}, wxEmptyString, 15);
346 mTextCtrl->GetValidator()->TransferToWindow();
358 if (
mTextCtrl->GetValidator()->TransferFromWindow())
383 if (
mTextCtrl->GetValidator()->TransferFromWindow())
400static const wxPoint2DDouble
outer[] =
402 wxPoint2DDouble( 2, 0 ),
403 wxPoint2DDouble( 8, 0 ),
404 wxPoint2DDouble( 10, 2 ),
405 wxPoint2DDouble( 10, 8 ),
406 wxPoint2DDouble( 5, 13 ),
407 wxPoint2DDouble( 0, 8 ),
408 wxPoint2DDouble( 0, 2 ),
409 wxPoint2DDouble( 2, 0 )
415 wxPoint2DDouble( 2, 1 ),
416 wxPoint2DDouble( 1, 2 ),
417 wxPoint2DDouble( 1, 8 ),
418 wxPoint2DDouble( 4, 4 ),
419 wxPoint2DDouble( 4, 7 )
423 wxPoint2DDouble( 8, 1 ),
424 wxPoint2DDouble( 1, 8 ),
425 wxPoint2DDouble( 5, 12 ),
426 wxPoint2DDouble( 6, 4 ),
427 wxPoint2DDouble( 6, 7 )
433 wxPoint2DDouble( 9, 2 ),
434 wxPoint2DDouble( 9, 8 ),
435 wxPoint2DDouble( 4, 5 ),
436 wxPoint2DDouble( 4, 8 ),
440 wxPoint2DDouble( 9, 8 ),
441 wxPoint2DDouble( 6, 11 ),
442 wxPoint2DDouble( 6, 5 ),
443 wxPoint2DDouble( 6, 8 )
449 wxPoint2DDouble( 3, 2 ),
450 wxPoint2DDouble( 5, 2 ),
451 wxPoint2DDouble( 7, 2 ),
452 wxPoint2DDouble( 2, 3 ),
453 wxPoint2DDouble( 2, 5 ),
454 wxPoint2DDouble( 2, 7 ),
458 wxPoint2DDouble( 8, 7 ),
459 wxPoint2DDouble( 8, 5 ),
460 wxPoint2DDouble( 8, 3 ),
461 wxPoint2DDouble( 7, 8 ),
462 wxPoint2DDouble( 6, 9 ),
463 wxPoint2DDouble( 5, 10 ),
469 wxPoint2DDouble( 9, 2 ),
470 wxPoint2DDouble( 9, 8 ),
474 wxPoint2DDouble( 9, 8 ),
475 wxPoint2DDouble( 6, 11 ),
496 Init(parent,
name, pos,
size, minValue, maxValue, stepValue,
497 canUseShift,
style, showlabels, drawticks, drawtrack,
498 alwayshidetip, heavyweight, popup, 1.0, orientation);
515 wxString leftLabel, rightLabel;
517 float minValue, maxValue, stepValue;
526 orientation = wxHORIZONTAL;
561 Init(parent,
name, pos,
size, minValue, maxValue, stepValue,
562 true,
style, showlabels, drawticks, drawtrack, alwayshidetip,
563 heavyweight, popup, speed, orientation);
745 dc.SetBackground( *wxTRANSPARENT_BRUSH );
750 const auto &thumbBitmap =
754 dc.DrawBitmap(thumbBitmap,
mLeft+thumbPos,
mTop+thumbOrtho,
true);
759 dc.DrawBitmap(thumbBitmap,
mLeft+thumbOrtho-5,
mTop+thumbPos,
true);
790 mBitmap = std::make_unique<wxBitmap>();
793#if defined(__WXMAC__)
802 dc.SetBackground(wxBrush(
mParent->GetBackgroundColour()));
831 wxFont labelFont(7, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
832 dc.SetFont(labelFont);
838 dc.DrawText(
_(
"L"),
mLeftX, 0);
841 dc.DrawText(
_(
"R"),
mRightX - dc.GetTextExtent(
_(
"R")).GetWidth(), 0);
872 bool bTicks = TickColour != wxColour(60,60,60);
882 upp = divs / (double)(
mWidthX-1);
890#ifdef OPTIONAL_SLIDER_TICKS
894 for(
int p = 0; p <= kMax; p++)
896 if (((
int)d) > int_d)
899 int tickLength = ((int_d == 0) || (int_d == divs)) ? 5: 3;
927 dc.SelectObject(wxNullBitmap);
1019 val =
XO(
"%+.1f dB").Format( value );
1029 const auto v = 100.0f * fabsf(value);
1032 val =
XO(
"%.0f%% Left").Format( v );
1035 val =
XO(
"%.0f%% Right").Format( v );
1041 val =
XO(
"%.3fx").Format( value );
1082 results.push_back(
GetTip( -1.99f ) );
1083 results.push_back(
GetTip( +1.99f ) );
1087 results.push_back(
GetTip(1.0f));
1090 results.push_back(
GetTip( -99.9f ) );
1091 results.push_back(
GetTip( +99.9f ) );
1097 results.push_back(
GetTip( 0.f ) );
1098 results.push_back(
GetTip( +1.f ) );
1099 results.push_back(
GetTip( -1.f ) );
1103 results.push_back(
GetTip( 9.99f ) );
1107 results.push_back(
GetTip( 999.f ) );
1132 bool changed =
false;
1146 if (pos == wxPoint(-1, -1)) {
1150 changed = (dlg.ShowModal() == wxID_OK);
1168 if (event.Entering())
1177 else if (event.Leaving())
1195 if ((event.RightDown() && !event.RightIsDown()) ||
1196 (event.RightUp() && event.GetPosition() == wxPoint(-1, -1)))
1219 wxRect tolerantThumbRect = r;
1220 tolerantThumbRect.Inflate(3, 3);
1223 if( event.ButtonDClick() &&
mPopup )
1228 else if( event.ButtonDown() )
1235 if( event.RightDown() ) {
1243 if( tolerantThumbRect.Contains( event.GetPosition() ) )
1256 (
mOrientation == wxHORIZONTAL) ? event.m_x : event.m_y,
1266 else if( event.ButtonUp() )
1278 if (event.m_y < (r.y - 2 * r.height) ||
1279 event.m_y > (r.y + 3 * r.height)) {
1292 if (event.m_x < (r.x - 2 * r.width) ||
1293 event.m_x > (r.x + 3 * r.width)) {
1305 else if( event.m_wheelRotation != 0 )
1309 double steps =
event.m_wheelRotation /
1310 (
event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);
1331 switch( event.GetKeyCode() )
1334 mParent->Navigate(event.ShiftDown()
1335 ? wxNavigationKeyEvent::IsBackward
1336 : wxNavigationKeyEvent::IsForward);
1376 case WXK_NUMPAD_ENTER:
1378 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(
mParent), wxTopLevelWindow);
1379 wxWindow *def = tlw->GetDefaultItem();
1380 if (def && def->IsEnabled()) {
1383 cevent.SetEventObject( def );
1384 mParent->GetEventHandler()->ProcessEvent(cevent);
1425 wxCommandEvent e( wxEVT_COMMAND_SLIDER_UPDATED,
mID );
1428 e.SetInt( intValue );
1429 mParent->GetEventHandler()->ProcessEvent(e);
1499 float val = (pos / (float)nSpan)
1579 if ( stepValue == 0.0 )
1602 if ( stepValue == 0.0 )
1665BEGIN_EVENT_TABLE(
ASlider, wxPanel)
1681 const wxPoint & pos,
1682 const wxSize &
size,
1684: wxPanel( parent,
id, pos,
size, wxWANTS_CHARS )
1689 mLWSlider = std::make_unique<LWSlider>(
this,
1697 options.alwaysHideTip,
1700 options.orientation);
1701 mLWSlider->mStepValue = options.stepValue;
1702 mLWSlider->SetId(
id );
1705 mSliderIsFocused =
false;
1706 mStyle = options.style;
1708 mTimer.SetOwner(
this);
1710#if wxUSE_ACCESSIBILITY
1711 SetAccessible(
safenew ASliderAx(
this ) );
1714 mLWSlider->SetScroll( options.line, options.page );
1726 auto res = wxPanel::SetBackgroundColour(colour);
1739 if ( event.GetId() ==
mLWSlider->GetId() )
1741#if wxUSE_ACCESSIBILITY
1742 GetAccessible()->NotifyEvent( wxACC_EVENT_OBJECT_VALUECHANGE,
1764 wxBufferedPaintDC dc(
this);
1767 GetClientRect().Contains(
1769 ::wxGetMousePosition() ) );
1784 if (event.Entering())
1788 else if (event.Leaving())
1798 wxMouseEvent e(wxEVT_LEFT_UP);
1877 wxWindow::Enable(enable);
1890 s_AcceptsFocus =
true;
1903#if wxUSE_ACCESSIBILITY
1905ASliderAx::ASliderAx( wxWindow * window ) :
1910ASliderAx::~ASliderAx()
1916wxAccStatus ASliderAx::GetChild(
int childId, wxAccessible** child )
1918 if ( childId == wxACC_SELF )
1931wxAccStatus ASliderAx::GetChildCount(
int* childCount)
1944wxAccStatus ASliderAx::GetDefaultAction(
int WXUNUSED(childId), wxString *actionName )
1946 actionName->clear();
1952wxAccStatus ASliderAx::GetDescription(
int WXUNUSED(childId), wxString *description )
1954 description->clear();
1963wxAccStatus ASliderAx::GetFocus(
int* childId, wxAccessible** child)
1972wxAccStatus ASliderAx::GetHelpText(
int WXUNUSED(childId), wxString *helpText )
1981wxAccStatus ASliderAx::GetKeyboardShortcut(
int WXUNUSED(childId), wxString *shortcut )
1990wxAccStatus ASliderAx::GetLocation( wxRect& rect,
int WXUNUSED(elementId) )
1994 rect = as->GetRect();
1995 rect.SetPosition( as->GetParent()->ClientToScreen( rect.GetPosition() ) );
2001wxAccStatus ASliderAx::GetName(
int WXUNUSED(childId), wxString*
name)
2005 *
name = as->GetName();
2011wxAccStatus ASliderAx::GetRole(
int childId, wxAccRole* role)
2016 *role = wxROLE_SYSTEM_SLIDER;
2021 *role = wxROLE_SYSTEM_PUSHBUTTON;
2025 *role = wxROLE_SYSTEM_INDICATOR;
2040wxAccStatus ASliderAx::GetSelections( wxVariant * WXUNUSED(selections) )
2042 return wxACC_NOT_IMPLEMENTED;
2046wxAccStatus ASliderAx::GetState(
int childId,
long* state)
2053 *state = wxACC_STATE_SYSTEM_FOCUSABLE;
2059 *state = wxACC_STATE_SYSTEM_INVISIBLE;
2066 *state = wxACC_STATE_SYSTEM_INVISIBLE;
2080wxAccStatus ASliderAx::GetValue(
int childId, wxString* strValue)
2086 *strValue = as->
mLWSlider->GetStringValue();
2089 return wxACC_NOT_SUPPORTED;
static const wxPoint2DDouble enabledLeftEnd[]
static const wxPoint2DDouble disabledRightEnd[]
static const wxPoint2DDouble enabledLeftBegin[]
static const wxPoint2DDouble disabledRightBegin[]
static const wxPoint2DDouble disabledStripesBegin[]
static const wxPoint2DDouble enabledRightBegin[]
static const wxPoint2DDouble enabledRightEnd[]
static const wxPoint2DDouble disabledStripesEnd[]
static const wxPoint2DDouble outer[]
wxEVT_COMMAND_BUTTON_CLICKED
const TranslatableString name
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
static wxBrush tooltipBrush
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
static void DrawFocus(wxDC &dc, wxRect &r)
ASlider is a custom slider, allowing for a slicker look and feel.
static TempAllowFocus TemporarilyAllowFocus()
void OnSetFocus(wxFocusEvent &event)
void SetFocusFromKbd() override
void SetSpeed(float speed)
void GetScroll(float &line, float &page)
bool ShowDialog(wxPoint pos=wxPoint(-1, -1))
std::unique_ptr< LWSlider > mLWSlider
void OnKeyDown(wxKeyEvent &event)
void OnTimer(wxTimerEvent &event)
std::unique_ptr< bool, Resetter > TempAllowFocus
void OnKillFocus(wxFocusEvent &event)
void Increase(float steps)
void OnCaptureLost(wxMouseCaptureLostEvent &event)
void Decrease(float steps)
void OnSlider(wxCommandEvent &event)
void SetToolTipTemplate(const TranslatableString &tip)
void OnMouseEvent(wxMouseEvent &event)
static bool s_AcceptsFocus
bool Enable(bool enable=true) override
void OnPaint(wxPaintEvent &event)
bool SetBackgroundColour(const wxColour &colour) override
void OnErase(wxEraseEvent &event)
void SetScroll(float line, float page)
void OnSize(wxSizeEvent &event)
float Get(bool convert=true)
Lightweight version of ASlider. In other words it does not have a window permanently associated with ...
void DrawToBitmap(wxDC &dc)
void OnPaint(wxDC &dc, bool highlighted)
float GetMinValue() const
std::unique_ptr< wxBitmap > mThumbBitmap
void SetEnabled(bool enabled)
void Init(wxWindow *parent, const TranslatableString &name, const wxPoint &pos, const wxSize &size, float minValue, float maxValue, float stepValue, bool canUseShift, int style, bool showlabels, bool drawticks, bool drawtrack, bool alwayshidetip, bool heavyweight, bool popup, float speed, int orientation=wxHORIZONTAL)
TranslatableString mTipTemplate
void OnMouseEvent(wxMouseEvent &event)
void Decrease(float steps)
void AdjustSize(const wxSize &sz)
void Increase(float steps)
float Get(bool convert=true)
void SetDefaultValue(float value)
wxString GetStringValue() const
void OnKeyDown(wxKeyEvent &event)
int ValueToPosition(float val)
TranslatableStrings GetWidestTips() const
std::unique_ptr< wxBitmap > mBitmap
void GetScroll(float &line, float &page)
void SetSpeed(float speed)
void SetDefaultShortcut(bool value)
std::unique_ptr< wxBitmap > mThumbBitmapHilited
float GetMaxValue() const
void SendUpdate(float newValue)
void SetName(const TranslatableString &name)
float DragPositionToValue(int fromPos, bool shiftDown)
void SetScroll(float line, float page)
bool DoShowDialog(wxPoint pos)
void OnSize(wxSizeEvent &event)
void SetId(wxWindowID id)
void SetToolTipTemplate(const TranslatableString &tip)
void Move(const wxPoint &newpos)
void SetParent(wxWindow *parent)
LWSlider(wxWindow *parent, const TranslatableString &name, const wxPoint &pos, const wxSize &size, float minValue, float maxValue, float stepValue, bool canUseShift, int style, bool showlabels=true, bool drawticks=true, bool drawtrack=true, bool alwayshidetip=false, bool heavyweight=false, bool popup=true, int orientation=wxHORIZONTAL)
float ClickPositionToValue(int fromPos, bool shiftDown)
wxWeakRef< TipWindow > mTipPanel
TranslatableString GetTip(float value) const
static ProjectStatus & Get(AudacityProject &project)
void Set(const TranslatableString &msg, StatusBarField field=MainStatusBarField())
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Pop up dialog used with an LWSlider.
bool TransferDataFromWindow() override
void OnSlider(wxCommandEvent &event)
void OnTextChange(wxCommandEvent &event)
bool TransferDataToWindow() override
wxColour & Colour(int iIndex)
wxBitmap & Bitmap(int iIndex)
A wxPopupWindow used to give the numerical value of an LWSlider or ASlider.
void OnPaint(wxPaintEvent &event)
TipWindow(wxWindow *parent, const TranslatableStrings &labels)
void SetLabel(const TranslatableString &label)
TranslatableString mLabel
void SetPos(const wxPoint &pos)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
TranslatableString & Format(Args &&...args) &
Capture variadic format arguments (by copy) when there is no plural.
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
__finl float __vecc rint(float a)