Audacity 3.2.0
auStaticText.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file auStaticText.cpp
6
7 Paul Licameli split from Theme.cpp
8
9*//*****************************************************************//*****************************************************************/
16#include "auStaticText.h"
17
18#include "AllThemeResources.h"
19#include "Theme.h"
20
21#include "AColor.h"
22
23#include <cassert>
24
25#include <wx/dcclient.h>
26
27BEGIN_EVENT_TABLE(auStaticText, wxWindow)
28 EVT_PAINT(auStaticText::OnPaint)
29 EVT_ERASE_BACKGROUND(auStaticText::OnErase)
31
32
33auStaticText::auStaticText(wxWindow* parent, wxString textIn) :
34 wxWindow(parent, wxID_ANY)
35{
36 int textWidth, textHeight;
37
38 int fontSize = 11;
39 #ifdef __WXMSW__
40 fontSize = 9;
41 #endif
42 wxFont font(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
43 GetTextExtent(textIn, &textWidth, &textHeight, NULL, NULL, &font);
44
45 SetFont( font );
46 SetMinSize( wxSize(textWidth, textHeight) );
47 SetBackgroundColour( theTheme.Colour( clrMedium));
48 SetForegroundColour( theTheme.Colour( clrTrackPanelText));
49 SetName(textIn);
50 SetLabel(textIn);
51}
52
53void auStaticText::OnPaint(wxPaintEvent & WXUNUSED(evt))
54{
55 wxPaintDC dc(this);
56 //dc.SetTextForeground( theTheme.Colour( clrTrackPanelText));
57 dc.Clear();
58 dc.DrawText( GetLabel(), 0,0);
59
60 if (mIsSelected)
61 {
62 auto rect = wxRect { GetSize() };
63 AColor::DrawFocus(dc, rect);
64 }
65}
66
67void auStaticText::ScaleFont(double scale)
68{
69 if (scale < 0.0)
70 {
71 assert(scale >= 0.0);
72 return;
73 }
74
75 int textWidth, textHeight;
76
77 auto font = GetFont();
78
79 const auto oldFontSize = font.GetPointSize();
80 const auto newFontSize = static_cast<int>(oldFontSize * scale);
81
82 if (newFontSize != oldFontSize)
83 {
84 font.SetPointSize(newFontSize);
85 GetTextExtent(GetLabel(), &textWidth, &textHeight, NULL, NULL, &font);
86 SetFont(font);
87 SetMinSize(wxSize(textWidth, textHeight));
88 }
89}
90
91void auStaticText::SetSelected(bool selected)
92{
93 if (selected == mIsSelected)
94 return;
95
96 mIsSelected = selected;
97 Refresh();
98}
99
100bool auStaticText::GetSelected() const noexcept
101{
102 return mIsSelected;
103}
END_EVENT_TABLE()
THEME_API Theme theTheme
Definition: Theme.cpp:82
static void DrawFocus(wxDC &dc, wxRect &r)
Definition: AColor.cpp:247
wxColour & Colour(int iIndex)
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: auStaticText.h:20
void SetSelected(bool selected)
void OnErase(wxEraseEvent &event)
Definition: auStaticText.h:25
void OnPaint(wxPaintEvent &evt)
bool mIsSelected
Definition: auStaticText.h:36
bool GetSelected() const noexcept
void ScaleFont(double scale)