1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-17 09:07:41 +02:00

TCP draw use hit target for button, slider state; remove hacky global

This commit is contained in:
Paul Licameli 2017-07-07 07:56:49 -04:00
parent 3d7471a612
commit f09a7be3dc
12 changed files with 161 additions and 127 deletions

View File

@ -1066,11 +1066,9 @@ void TrackPanel::OnContextMenu(wxContextMenuEvent & WXUNUSED(event))
struct TrackInfo::TCPLine { struct TrackInfo::TCPLine {
using DrawFunction = void (*)( using DrawFunction = void (*)(
wxDC *dc, TrackPanelDrawingContext &context,
const wxRect &rect, const wxRect &rect,
const Track *maybeNULL, const Track *maybeNULL
int pressed, // a value from MouseCaptureEnum; TODO: make it bool
bool captured
); );
unsigned items; // a bitwise OR of values of the enum above unsigned items; // a bitwise OR of values of the enum above
@ -1696,6 +1694,8 @@ void TrackPanel::Refresh(bool eraseBackground /* = TRUE */,
DisplaySelection(); DisplaySelection();
} }
#include "TrackPanelDrawingContext.h"
/// Draw the actual track areas. We only draw the borders /// Draw the actual track areas. We only draw the borders
/// and the little buttons and menues and whatnot here, the /// and the little buttons and menues and whatnot here, the
/// actual contents of each track are drawn by the TrackArtist. /// actual contents of each track are drawn by the TrackArtist.
@ -1856,20 +1856,21 @@ void TrackPanel::DrawEverythingElse(wxDC * dc,
#include "tracks/ui/TrackControls.h" #include "tracks/ui/TrackControls.h"
void TrackInfo::DrawItems void TrackInfo::DrawItems
( wxDC *dc, const wxRect &rect, const Track &track, ( TrackPanelDrawingContext &context,
int mouseCapture, bool captured ) const wxRect &rect, const Track &track )
{ {
const auto topLines = getTCPLines( track ); const auto topLines = getTCPLines( track );
const auto bottomLines = commonTrackTCPBottomLines; const auto bottomLines = commonTrackTCPBottomLines;
DrawItems DrawItems
( dc, rect, &track, topLines, bottomLines, mouseCapture, captured ); ( context, rect, &track, topLines, bottomLines );
} }
void TrackInfo::DrawItems void TrackInfo::DrawItems
( wxDC *dc, const wxRect &rect, const Track *pTrack, ( TrackPanelDrawingContext &context,
const std::vector<TCPLine> &topLines, const std::vector<TCPLine> &bottomLines, const wxRect &rect, const Track *pTrack,
int mouseCapture, bool captured ) const std::vector<TCPLine> &topLines, const std::vector<TCPLine> &bottomLines )
{ {
auto dc = &context.dc;
TrackInfo::SetTrackInfoFont(dc); TrackInfo::SetTrackInfoFont(dc);
dc->SetTextForeground(theTheme.Colour(clrTrackPanelText)); dc->SetTextForeground(theTheme.Colour(clrTrackPanelText));
@ -1882,7 +1883,7 @@ void TrackInfo::DrawItems
}; };
if ( !TrackInfo::HideTopItem( rect, itemRect ) && if ( !TrackInfo::HideTopItem( rect, itemRect ) &&
line.drawFunction ) line.drawFunction )
line.drawFunction( dc, itemRect, pTrack, mouseCapture, captured ); line.drawFunction( context, itemRect, pTrack );
yy += line.height + line.extraSpace; yy += line.height + line.extraSpace;
} }
} }
@ -1895,20 +1896,26 @@ void TrackInfo::DrawItems
rect.x, rect.y + yy, rect.x, rect.y + yy,
rect.width, line.height rect.width, line.height
}; };
line.drawFunction( dc, itemRect, pTrack, mouseCapture, captured ); line.drawFunction( context, itemRect, pTrack );
} }
} }
} }
} }
#include "tracks/ui/TrackButtonHandles.h"
void TrackInfo::CloseTitleDrawFunction void TrackInfo::CloseTitleDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, bool captured ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto dc = &context.dc;
bool selected = pTrack ? pTrack->GetSelected() : true; bool selected = pTrack ? pTrack->GetSelected() : true;
{ {
bool down = captured && (pressed == TrackPanel::IsClosing);
wxRect bev = rect; wxRect bev = rect;
GetCloseBoxHorizontalBounds( rect, bev ); GetCloseBoxHorizontalBounds( rect, bev );
auto target = dynamic_cast<CloseButtonHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
bool down = captured && bev.Contains( context.lastState.GetPosition());
AColor::Bevel2(*dc, !down, bev, selected ); AColor::Bevel2(*dc, !down, bev, selected );
#ifdef EXPERIMENTAL_THEMING #ifdef EXPERIMENTAL_THEMING
@ -1935,12 +1942,15 @@ void TrackInfo::CloseTitleDrawFunction
} }
{ {
wxRect bev = rect;
GetTitleBarHorizontalBounds( rect, bev );
auto target = dynamic_cast<MenuButtonHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
bool down = captured && bev.Contains( context.lastState.GetPosition());
wxString titleStr = wxString titleStr =
pTrack ? pTrack->GetName() : _("Name"); pTrack ? pTrack->GetName() : _("Name");
bool down = captured && (pressed == TrackPanel::IsPopping);
wxRect bev = rect;
GetTitleBarHorizontalBounds( rect, bev );
//bev.Inflate(-1, -1); //bev.Inflate(-1, -1);
AColor::Bevel2(*dc, !down, bev, selected); AColor::Bevel2(*dc, !down, bev, selected);
@ -1993,15 +2003,20 @@ void TrackInfo::CloseTitleDrawFunction
} }
void TrackInfo::MinimizeSyncLockDrawFunction void TrackInfo::MinimizeSyncLockDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, bool captured ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto dc = &context.dc;
bool selected = pTrack ? pTrack->GetSelected() : true; bool selected = pTrack ? pTrack->GetSelected() : true;
bool syncLockSelected = pTrack ? pTrack->IsSyncLockSelected() : true; bool syncLockSelected = pTrack ? pTrack->IsSyncLockSelected() : true;
bool minimized = pTrack ? pTrack->GetMinimized() : false; bool minimized = pTrack ? pTrack->GetMinimized() : false;
{ {
bool down = captured && (pressed == TrackPanel::IsMinimizing);
wxRect bev = rect; wxRect bev = rect;
GetMinimizeHorizontalBounds(rect, bev); GetMinimizeHorizontalBounds(rect, bev);
auto target = dynamic_cast<MinimizeButtonHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
bool down = captured && bev.Contains( context.lastState.GetPosition());
// Clear background to get rid of previous arrow // Clear background to get rid of previous arrow
//AColor::MediumTrackInfo(dc, t->GetSelected()); //AColor::MediumTrackInfo(dc, t->GetSelected());
@ -2040,13 +2055,15 @@ void TrackInfo::MinimizeSyncLockDrawFunction
} }
void TrackInfo::MidiControlsDrawFunction void TrackInfo::MidiControlsDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int, bool ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
auto &dc = context.dc;
wxRect midiRect = rect; wxRect midiRect = rect;
GetMidiControlsHorizontalBounds(rect, midiRect); GetMidiControlsHorizontalBounds(rect, midiRect);
NoteTrack::DrawLabelControls NoteTrack::DrawLabelControls
( static_cast<const NoteTrack *>(pTrack), *dc, midiRect ); ( static_cast<const NoteTrack *>(pTrack), dc, midiRect );
#endif // EXPERIMENTAL_MIDI_OUT #endif // EXPERIMENTAL_MIDI_OUT
} }
@ -2062,35 +2079,50 @@ void TrackInfo::SliderDrawFunction
Selector( sliderRect, wt, captured, nullptr )->OnPaint(*dc, false); Selector( sliderRect, wt, captured, nullptr )->OnPaint(*dc, false);
} }
#include "tracks/playabletrack/wavetrack/ui/WaveTrackSliderHandles.h"
void TrackInfo::PanSliderDrawFunction void TrackInfo::PanSliderDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int, bool captured ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto target = dynamic_cast<PanSliderHandle*>( context.target.get() );
auto dc = &context.dc;
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
SliderDrawFunction<WaveTrack> SliderDrawFunction<WaveTrack>
( &TrackInfo::PanSlider, dc, rect, pTrack, captured); ( &TrackInfo::PanSlider, dc, rect, pTrack, captured);
} }
void TrackInfo::GainSliderDrawFunction void TrackInfo::GainSliderDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int, bool captured ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto target = dynamic_cast<GainSliderHandle*>( context.target.get() );
auto dc = &context.dc;
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
SliderDrawFunction<WaveTrack> SliderDrawFunction<WaveTrack>
( &TrackInfo::GainSlider, dc, rect, pTrack, captured); ( &TrackInfo::GainSlider, dc, rect, pTrack, captured);
} }
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
#include "tracks/playabletrack/notetrack/ui/NoteTrackSliderHandles.h"
void TrackInfo::VelocitySliderDrawFunction void TrackInfo::VelocitySliderDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int, bool captured ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto dc = &context.dc;
auto target = dynamic_cast<VelocitySliderHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
SliderDrawFunction<NoteTrack> SliderDrawFunction<NoteTrack>
( &TrackInfo::VelocitySlider, dc, rect, pTrack, captured); ( &TrackInfo::VelocitySlider, dc, rect, pTrack, captured);
} }
#endif #endif
void TrackInfo::MuteOrSoloDrawFunction void TrackInfo::MuteOrSoloDrawFunction
( wxDC *dc, const wxRect &bev, const Track *pTrack, int pressed, bool captured, ( wxDC *dc, const wxRect &bev, const Track *pTrack, bool down, bool captured,
bool solo ) bool solo )
{ {
bool down = captured &&
(pressed == ( solo ? TrackPanel::IsSoloing : TrackPanel::IsMuting ));
//bev.Inflate(-1, -1); //bev.Inflate(-1, -1);
bool selected = pTrack ? pTrack->GetSelected() : true; bool selected = pTrack ? pTrack->GetSelected() : true;
auto pt = dynamic_cast<const PlayableTrack *>(pTrack); auto pt = dynamic_cast<const PlayableTrack *>(pTrack);
@ -2137,25 +2169,40 @@ void TrackInfo::MuteOrSoloDrawFunction
dc->DrawText(str, bev.x + (bev.width - textWidth) / 2, bev.y + (bev.height - textHeight) / 2); dc->DrawText(str, bev.x + (bev.width - textWidth) / 2, bev.y + (bev.height - textHeight) / 2);
} }
#include "tracks/playabletrack/ui/PlayableTrackButtonHandles.h"
void TrackInfo::WideMuteDrawFunction void TrackInfo::WideMuteDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, bool captured ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto dc = &context.dc;
wxRect bev = rect; wxRect bev = rect;
GetWideMuteSoloHorizontalBounds( rect, bev ); GetWideMuteSoloHorizontalBounds( rect, bev );
MuteOrSoloDrawFunction( dc, bev, pTrack, pressed, captured, false ); auto target = dynamic_cast<MuteButtonHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
bool down = captured && bev.Contains( context.lastState.GetPosition());
MuteOrSoloDrawFunction( dc, bev, pTrack, down, captured, false );
} }
void TrackInfo::WideSoloDrawFunction void TrackInfo::WideSoloDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, bool captured ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto dc = &context.dc;
wxRect bev = rect; wxRect bev = rect;
GetWideMuteSoloHorizontalBounds( rect, bev ); GetWideMuteSoloHorizontalBounds( rect, bev );
MuteOrSoloDrawFunction( dc, bev, pTrack, pressed, captured, true ); auto target = dynamic_cast<SoloButtonHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
bool down = captured && bev.Contains( context.lastState.GetPosition());
MuteOrSoloDrawFunction( dc, bev, pTrack, down, captured, true );
} }
void TrackInfo::MuteAndSoloDrawFunction void TrackInfo::MuteAndSoloDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, bool captured ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto dc = &context.dc;
bool bHasSoloButton = TrackPanel::HasSoloButton(); bool bHasSoloButton = TrackPanel::HasSoloButton();
wxRect bev = rect; wxRect bev = rect;
@ -2163,13 +2210,25 @@ void TrackInfo::MuteAndSoloDrawFunction
GetNarrowMuteHorizontalBounds( rect, bev ); GetNarrowMuteHorizontalBounds( rect, bev );
else else
GetWideMuteSoloHorizontalBounds( rect, bev ); GetWideMuteSoloHorizontalBounds( rect, bev );
MuteOrSoloDrawFunction( dc, bev, pTrack, pressed, captured, false ); {
auto target = dynamic_cast<MuteButtonHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
bool down = captured && bev.Contains( context.lastState.GetPosition());
MuteOrSoloDrawFunction( dc, bev, pTrack, down, captured, false );
}
if( !bHasSoloButton ) if( !bHasSoloButton )
return; return;
GetNarrowSoloHorizontalBounds( rect, bev ); GetNarrowSoloHorizontalBounds( rect, bev );
MuteOrSoloDrawFunction( dc, bev, pTrack, pressed, captured, true ); {
auto target = dynamic_cast<SoloButtonHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
bool down = captured && bev.Contains( context.lastState.GetPosition());
MuteOrSoloDrawFunction( dc, bev, pTrack, down, captured, true );
}
} }
void TrackInfo::StatusDrawFunction void TrackInfo::StatusDrawFunction
@ -2180,8 +2239,10 @@ void TrackInfo::StatusDrawFunction
} }
void TrackInfo::Status1DrawFunction void TrackInfo::Status1DrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int, bool ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto dc = &context.dc;
auto wt = static_cast<const WaveTrack*>(pTrack); auto wt = static_cast<const WaveTrack*>(pTrack);
/// Returns the string to be displayed in the track label /// Returns the string to be displayed in the track label
@ -2208,8 +2269,10 @@ void TrackInfo::Status1DrawFunction
} }
void TrackInfo::Status2DrawFunction void TrackInfo::Status2DrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int, bool ) ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack )
{ {
auto dc = &context.dc;
auto wt = static_cast<const WaveTrack*>(pTrack); auto wt = static_cast<const WaveTrack*>(pTrack);
auto format = wt ? wt->GetSampleFormat() : floatSample; auto format = wt ? wt->GetSampleFormat() : floatSample;
auto s = GetSampleFormatStr(format); auto s = GetSampleFormatStr(format);
@ -2256,16 +2319,8 @@ void TrackPanel::DrawOutside(Track * t, wxDC * dc, const wxRect & rec)
rect.y += kTopMargin; rect.y += kTopMargin;
rect.height -= (kBottomMargin + kTopMargin); rect.height -= (kBottomMargin + kTopMargin);
// Need to know which button, if any, to draw as pressed. TrackPanelDrawingContext context{ *dc, Target(), mLastMouseState };
const MouseCaptureEnum mouseCapture = TrackInfo::DrawItems( context, rect, *t );
// This public global variable is a hack for now, which should go away
// when TrackPanelCell gets a virtual function into which we move this
// drawing code.
MouseCaptureEnum(TrackControls::gCaptureState);
auto pClickedTrack = GetTracks()->Lock(mpClickedTrack);
const bool captured = (t == pClickedTrack.get());
TrackInfo::DrawItems( dc, rect, *t, mouseCapture, captured );
//mTrackInfo.DrawBordersWithin( dc, rect, *t ); //mTrackInfo.DrawBordersWithin( dc, rect, *t );
} }

View File

@ -61,6 +61,8 @@ using UIHandlePtr = std::shared_ptr<UIHandle>;
// Declared elsewhere, to reduce compilation dependencies // Declared elsewhere, to reduce compilation dependencies
class TrackPanelListener; class TrackPanelListener;
struct TrackPanelDrawingContext;
enum class UndoPush : unsigned char; enum class UndoPush : unsigned char;
// JKC Nov 2011: Disabled warning C4251 which is to do with DLL linkage // JKC Nov 2011: Disabled warning C4251 which is to do with DLL linkage
@ -93,26 +95,26 @@ public:
struct TCPLine; struct TCPLine;
static void DrawItems static void DrawItems
( wxDC *dc, const wxRect &rect, const Track &track, int mouseCapture, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track &track );
static void DrawItems static void DrawItems
( wxDC *dc, const wxRect &rect, const Track *pTrack, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack,
const std::vector<TCPLine> &topLines, const std::vector<TCPLine> &topLines,
const std::vector<TCPLine> &bottomLines, const std::vector<TCPLine> &bottomLines );
int mouseCapture, bool captured );
static void CloseTitleDrawFunction static void CloseTitleDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
static void MinimizeSyncLockDrawFunction static void MinimizeSyncLockDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
static void MidiControlsDrawFunction static void MidiControlsDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
template<typename TrackClass> template<typename TrackClass>
static void SliderDrawFunction static void SliderDrawFunction
@ -122,45 +124,45 @@ public:
wxDC *dc, const wxRect &rect, const Track *pTrack, bool captured ); wxDC *dc, const wxRect &rect, const Track *pTrack, bool captured );
static void PanSliderDrawFunction static void PanSliderDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
static void GainSliderDrawFunction static void GainSliderDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
static void VelocitySliderDrawFunction static void VelocitySliderDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
#endif #endif
static void MuteOrSoloDrawFunction static void MuteOrSoloDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( wxDC *dc, const wxRect &rect, const Track *pTrack, bool down,
bool captured, bool solo ); bool captured, bool solo );
static void WideMuteDrawFunction static void WideMuteDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
static void WideSoloDrawFunction static void WideSoloDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
static void MuteAndSoloDrawFunction static void MuteAndSoloDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
static void StatusDrawFunction static void StatusDrawFunction
( const wxString &string, wxDC *dc, const wxRect &rect ); ( const wxString &string, wxDC *dc, const wxRect &rect );
static void Status1DrawFunction static void Status1DrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
static void Status2DrawFunction static void Status2DrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, int pressed, ( TrackPanelDrawingContext &context,
bool captured ); const wxRect &rect, const Track *pTrack );
public: public:
int GetTrackInfoWidth() const; int GetTrackInfoWidth() const;
@ -492,20 +494,6 @@ protected:
int mMouseMostRecentX; int mMouseMostRecentX;
int mMouseMostRecentY; int mMouseMostRecentY;
public:
// Old enumeration of click-and-drag states, which will shrink and disappear
// as UIHandle subclasses take over the repsonsibilities.
enum MouseCaptureEnum
{
IsUncaptured = 0,
IsClosing,
IsMuting,
IsSoloing,
IsMinimizing,
IsPopping,
};
protected:
friend class TrackPanelAx; friend class TrackPanelAx;
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY

