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
308wxColour AColor::Blend( const wxColour & c1, const wxColour & c2 )
309{
310 wxColour c3(
311 (c1.Red() + c2.Red())/2,
312 (c1.Green() + c2.Green())/2,
313 (c1.Blue() + c2.Blue())/2);
314 return c3;
315}
316
317void AColor::BevelTrackInfo(wxDC & dc, bool up, const wxRect & r, bool highlight)
318{
319#ifndef EXPERIMENTAL_THEMING
320 Bevel( dc, up, r );
321#else
322 // Note that the actually drawn rectangle extends one pixel right of and
323 // below the given
324
325 wxColour col;
326 col = Blend( theTheme.Colour( clrTrackInfo ), up ? wxColour( 255,255,255):wxColour(0,0,0));
327
328 wxPen pen( highlight ? uglyPen : col );
329 dc.SetPen( pen );
330
331 dc.DrawLine(r.x, r.y, r.x + r.width, r.y);
332 dc.DrawLine(r.x, r.y, r.x, r.y + r.height);
333
334 col = Blend( theTheme.Colour( clrTrackInfo ), up ? wxColour(0,0,0): wxColour(255,255,255));
335
336 pen.SetColour( col );
337 dc.SetPen( highlight ? uglyPen : pen );
338
339 dc.DrawLine(r.x + r.width, r.y, r.x + r.width, r.y + r.height);
340 dc.DrawLine(r.x, r.y + r.height, r.x + r.width, r.y + r.height);
341#endif
342}
343
344// Set colour of and select brush and pen.
345// Use -1 to omit brush or pen.
346// If pen omitted, then the same colour as the brush will be used.
347// alpha for the brush is normally 255, but if set will make a difference
348// on mac (only) currently.
349void AColor::UseThemeColour( wxDC * dc, int iBrush, int iPen, int alpha )
350{
351 if (!inited)
352 Init();
353 // do nothing if no colours set.
354 if( (iBrush == -1) && ( iPen ==-1))
355 return;
356 wxColour col = wxColour(0,0,0);
357 if( iBrush !=-1 ){
358 col = theTheme.Colour( iBrush );
359 col.Set( col.Red(), col.Green(), col.Blue(), alpha);
360 spareBrush.SetColour( col );
361 dc->SetBrush( spareBrush );
362 }
363 if( iPen != -1)
364 col = theTheme.Colour( iPen );
365 sparePen.SetColour( col );
366 dc->SetPen( sparePen );
367}
368
369void AColor::UseThemeColour( wxGraphicsContext * gc, int iBrush, int iPen, int alpha )
370{
371 if (!inited)
372 Init();
373 // do nothing if no colours set.
374 if( (iBrush == -1) && ( iPen ==-1))
375 return;
376 wxColour col = wxColour(0,0,0);
377 if( iBrush !=-1 ){
378 col = theTheme.Colour( iBrush );
379 col.Set( col.Red(), col.Green(), col.Blue(), alpha);
380 spareBrush.SetColour( col );
381 gc->SetBrush( spareBrush );
382 }
383 if( iPen != -1)
384 col = theTheme.Colour( iPen );
385 sparePen.SetColour( col );
386 gc->SetPen( sparePen );
387}
388
389
390void AColor::Light(wxDC * dc, bool selected, bool highlight)
391{
392 if (!inited)
393 Init();
394 int index = (int) selected;
395 auto &brush = highlight ? AColor::uglyBrush : lightBrush[index];
396 dc->SetBrush( brush );
397 auto &pen = highlight ? AColor::uglyPen : lightPen[index];
398 dc->SetPen( pen );
399}
400
401void AColor::Medium(wxDC * dc, bool selected)
402{
403 if (!inited)
404 Init();
405 int index = (int) selected;
406 dc->SetBrush(mediumBrush[index]);
407 dc->SetPen(mediumPen[index]);
408}
409
410void AColor::MediumTrackInfo(wxDC * dc, bool selected)
411{
412#ifdef EXPERIMENTAL_THEMING
413 UseThemeColour( dc, selected ? clrTrackInfoSelected : clrTrackInfo );
414#else
415 Medium( dc, selected );
416#endif
417}
418
419
420void AColor::Dark(wxDC * dc, bool selected, bool highlight)
421{
422 if (!inited)
423 Init();
424 int index = (int) selected;
425 auto &brush = highlight ? AColor::uglyBrush : darkBrush[index];
426 dc->SetBrush( brush );
427 auto &pen = highlight ? AColor::uglyPen : darkPen[index];
428 dc->SetPen( pen );
429}
430
431void AColor::TrackPanelBackground(wxDC * dc, bool selected)
432{
433#ifdef EXPERIMENTAL_THEMING
434 UseThemeColour( dc, selected ? clrMediumSelected : clrTrackBackground );
435#else
436 Dark( dc, selected );
437#endif
438}
439
440void AColor::CursorColor(wxDC * dc)
441{
442 if (!inited)
443 Init();
444
445 dc->SetLogicalFunction(wxCOPY);
446 dc->SetPen(cursorPen);
447}
448
449void AColor::IndicatorColor(wxDC * dc, bool bIsNotRecording)
450{
451 if (!inited)
452 Init();
453 int index = (int) bIsNotRecording;
454 dc->SetPen(indicatorPen[index]);
455 dc->SetBrush(indicatorBrush[index]);
456}
457
458void AColor::TrackFocusPen(wxDC * dc, int level)
459{
460 if (!inited)
461 Init();
462 dc->SetPen(trackFocusPens[level]);
463}
464
465void AColor::SnapGuidePen(wxDC * dc)
466{
467 if (!inited)
468 Init();
469 dc->SetPen(snapGuidePen);
470}
471
472void AColor::Mute(wxDC * dc, bool on, bool selected, bool soloing)
473{
474 if (!inited)
475 Init();
476 int index = (int) selected;
477 if (on) {
478 dc->SetPen(*wxBLACK_PEN);
479 dc->SetBrush(muteBrush[(int) soloing]);
480 }
481 else {
482 dc->SetPen(*wxTRANSPARENT_PEN);
483 dc->SetBrush(mediumBrush[index]);
484 }
485}
486
487void AColor::Solo(wxDC * dc, bool on, bool selected)
488{
489 if (!inited)
490 Init();
491 int index = (int) selected;
492 if (on) {
493 dc->SetPen(*wxBLACK_PEN);
494 dc->SetBrush(soloBrush);
495 }
496 else {
497 dc->SetPen(*wxTRANSPARENT_PEN);
498 dc->SetBrush(mediumBrush[index]);
499 }
500}
501
503
505{
506 inited=false;
507 Init();
510}
511
512wxColour InvertOfColour( const wxColour & c )
513{
514 return wxColour( 255-c.Red(), 255-c.Green(), 255-c.Blue() );
515}
516
517// Fix up the cursor colour, if it is 'unacceptable'.
518// Unacceptable if it is too close to the background colour.
519wxColour CursorColour( )
520{
521 wxColour cCursor = theTheme.Colour( clrCursorPen );
522 wxColour cBack = theTheme.Colour( clrMedium );
523
524 int d = theTheme.ColourDistance( cCursor, cBack );
525
526 // Pen colour is fine, if there is plenty of contrast.
527 if( d > 200 )
528 return theTheme.Colour( clrCursorPen );
529
530 // otherwise return same colour as a selection.
531 return theTheme.Colour( clrSelected );
532}
533
535{
536 if (inited)
537 return;
538
539 wxColour light = theTheme.Colour( clrLight );
540 // wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
541 wxColour med = theTheme.Colour( clrMedium );
542 // wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
543 wxColour dark = theTheme.Colour( clrDark );
544 // wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW);
545
546 wxColour lightSelected = theTheme.Colour( clrLightSelected );
547 wxColour medSelected = theTheme.Colour( clrMediumSelected );
548 wxColour darkSelected = theTheme.Colour( clrDarkSelected );
549
550
551 clippingPen.SetColour(0xCC, 0x11, 0x00);
552
553 theTheme.SetPenColour( envelopePen, clrEnvelope );
554 theTheme.SetPenColour( WideEnvelopePen, clrEnvelope );
555 theTheme.SetBrushColour( envelopeBrush, clrEnvelope );
556
557 WideEnvelopePen.SetWidth( 3 );
558
559 theTheme.SetBrushColour( labelTextNormalBrush, clrLabelTextNormalBrush );
560 theTheme.SetBrushColour( labelTextEditBrush, clrLabelTextEditBrush );
561 theTheme.SetBrushColour( labelUnselectedBrush, clrLabelUnselectedBrush );
562 theTheme.SetBrushColour( labelSelectedBrush, clrLabelSelectedBrush );
564 theTheme.SetPenColour( labelUnselectedPen, clrLabelUnselectedPen );
565 theTheme.SetPenColour( labelSelectedPen, clrLabelSelectedPen );
566 theTheme.SetPenColour( labelSyncLockSelPen, clrSyncLockSel );
567 theTheme.SetPenColour( labelSurroundPen, clrLabelSurroundPen );
568
569 // These colors were modified to avoid using reserved colors red and green
570 // for the buttons.
571 theTheme.SetBrushColour( muteBrush[0], clrMuteButtonActive);
572 theTheme.SetBrushColour( muteBrush[1], clrMuteButtonVetoed);
573 theTheme.SetBrushColour( soloBrush, clrMuteButtonActive);
574
575 cursorPen.SetColour( CursorColour() );
576 theTheme.SetPenColour( indicatorPen[0], clrRecordingPen);
577 theTheme.SetPenColour( indicatorPen[1], clrPlaybackPen);
578 theTheme.SetBrushColour( indicatorBrush[0], clrRecordingBrush);
579 theTheme.SetBrushColour( indicatorBrush[1], clrPlaybackBrush);
580
581 theTheme.SetBrushColour( playRegionBrush[0],clrRulerRecordingBrush);
582 // theTheme.SetPenColour( playRegionPen[0], clrRulerRecordingPen);
583 // theTheme.SetBrushColour( playRegionBrush[1],clrRulerPlaybackBrush);
584 // theTheme.SetPenColour( playRegionPen[1], clrRulerPlaybackPen);
585
586 //Determine tooltip color
587 tooltipPen.SetColour( wxSystemSettingsNative::GetColour(wxSYS_COLOUR_INFOTEXT) );
588 tooltipBrush.SetColour( wxSystemSettingsNative::GetColour(wxSYS_COLOUR_INFOBK) );
589
590 uglyPen.SetColour( wxColour{ 0, 255, 0 } ); // saturated green
591 uglyBrush.SetColour( wxColour{ 255, 0, 255 } ); // saturated magenta
592
593 // A tiny gradient of yellow surrounding the current focused track
594 theTheme.SetPenColour( trackFocusPens[0], clrTrackFocus0);
595 theTheme.SetPenColour( trackFocusPens[1], clrTrackFocus1);
596 theTheme.SetPenColour( trackFocusPens[2], clrTrackFocus2);
597
598 // A vertical line indicating that the selection or sliding has
599 // been snapped to the nearest boundary.
600 theTheme.SetPenColour( snapGuidePen, clrSnapGuide);
601
602 // unselected
603 lightBrush[0].SetColour(light);
604 mediumBrush[0].SetColour(med);
605 darkBrush[0].SetColour(dark);
606 lightPen[0].SetColour(light);
607 mediumPen[0].SetColour(med);
608 darkPen[0].SetColour(dark);
609
610 // selected
611 lightBrush[1].SetColour(lightSelected);
612 mediumBrush[1].SetColour(medSelected);
613 darkBrush[1].SetColour(darkSelected);
614 lightPen[1].SetColour(lightSelected);
615 mediumPen[1].SetColour(medSelected);
616 darkPen[1].SetColour(darkSelected);
617
618 inited = true;
619}
620
621// These colours are chosen so that black text shows up OK on them.
622const int AColor_midicolors[16][3] = {
623 {255, 102, 102}, // 1=salmon
624 {204, 0, 0}, // 2=red
625 {255, 117, 23}, // 3=orange
626 {255, 255, 0}, // 4=yellow
627 {0, 204, 0}, // 5=green
628 {0, 204, 204}, // 6=turquoise
629 {125, 125, 255}, // 7=blue
630 {153, 0, 255}, // 8=blue-violet
631
632 {140, 97, 54}, // 9=brown
633 {120, 120, 120}, // 10=gray (drums)
634 {255, 175, 40}, // 11=lt orange
635 {102, 255, 102}, // 12=lt green
636 {153, 255, 255}, // 13=lt turquoise
637 {190, 190, 255}, // 14=lt blue
638 {204, 102, 255}, // 15=lt blue-violet
639 {255, 51, 204} // 16=lt red-violet
640};
641
642void AColor::MIDIChannel(wxDC * dc, int channel /* 1 - 16 */ )
643{
644 if (channel >= 1 && channel <= 16) {
645 const int *colors = AColor_midicolors[channel - 1];
646
647 dc->SetPen(wxPen(wxColour(colors[0],
648 colors[1], colors[2]), 1, wxPENSTYLE_SOLID));
649 dc->SetBrush(wxBrush(wxColour(colors[0],
650 colors[1], colors[2]), wxBRUSHSTYLE_SOLID));
651 } else {
652 dc->SetPen(wxPen(wxColour(153, 153, 153), 1, wxPENSTYLE_SOLID));
653 dc->SetBrush(wxBrush(wxColour(153, 153, 153), wxBRUSHSTYLE_SOLID));
654 }
655
656}
657
658void AColor::LightMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ )
659{
660 if (channel >= 1 && channel <= 16) {
661 const int *colors = AColor_midicolors[channel - 1];
662
663 dc->SetPen(wxPen(wxColour(127 + colors[0] / 2,
664 127 + colors[1] / 2,
665 127 + colors[2] / 2), 1, wxPENSTYLE_SOLID));
666 dc->SetBrush(wxBrush(wxColour(127 + colors[0] / 2,
667 127 + colors[1] / 2,
668 127 + colors[2] / 2), wxBRUSHSTYLE_SOLID));
669 } else {
670 dc->SetPen(wxPen(wxColour(204, 204, 204), 1, wxPENSTYLE_SOLID));
671 dc->SetBrush(wxBrush(wxColour(204, 204, 204), wxBRUSHSTYLE_SOLID));
672 }
673
674}
675
676void AColor::DarkMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ )
677{
678 if (channel >= 1 && channel <= 16) {
679 const int *colors = AColor_midicolors[channel - 1];
680
681 dc->SetPen(wxPen(wxColour(colors[0] / 2,
682 colors[1] / 2,
683 colors[2] / 2), 1, wxPENSTYLE_SOLID));
684 dc->SetBrush(wxBrush(wxColour(colors[0] / 2,
685 colors[1] / 2,
686 colors[2] / 2), wxBRUSHSTYLE_SOLID));
687 } else {
688 dc->SetPen(wxPen(wxColour(102, 102, 102), 1, wxPENSTYLE_SOLID));
689 dc->SetBrush(wxBrush(wxColour(102, 102, 102), wxBRUSHSTYLE_SOLID));
690 }
691
692}
693
694
695
696unsigned char AColor::gradient_pre[ColorGradientTotal][colorSchemes][gradientSteps][3];
697
699 if (gradient_inited) return;
700 gradient_inited = 1;
701
702 // Keep in correspondence with enum SpectrogramSettings::ColorScheme
703
704 // colorScheme 0: Color (New)
705 std::copy_n(&specColormap[0][0], gradientSteps * 3, &gradient_pre[ColorGradientUnselected][0][0][0]);
706 std::copy_n(&selColormap[0][0], gradientSteps * 3, &gradient_pre[ColorGradientTimeSelected][0][0][0]);
708 std::fill_n(&gradient_pre[ColorGradientEdge][0][0][0], gradientSteps * 3, 0);
709
710
711 for (int selected = 0; selected < ColorGradientTotal; selected++) {
712 // Get color scheme from Theme
713 const int gsteps = 4;
714 float gradient[gsteps + 1][3];
715 theTheme.Colour( clrSpectro1 ) = theTheme.Colour( clrUnselected );
716 theTheme.Colour( clrSpectro1Sel ) = theTheme.Colour( clrSelected );
717 int clrFirst = (selected == ColorGradientUnselected ) ? clrSpectro1 : clrSpectro1Sel;
718 for(int j=0;j<(gsteps+1);j++){
719 wxColour c = theTheme.Colour( clrFirst+j );
720 gradient[ j] [0] = c.Red()/255.0;
721 gradient[ j] [1] = c.Green()/255.0;
722 gradient[ j] [2] = c.Blue()/255.0;
723 }
724
725 // colorScheme 1: Color (from theme)
726 for (int i = 0; i<gradientSteps; i++) {
727 float r, g, b;
728 float value = float(i)/gradientSteps;
729
730 int left = (int)(value * gsteps);
731 int right = (left == gsteps ? gsteps : left + 1);
732
733 float rweight = (value * gsteps) - left;
734 float lweight = 1.0 - rweight;
735
736 r = (gradient[left][0] * lweight) + (gradient[right][0] * rweight);
737 g = (gradient[left][1] * lweight) + (gradient[right][1] * rweight);
738 b = (gradient[left][2] * lweight) + (gradient[right][2] * rweight);
739
740 switch (selected) {
742 // not dimmed
743 break;
744
746 float temp;
747 temp = r;
748 r = g;
749 g = b;
750 b = temp;
751 break;
752
754 // partly dimmed
755 r *= 0.75f;
756 g *= 0.75f;
757 b *= 0.75f;
758 break;
759
760
761 // For now edge colour is just black (or white if grey-scale)
762 // Later we might invert or something else funky.
764 // fully dimmed
765 r = 0;
766 g = 0;
767 b = 0;
768 break;
769 }
770 gradient_pre[selected][1][i][0] = (unsigned char) (255 * r);
771 gradient_pre[selected][1][i][1] = (unsigned char) (255 * g);
772 gradient_pre[selected][1][i][2] = (unsigned char) (255 * b);
773 }
774
775 // colorScheme 3: Inverse Grayscale
776 for (int i = 0; i < gradientSteps; i++) {
777 float r, g, b;
778 float value = float(i) / gradientSteps;
779
780 r = g = b = value;
781
782 switch (selected) {
784 // not dimmed
785 break;
786
788 // else fall through to SAME grayscale colour as normal selection.
789 // The white lines show it up clearly enough.
790
792 // partly dimmed
793 r = r * 0.75f + 0.25f;
794 g = g * 0.75f + 0.25f;
795 b = b * 0.75f + 0.25f;
796 break;
797
799 r = 1.0f;
800 g = 1.0f;
801 b = 1.0f;
802 break;
803 }
804 gradient_pre[selected][3][i][0] = (unsigned char)(255 * r);
805 gradient_pre[selected][3][i][1] = (unsigned char)(255 * g);
806 gradient_pre[selected][3][i][2] = (unsigned char)(255 * b);
807 }
808
809 // colorScheme 2: Grayscale (=Old grayscale)
810 for (int i = 0; i<gradientSteps; i++) {
811 float r, g, b;
812 float value = float(i)/gradientSteps;
813
814 r = g = b = 0.84 - 0.84 * value;
815
816 switch (selected) {
818 // not dimmed
819 break;
820
822 // else fall through to SAME grayscale colour as normal selection.
823 // The white lines show it up clearly enough.
824
826 // partly dimmed
827 r *= 0.75f;
828 g *= 0.75f;
829 b *= 0.75f;
830 break;
831
832
833 // For now edge colour is just black (or white if grey-scale)
834 // Later we might invert or something else funky.
836 // fully dimmed
837 r = 1.0f;
838 g = 1.0f;
839 b = 1.0f;
840 break;
841 }
842 gradient_pre[selected][2][i][0] = (unsigned char) (255 * r);
843 gradient_pre[selected][2][i][1] = (unsigned char) (255 * g);
844 gradient_pre[selected][2][i][2] = (unsigned char) (255 * b);
845 }
846 }
847}
848
850{
851 ReInit();
852 theTheme.Publish({});
853}
wxColour InvertOfColour(const wxColour &c)
Definition: AColor.cpp:512
wxColour CursorColour()
Definition: AColor.cpp:519
const int AColor_midicolors[16][3]
Definition: AColor.cpp:622
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:93
static void Arrow(wxDC &dc, wxCoord x, wxCoord y, int width, bool down=true)
Definition: AColor.cpp:160
static wxBrush labelSelectedBrush
Definition: AColor.h:117
static wxBrush darkBrush[2]
Definition: AColor.h:94
static void Solo(wxDC *dc, bool on, bool selected)
Definition: AColor.cpp:487
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:124
static wxPen clippingPen
Definition: AColor.h:108
static wxPen WideEnvelopePen
Definition: AColor.h:111
static void IndicatorColor(wxDC *dc, bool bIsNotRecording)
Definition: AColor.cpp:449
static wxPen sparePen
Definition: AColor.h:140
static void Mute(wxDC *dc, bool on, bool selected, bool soloing)
Definition: AColor.cpp:472
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:308
static void PreComputeGradient()
Definition: AColor.cpp:698
static wxBrush uglyBrush
Definition: AColor.h:137
static bool inited
Definition: AColor.h:142
static wxBrush lightBrush[2]
Definition: AColor.h:92
static wxBrush playRegionBrush[1]
Definition: AColor.h:103
static void SnapGuidePen(wxDC *dc)
Definition: AColor.cpp:465
static void CursorColor(wxDC *dc)
Definition: AColor.cpp:440
static void Lines(wxDC &dc, size_t nPoints, const wxPoint points[])
Definition: AColor.cpp:194
static wxPen labelSurroundPen
Definition: AColor.h:122
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:266
static wxBrush muteBrush[2]
Definition: AColor.h:105
static wxPen cursorPen
Definition: AColor.h:99
static void Light(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:390
static void LightMIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:658
static void ReInit()
Definition: AColor.cpp:504
static wxPen tooltipPen
Definition: AColor.h:127
static wxPen lightPen[2]
Definition: AColor.h:95
static wxPen mediumPen[2]
Definition: AColor.h:96
static void MediumTrackInfo(wxDC *dc, bool selected)
Definition: AColor.cpp:410
static void ApplyUpdatedImages()
Definition: AColor.cpp:849
static wxBrush envelopeBrush
Definition: AColor.h:112
static wxBrush labelTextNormalBrush
Definition: AColor.h:114
static wxBrush labelTextEditBrush
Definition: AColor.h:115
static wxPen uglyPen
Definition: AColor.h:136
static const int gradientSteps
Definition: AColor.h:132
static void Init()
Definition: AColor.cpp:534
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:420
static void Medium(wxDC *dc, bool selected)
Definition: AColor.cpp:401
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:118
static wxPen envelopePen
Definition: AColor.h:110
static unsigned char gradient_pre[ColorGradientTotal][colorSchemes][gradientSteps][3]
Definition: AColor.h:133
static wxPen labelSelectedPen
Definition: AColor.h:120
static wxBrush tooltipBrush
Definition: AColor.h:128
static void MIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:642
static wxBrush indicatorBrush[2]
Definition: AColor.h:101
static void TrackFocusPen(wxDC *dc, int level)
Definition: AColor.cpp:458
static void BevelTrackInfo(wxDC &dc, bool up, const wxRect &r, bool highlight=false)
Definition: AColor.cpp:317
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:431
static wxBrush soloBrush
Definition: AColor.h:106
static wxBrush labelUnselectedBrush
Definition: AColor.h:116
static wxPen darkPen[2]
Definition: AColor.h:97
static wxPen snapGuidePen
Definition: AColor.h:125
static wxPen indicatorPen[2]
Definition: AColor.h:100
static wxBrush spareBrush
Definition: AColor.h:141
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:349
static void DarkMIDIChannel(wxDC *dc, int channel)
Definition: AColor.cpp:676
static void DrawFocus(wxDC &dc, wxRect &r)
Definition: AColor.cpp:235
static wxPen labelUnselectedPen
Definition: AColor.h:119
static bool gradient_inited
Definition: AColor.h:130
static wxPen labelSyncLockSelPen
Definition: AColor.h:121
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:307
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