Audacity 3.2.0
AColor.cpp
Go to the documentation of this file.
1
2/**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 AColor.cpp
7
8 Dominic Mazzoni
9
10
11********************************************************************//********************************************************************/
19
20#include "AColor.h"
21#include "AColorResources.h"
22
23#include <wx/colour.h>
24#include <wx/dc.h>
25#include <wx/dcmemory.h>
26#include <wx/graphics.h>
27#include <wx/settings.h>
28#include <wx/utils.h>
29
30#include "AllThemeResources.h"
31#include "Theme.h"
32
33bool AColor::inited = false;
34wxBrush AColor::lightBrush[2];
35wxBrush AColor::mediumBrush[2];
36wxBrush AColor::darkBrush[2];
37wxPen AColor::lightPen[2];
38wxPen AColor::mediumPen[2];
39wxPen AColor::darkPen[2];
40
42wxBrush AColor::indicatorBrush[2];
44// wxPen AColor::playRegionPen[2];
46
47wxBrush AColor::muteBrush[2];
48wxBrush AColor::soloBrush;
49
51
55
67
70
71// The spare pen and brush possibly help us cut down on the
72// number of pens and brushes we need.
74wxBrush AColor::spareBrush;
75
76wxPen AColor::uglyPen;
77wxBrush AColor::uglyBrush;
78
79namespace
80{
81 //Simplified variation of nine patch scale drawing
82 //https://en.wikipedia.org/wiki/9-slice_scaling
83 //Bitmap and rect expected to have at least 3px in both directions
84 void DrawNinePatch(wxDC& dc, wxBitmap& bitmap, const wxRect& r)
85 {
86 wxMemoryDC memDC;
87 memDC.SelectObject(bitmap);
88
89 // image slices
90
91 const auto uw0 = bitmap.GetWidth() / 2;
92 const auto uw1 = 1;
93 const auto uw2 = bitmap.GetWidth() - uw0 - uw1;
94
95 const auto vh0 = bitmap.GetHeight() / 2;
96 const auto vh1 = 1;
97 const auto vh2 = bitmap.GetHeight() - vh1 - vh0;
98
99 const auto u0 = 0;
100 const auto u1 = uw0;
101 const auto u2 = uw0 + uw1;
102
103 const auto v0 = 0;
104 const auto v1 = vh0;
105 const auto v2 = vh0 + vh1;
106
107 //Button geometry
108
109 const auto xw0 = std::min(uw0, r.width / 2);
110 const auto xw2 = std::min(uw2, r.width / 2);
111 const auto xw1 = r.width - xw0 - xw2;
112
113 const auto yh0 = std::min(vh0, r.height / 2);
114 const auto yh2 = std::min(vh2, r.height / 2);
115 const auto yh1 = r.height - yh0 - yh2;
116
117 const auto x0 = r.x;
118 const auto x1 = r.x + xw0;
119 const auto x2 = r.x + xw0 + xw1;
120
121 const auto y0 = r.y;
122 const auto y1 = r.y + yh0;
123 const auto y2 = r.y + yh0 + yh1;
124
125 dc.StretchBlit(x0, y0, xw0, yh0, &memDC, u0, v0, uw0, vh0, wxCOPY, true);
126 dc.StretchBlit(x1, y0, xw1, yh0, &memDC, u1, v0, uw1, vh0, wxCOPY, true);
127 dc.StretchBlit(x2, y0, xw2, yh0, &memDC, u2, v0, uw2, vh0, wxCOPY, true);
128
129 dc.StretchBlit(x0, y1, xw0, yh1, &memDC, u0, v1, uw0, vh1, wxCOPY, true);
130 dc.StretchBlit(x1, y1, xw1, yh1, &memDC, u1, v1, uw1, vh1, wxCOPY, true);
131 dc.StretchBlit(x2, y1, xw2, yh1, &memDC, u2, v1, uw2, vh1, wxCOPY, true);
132
133 dc.StretchBlit(x0, y2, xw0, yh2, &memDC, u0, v2, uw0, vh2, wxCOPY, true);
134 dc.StretchBlit(x1, y2, xw1, yh2, &memDC, u1, v2, uw1, vh2, wxCOPY, true);
135 dc.StretchBlit(x2, y2, xw2, yh2, &memDC, u2, v2, uw2, vh2, wxCOPY, true);
136 }
137
138 int GetButtonImageIndex(bool up, bool selected, bool highlight)
139 {
140 // There are eight button states in the TCP.
141 // A theme might not differentiate among them all. That's up to
142 // the theme designer.
143 // Button highlighted (i.e. hovered over) or not.
144 // Track selected or not
145 // Button up or down.
146 // Highlight in most themes is lighter than not highlighted.
147 if ( highlight && selected)
148 return up ? bmpHiliteUpButtonExpandSel : bmpHiliteButtonExpandSel;
149 if ( highlight )
150 return up ? bmpHiliteUpButtonExpand : bmpHiliteButtonExpand;
151 if( selected )
152 return up ? bmpUpButtonExpandSel : bmpDownButtonExpandSel;
153 return up ? bmpUpButtonExpand : bmpDownButtonExpand;
154 }
155}
156
157//
158// Draw an upward or downward pointing arrow.
159//
160void AColor::Arrow(wxDC & dc, wxCoord x, wxCoord y, int width, bool down)
161{
162 if (width & 0x01) {
163 width--;
164 }
165
166 wxPoint pt[3];
167 int half = width / 2;
168
169 if (down) {
170 pt[0].x = 0; pt[0].y = 0;
171 pt[1].x = width; pt[1].y = 0;
172 pt[2].x = half; pt[2].y = half;
173 }
174 else {
175 pt[0].x = 0; pt[0].y = half;
176 pt[1].x = half; pt[1].y = 0;
177 pt[2].x = width; pt[2].y = half;
178 }
179
180 dc.DrawPolygon(3, pt, x, y);
181}
182
183//
184// Draw a line, inclusive of endpoints,
185// compensating for differences in wxWidgets versions across platforms
186//
187void AColor::Line(wxDC & dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
188{
189 const wxPoint points[] { { x1, y1 }, { x2, y2 } };
190 Lines( dc, 2, points );
191}
192
193// Draw lines, INCLUSIVE of all endpoints
194void AColor::Lines(wxDC &dc, size_t nPoints, const wxPoint points[])
195{
196 if ( nPoints <= 1 ) {
197 if (nPoints == 1)
198 dc.DrawPoint( points[0] );
199 return;
200 }
201
202 for (size_t ii = 0; ii < nPoints - 1; ++ii) {
203 const auto &p1 = points[ii];
204 const auto &p2 = points[ii + 1];
205
206 // As of 2.8.9 (possibly earlier), wxDC::DrawLine() on the Mac draws the
207 // last point since it is now based on the NEW wxGraphicsContext system.
208 // Make the other platforms do the same thing since the other platforms
209 // "may" follow they get wxGraphicsContext going.
210
211 // PRL: as of 3.1.1, I still observe that on Mac, the last point is
212 // included, contrary to what documentation says. Also that on Windows,
213 // sometimes it is the first point that is excluded.
214
215#if defined(__WXMAC__) || defined(__WXGTK3__)
216 dc.DrawLine(p1, p2);
217#else
218 dc.DrawPoint(p1);
219 if ( p1 != p2 ) {
220 dc.DrawLine(p1, p2);
221 }
222#endif
223 }
224
225#if defined(__WXMAC__) || defined(__WXGTK3__)
226 ;
227#else
228 dc.DrawPoint( points[ nPoints - 1 ] );
229#endif
230}
231
232//
233// Draws a focus rectangle (Taken directly from wxWidgets source)
234//
235void AColor::DrawFocus(wxDC & dc, wxRect & rect)
236{
237 // draw the pixels manually: note that to behave in the same manner as
238 // DrawRect(), we must exclude the bottom and right borders from the
239 // rectangle
240 wxCoord x1 = rect.GetLeft(),
241 y1 = rect.GetTop(),
242 x2 = rect.GetRight(),
243 y2 = rect.GetBottom();
244
245 // -1 for brush, so it just sets the pen colour, and does not change the brush.
246 UseThemeColour( &dc, -1, clrTrackPanelText );
247
248 wxCoord z;
249 for ( z = x1 + 1; z < x2; z += 2 )
250 dc.DrawPoint(z, y1);
251
252 wxCoord shift = z == x2 ? 0 : 1;
253 for ( z = y1 + shift; z < y2; z += 2 )
254 dc.DrawPoint(x2, z);
255
256 shift = z == y2 ? 0 : 1;
257 for ( z = x2 - shift; z > x1; z -= 2 )
258 dc.DrawPoint(z, y2);
259
260 shift = z == x1 ? 0 : 1;
261 for ( z = y2 - shift; z > y1; z -= 2 )
262 dc.DrawPoint(x1, z);
263
264}
265
266void AColor::Bevel(wxDC & dc, bool up, const wxRect & r)
267{
268 if (up)
269 AColor::Light(&dc, false);
270 else
271 AColor::Dark(&dc, false);
272
273 AColor::Line(dc, r.x, r.y, r.x + r.width, r.y);
274 AColor::Line(dc, r.x, r.y, r.x, r.y + r.height);
275
276 if (!up)
277 AColor::Light(&dc, false);
278 else
279 AColor::Dark(&dc, false);
280
281 AColor::Line(dc, r.x + r.width, r.y, r.x + r.width, r.y + r.height);
282 AColor::Line(dc, r.x, r.y + r.height, r.x + r.width, r.y + r.height);
283}
284
285void AColor::ButtonStretch(wxDC& dc, bool up, const wxRect& r, bool selected, bool highlight)
286{
288 dc,
289 theTheme.Bitmap(GetButtonImageIndex(up, selected, highlight)),
290 r
291 );
292}
293
294void AColor::Bevel2(wxDC & dc, bool up, const wxRect & r, bool bSel, bool bHighlight)
295{
296 auto& Bmp = theTheme.Bitmap( GetButtonImageIndex(up, bSel, bHighlight) );
297 wxMemoryDC memDC;
298 memDC.SelectObject(Bmp);
299
300 int h = std::min(r.height, Bmp.GetHeight());
301
302 dc.Blit( r.x,r.y,r.width/2, h, &memDC, 0, 0, wxCOPY, true );
303 int r2 = r.width - r.width/2;
304 dc.Blit( r.x+r.width/2,r.y,r2, h, &memDC,
305 Bmp.GetWidth() - r2, 0, wxCOPY, true );
306}
307
308void AColor::DrawHStretch(wxDC& dc, const wxRect& rect, wxBitmap& bitmap)
309{
310 wxMemoryDC srcDC;
311 srcDC.SelectObject(bitmap);
312
313 const auto sh = bitmap.GetHeight();
314 const auto dh = rect.height;
315 const auto w0 = std::min((bitmap.GetWidth() - 1) / 2, rect.width / 2);
316 const auto dx0 = rect.x;
317 const auto dx1 = rect.x + w0;
318 const auto dx2 = rect.x + rect.width - w0;
319
320 dc.StretchBlit(dx0, rect.y, w0, dh, &srcDC, 0, 0, w0, sh);
321 dc.StretchBlit(dx1, rect.y, rect.width - w0 * 2, dh, &srcDC, w0, 0, 1, sh);
322 dc.StretchBlit(dx2, rect.y, w0, dh, &srcDC, bitmap.GetWidth() - w0, 0, w0, sh);
323}
324
325void AColor::DrawFrame(wxDC& dc, const wxRect& r, wxBitmap& bitmap)
326{
327 DrawNinePatch(dc, bitmap, r);
328}
329
330
331wxColour AColor::Blend( const wxColour & c1, const wxColour & c2 )
332{
333 wxColour c3(
334 (c1.Red() + c2.Red())/2,
335 (c1.Green() + c2.Green())/2,
336 (c1.Blue() + c2.Blue())/2);
337 return c3;
338}
339
340void AColor::BevelTrackInfo(wxDC & dc, bool up, const wxRect & r, bool highlight)
341{
342 // Note that the actually drawn rectangle extends one pixel right of and
343 // below the given
344
345 wxColour col;
346 col = Blend( theTheme.Colour( clrTrackInfo ), up ? wxColour( 255,255,255):wxColour(0,0,0));
347
348 wxPen pen( highlight ? uglyPen : col );
349 dc.SetPen( pen );
350
351 dc.DrawLine(r.x, r.y, r.x + r.width, r.y);
352 dc.DrawLine(r.x, r.y, r.x, r.y + r.height);
353
354 col = Blend( theTheme.Colour( clrTrackInfo ), up ? wxColour(0,0,0): wxColour(255,255,255));
355
356 pen.SetColour( col );
357 dc.SetPen( highlight ? uglyPen : pen );
358
359 dc.DrawLine(r.x + r.width, r.y, r.x + r.width, r.y + r.height);
360 dc.DrawLine(r.x, r.y + r.height, r.x + r.width, r.y + r.height);
361}
362
363// Set colour of and select brush and pen.
364// Use -1 to omit brush or pen.
365// If pen omitted, then the same colour as the brush will be used.
366// alpha for the brush is normally 255, but if set will make a difference
367// on mac (only) currently.
368void AColor::UseThemeColour( wxDC * dc, int iBrush, int iPen, int alpha )
369{
370 if (!inited)
371 Init();
372 // do nothing if no colours set.
373 if( (iBrush == -1) && ( iPen ==-1))
374 return;
375 wxColour col = wxColour(0,0,0);
376 if( iBrush !=-1 ){
377 col = theTheme.Colour( iBrush );
378 col.Set( col.Red(), col.Green(), col.Blue(), alpha);
379 spareBrush.SetColour( col );
380 dc->SetBrush( spareBrush );
381 }
382 if( iPen != -1)
383 col = theTheme.Colour( iPen );
384 sparePen.SetColour( col );
385 dc->SetPen( sparePen );
386}
387
388void AColor::UseThemeColour( wxGraphicsContext * gc, int iBrush, int iPen, int alpha )
389{
390 if (!inited)
391 Init();
392 // do nothing if no colours set.
393 if( (iBrush == -1) && ( iPen ==-1))
394 return;
395 wxColour col = wxColour(0,0,0);
396 if( iBrush !=-1 ){
397 col = theTheme.Colour( iBrush );
398 col.Set( col.Red(), col.Green(), col.Blue(), alpha);
399 spareBrush.SetColour( col );
400 gc->SetBrush( spareBrush );
401 }
402 if( iPen != -1)
403 col = theTheme.Colour( iPen );
404 sparePen.SetColour( col );
405 gc->SetPen( sparePen );
406}
407
408
409void AColor::Light(wxDC * dc, bool selected, bool highlight)
410{
411 if (!inited)
412 Init();
413 int index = (int) selected;
414 auto &brush = highlight ? AColor::uglyBrush : lightBrush[index];
415 dc->SetBrush( brush );
416 auto &pen = highlight ? AColor::uglyPen : lightPen[index];
417 dc->SetPen( pen );
418}
419
420void AColor::Medium(wxDC * dc, bool selected)
421{
422 if (!inited)
423 Init();
424 int index = (int) selected;
425 dc->SetBrush(mediumBrush[index]);
426 dc->SetPen(mediumPen[index]);
427}
428
429void AColor::MediumTrackInfo(wxDC * dc, bool selected)
430{
431 UseThemeColour( dc, selected ? clrTrackInfoSelected : clrTrackInfo );
432}
433
434
435void AColor::Dark(wxDC * dc, bool selected, bool highlight)
436{
437 if (!inited)
438 Init();
439 int index = (int) selected;
440 auto &brush = highlight ? AColor::uglyBrush : darkBrush[index];
441 dc->SetBrush( brush );
442 auto &pen = highlight ? AColor::uglyPen : darkPen[index];
443 dc->SetPen( pen );
444}
445
446void AColor::TrackPanelBackground(wxDC * dc, bool selected)
447{
448 UseThemeColour( dc, selected ? clrMediumSelected : clrTrackBackground );
449}
450
451void AColor::CursorColor(wxDC * dc)
452{
453 if (!inited)
454 Init();
455
456 dc->SetLogicalFunction(wxCOPY);
457 dc->SetPen(cursorPen);
458}
459
460void AColor::IndicatorColor(wxDC * dc, bool bIsNotRecording)
461{
462 if (!inited)
463 Init();
464 int index = (int) bIsNotRecording;
465 dc->SetPen(indicatorPen[index]);
466 dc->SetBrush(indicatorBrush[index]);
467}
468
469void AColor::TrackFocusPen(wxDC * dc, int level)
470{
471 if (!inited)
472 Init();
473 dc->SetPen(trackFocusPens[level]);
474}
475
476void AColor::SnapGuidePen(wxDC * dc)
477{
478 if (!inited)
479 Init();
480 dc->SetPen(snapGuidePen);
481}
482
483void AColor::Mute(wxDC * dc, bool on, bool selected, bool soloing)
484{
485 if (!inited)
486 Init();
487 int index = (int) selected;
488 if (on) {
489 dc->SetPen(*wxBLACK_PEN);
490 dc->SetBrush(muteBrush[(int) soloing]);
491 }
492 else {
493 dc->SetPen(*wxTRANSPARENT_PEN);
494 dc->SetBrush(mediumBrush[index]);
495 }
496}
497
498void AColor::Solo(wxDC * dc, bool on, bool selected)
499{
500 if (!inited)
501 Init();
502 int index = (int) selected;
503 if (on) {
504 dc->SetPen(*wxBLACK_PEN);
505 dc->SetBrush(soloBrush);
506 }
507 else {
508 dc->SetPen(*wxTRANSPARENT_PEN);
509 dc->SetBrush(mediumBrush[index]);
510 }
511}
512
514
516{
517 inited=false;
518 Init();
521}
522
523wxColour InvertOfColour( const wxColour & c )
524{
525 return wxColour( 255-c.Red(), 255-c.Green(), 255-c.Blue() );
526}
527
528// Fix up the cursor colour, if it is 'unacceptable'.
529// Unacceptable if it is too close to the background colour.
530wxColour CursorColour( )
531{
532 wxColour cCursor = theTheme.Colour( clrCursorPen );
533 wxColour cBack = theTheme.Colour( clrMedium );
534
535 int d = theTheme.ColourDistance( cCursor, cBack );
536
537 // Pen colour is fine, if there is plenty of contrast.
538 if( d > 200 )
539 return theTheme.Colour( clrCursorPen );
540
541 // otherwise return same colour as a selection.
542 return theTheme.Colour( clrSelected );
543}
544
546{
547 if (inited)
548 return;
549
550 wxColour light = theTheme.Colour( clrLight );
551 // wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
552 wxColour med = theTheme.Colour( clrMedium );
553 // wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
554 wxColour dark = theTheme.Colour( clrDark );
555 // wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW);
556
557 wxColour lightSelected = theTheme.Colour( clrLightSelected );
558 wxColour medSelected = theTheme.Colour( clrMediumSelected );
559 wxColour darkSelected = theTheme.Colour( clrDarkSelected );
560
561
562 clippingPen.SetColour(0xCC, 0x11, 0x00);
563
564 theTheme.SetPenColour( envelopePen, clrEnvelope );
565 theTheme.SetPenColour( WideEnvelopePen, clrEnvelope );
566 theTheme.SetBrushColour( envelopeBrush, clrEnvelope );
567
568 WideEnvelopePen.SetWidth( 3 );
569
570 theTheme.SetBrushColour( labelTextNormalBrush, clrLabelTextNormalBrush );
571 theTheme.SetBrushColour( labelTextEditBrush, clrLabelTextEditBrush );
572 theTheme.SetBrushColour( labelUnselectedBrush, clrLabelUnselectedBrush );
573 theTheme.SetBrushColour( labelSelectedBrush, clrLabelSelectedBrush );
575 theTheme.SetPenColour( labelUnselectedPen, clrLabelUnselectedPen );
576 theTheme.SetPenColour( labelSelectedPen, clrLabelSelectedPen );
577 theTheme.SetPenColour( labelSyncLockSelPen, clrSyncLockSel );
578 theTheme.SetPenColour( labelSurroundPen, clrLabelSurroundPen );
579
580 // These colors were modified to avoid using reserved colors red and green
581 // for the buttons.
582 theTheme.SetBrushColour( muteBrush[0], clrMuteButtonActive);
583 theTheme.SetBrushColour( muteBrush[1], clrMuteButtonVetoed);
584 theTheme.SetBrushColour( soloBrush, clrMuteButtonActive);
585
586 cursorPen.SetColour( CursorColour() );
587 theTheme.SetPenColour( indicatorPen[0], clrRecordingPen);
588 theTheme.SetPenColour( indicatorPen[1], clrPlaybackPen);
589 theTheme.SetBrushColour( indicatorBrush[0], clrRecordingBrush);
590 theTheme.SetBrushColour( indicatorBrush[1], clrPlaybackBrush);
591
592 theTheme.SetBrushColour( playRegionBrush[0],clrRulerRecordingBrush);
593 // theTheme.SetPenColour( playRegionPen[0], clrRulerRecordingPen);
594 // theTheme.SetBrushColour( playRegionBrush[1],clrRulerPlaybackBrush);
595 // theTheme.SetPenColour( playRegionPen[1], clrRulerPlaybackPen);
596
597 //Determine tooltip color
598 tooltipPen.SetColour( wxSystemSettingsNative::GetColour(wxSYS_COLOUR_INFOTEXT) );
599 tooltipBrush.SetColour( wxSystemSettingsNative::GetColour(wxSYS_COLOUR_INFOBK) );
600
601 uglyPen.SetColour( wxColour{ 0, 255, 0 } ); // saturated green
602 uglyBrush.SetColour( wxColour{ 255, 0, 255 } ); // saturated magenta
603
604 // A tiny gradient of yellow surrounding the current focused track
605 theTheme.SetPenColour( trackFocusPens[0], clrTrackFocus0);
606 theTheme.SetPenColour( trackFocusPens[1], clrTrackFocus1);
607 theTheme.SetPenColour( trackFocusPens[2], clrTrackFocus2);
608
609 // A vertical line indicating that the selection or sliding has
610 // been snapped to the nearest boundary.
611 theTheme.SetPenColour( snapGuidePen, clrSnapGuide);
612
613 // unselected
614 lightBrush[0].SetColour(light);
615 mediumBrush[0].SetColour(med);
616 darkBrush[0].SetColour(dark);
617 lightPen[0].SetColour(light);
618 mediumPen[0].SetColour(med);
619 darkPen[0].SetColour(dark);
620
621 // selected
622 lightBrush[1].SetColour(lightSelected);
623 mediumBrush[1].SetColour(medSelected);
624 darkBrush[1].SetColour(darkSelected);
625 lightPen[1].SetColour(lightSelected);
626 mediumPen[1].SetColour(medSelected);
627 darkPen[1].SetColour(darkSelected);
628
629 inited = true;
630}
631
632// These colours are chosen so that black text shows up OK on them.
633const int AColor_midicolors[16][3] = {
634 {255, 102, 102}, // 1=salmon
635 {204, 0, 0}, // 2=red
636 {255, 117, 23}, // 3=orange
637 {255, 255, 0}, // 4=yellow
638 {0, 204, 0}, // 5=green
639 {0, 204, 204}, // 6=turquoise
640 {125, 125, 255}, // 7=blue
641 {153, 0, 255}, // 8=blue-violet
642
643 {140, 97, 54}, // 9=brown
644 {120, 120, 120}, // 10=gray (drums)
645 {255, 175, 40}, // 11=lt orange
646 {102, 255, 102}, // 12=lt green
647 {153, 255, 255}, // 13=lt turquoise
648 {190, 190, 255}, // 14=lt blue
649 {204, 102, 255}, // 15=lt blue-violet
650 {255, 51, 204} // 16=lt red-violet
651};
652
653void AColor::MIDIChannel(wxDC * dc, int channel /* 1 - 16 */ )
654{
655 if (channel >= 1 && channel <= 16) {
656 const int *colors = AColor_midicolors[channel - 1];
657
658 dc->SetPen(wxPen(wxColour(colors[0],
659 colors[1], colors[2]), 1, wxPENSTYLE_SOLID));
660 dc->SetBrush(wxBrush(wxColour(colors[0],
661 colors[1], colors[2]), wxBRUSHSTYLE_SOLID));
662 } else {
663 dc->SetPen(wxPen(wxColour(153, 153, 153), 1, wxPENSTYLE_SOLID));
664 dc->SetBrush(wxBrush(wxColour(153, 153, 153), wxBRUSHSTYLE_SOLID));
665 }
666
667}
668
669void AColor::LightMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ )
670{
671 if (channel >= 1 && channel <= 16) {
672 const int *colors = AColor_midicolors[channel - 1];
673
674 dc->SetPen(wxPen(wxColour(127 + colors[0] / 2,
675 127 + colors[1] / 2,
676 127 + colors[2] / 2), 1, wxPENSTYLE_SOLID));
677 dc->SetBrush(wxBrush(wxColour(127 + colors[0] / 2,
678 127 + colors[1] / 2,
679 127 + colors[2] / 2), wxBRUSHSTYLE_SOLID));
680 } else {
681 dc->SetPen(wxPen(wxColour(204, 204, 204), 1, wxPENSTYLE_SOLID));
682 dc->SetBrush(wxBrush(wxColour(204, 204, 204), wxBRUSHSTYLE_SOLID));
683 }
684
685}
686
687void AColor::DarkMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ )
688{
689 if (channel >= 1 && channel <= 16) {
690 const int *colors = AColor_midicolors[channel - 1];
691
692 dc->SetPen(wxPen(wxColour(colors[0] / 2,
693 colors[1] / 2,
694 colors[2] / 2), 1, wxPENSTYLE_SOLID));
695 dc->SetBrush(wxBrush(wxColour(colors[0] / 2,
696 colors[1] / 2,
697 colors[2] / 2), wxBRUSHSTYLE_SOLID));
698 } else {
699 dc->SetPen(wxPen(wxColour(102, 102, 102), 1, wxPENSTYLE_SOLID));
700 dc->SetBrush(wxBrush(wxColour(102, 102, 102), wxBRUSHSTYLE_SOLID));
701 }
702
703}
704
705
706
707unsigned char AColor::gradient_pre[ColorGradientTotal][colorSchemes][gradientSteps][3];
708
710 if (gradient_inited) return;
711 gradient_inited = 1;
712
713 // Keep in correspondence with enum SpectrogramSettings::ColorScheme
714
715 // colorScheme 0: Color (New)
716 std::copy_n(&specColormap[0][0], gradientSteps * 3, &gradient_pre[ColorGradientUnselected][0][0][0]);
717 std::copy_n(&selColormap[0][0], gradientSteps * 3, &gradient_pre[ColorGradientTimeSelected][0][0][0]);
719 std::fill_n(&gradient_pre[ColorGradientEdge][0][0][0], gradientSteps * 3, 0);
720
721
722 for (int selected = 0; selected < ColorGradientTotal; selected++) {
723 // Get color scheme from Theme
724 const int gsteps = 4;
725 float gradient[gsteps + 1][3];
726 theTheme.Colour( clrSpectro1 ) = theTheme.Colour( clrUnselected );
727 theTheme.Colour( clrSpectro1Sel ) = theTheme.Colour( clrSelected );
728 int clrFirst = (selected == ColorGradientUnselected ) ? clrSpectro1 : clrSpectro1Sel;
729 for(int j=0;j<(gsteps+1);j++){
730 wxColour c = theTheme.Colour( clrFirst+j );
731 gradient[ j] [0] = c.Red()/255.0;
732 gradient[ j] [1] = c.Green()/255.0;
733 gradient[ j] [2] = c.Blue()/255.0;
734 }
735
736 // colorScheme 1: Color (from theme)
737 for (int i = 0; i<gradientSteps; i++) {
738 float r, g, b;
739 float value = float(i)/gradientSteps;
740
741 int left = (int)(value * gsteps);
742 int right = (left == gsteps ? gsteps : left + 1);
743
744 float rweight = (value * gsteps) - left;
745 float lweight = 1.0 - rweight;
746
747 r = (gradient[left][0] * lweight) + (gradient[right][0] * rweight);
748 g = (gradient[left][1] * lweight) + (gradient[right][1] * rweight);
749 b = (gradient[left][2] * lweight) + (gradient[right][2] * rweight);
750
751 switch (selected) {
753 // not dimmed
754 break;
755
757 float temp;
758 temp = r;
759 r = g;
760 g = b;
761 b = temp;
762 break;
763
765 // partly dimmed
766 r *= 0.75f;
767 g *= 0.75f;
768 b *= 0.75f;
769 break;
770
771
772 // For now edge colour is just black (or white if grey-scale)
773 // Later we might invert or something else funky.
775 // fully dimmed
776 r = 0;
777 g = 0;
778 b = 0;
779 break;
780 }
781 gradient_pre[selected][1][i][0] = (unsigned char) (255 * r);
782 gradient_pre[selected][1][i][1] = (unsigned char) (255 * g);
783 gradient_pre[selected][1][i][2] = (unsigned char) (255 * b);
784 }
785
786 // colorScheme 3: Inverse Grayscale
787 for (int i = 0; i < gradientSteps; i++) {
788 float r, g, b;
789 float value = float(i) / gradientSteps;
790
791 r = g = b = value;
792
793 switch (selected) {
795 // not dimmed
796 break;
797
799 // else fall through to SAME grayscale colour as normal selection.
800 // The white lines show it up clearly enough.
801
803 // partly dimmed
804 r = r * 0.75f + 0.25f;
805 g = g * 0.75f + 0.25f;
806 b = b * 0.75f + 0.25f;
807 break;
808
810 r = 1.0f;
811 g = 1.0f;
812 b = 1.0f;
813 break;
814 }
815 gradient_pre[selected][3][i][0] = (unsigned char)(255 * r);
816 gradient_pre[selected][3][i][1] = (unsigned char)(255 * g);
817 gradient_pre[selected][3][i][2] = (unsigned char)(255 * b);
818 }
819
820 // colorScheme 2: Grayscale (=Old grayscale)
821 for (int i = 0; i<gradientSteps; i++) {
822 float r, g, b;
823 float value = float(i)/gradientSteps;
824
825 r = g = b = 0.84 - 0.84 * value;
826
827 switch (selected) {
829 // not dimmed
830 break;
831
833 // else fall through to SAME grayscale colour as normal selection.
834 // The white lines show it up clearly enough.
835
837 // partly dimmed
838 r *= 0.75f;
839 g *= 0.75f;
840 b *= 0.75f;
841 break;
842
843
844 // For now edge colour is just black (or white if grey-scale)
845 // Later we might invert or something else funky.
847 // fully dimmed
848 r = 1.0f;
849 g = 1.0f;
850 b = 1.0f;
851 break;
852 }
853 gradient_pre[selected][2][i][0] = (unsigned char) (255 * r);
854 gradient_pre[selected][2][i][1] = (unsigned char) (255 * g);
855 gradient_pre[selected][2][i][2] = (unsigned char) (255 * b);
856 }
857 }
858}
859
861{
862 ReInit();
863 theTheme.Publish({});
864}
wxColour InvertOfColour(const wxColour &c)
Definition: AColor.cpp:523
wxColour CursorColour()
Definition: AColor.cpp:530
const int AColor_midicolors[16][3]
Definition: AColor.cpp:633
const unsigned char specColormap[256][3]
const unsigned char freqSelColormap[256][3]
const unsigned char selColormap[256][3]
int min(int a, int b)
THEME_API Theme theTheme
Definition: Theme.cpp:82
static wxBrush mediumBrush[2]
Definition: AColor.h:98
static void Arrow(wxDC &dc, wxCoord x, wxCoord y, int width, bool down=true)
Definition: AColor.cpp:160
static wxBrush labelSelectedBrush
Definition: AColor.h:122
static wxBrush darkBrush[2]
Definition: AColor.h:99
static void Solo(wxDC *dc, bool on, bool selected)
Definition: AColor.cpp:498
static void Bevel2(wxDC &dc, bool up, const wxRect &r, bool bSel=false, bool bHighlight=false)
Definition: AColor.cpp:294
static wxPen trackFocusPens[3]
Definition: AColor.h:129
static wxPen clippingPen
Definition: AColor.h:113
static wxPen WideEnvelopePen
Definition: AColor.h:116
static void IndicatorColor(wxDC *dc, bool bIsNotRecording)
Definition: AColor.cpp:460
static wxPen sparePen
Definition: AColor.h:145
static void Mute(wxDC *dc, bool on, bool selected, bool soloing)
Definition: AColor.cpp:483
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
@ ColorGradientTotal
Definition: AColor.h:34
@ ColorGradientUnselected
Definition: AColor.h:29
@ ColorGradientTimeAndFrequencySelected
Definition: AColor.h:31
@ ColorGradientEdge
Definition: AColor.h:32
@ ColorGradientTimeSelected
Definition: AColor.h:30
static wxColour Blend(const wxColour &c1, const wxColour &c2)
Definition: AColor.cpp:331
static void PreComputeGradient()
Definition: AColor.cpp:709
static wxBrush uglyBrush
Definition: AColor.h:142
static bool inited
Definition: AColor.h:147
static wxBrush lightBrush[2]
Definition: AColor.h:97
static wxBrush playRegionBrush[1]
Definition: AColor.h:108
static void SnapGuidePen(wxDC *dc)
Definition: AColor.cpp:476
static void CursorColor(wxDC *dc)
Definition: AColor.cpp:451
static void Lines(wxDC &dc, size_t nPoints, const wxPoint points[])
Definition: AColor.cpp:194
static wxPen labelSurroundPen
Definition: AColor.h:127
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:266
static wxBrush muteBrush[2]
Definition: AColor.h:110
static wxPen cursorPen
Definition: AColor.h:104
static void Light(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:409
static void LightMIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:669
static void ReInit()
Definition: AColor.cpp:515
static wxPen tooltipPen
Definition: AColor.h:132
static wxPen lightPen[2]
Definition: AColor.h:100
static wxPen mediumPen[2]
Definition: AColor.h:101
static void MediumTrackInfo(wxDC *dc, bool selected)
Definition: AColor.cpp:429
static void ApplyUpdatedImages()
Definition: AColor.cpp:860
static wxBrush envelopeBrush
Definition: AColor.h:117
static wxBrush labelTextNormalBrush
Definition: AColor.h:119
static wxBrush labelTextEditBrush
Definition: AColor.h:120
static wxPen uglyPen
Definition: AColor.h:141
static const int gradientSteps
Definition: AColor.h:137
static void DrawHStretch(wxDC &dc, const wxRect &rect, wxBitmap &bitmap)
Definition: AColor.cpp:308
static void Init()
Definition: AColor.cpp:545
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:435
static void Medium(wxDC *dc, bool selected)
Definition: AColor.cpp:420
static void ButtonStretch(wxDC &dc, bool up, const wxRect &r, bool selected=false, bool highlight=false)
Draw a button that fills a given rect.
Definition: AColor.cpp:285
static wxBrush labelSyncLockSelBrush
Definition: AColor.h:123
static wxPen envelopePen
Definition: AColor.h:115
static unsigned char gradient_pre[ColorGradientTotal][colorSchemes][gradientSteps][3]
Definition: AColor.h:138
static wxPen labelSelectedPen
Definition: AColor.h:125
static wxBrush tooltipBrush
Definition: AColor.h:133
static void MIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:653
static wxBrush indicatorBrush[2]
Definition: AColor.h:106
static void TrackFocusPen(wxDC *dc, int level)
Definition: AColor.cpp:469
static void BevelTrackInfo(wxDC &dc, bool up, const wxRect &r, bool highlight=false)
Definition: AColor.cpp:340
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:446
static wxBrush soloBrush
Definition: AColor.h:111
static wxBrush labelUnselectedBrush
Definition: AColor.h:121
static wxPen darkPen[2]
Definition: AColor.h:102
static void DrawFrame(wxDC &dc, const wxRect &r, wxBitmap &bitmap)
Definition: AColor.cpp:325
static wxPen snapGuidePen
Definition: AColor.h:130
static wxPen indicatorPen[2]
Definition: AColor.h:105
static wxBrush spareBrush
Definition: AColor.h:146
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:368
static void DarkMIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:687
static void DrawFocus(wxDC &dc, wxRect &r)
Definition: AColor.cpp:235
static wxPen labelUnselectedPen
Definition: AColor.h:124
static bool gradient_inited
Definition: AColor.h:135
static wxPen labelSyncLockSelPen
Definition: AColor.h:126
CallbackReturn Publish(const Message &message)
Send a message to connected callbacks.
Definition: Observer.h:207
wxColour & Colour(int iIndex)
void SetBrushColour(wxBrush &Brush, int iIndex)
wxBitmap & Bitmap(int iIndex)
int ColourDistance(wxColour &From, wxColour &To)
Definition: Theme.cpp:285
void SetPenColour(wxPen &Pen, int iIndex)
void DrawNinePatch(wxDC &dc, wxBitmap &bitmap, const wxRect &r)
Definition: AColor.cpp:84
int GetButtonImageIndex(bool up, bool selected, bool highlight)
Definition: AColor.cpp:138