View File

@ -20,7 +20,7 @@ Paul Licameli split from TrackPanel.cpp
MuteButtonHandle::MuteButtonHandle MuteButtonHandle::MuteButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect ) ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect, TrackPanel::IsMuting } : ButtonHandle{ pTrack, rect }
{} {}
MuteButtonHandle::~MuteButtonHandle() MuteButtonHandle::~MuteButtonHandle()
@ -62,7 +62,7 @@ UIHandlePtr MuteButtonHandle::HitTest
SoloButtonHandle::SoloButtonHandle SoloButtonHandle::SoloButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect ) ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect, TrackPanel::IsSoloing } : ButtonHandle{ pTrack, rect }
{} {}
SoloButtonHandle::~SoloButtonHandle() SoloButtonHandle::~SoloButtonHandle()

View File

@ -12,8 +12,6 @@ Paul Licameli split from TrackPanel.cpp
#define __AUDACITY_PLAYABLE_TRACK_BUTTON_HANDLES__ #define __AUDACITY_PLAYABLE_TRACK_BUTTON_HANDLES__
#include "../../ui/ButtonHandle.h" #include "../../ui/ButtonHandle.h"
#include "../../../TrackPanel.h"
class wxMouseState; class wxMouseState;
class MuteButtonHandle final : public ButtonHandle class MuteButtonHandle final : public ButtonHandle
@ -50,7 +48,7 @@ class SoloButtonHandle final : public ButtonHandle
public: public:
explicit SoloButtonHandle explicit SoloButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect ); ( const std::shared_ptr<Track> &pTrack, const wxRect &rect );
SoloButtonHandle &operator=(const SoloButtonHandle&) = default; SoloButtonHandle &operator=(const SoloButtonHandle&) = default;

