1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-25 07:43:54 +02:00

Draw the Quick Pay and Scub Bar pushbuttons

This commit is contained in:
Paul Licameli
2016-04-30 13:48:04 -04:00
parent e1352d599f
commit 055c33459c
4 changed files with 119 additions and 7 deletions

View File

@@ -183,7 +183,7 @@ void AColor::DrawFocus(wxDC & dc, wxRect & rect)
dc.SetLogicalFunction(wxCOPY); dc.SetLogicalFunction(wxCOPY);
} }
void AColor::Bevel(wxDC & dc, bool up, wxRect & r) void AColor::Bevel(wxDC & dc, bool up, const wxRect & r)
{ {
if (up) if (up)
AColor::Light(&dc, false); AColor::Light(&dc, false);
@@ -211,7 +211,7 @@ wxColour AColor::Blend( const wxColour & c1, const wxColour & c2 )
return c3; return c3;
} }
void AColor::BevelTrackInfo(wxDC & dc, bool up, wxRect & r) void AColor::BevelTrackInfo(wxDC & dc, bool up, const wxRect & r)
{ {
#ifndef EXPERIMENTAL_THEMING #ifndef EXPERIMENTAL_THEMING
Bevel( dc, up, r ); Bevel( dc, up, r );

View File

@@ -38,8 +38,8 @@ class AColor {
static void Arrow(wxDC & dc, wxCoord x, wxCoord y, int width, bool down = true); static void Arrow(wxDC & dc, wxCoord x, wxCoord y, int width, bool down = true);
static void Line(wxDC & dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); static void Line(wxDC & dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
static void DrawFocus(wxDC & dc, wxRect & r); static void DrawFocus(wxDC & dc, wxRect & r);
static void Bevel(wxDC & dc, bool up, wxRect & r); static void Bevel(wxDC & dc, bool up, const wxRect & r);
static void BevelTrackInfo(wxDC & dc, bool up, wxRect & r); static void BevelTrackInfo(wxDC & dc, bool up, const wxRect & r);
static wxColour Blend(const wxColour & c1, const wxColour & c2); static wxColour Blend(const wxColour & c1, const wxColour & c2);
static void UseThemeColour( wxDC * dc, int iIndex ); static void UseThemeColour( wxDC * dc, int iIndex );

View File

@@ -1830,6 +1830,9 @@ AdornedRulerPanel::AdornedRulerPanel(AudacityProject* parent,
mPlayRegionDragsSelection = (gPrefs->Read(wxT("/QuickPlay/DragSelection"), 0L) == 1)? true : false; mPlayRegionDragsSelection = (gPrefs->Read(wxT("/QuickPlay/DragSelection"), 0L) == 1)? true : false;
mQuickPlayEnabled = !!gPrefs->Read(wxT("/QuickPlay/QuickPlayEnabled"), 1L); mQuickPlayEnabled = !!gPrefs->Read(wxT("/QuickPlay/QuickPlayEnabled"), 1L);
int fontSize = 10;
mButtonFont.Create(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
UpdatePrefs(); UpdatePrefs();
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
@@ -1980,7 +1983,7 @@ int AdornedRulerPanel::IndicatorBigWidth()
enum { enum {
ScrubHeight = 14, ScrubHeight = 14,
RulerHeight = 28 ProperRulerHeight = 28
}; };
int AdornedRulerPanel::IndicatorBigHeight() int AdornedRulerPanel::IndicatorBigHeight()
@@ -2027,6 +2030,8 @@ void AdornedRulerPanel::OnPaint(wxPaintEvent & WXUNUSED(evt))
DoDrawPlayRegion(&mBackDC); DoDrawPlayRegion(&mBackDC);
DoDrawPushbuttons(&mBackDC);
dc.Blit(0, 0, mBack->GetWidth(), mBack->GetHeight(), &mBackDC, 0, 0); dc.Blit(0, 0, mBack->GetWidth(), mBack->GetHeight(), &mBackDC, 0, 0);
if (mQuickPlayInd) if (mQuickPlayInd)
@@ -2777,6 +2782,95 @@ void AdornedRulerPanel::DoDrawPlayRegion(wxDC * dc)
} }
} }
wxRect AdornedRulerPanel::GetButtonAreaRect() const
{
auto x = LeftMargin, y = TopMargin;
wxRect rect {
x, y,
mProject->GetTrackPanel()->GetLeftOffset() - x,
GetRulerHeight() - y - BottomMargin
};
// Leave room for one digit on the ruler, so "0.0" is not obscured if you go to start.
// But the digit string at the left end may be longer if you are not at the start.
// Perhaps there should be room for more than one digit.
wxScreenDC dc;
dc.SetFont(*mRuler.GetFonts().major);
rect.width -= dc.GetTextExtent(wxT("0")).GetWidth();
return rect;
}
wxRect AdornedRulerPanel::GetButtonRect( Button button ) const
{
wxRect rect { GetButtonAreaRect() };
// Reduce the height
rect.height -= (GetRulerHeight() - ProperRulerHeight);
auto num = static_cast<unsigned>(button);
auto denom = static_cast<unsigned>(Button::NumButtons);
rect.x += (num * rect.width) / denom;
rect.width = (((1 + num) * rect.width) / denom) - rect.x;
return rect;
}
bool AdornedRulerPanel::GetButtonState( Button button ) const
{
switch(button) {
case Button::QuickPlay:
return mQuickPlayEnabled;
case Button::ScrubBar:
return mShowScrubbing;
default:
wxASSERT(false);
return false;
}
}
void AdornedRulerPanel::DoDrawPushbutton(wxDC *dc, Button button, bool down) const
{
// Adapted from TrackInfo::DrawMuteSolo()
static const wxString labels[static_cast<size_t>(Button::NumButtons)] {
XO("Quick Play"),
/* i18n-hint: A long screen area (bar) controlling variable speed play (scrubbing) */
XO("Scrub Bar"),
};
const auto bev = GetButtonRect( button ).Inflate(-1, -1);
if (down)
AColor::Solo(dc, true, false);
else
AColor::MediumTrackInfo(dc, false);
dc->SetPen( *wxTRANSPARENT_PEN );//No border!
dc->DrawRectangle(bev);
dc->SetTextForeground(theTheme.Colour(clrTrackPanelText));
wxCoord textWidth, textHeight;
wxString str = wxGetTranslation(labels[static_cast<unsigned>(button)]);
dc->SetFont(mButtonFont);
dc->GetTextExtent(str, &textWidth, &textHeight);
dc->DrawText(str, bev.x + (bev.width - textWidth) / 2,
bev.y + (bev.height - textHeight) / 2);
AColor::BevelTrackInfo(*dc, !down, bev);
}
void AdornedRulerPanel::DoDrawPushbuttons(wxDC *dc) const
{
// Paint the area behind the buttons
wxRect background = GetButtonAreaRect();
AColor::MediumTrackInfo(dc, false);
dc->DrawRectangle(background);
for (unsigned ii = 0; ii < static_cast<unsigned>(Button::NumButtons); ++ii) {
auto button = static_cast<Button>(ii);
DoDrawPushbutton(dc, button, GetButtonState(button));
}
}
void AdornedRulerPanel::DoDrawBorder(wxDC * dc) void AdornedRulerPanel::DoDrawBorder(wxDC * dc)
{ {
// Draw AdornedRulerPanel border // Draw AdornedRulerPanel border
@@ -2786,7 +2880,7 @@ void AdornedRulerPanel::DoDrawBorder(wxDC * dc)
if (mShowScrubbing) { if (mShowScrubbing) {
// Let's distinguish the scrubbing area by using the same gray as for // Let's distinguish the scrubbing area by using the same gray as for
// selected track control panel. // selected track control panel.
AColor::Medium(dc, true); AColor::MediumTrackInfo(dc, true);
dc->DrawRectangle(mScrubZone); dc->DrawRectangle(mScrubZone);
} }
@@ -2843,7 +2937,7 @@ int AdornedRulerPanel::GetRulerHeight()
int AdornedRulerPanel::GetRulerHeight(bool showScrubBar) int AdornedRulerPanel::GetRulerHeight(bool showScrubBar)
{ {
return RulerHeight + (showScrubBar ? ScrubHeight : 0); return ProperRulerHeight + (showScrubBar ? ScrubHeight : 0);
} }
void AdornedRulerPanel::SetLeftOffset(int offset) void AdornedRulerPanel::SetLeftOffset(int offset)

View File

@@ -102,6 +102,9 @@ class AUDACITY_DLL_API Ruler {
// Good defaults are provided, but you can override here // Good defaults are provided, but you can override here
void SetFonts(const wxFont &minorFont, const wxFont &majorFont, const wxFont &minorMinorFont); void SetFonts(const wxFont &minorFont, const wxFont &majorFont, const wxFont &minorMinorFont);
struct Fonts { wxFont *major, *minor, *minorMinor; };
Fonts GetFonts() const
{ return { mMajorFont, mMinorFont, mMinorMinorFont }; }
// Copies *pScale if it is not NULL // Copies *pScale if it is not NULL
void SetNumberScale(const NumberScale *pScale); void SetNumberScale(const NumberScale *pScale);
@@ -346,6 +349,19 @@ private:
void DrawQuickPlayIndicator(wxDC * dc /*NULL to DELETE old only*/); void DrawQuickPlayIndicator(wxDC * dc /*NULL to DELETE old only*/);
void DoDrawPlayRegion(wxDC * dc); void DoDrawPlayRegion(wxDC * dc);
wxRect GetButtonAreaRect() const;
enum class Button {
QuickPlay = 0,
ScrubBar,
NumButtons,
NoButton = -1
};
wxRect GetButtonRect( Button button ) const;
bool GetButtonState( Button button ) const;
void DoDrawPushbutton(wxDC *dc, Button button, bool down) const;
void DoDrawPushbuttons(wxDC *dc) const;
double Pos2Time(int p, bool ignoreFisheye = false); double Pos2Time(int p, bool ignoreFisheye = false);
int Time2Pos(double t, bool ignoreFisheye = false); int Time2Pos(double t, bool ignoreFisheye = false);
@@ -434,6 +450,8 @@ private:
bool mPrevInScrubZone{}; bool mPrevInScrubZone{};
bool mShowScrubbing { true }; bool mShowScrubbing { true };
wxFont mButtonFont;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };