mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 00:20:06 +02:00
A close box button for sub-views
This commit is contained in:
parent
0f3f13502c
commit
f10b303279
@ -263,6 +263,39 @@ void TrackInfo::DrawItems
|
||||
}
|
||||
|
||||
#include "tracks/ui/TrackButtonHandles.h"
|
||||
void TrackInfo::DrawCloseButton(
|
||||
TrackPanelDrawingContext &context, const wxRect &bev,
|
||||
const Track *pTrack, ButtonHandle *target )
|
||||
{
|
||||
auto dc = &context.dc;
|
||||
bool selected = pTrack ? pTrack->GetSelected() : true;
|
||||
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, hit );
|
||||
|
||||
#ifdef EXPERIMENTAL_THEMING
|
||||
wxPen pen( theTheme.Colour( clrTrackPanelText ));
|
||||
dc->SetPen( pen );
|
||||
#else
|
||||
dc->SetPen(*wxBLACK_PEN);
|
||||
#endif
|
||||
bev.Inflate( -1, -1 );
|
||||
// Draw the "X"
|
||||
const int s = 6;
|
||||
|
||||
int ls = bev.x + ((bev.width - s) / 2);
|
||||
int ts = bev.y + ((bev.height - s) / 2);
|
||||
int rs = ls + s;
|
||||
int bs = ts + s;
|
||||
|
||||
AColor::Line(*dc, ls, ts, rs, bs);
|
||||
AColor::Line(*dc, ls + 1, ts, rs + 1, bs);
|
||||
AColor::Line(*dc, rs, ts, ls, bs);
|
||||
AColor::Line(*dc, rs + 1, ts, ls + 1, bs);
|
||||
// bev.Inflate(-1, -1);
|
||||
}
|
||||
|
||||
void TrackInfo::CloseTitleDrawFunction
|
||||
( TrackPanelDrawingContext &context,
|
||||
const wxRect &rect, const Track *pTrack )
|
||||
@ -273,32 +306,7 @@ void TrackInfo::CloseTitleDrawFunction
|
||||
wxRect bev = rect;
|
||||
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, hit );
|
||||
|
||||
#ifdef EXPERIMENTAL_THEMING
|
||||
wxPen pen( theTheme.Colour( clrTrackPanelText ));
|
||||
dc->SetPen( pen );
|
||||
#else
|
||||
dc->SetPen(*wxBLACK_PEN);
|
||||
#endif
|
||||
bev.Inflate( -1, -1 );
|
||||
// Draw the "X"
|
||||
const int s = 6;
|
||||
|
||||
int ls = bev.x + ((bev.width - s) / 2);
|
||||
int ts = bev.y + ((bev.height - s) / 2);
|
||||
int rs = ls + s;
|
||||
int bs = ts + s;
|
||||
|
||||
AColor::Line(*dc, ls, ts, rs, bs);
|
||||
AColor::Line(*dc, ls + 1, ts, rs + 1, bs);
|
||||
AColor::Line(*dc, rs, ts, ls, bs);
|
||||
AColor::Line(*dc, rs + 1, ts, ls + 1, bs);
|
||||
|
||||
// bev.Inflate(-1, -1);
|
||||
DrawCloseButton( context, bev, pTrack, target );
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -22,6 +22,7 @@ class wxRect;
|
||||
class wxString;
|
||||
class wxWindow;
|
||||
|
||||
class ButtonHandle;
|
||||
class LWSlider;
|
||||
class NoteTrack;
|
||||
class Track;
|
||||
@ -81,6 +82,10 @@ namespace TrackInfo
|
||||
const std::vector<TCPLine> &topLines,
|
||||
const std::vector<TCPLine> &bottomLines );
|
||||
|
||||
void DrawCloseButton(
|
||||
TrackPanelDrawingContext &context, const wxRect &bev,
|
||||
const Track *pTrack, ButtonHandle *target );
|
||||
|
||||
void CloseTitleDrawFunction
|
||||
( TrackPanelDrawingContext &context,
|
||||
const wxRect &rect, const Track *pTrack );
|
||||
|
@ -37,6 +37,8 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include "../../../../prefs/TracksPrefs.h"
|
||||
|
||||
#include "../../../ui/TimeShiftHandle.h"
|
||||
#include "../../../ui/ButtonHandle.h"
|
||||
#include "../../../../TrackInfo.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -603,6 +605,80 @@ private:
|
||||
wxCoord mViewHeight{}; // Total height of all sub-views
|
||||
};
|
||||
|
||||
class SubViewCloseHandle : public ButtonHandle
|
||||
{
|
||||
static wxRect GetButtonRect( const wxRect &rect )
|
||||
{
|
||||
return {
|
||||
rect.GetLeft(),
|
||||
rect.GetTop(),
|
||||
kTrackInfoBtnSize,
|
||||
kTrackInfoBtnSize
|
||||
};
|
||||
}
|
||||
|
||||
public:
|
||||
static UIHandlePtr HitTest( std::weak_ptr<UIHandle> &holder,
|
||||
WaveTrackView &view, WaveTrackSubView &subView,
|
||||
const TrackPanelMouseState &state )
|
||||
{
|
||||
SubViewAdjuster adjuster{ view };
|
||||
if ( adjuster.NVisible() < 2 )
|
||||
return {};
|
||||
|
||||
const auto rect = GetButtonRect( state.rect );
|
||||
if ( !rect.Contains( state.state.GetPosition() ) )
|
||||
return {};
|
||||
auto index = adjuster.FindIndex( subView );
|
||||
UIHandlePtr result = std::make_shared<SubViewCloseHandle>(
|
||||
std::move( adjuster ), index, view.FindTrack(), rect );
|
||||
result = AssignUIHandlePtr( holder, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
SubViewCloseHandle(
|
||||
SubViewAdjuster &&adjuster, size_t index,
|
||||
const std::shared_ptr<Track> &pTrack, const wxRect &rect )
|
||||
: ButtonHandle{ pTrack, rect }
|
||||
, mAdjuster{ std::move( adjuster ) }
|
||||
, mMySubView{ index }
|
||||
{
|
||||
}
|
||||
|
||||
Result CommitChanges(
|
||||
const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)
|
||||
override
|
||||
{
|
||||
ProjectHistory::Get( *pProject ).ModifyState( false );
|
||||
auto &myPlacement =
|
||||
mAdjuster.mNewPlacements[ mAdjuster.mPermutation[ mMySubView ] ];
|
||||
myPlacement.fraction = 0;
|
||||
mAdjuster.UpdateViews( false );
|
||||
return RefreshCode::RefreshAll;
|
||||
}
|
||||
|
||||
TranslatableString Tip(
|
||||
const wxMouseState &state, AudacityProject &project) const override
|
||||
{
|
||||
return XO("Close sub-view");
|
||||
}
|
||||
|
||||
// TrackPanelDrawable implementation
|
||||
void Draw(
|
||||
TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass )
|
||||
override
|
||||
{
|
||||
if ( iPass == TrackArtist::PassMargins ) { // after PassTracks
|
||||
TrackInfo::DrawCloseButton(
|
||||
context, GetButtonRect(rect), GetTrack().get(), this );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SubViewAdjuster mAdjuster;
|
||||
size_t mMySubView{};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::pair<
|
||||
@ -620,6 +696,10 @@ std::pair<
|
||||
|
||||
auto pWaveTrackView = mwWaveTrackView.lock();
|
||||
if ( pWaveTrackView && !state.state.HasModifiers() ) {
|
||||
if ( auto pHandle = SubViewCloseHandle::HitTest(
|
||||
mCloseHandle,
|
||||
*pWaveTrackView, *this, state ) )
|
||||
results.second.push_back( pHandle );
|
||||
if ( auto pHandle = SubViewAdjustHandle::HitTest(
|
||||
mAdjustHandle,
|
||||
*pWaveTrackView, *this, state ) )
|
||||
|
@ -41,6 +41,7 @@ protected:
|
||||
const wxRect &rect );
|
||||
|
||||
private:
|
||||
std::weak_ptr<UIHandle> mCloseHandle;
|
||||
std::weak_ptr<UIHandle> mAdjustHandle;
|
||||
std::weak_ptr<UIHandle> mRearrangeHandle;
|
||||
std::weak_ptr<CutlineHandle> mCutlineHandle;
|
||||
|
Loading…
x
Reference in New Issue
Block a user