Audacity  2.2.0
AColor.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  AColor.h
6 
7  Dominic Mazzoni
8 
9  Manages color brushes and pens and provides utility
10  drawing functions
11 
12 **********************************************************************/
13 
14 #ifndef __AUDACITY_COLOR__
15 #define __AUDACITY_COLOR__
16 
17 #include "MemoryX.h"
18 #include <wx/brush.h>
19 #include <wx/pen.h>
20 
21 class wxDC;
22 class wxRect;
23 
24 struct DCUnchanger {
25 public:
27 
28  DCUnchanger(const wxBrush &brush_, const wxPen &pen_, long logicalOperation_)
29  : brush(brush_), pen(pen_), logicalOperation(logicalOperation_)
30  {}
31 
32  void operator () (wxDC *pDC) const;
33 
34  wxBrush brush {};
35  wxPen pen {};
37 };
38 
39 // Like wxDCPenChanger, etc., but simple and general
40 // Make temporary drawing context changes that you back out of, RAII style
41 
42 class ADCChanger : public std::unique_ptr<wxDC, ::DCUnchanger>
43 {
44  using Base = std::unique_ptr<wxDC, ::DCUnchanger>;
45 public:
46  ADCChanger() : Base{} {}
47  ADCChanger(wxDC *pDC);
48 };
49 
50 class AColor {
51  public:
52 
58 
59  ColorGradientTotal // keep me last
60  };
61 
62  static void Init();
63  static void ReInit();
64 
65  static void Arrow(wxDC & dc, wxCoord x, wxCoord y, int width, bool down = true);
66  static void Line(wxDC & dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
67  static void DrawFocus(wxDC & dc, wxRect & r);
68  static void Bevel(wxDC & dc, bool up, const wxRect & r);
69  static void Bevel2
70  (wxDC & dc, bool up, const wxRect & r, bool bSel=false, bool bHighlight = false);
71  static void BevelTrackInfo(wxDC & dc, bool up, const wxRect & r, bool highlight = false);
72  static wxColour Blend(const wxColour & c1, const wxColour & c2);
73 
74  static void UseThemeColour( wxDC * dc, int iBrush, int iPen=-1 );
75  static void TrackPanelBackground(wxDC * dc, bool selected);
76 
77  static void Light(wxDC * dc, bool selected, bool highlight = false);
78  static void Medium(wxDC * dc, bool selected);
79  static void MediumTrackInfo(wxDC * dc, bool selected);
80  static void Dark(wxDC * dc, bool selected, bool highlight = false);
81 
82  static void CursorColor(wxDC * dc);
83  static void IndicatorColor(wxDC * dc, bool bIsNotRecording);
84  static void PlayRegionColor(wxDC * dc, bool locked);
85 
86  static void Mute(wxDC * dc, bool on, bool selected, bool soloing);
87  static void Solo(wxDC * dc, bool on, bool selected);
88 
89  // In all of these, channel is 1-indexed (1 through 16); if out of bounds
90  // (either due to being explicitly set to 0 or due to an allegro file with
91  // more than 16 channels) a gray color is returned.
92 
93  static void MIDIChannel(wxDC * dc, int channel /* 1 - 16 */ );
94  static void LightMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ );
95  static void DarkMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ );
96 
97  static void TrackFocusPen(wxDC * dc, int level /* 0 - 2 */);
98  static void SnapGuidePen(wxDC * dc);
99 
100  static void PreComputeGradient();
101 
102  // Member variables
103 
104  static wxBrush lightBrush[2];
105  static wxBrush mediumBrush[2];
106  static wxBrush darkBrush[2];
107  static wxPen lightPen[2];
108  static wxPen mediumPen[2];
109  static wxPen darkPen[2];
110 
111  static wxPen cursorPen;
112  static wxPen indicatorPen[2];
113  static wxBrush indicatorBrush[2];
114  static wxPen playRegionPen[2];
115  static wxBrush playRegionBrush[2];
116 
117  static wxBrush muteBrush[2];
118  static wxBrush soloBrush;
119 
120  static wxPen clippingPen;
121 
122  static wxPen envelopePen;
123  static wxPen WideEnvelopePen;
124  static wxBrush envelopeBrush;
125 
126  static wxBrush labelTextNormalBrush;
127  static wxBrush labelTextEditBrush;
128  static wxBrush labelUnselectedBrush;
129  static wxBrush labelSelectedBrush;
130  static wxBrush labelSyncLockSelBrush;
131  static wxPen labelUnselectedPen;
132  static wxPen labelSelectedPen;
133  static wxPen labelSyncLockSelPen;
134  static wxPen labelSurroundPen;
135 
136  static wxPen trackFocusPens[3];
137  static wxPen snapGuidePen;
138 
139  static wxPen tooltipPen;
140  static wxBrush tooltipBrush;
141 
142  static bool gradient_inited;
143  static const int gradientSteps = 512;
144  static unsigned char gradient_pre[ColorGradientTotal][2][gradientSteps][3];
145 
146  // For experiments in mouse-over highlighting only
147  static wxPen uglyPen;
148  static wxBrush uglyBrush;
149 
150  private:
151  static wxPen sparePen;
152  static wxBrush spareBrush;
153  static bool inited;
154 
155 };
156 
157 inline void GetColorGradient(float value,
159  bool grayscale,
160  unsigned char * __restrict red,
161  unsigned char * __restrict green,
162  unsigned char * __restrict blue) {
163 
164  int idx = value * (AColor::gradientSteps - 1);
165 
166  *red = AColor::gradient_pre[selected][grayscale][idx][0];
167  *green = AColor::gradient_pre[selected][grayscale][idx][1];
168  *blue = AColor::gradient_pre[selected][grayscale][idx][2];
169 }
170 
171 #endif
static void PlayRegionColor(wxDC *dc, bool locked)
Definition: AColor.cpp:376
Definition: AColor.h:55
long logicalOperation
Definition: AColor.h:36
static const int gradientSteps
Definition: AColor.h:143
static wxBrush labelSelectedBrush
Definition: AColor.h:129
static wxPen tooltipPen
Definition: AColor.h:139
static wxBrush indicatorBrush[2]
Definition: AColor.h:113
static wxPen darkPen[2]
Definition: AColor.h:109
ColorGradientChoice
Definition: AColor.h:53
static void CursorColor(wxDC *dc)
Definition: AColor.cpp:358
static wxBrush lightBrush[2]
Definition: AColor.h:104
static void DarkMIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:602
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:349
static void Arrow(wxDC &dc, wxCoord x, wxCoord y, int width, bool down=true)
Definition: AColor.cpp:96
static wxBrush uglyBrush
Definition: AColor.h:148
static void Bevel2(wxDC &dc, bool up, const wxRect &r, bool bSel=false, bool bHighlight=false)
Definition: AColor.cpp:222
static wxBrush labelSyncLockSelBrush
Definition: AColor.h:130
void GetColorGradient(float value, AColor::ColorGradientChoice selected, bool grayscale, unsigned char *__restrict red, unsigned char *__restrict green, unsigned char *__restrict blue)
Definition: AColor.h:157
static wxBrush labelTextNormalBrush
Definition: AColor.h:126
static wxPen mediumPen[2]
Definition: AColor.h:108
Definition: AColor.h:24
static wxBrush soloBrush
Definition: AColor.h:118
static void MediumTrackInfo(wxDC *dc, bool selected)
Definition: AColor.cpp:328
static void ReInit()
Definition: AColor.cpp:430
static void DrawFocus(wxDC &dc, wxRect &r)
Definition: AColor.cpp:171
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:338
static wxBrush muteBrush[2]
Definition: AColor.h:117
static wxPen uglyPen
Definition: AColor.h:147
static void Medium(wxDC *dc, bool selected)
Definition: AColor.cpp:319
static wxPen lightPen[2]
Definition: AColor.h:107
static void IndicatorColor(wxDC *dc, bool bIsNotRecording)
Definition: AColor.cpp:367
static wxPen labelSyncLockSelPen
Definition: AColor.h:133
static wxPen envelopePen
Definition: AColor.h:122
static wxPen cursorPen
Definition: AColor.h:111
Definition: AColor.h:59
wxBrush brush
Definition: AColor.h:34
Definition: AColor.h:57
wxPen pen
Definition: AColor.h:35
static void Mute(wxDC *dc, bool on, bool selected, bool soloing)
Definition: AColor.cpp:398
static void LightMIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:584
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:202
static wxPen sparePen
Definition: AColor.h:151
static void Solo(wxDC *dc, bool on, bool selected)
Definition: AColor.cpp:413
static wxBrush spareBrush
Definition: AColor.h:152
static wxBrush labelTextEditBrush
Definition: AColor.h:127
DCUnchanger(const wxBrush &brush_, const wxPen &pen_, long logicalOperation_)
Definition: AColor.h:28
static void MIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:568
static void Init()
Definition: AColor.cpp:460
static void PreComputeGradient()
Definition: AColor.cpp:624
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1)
Definition: AColor.cpp:289
static bool inited
Definition: AColor.h:153
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
static wxBrush mediumBrush[2]
Definition: AColor.h:105
static void Light(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:308
static wxBrush envelopeBrush
Definition: AColor.h:124
std::unique_ptr< wxDC,::DCUnchanger > Base
Definition: AColor.h:44
DCUnchanger()
Definition: AColor.h:26
AColor Manages color brushes and pens.
Definition: AColor.h:50
static wxBrush tooltipBrush
Definition: AColor.h:140
static void TrackFocusPen(wxDC *dc, int level)
Definition: AColor.cpp:384
static wxPen labelSelectedPen
Definition: AColor.h:132
static void SnapGuidePen(wxDC *dc)
Definition: AColor.cpp:391
static wxBrush darkBrush[2]
Definition: AColor.h:106
Definition: AColor.h:54
static wxPen labelUnselectedPen
Definition: AColor.h:131
static wxColour Blend(const wxColour &c1, const wxColour &c2)
Definition: AColor.cpp:253
static wxPen snapGuidePen
Definition: AColor.h:137
void operator()(wxDC *pDC) const
Definition: AColor.cpp:33
static bool gradient_inited
Definition: AColor.h:142
static void BevelTrackInfo(wxDC &dc, bool up, const wxRect &r, bool highlight=false)
Definition: AColor.cpp:262
static wxPen WideEnvelopePen
Definition: AColor.h:123
static wxPen labelSurroundPen
Definition: AColor.h:134
static wxPen indicatorPen[2]
Definition: AColor.h:112
static unsigned char gradient_pre[ColorGradientTotal][2][gradientSteps][3]
Definition: AColor.h:144
static wxPen clippingPen
Definition: AColor.h:120
static wxPen playRegionPen[2]
Definition: AColor.h:114
static wxPen trackFocusPens[3]
Definition: AColor.h:136
ADCChanger()
Definition: AColor.h:46
Definition: AColor.h:42
static wxBrush playRegionBrush[2]
Definition: AColor.h:115
static wxBrush labelUnselectedBrush
Definition: AColor.h:128