mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-22 15:20:15 +02:00
Factor rectangle computation out of DrawTrackName
This commit is contained in:
parent
a65ab2146b
commit
71b3fc0647
@ -95,6 +95,25 @@ namespace {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void GetTrackNameExtent(
|
||||||
|
wxDC &dc, const Track *t, wxCoord *pW, wxCoord *pH )
|
||||||
|
{
|
||||||
|
wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
||||||
|
dc.SetFont(labelFont);
|
||||||
|
dc.GetTextExtent( t->GetName(), pW, pH );
|
||||||
|
}
|
||||||
|
|
||||||
|
static wxRect GetTrackNameRect(
|
||||||
|
const wxRect &trackRect, wxCoord textWidth, wxCoord textHeight )
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
trackRect.x + DisplaceX,
|
||||||
|
trackRect.y + DisplaceY,
|
||||||
|
textWidth + MarginsX,
|
||||||
|
textHeight + MarginsY
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Draws the track name on the track, if it is needed.
|
// Draws the track name on the track, if it is needed.
|
||||||
static void DrawTrackName(
|
static void DrawTrackName(
|
||||||
TrackPanelDrawingContext &context, const Track * t, const wxRect & rect )
|
TrackPanelDrawingContext &context, const Track * t, const wxRect & rect )
|
||||||
@ -109,9 +128,7 @@ static void DrawTrackName(
|
|||||||
auto &dc = context.dc;
|
auto &dc = context.dc;
|
||||||
wxBrush Brush;
|
wxBrush Brush;
|
||||||
wxCoord textWidth, textHeight;
|
wxCoord textWidth, textHeight;
|
||||||
wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
GetTrackNameExtent( dc, t, &textWidth, &textHeight );
|
||||||
dc.SetFont(labelFont);
|
|
||||||
dc.GetTextExtent( t->GetName(), &textWidth, &textHeight );
|
|
||||||
|
|
||||||
// Logic for name background translucency (aka 'shields')
|
// Logic for name background translucency (aka 'shields')
|
||||||
// Tracks less than kOpaqueHeight high will have opaque shields.
|
// Tracks less than kOpaqueHeight high will have opaque shields.
|
||||||
@ -128,12 +145,12 @@ static void DrawTrackName(
|
|||||||
// 0.0 maps to full opacity, 1.0 maps to full translucency.
|
// 0.0 maps to full opacity, 1.0 maps to full translucency.
|
||||||
int opacity = 255 - (255-140)*f;
|
int opacity = 255 - (255-140)*f;
|
||||||
|
|
||||||
|
const auto nameRect = GetTrackNameRect( rect, textWidth, textHeight );
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
// Mac dc is a graphics dc already.
|
// Mac dc is a graphics dc already.
|
||||||
AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, opacity );
|
AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, opacity );
|
||||||
dc.DrawRoundedRectangle(
|
dc.DrawRoundedRectangle( nameRect, 8.0 );
|
||||||
rect.x + DisplaceX, rect.y + DisplaceY,
|
|
||||||
textWidth + MarginsX, textHeight + MarginsY, 8.0 );
|
|
||||||
#else
|
#else
|
||||||
// This little dance with wxImage in order to draw to a graphic dc
|
// 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.
|
// which we can then paste as a translucent bitmap onto the real dc.
|
||||||
@ -162,12 +179,12 @@ static void DrawTrackName(
|
|||||||
}
|
}
|
||||||
wxBitmap bitmap( image );
|
wxBitmap bitmap( image );
|
||||||
dc.DrawBitmap( bitmap,
|
dc.DrawBitmap( bitmap,
|
||||||
rect.x + DisplaceX - SecondMarginX, rect.y + DisplaceY - SecondMarginY );
|
nameRect.x - SecondMarginX, nameRect.y - SecondMarginY );
|
||||||
#endif
|
#endif
|
||||||
dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
|
dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
|
||||||
dc.DrawText(t->GetName(),
|
dc.DrawText(t->GetName(),
|
||||||
rect.x + DisplaceX + MarginX,
|
nameRect.x + MarginX,
|
||||||
rect.y + DisplaceY + MarginY);
|
nameRect.y + MarginY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommonTrackView::Draw(
|
void CommonTrackView::Draw(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user