View File

@ -21,10 +21,9 @@ Paul Licameli
#include "../ui/TrackControls.h" #include "../ui/TrackControls.h"
ButtonHandle::ButtonHandle ButtonHandle::ButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect, int dragCode ) ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: mpTrack{ pTrack } : mpTrack{ pTrack }
, mRect{ rect } , mRect{ rect }
, mDragCode{ dragCode }
{} {}
ButtonHandle::~ButtonHandle() ButtonHandle::~ButtonHandle()
@ -45,7 +44,8 @@ UIHandle::Result ButtonHandle::Click
// Come here for left click or double click // Come here for left click or double click
if (mRect.Contains(event.m_x, event.m_y)) { if (mRect.Contains(event.m_x, event.m_y)) {
TrackControls::gCaptureState = mDragCode; mWasIn = true;
mIsClicked = true;
// Toggle visible button state // Toggle visible button state
return RefreshCell; return RefreshCell;
} }
@ -62,14 +62,10 @@ UIHandle::Result ButtonHandle::Drag
if (!pTrack) if (!pTrack)
return Cancelled; return Cancelled;
const int newState = auto isIn = mRect.Contains(event.m_x, event.m_y);
mRect.Contains(event.m_x, event.m_y) ? mDragCode : 0; auto result = (isIn == mWasIn) ? RefreshNone : RefreshCell;
if (TrackControls::gCaptureState == newState) mWasIn = isIn;
return RefreshNone; return result;
else {
TrackControls::gCaptureState = newState;
return RefreshCell;
}
} }
HitTestPreview ButtonHandle::Preview HitTestPreview ButtonHandle::Preview
@ -90,22 +86,13 @@ UIHandle::Result ButtonHandle::Release
Result result = RefreshNone; Result result = RefreshNone;
const wxMouseEvent &event = evt.event; const wxMouseEvent &event = evt.event;
if (TrackControls::gCaptureState) {
TrackControls::gCaptureState = 0;
result = RefreshCell;
}
if (pTrack && mRect.Contains(event.m_x, event.m_y)) if (pTrack && mRect.Contains(event.m_x, event.m_y))
result |= CommitChanges(event, pProject, pParent); result |= RefreshCell | CommitChanges(event, pProject, pParent);
return result; return result;
} }
UIHandle::Result ButtonHandle::Cancel(AudacityProject *pProject) UIHandle::Result ButtonHandle::Cancel(AudacityProject *pProject)
{ {
using namespace RefreshCode; using namespace RefreshCode;
if (TrackControls::gCaptureState) { return RefreshCell; // perhaps unnecessarily if pointer is out of the box
TrackControls::gCaptureState = 0;
return RefreshCell;
}
else
return RefreshNone;
} }

