diff --git a/src/AColor.cpp b/src/AColor.cpp index 7d2009f7a..8993e85ce 100644 --- a/src/AColor.cpp +++ b/src/AColor.cpp @@ -62,6 +62,7 @@ wxPen AColor::labelSurroundPen; wxPen AColor::trackFocusPens[3]; wxPen AColor::snapGuidePen; +wxPen AColor::tooltipPen; wxBrush AColor::tooltipBrush; // The spare pen and brush possibly help us cut down on the @@ -423,6 +424,7 @@ void AColor::Init() theTheme.SetPenColour( playRegionPen[1], clrRulerPlaybackPen); //Determine tooltip color + tooltipPen.SetColour( wxSystemSettingsNative::GetColour(wxSYS_COLOUR_INFOTEXT) ); tooltipBrush.SetColour( wxSystemSettingsNative::GetColour(wxSYS_COLOUR_INFOBK) ); // A tiny gradient of yellow surrounding the current focused track diff --git a/src/AColor.h b/src/AColor.h index 76743b5ed..d18efc037 100644 --- a/src/AColor.h +++ b/src/AColor.h @@ -103,6 +103,7 @@ class AColor { static wxPen trackFocusPens[3]; static wxPen snapGuidePen; + static wxPen tooltipPen; static wxBrush tooltipBrush; static bool gradient_inited; diff --git a/src/WaveClip.h b/src/WaveClip.h index 0beddc6dd..32e1c6727 100644 --- a/src/WaveClip.h +++ b/src/WaveClip.h @@ -51,10 +51,10 @@ public: , windowSize(-1) , zeroPaddingFactor(-1) , frequencyGain(-1) - +#if 0 , freq(NULL) , where(NULL) - +#endif , dirty(-1) { } diff --git a/src/toolbars/MixerToolBar.cpp b/src/toolbars/MixerToolBar.cpp index 6ea303c20..9d59add4d 100644 --- a/src/toolbars/MixerToolBar.cpp +++ b/src/toolbars/MixerToolBar.cpp @@ -286,24 +286,18 @@ void MixerToolBar::AdjustInputGain(int adj) void MixerToolBar::SetToolTips() { -#if wxUSE_TOOLTIPS if (mInputSlider->IsEnabled()) { - mInputSlider->SetToolTip(wxString::Format( - _("Recording Volume: %.2f"), mInputSliderVolume)); + mInputSlider->SetToolTipTemplate(_("Recording Volume: %.2f")); } else { - mInputSlider->SetToolTip( - _("Recording Volume (Unavailable; use system mixer.)")); + mInputSlider->SetToolTipTemplate(_("Recording Volume (Unavailable; use system mixer.)")); } if (mOutputSlider->IsEnabled()) { - mOutputSlider->SetToolTip(wxString::Format( - _("Playback Volume: %.2f%s"), mOutputSliderVolume, gAudioIO->OutputMixerEmulated() ? _(" (emulated)") : wxT(""))); + mOutputSlider->SetToolTipTemplate(wxString::Format( + _("Playback Volume: %%.2f%s"), gAudioIO->OutputMixerEmulated() ? _(" (emulated)") : wxT(""))); } else { - mOutputSlider->SetToolTip( - _("Playback Volume (Unavailable; use system mixer.)")); + mOutputSlider->SetToolTipTemplate(_("Playback Volume (Unavailable; use system mixer.)")); } -#endif } - diff --git a/src/toolbars/TranscriptionToolBar.cpp b/src/toolbars/TranscriptionToolBar.cpp index 914b19b7f..f6a3db8cc 100644 --- a/src/toolbars/TranscriptionToolBar.cpp +++ b/src/toolbars/TranscriptionToolBar.cpp @@ -303,13 +303,8 @@ void TranscriptionToolBar::UpdatePrefs() void TranscriptionToolBar::RegenerateTooltips() { -#if wxUSE_TOOLTIPS mButtons[TTB_PlaySpeed]->SetToolTip(_("Play-at-speed")); - wxString tip; - tip.Printf(_("Playback Speed") + wxT(": %.2fx"), mPlaySpeedSlider->Get()); - mPlaySpeedSlider->SetToolTip(tip); - #ifdef EXPERIMENTAL_VOICE_DETECTION mButtons[TTB_StartOn]->SetToolTip(TRANSLATABLE("Left-to-On")); mButtons[TTB_EndOn]->SetToolTip( TRANSLATABLE("Right-to-Off")); @@ -324,7 +319,6 @@ void TranscriptionToolBar::RegenerateTooltips() mSensitivitySlider->SetToolTip(TRANSLATABLE("Sensitivity")); mKeyTypeChoice->SetToolTip(TRANSLATABLE("Key type")); #endif -#endif } void TranscriptionToolBar::OnFocus(wxFocusEvent &event) diff --git a/src/widgets/ASlider.cpp b/src/widgets/ASlider.cpp index 7ed1bce07..5b688b51b 100644 --- a/src/widgets/ASlider.cpp +++ b/src/widgets/ASlider.cpp @@ -40,8 +40,10 @@ or ASlider. #include #include +#include #include #include +#include #include #include #include @@ -99,6 +101,9 @@ class TipPanel : public wxPopupWindow private: void OnPaint(wxPaintEvent & event); +#if defined(__WXGTK__) + void OnCreate(wxWindowCreateEvent & event); +#endif private: wxString mMaxLabel; @@ -111,19 +116,28 @@ private: BEGIN_EVENT_TABLE(TipPanel, wxPopupWindow) EVT_PAINT(TipPanel::OnPaint) +#if defined(__WXGTK__) + EVT_WINDOW_CREATE(TipPanel::OnCreate) +#endif END_EVENT_TABLE() TipPanel::TipPanel(wxWindow *parent, const wxString & maxLabel) -: wxPopupWindow(parent) +: wxPopupWindow(parent, wxFRAME_SHAPED) { + SetBackgroundStyle(wxBG_STYLE_PAINT); + mMaxLabel = maxLabel; - wxFont labelFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL); - GetTextExtent(mMaxLabel, &mWidth, &mHeight, NULL, NULL, &labelFont); mWidth += 8; mHeight += 8; + +#if defined(__WXMSW__) || defined(__WXMAC__) + wxGraphicsPath path = wxGraphicsRenderer::GetDefaultRenderer()->CreatePath(); + path.AddRoundedRectangle(0, 0, mWidth, mHeight, 5); + SetShape(path); +#endif } void TipPanel::SetPos(const wxPoint & pos) @@ -136,21 +150,32 @@ void TipPanel::SetLabel(const wxString & label) mLabel = label; } -void TipPanel::OnPaint(wxPaintEvent& WXUNUSED(event)) +void TipPanel::OnPaint(wxPaintEvent & WXUNUSED(event)) { - wxPaintDC dc(this); - - dc.SetFont(wxFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL)); + wxAutoBufferedPaintDC dc(this); + DisableAntialiasing(dc); dc.SetPen(*wxBLACK_PEN); dc.SetBrush(AColor::tooltipBrush); - dc.DrawRectangle(0, 0, mWidth, mHeight); + dc.DrawRoundedRectangle(0, 0, mWidth, mHeight, 5); + + dc.SetFont(wxFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL)); + dc.SetTextForeground(AColor::tooltipPen.GetColour()); int textWidth, textHeight; dc.GetTextExtent(mLabel, &textWidth, &textHeight); - dc.DrawText(mLabel, (mWidth - textWidth) / 2, (mHeight - textHeight) / 2); + DrawText(dc, mLabel, (mWidth - textWidth) / 2, (mHeight - textHeight) / 2); } +#if defined(__WXGTK__) +void TipPanel::OnCreate(wxWindowCreateEvent & WXUNUSED(event)) +{ + wxGraphicsPath path = wxGraphicsRenderer::GetDefaultRenderer()->CreatePath(); + path.AddRoundedRectangle(0, 0, mWidth, mHeight, 5); + SetShape(path); +} +#endif + // // SliderDialog // @@ -463,39 +488,6 @@ void LWSlider::SetScroll(float line, float page) mScrollPage = page; } -void LWSlider::CreatePopWin() -{ - if (mTipPanel) - { - delete mTipPanel; - mTipPanel = NULL; - } - - wxString maxTipLabel = mName + wxT(": 000000"); - - if (mStyle == PAN_SLIDER || mStyle == DB_SLIDER || mStyle == SPEED_SLIDER -#ifdef EXPERIMENTAL_MIDI_OUT - || mStyle == VEL_SLIDER -#endif - ) - maxTipLabel += wxT("000"); - - mTipPanel = new TipPanel(mParent, maxTipLabel); -} - -void LWSlider::SetPopWinPosition() -{ - wxPoint pt; - if (mOrientation == wxHORIZONTAL) - pt = wxPoint(mWidth/2 + mLeft, mHeight + mTop + 1); - else - pt = wxPoint(mWidth + mLeft + 1, mHeight/2 + mTop); - pt = mParent->ClientToScreen(pt); - - if (mTipPanel) - mTipPanel->SetPos(pt); -} - void LWSlider::Move(const wxPoint &newpos) { mLeft = newpos.x; @@ -533,7 +525,7 @@ void LWSlider::OnPaint(wxDC &dc, bool WXUNUSED(selected)) dc.DrawBitmap(*mThumbBitmap, mLeft+thumbOrtho, mTop+thumbPos, true); if (mTipPanel) - mTipPanel->Refresh(); + mTipPanel->Update(); } void LWSlider::OnSize( wxSizeEvent & event ) @@ -806,57 +798,132 @@ void LWSlider::Draw() mBitmap->SetMask( new wxMask( *mBitmap, TransparentColour ) ); } +void LWSlider::SetToolTipTemplate(const wxString & tip) +{ + mTipTemplate = tip; +} + +void LWSlider::ShowTip(bool show) +{ + if (show) + { + if (mTipPanel) + { + delete mTipPanel; + mTipPanel = NULL; + } + + CreatePopWin(); + FormatPopWin(); + SetPopWinPosition(); + mTipPanel->Show(); + } + else + { + if (mTipPanel) + { + mTipPanel->Hide(); + delete mTipPanel; + mTipPanel = NULL; + } + } +} + +void LWSlider::CreatePopWin() +{ + if (mTipPanel) + { + delete mTipPanel; + mTipPanel = NULL; + } + + wxString mintip = GetTip(mMinValue); + wxString maxtip = GetTip(mMaxValue); + mTipPanel = new TipPanel(mParent, mintip.Length() > maxtip.Length() ? mintip : maxtip); +} + +void LWSlider::SetPopWinPosition() +{ + wxPoint pt; + + if (mOrientation == wxHORIZONTAL) + { + pt = wxPoint(mWidth/2 + mLeft, mHeight + mTop + 1); + } + else + { + pt = wxPoint(mWidth + mLeft + 1, mHeight/2 + mTop); + } + + if (mTipPanel) + { + mTipPanel->SetPos(mParent->ClientToScreen(pt)); + } +} void LWSlider::FormatPopWin() { - if (!mTipPanel) { + if (!mTipPanel) + { return; } + mTipPanel->SetLabel(GetTip(mCurrentValue)); + mTipPanel->Refresh(); +} + +wxString LWSlider::GetTip(float value) const +{ wxString label; - wxString valstr; - switch(mStyle) { - case FRAC_SLIDER: - label.Printf(wxT("%s: %.2f"), mName.c_str(), mCurrentValue); - break; + if (mTipTemplate.IsEmpty()) + { + wxString val; - case DB_SLIDER: - valstr.Printf(wxT("%.1f"), mCurrentValue); - if (valstr.Right(1) == wxT("0")) - valstr = valstr.Left(valstr.Length() - 2); - if (mCurrentValue > 0) - valstr = wxT("+") + valstr; + switch(mStyle) + { + case FRAC_SLIDER: + val.Printf(wxT("%.2f"), value); + break; + + case DB_SLIDER: + val.Printf(wxT("%.3g dB"), value); + break; - label.Printf(wxT("%s: %s dB"), mName.c_str(), valstr.c_str()); - break; - case PAN_SLIDER: - if (mCurrentValue == 0.0) - label.Printf(wxT("%s: %s"), mName.c_str(), - _("Center")); - else { - if (mCurrentValue < 0.0) - label.Printf(wxT("%s: %.0f%% %s"), mName.c_str(), - -mCurrentValue * 100.0f, _("Left")); - else /* if (val > 0.0) */ - label.Printf(wxT("%s: %.0f%% %s"), mName.c_str(), - mCurrentValue * 100.0f, _("Right")); + case PAN_SLIDER: + if (value == 0.0) + { + val = _("Center"); + } + else + { + val.Printf(wxT("%.0f%% %s"), + value * (value < 0.0 ? -100.0f : 100.0f), + value < 0.0 ? _("Left") : _("Right")); + } + break; + + case SPEED_SLIDER: + val.Printf(wxT("%.2fx"), value); + break; + +#ifdef EXPERIMENTAL_MIDI_OUT + case VEL_SLIDER: + val.Printf(wxT("%s%d"), + (value > 0.0f ? _("+") : wxT("")), + (int) value); + break; +#endif } - break; - case SPEED_SLIDER: - label.Printf(wxT("%s: %.2fx"), mName.c_str(), mCurrentValue); - break; -#ifdef EXPERIMENTAL_MIDI_OUT - case VEL_SLIDER: - label.Printf(wxT("%s: %s%d"), mName.c_str(), - (mCurrentValue > 0.0f ? _("+") : wxT("")), - (int) mCurrentValue); -#endif + label.Printf(wxT("%s: %s"), mName.c_str(), val.c_str()); + } + else + { + label.Printf(mTipTemplate, value); } - mTipPanel->SetLabel(label); - mTipPanel->Refresh(); + return label; } bool LWSlider::ShowDialog() @@ -902,19 +969,19 @@ bool LWSlider::DoShowDialog(wxPoint pos) void LWSlider::OnMouseEvent(wxMouseEvent & event) { - if (event.Entering()) { - #if wxUSE_TOOLTIPS // Not available in wxX11 + if (event.Entering()) + { // Display the tooltip in the status bar - if (mParent->GetToolTip()) - { - wxString tip = mParent->GetToolTip()->GetTip(); - GetActiveProject()->TP_DisplayStatusMessage(tip); - Refresh(); - } - #endif + wxString tip = GetTip(mCurrentValue); + GetActiveProject()->TP_DisplayStatusMessage(tip); + Refresh(); } else if (event.Leaving()) { + if (!mIsDragging) + { + ShowTip(false); + } GetActiveProject()->TP_DisplayStatusMessage(wxT("")); Refresh(); } @@ -994,13 +1061,7 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event) mParent->CaptureMouse(); } - CreatePopWin(); - FormatPopWin(); - SetPopWinPosition(); - mTipPanel->Show(); - - //hide mouseover tooltip - wxToolTip::Enable(false); + ShowTip(true); } else if( event.ButtonUp() ) { @@ -1008,14 +1069,7 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event) if (mParent->HasCapture()) mParent->ReleaseMouse(); - if (mTipPanel) - { - delete mTipPanel; - mTipPanel = NULL; - } - - //restore normal tooltip behavor for mouseovers - wxToolTip::Enable(true); + ShowTip(false); } else if (event.Dragging() && mIsDragging) { @@ -1345,6 +1399,7 @@ BEGIN_EVENT_TABLE(ASlider, wxWindow) EVT_SLIDER(wxID_ANY, ASlider::OnSlider) EVT_SET_FOCUS(ASlider::OnSetFocus) EVT_KILL_FOCUS(ASlider::OnKillFocus) + EVT_TIMER(wxID_ANY, ASlider::OnTimer) END_EVENT_TABLE() ASlider::ASlider( wxWindow * parent, @@ -1375,6 +1430,8 @@ ASlider::ASlider( wxWindow * parent, mStyle = style; + mTimer.SetOwner(this); + #if wxUSE_ACCESSIBILITY SetAccessible( new ASliderAx( this ) ); #endif @@ -1435,6 +1492,15 @@ void ASlider::OnPaint(wxPaintEvent & WXUNUSED(event)) void ASlider::OnMouseEvent(wxMouseEvent &event) { + if (event.Entering()) + { + mTimer.StartOnce(1000); + } + else if (event.Leaving()) + { + mTimer.Stop(); + } + mLWSlider->OnMouseEvent(event); } @@ -1461,6 +1527,11 @@ void ASlider::OnKillFocus(wxFocusEvent & WXUNUSED(event)) Refresh(); } +void ASlider::OnTimer(wxTimerEvent & WXUNUSED(event)) +{ + mLWSlider->ShowTip(true); +} + void ASlider::GetScroll(float & line, float & page) { mLWSlider->GetScroll(line, page); @@ -1471,6 +1542,11 @@ void ASlider::SetScroll(float line, float page) mLWSlider->SetScroll(line, page); } +void ASlider::SetToolTipTemplate(const wxString & tip) +{ + mLWSlider->SetToolTipTemplate(tip); +} + float ASlider::Get( bool convert ) { return mLWSlider->Get( convert ); diff --git a/src/widgets/ASlider.h b/src/widgets/ASlider.h index 706d81cbb..cf6b49ae6 100644 --- a/src/widgets/ASlider.h +++ b/src/widgets/ASlider.h @@ -17,6 +17,7 @@ #include #include #include +#include #if wxUSE_ACCESSIBILITY #include @@ -122,6 +123,9 @@ class LWSlider void GetScroll(float & line, float & page); void SetScroll(float line, float page); + void ShowTip(bool show); + void SetToolTipTemplate(const wxString & tip); + float Get(bool convert = true); void Set(float value); #ifdef EXPERIMENTAL_MIDI_OUT @@ -152,6 +156,7 @@ class LWSlider private: + wxString GetTip(float value) const; void FormatPopWin(); void SetPopWinPosition(); void CreatePopWin(); @@ -218,6 +223,8 @@ class LWSlider wxWindowID mID; TipPanel *mTipPanel; + wxString mTipTemplate; + wxTimer mTimer; Ruler* mpRuler; @@ -256,6 +263,8 @@ class ASlider :public wxPanel void GetScroll(float & line, float & page); void SetScroll(float line, float page); + void SetToolTipTemplate(const wxString & tip); + float Get( bool convert = true ); void Set(float value); #ifdef EXPERIMENTAL_MIDI_OUT @@ -277,6 +286,7 @@ class ASlider :public wxPanel void OnSlider(wxCommandEvent &event); void OnSetFocus(wxFocusEvent & event); void OnKillFocus(wxFocusEvent & event); + void OnTimer(wxTimerEvent & event); // Overrides of the wxWindow functions with the same semantics bool Enable(bool enable = true); @@ -285,6 +295,7 @@ class ASlider :public wxPanel private: LWSlider *mLWSlider; bool mSliderIsFocused; + wxTimer mTimer; protected: int mStyle;