Translucent background to track name (all platforms)

wxDC can draw translucently, if given a bitmap.  So we now create a suitable bitmap, using a wxGraphicsContext.
This commit is contained in:
James Crook 2019-04-06 16:34:47 +01:00
parent 2463a6683b
commit 81dd2befab
3 changed files with 47 additions and 4 deletions

View File

@ -314,6 +314,27 @@ void AColor::UseThemeColour( wxDC * dc, int iBrush, int iPen, int alpha )
dc->SetPen( sparePen );
}
void AColor::UseThemeColour( wxGraphicsContext * gc, int iBrush, int iPen, int alpha )
{
if (!inited)
Init();
// do nothing if no colours set.
if( (iBrush == -1) && ( iPen ==-1))
return;
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 );
gc->SetBrush( spareBrush );
}
if( iPen != -1)
col = theTheme.Colour( iPen );
sparePen.SetColour( col );
gc->SetPen( sparePen );
}
void AColor::Light(wxDC * dc, bool selected, bool highlight)
{
if (!inited)

View File

@ -19,6 +19,7 @@
#include <wx/pen.h> // member variable
class wxDC;
class wxGraphicsContext;
class wxRect;
/// Used to restore pen, brush and logical-op in a DC back to what they were.
@ -79,6 +80,7 @@ class AColor {
static wxColour Blend(const wxColour & c1, const wxColour & c2);
static void UseThemeColour( wxDC * dc, int iBrush, int iPen=-1, int alpha = 255 );
static void UseThemeColour( wxGraphicsContext * gc, 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

@ -337,11 +337,31 @@ void TrackArt::DrawTrack(TrackPanelDrawingContext &context,
wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
dc.SetFont(labelFont);
dc.GetTextExtent( wt->GetName(), &x, &y );
dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
// Shield's background is translucent, alpha=100, but currently
// only on mac.
AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, 100 );
#ifdef __WXMAC__
// Mac dc is a graphics dc already.
// Shield's background is translucent, alpha=180
AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, 180 );
dc.DrawRoundedRectangle( rect.x+7, rect.y+1, x+16, y+4, 8.0 );
#else
// This little dance with wxImage in order to draw to a graphic dc
// which we can then paste as a translucent bitmap onto the real dc.
wxImage image( x+18, y+6 );
image.InitAlpha();
unsigned char *alpha=image.GetAlpha();
memset(alpha, wxIMAGE_ALPHA_TRANSPARENT, image.GetWidth()*image.GetHeight());
wxGraphicsContext &gc=*wxGraphicsContext::Create(image);
// Shield's background is translucent, alpha=180. This is to a gc, not a dc.
AColor::UseThemeColour( &gc, clrTrackInfoSelected, clrTrackPanelText, 180 );
// Draw at 1,1, not at 0,0 to avoid clipping of the antialiasing.
gc.DrawRoundedRectangle( 1, 1, x+16, y+4, 8.0 );
// delete the gc so as to free and so update the wxImage.
delete &gc;
wxBitmap bitmap( image );
dc.DrawBitmap( bitmap, rect.x+6, rect.y);
#endif
dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
dc.DrawText (wt->GetName(), rect.x+15, rect.y+3); // move right 15 pixels to avoid overwriting <- symbol
}
},