View File

@ -23,9 +23,13 @@ class ButtonHandle /* not final */ : public UIHandle
{ {
ButtonHandle(const ButtonHandle&) = delete; ButtonHandle(const ButtonHandle&) = delete;
public:
std::shared_ptr<Track> GetTrack() const { return mpTrack.lock(); }
bool IsClicked() const { return mIsClicked; }
protected: protected:
explicit ButtonHandle explicit ButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect, int dragCode ); ( const std::shared_ptr<Track> &pTrack, const wxRect &rect );
ButtonHandle &operator=(const ButtonHandle&) = default; ButtonHandle &operator=(const ButtonHandle&) = default;
@ -56,7 +60,8 @@ protected:
std::weak_ptr<Track> mpTrack; std::weak_ptr<Track> mpTrack;
wxRect mRect; wxRect mRect;
int mDragCode; bool mWasIn{ true };
bool mIsClicked{};
}; };
#endif #endif

View File

@ -44,8 +44,10 @@ UIHandle::Result SliderHandle::Click
// Just did a modal dialog in OnMouseEvent // Just did a modal dialog in OnMouseEvent
// Do not start a drag // Do not start a drag
return RefreshCell | Cancelled; return RefreshCell | Cancelled;
else else {
mIsClicked = true;
return RefreshCell; return RefreshCell;
}
} }
UIHandle::Result SliderHandle::Drag UIHandle::Result SliderHandle::Drag

