15#include "../../../HitTestResult.h"
18#include "../../../RefreshCode.h"
19#include "../../../TrackPanelMouseEvent.h"
24#include "../../../../images/Cursors.h"
28#include <wx/translation.h>
52 auto update = [=](
int &index ){
53 if ( index == former )
55 else if ( former < index && index <= present )
57 else if ( former > index && index >= present )
67(
const std::shared_ptr<LabelTrack> &pLT,
68 const wxRect &rect,
const std::shared_ptr<LabelTrackHit> &pHit)
83 if (oldState.
mpHit->mEdge != newState.
mpHit->mEdge)
90(std::weak_ptr<LabelGlyphHandle> &holder,
91 const wxMouseState &state,
92 const std::shared_ptr<LabelTrack> &pLT,
const wxRect &rect)
97 auto pHit = std::make_shared<LabelTrackHit>( pLT );
103 if ( pHit->mEdge & 3 )
105 auto result = std::make_shared<LabelGlyphHandle>( pLT, rect, pHit );
124 const wxRect & r,
const ZoomInfo &zoomInfo,
127 if (evt.ButtonDown())
130 const auto pTrack =
mpLT;
134 ( hit.
mEdge & 3 ) != 0;
139 view.ResetTextSelection();
156 const auto &mLabels = pTrack->GetLabels();
176 if (!(isPointLabel && evt.ShiftDown()))
206 const wxMouseEvent &
event = evt.
event;
212 *
mpHit, event,
mRect, viewInfo, viewInfo.selectedRegion);
214 if (!
mpHit->mIsAdjustingLabel )
233(
LabelTrackHit &hit,
int iLabel,
int iEdge,
bool bAllowSwapping,
double fNewTime)
238 const auto pTrack =
mpLT;
239 const auto &mLabels = pTrack->GetLabels();
240 auto labelStruct = mLabels[ iLabel ];
243 bool flipped = labelStruct.AdjustEdge( iEdge, fNewTime );
246 pTrack->SetLabel( iLabel, labelStruct );
252 if( !bAllowSwapping )
254 labelStruct.AdjustEdge( -iEdge, fNewTime );
255 pTrack->SetLabel( iLabel, labelStruct );
259 pTrack->SetLabel( iLabel, labelStruct );
271 const auto pTrack =
mpLT;
272 const auto &mLabels = pTrack->GetLabels();
273 auto labelStruct = mLabels[ iLabel ];
274 labelStruct.MoveLabel( iEdge, fNewTime );
275 pTrack->SetLabel( iLabel, labelStruct );
282 wxASSERT(
min <= max );
294 wxRect & r,
const ZoomInfo &zoomInfo,
297 const auto pTrack =
mpLT;
298 const auto &mLabels = pTrack->GetLabels();
301 bool updated =
false;
304 updated |= labelStruct.updated;
305 labelStruct.updated =
false;
310 updated |= labelStruct.updated;
311 labelStruct.updated =
false;
318 if (!labelStruct.updated)
321 newSel = labelStruct.selectedRegion;
328 bool done =
tracks.Selected().any_of(
329 [&](
const Track* track) {
return track !=
static_cast<Track*
>(pTrack.get()); }
335 selectionState.SelectTrack(*t,
true,
true);
340 selectionState.SelectTrack(*pTrack,
true,
true);
350 labelStruct.updated =
false;
378 for (
auto i = 0, count =
static_cast<int>(mLabels.size()); i < count; ++i)
395 bool bAllowSwapping =
403 auto navigationIndex = view.GetNavigationIndex(
project);
404 if(navigationIndex != -1 &&
411 newSel = mLabels[navigationIndex].selectedRegion;
413 pTrack->SortLabels();
424 const wxMouseEvent &
event = evt.
event;
427 *pProject, *
mpHit, event,
mRect, viewInfo, viewInfo.selectedRegion);
436 static wxCursor arrowCursor{ wxCURSOR_ARROW };
438 MakeCursor(wxCURSOR_HAND, RearrangeCursorXpm, 16, 16);
439 static auto handClosedCursor =
440 MakeCursor(wxCURSOR_HAND, RearrangingCursorXpm, 16, 16);
442 if (
mpHit->mMouseOverLabel != -1)
445 XO(
"Drag label. Hold shift and drag to move all labels on the same track."),
449 else if ((
mpHit->mEdge & 4) != 0)
450 return {
XO(
"Drag one or more label boundaries."), &arrowCursor };
452 return {
XO(
"Drag label boundary."), &arrowCursor };
461 const wxMouseEvent &
event = evt.
event;
464 *pProject, *
mpHit, event,
mRect, viewInfo, viewInfo.selectedRegion)) {
static std::unique_ptr< wxCursor > handOpenCursor
std::shared_ptr< UIHandle > UIHandlePtr
static int Constrain(int value, int min, int max)
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Result Cancel(AudacityProject *pProject) override
Result Cancel(AudacityProject *pProject) override
void Enter(bool forward, AudacityProject *) override
std::shared_ptr< LabelTrackHit > mpHit
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
void MayAdjustLabel(LabelTrackHit &hit, int iLabel, int iEdge, bool bAllowSwapping, double fNewTime)
bool HandleGlyphDragRelease(AudacityProject &project, LabelTrackHit &hit, const wxMouseEvent &evt, wxRect &r, const ZoomInfo &zoomInfo, NotifyingSelectedRegion &newSel)
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
std::shared_ptr< LabelTrack > mpLT
static UIHandlePtr HitTest(std::weak_ptr< LabelGlyphHandle > &holder, const wxMouseState &state, const std::shared_ptr< LabelTrack > &pLT, const wxRect &rect)
virtual ~LabelGlyphHandle()
static UIHandle::Result NeedChangeHighlight(const LabelGlyphHandle &oldState, const LabelGlyphHandle &newState)
void MayMoveLabel(int iLabel, int iEdge, double fNewTime)
void HandleGlyphClick(LabelTrackHit &hit, const wxMouseEvent &evt, const wxRect &r, const ZoomInfo &zoomInfo, NotifyingSelectedRegion &newSel)
LabelGlyphHandle(const std::shared_ptr< LabelTrack > &pLT, const wxRect &rect, const std::shared_ptr< LabelTrackHit > &pHit)
HitTestPreview Preview(const TrackPanelMouseState &state, AudacityProject *pProject) override
int mxMouseDisplacement
Displacement of mouse cursor from the centre being dragged.
std::shared_ptr< const Track > FindTrack() const override
static LabelTrackView & Get(LabelTrack &)
static void OverGlyph(const LabelTrack &track, LabelTrackHit &hit, int x, int y)
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static SelectionState & Get(AudacityProject &project)
Abstract base class for an object holding data associated with points on a time axis.
static TrackList & Get(AudacityProject &project)
static ViewInfo & Get(AudacityProject &project)
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
int64 TimeToPosition(double time, int64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
const std::weak_ptr< Track > mpTrack
enum LabelTrackEvent::Type type
int mMouseOverLabelRight
Keeps track of which left label the mouse is currently over.
LabelTrackHit(const std::shared_ptr< LabelTrack > &pLT)
int mMouseOverLabelLeft
Keeps track of which (ranged) label the mouse is currently over.
std::shared_ptr< LabelTrack > mpLT
void OnLabelPermuted(const LabelTrackEvent &e)
Observer::Subscription mSubscription
bool mIsAdjustingLabel
Keeps track of which right label the mouse is currently over.