1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-18 17:10:05 +02:00

Translucent background to track name (on Mac)

Mac only, as mac supports translucent brushes by default.
wxWidgets makes using a wxDC and wxGraphicContext at the same time
complex and slow.  Hence just for mac.
This commit is contained in:
James Crook 2019-03-29 22:06:03 +00:00
parent 3760db9dff
commit 8b9518a90a
3 changed files with 10 additions and 5 deletions

View File

@ -26,6 +26,7 @@ It is also a place to document colour usage policy in Audacity
#include <wx/colour.h>
#include <wx/dc.h>
#include <wx/dcmemory.h>
#include <wx/graphics.h>
#include <wx/settings.h>
#include <wx/utils.h>
@ -291,7 +292,9 @@ void AColor::BevelTrackInfo(wxDC & dc, bool up, const wxRect & r, bool highlight
// Set colour of and select brush and pen.
// Use -1 to omit brush or pen.
// If pen omitted, then the same colour as the brush will be used.
void AColor::UseThemeColour( wxDC * dc, int iBrush, int iPen )
// alpha for the brush is normally 255, but if set will make a difference
// on mac (only) currently.
void AColor::UseThemeColour( wxDC * dc, int iBrush, int iPen, int alpha )
{
if (!inited)
Init();
@ -301,6 +304,7 @@ void AColor::UseThemeColour( wxDC * dc, int iBrush, int iPen )
wxColour col = wxColour(0,0,0);
if( iBrush !=-1 ){
col = theTheme.Colour( iBrush );
col.Set( col.Red(), col.Green(), col.Blue(), alpha);
spareBrush.SetColour( col );
dc->SetBrush( spareBrush );
}

View File

@ -78,7 +78,7 @@ class AColor {
static void BevelTrackInfo(wxDC & dc, bool up, const wxRect & r, bool highlight = false);
static wxColour Blend(const wxColour & c1, const wxColour & c2);
static void UseThemeColour( wxDC * dc, int iBrush, int iPen=-1 );
static void UseThemeColour( wxDC * dc, int iBrush, int iPen=-1, int alpha = 255 );
static void TrackPanelBackground(wxDC * dc, bool selected);
static void Light(wxDC * dc, bool selected, bool highlight = false);

View File

@ -338,9 +338,10 @@ void TrackArt::DrawTrack(TrackPanelDrawingContext &context,
dc.SetFont(labelFont);
dc.GetTextExtent( wt->GetName(), &x, &y );
dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
// A nice improvement would be to draw the shield / background translucently.
AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText );
dc.DrawRoundedRectangle( wxPoint( rect.x+7, rect.y+1 ), wxSize( x+16, y+4), 8.0 );
// Shield's background is translucent, alpha=100, but currently
// only on mac.
AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, 100 );
dc.DrawRoundedRectangle( rect.x+7, rect.y+1, x+16, y+4, 8.0 );
dc.DrawText (wt->GetName(), rect.x+15, rect.y+3); // move right 15 pixels to avoid overwriting <- symbol
}
},