View File

@ -32,6 +32,9 @@ public:
SliderHandle &operator=(const SliderHandle&) = default; SliderHandle &operator=(const SliderHandle&) = default;
std::shared_ptr<Track> GetTrack() const { return mpTrack.lock(); }
bool IsClicked() const { return mIsClicked; }
protected: protected:
virtual ~SliderHandle(); virtual ~SliderHandle();
@ -67,6 +70,8 @@ protected:
LWSlider *GetSlider( AudacityProject *pProject ); LWSlider *GetSlider( AudacityProject *pProject );
float mStartingValue {}; float mStartingValue {};
bool mIsClicked{};
}; };
#endif #endif

View File

@ -19,7 +19,7 @@ Paul Licameli split from TrackPanel.cpp
MinimizeButtonHandle::MinimizeButtonHandle MinimizeButtonHandle::MinimizeButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect ) ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect, TrackPanel::IsMinimizing } : ButtonHandle{ pTrack, rect }
{} {}
MinimizeButtonHandle::~MinimizeButtonHandle() MinimizeButtonHandle::~MinimizeButtonHandle()
@ -69,7 +69,7 @@ UIHandlePtr MinimizeButtonHandle::HitTest
CloseButtonHandle::CloseButtonHandle CloseButtonHandle::CloseButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect ) ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect, TrackPanel::IsClosing } : ButtonHandle{ pTrack, rect }
{} {}
CloseButtonHandle::~CloseButtonHandle() CloseButtonHandle::~CloseButtonHandle()
@ -121,7 +121,7 @@ UIHandlePtr CloseButtonHandle::HitTest
MenuButtonHandle::MenuButtonHandle MenuButtonHandle::MenuButtonHandle
( const std::shared_ptr<TrackPanelCell> &pCell, ( const std::shared_ptr<TrackPanelCell> &pCell,
const std::shared_ptr<Track> &pTrack, const wxRect &rect ) const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect, TrackPanel::IsPopping } : ButtonHandle{ pTrack, rect }
, mpCell{ pCell } , mpCell{ pCell }
{} {}

View File

@ -12,7 +12,6 @@ Paul Licameli split from TrackPanel.cpp
#define __AUDACITY_TRACK_BUTTON_HANDLES__ #define __AUDACITY_TRACK_BUTTON_HANDLES__
#include "../ui/ButtonHandle.h" #include "../ui/ButtonHandle.h"
#include "../../TrackPanel.h"
class wxMouseState; class wxMouseState;

View File

@ -21,8 +21,6 @@ Paul Licameli split from TrackPanel.cpp
#include "../../Track.h" #include "../../Track.h"
#include <wx/textdlg.h> #include <wx/textdlg.h>
int TrackControls::gCaptureState;
TrackControls::TrackControls( std::shared_ptr<Track> pTrack ) TrackControls::TrackControls( std::shared_ptr<Track> pTrack )
: mwTrack{ pTrack } : mwTrack{ pTrack }
{ {

View File

@ -42,9 +42,6 @@ public:
unsigned result; unsigned result;
}; };
// Make this hack go away! See TrackPanel::DrawOutside
static int gCaptureState;
protected: protected:
// An override is supplied for derived classes to call through but it is // An override is supplied for derived classes to call through but it is
// still marked pure virtual // still marked pure virtual