15#include "../../../HitTestResult.h"
16#include "../../../LabelTrack.h"
18#include "../../../RefreshCode.h"
19#include "../../../TrackPanelMouseEvent.h"
24#include "../../../../images/Cursors.h"
25#include "../../../tracks/ui/TimeShiftHandle.h"
29#include <wx/translation.h>
51 auto update = [=](
int &index ){
52 if ( index == former )
54 else if ( former < index && index <= present )
56 else if ( former > index && index >= present )
66(
const std::shared_ptr<LabelTrack> &pLT,
67 const wxRect &rect,
const std::shared_ptr<LabelTrackHit> &pHit)
82 if (oldState.
mpHit->mEdge != newState.
mpHit->mEdge)
89(std::weak_ptr<LabelGlyphHandle> &holder,
90 const wxMouseState &state,
91 const std::shared_ptr<LabelTrack> &pLT,
const wxRect &rect)
96 auto pHit = std::make_shared<LabelTrackHit>( pLT );
102 if ( pHit->mEdge & 3 )
104 auto result = std::make_shared<LabelGlyphHandle>( pLT, rect, pHit );
118 const wxRect & r,
const ZoomInfo &zoomInfo,
121 if (evt.ButtonDown())
124 const auto pTrack =
mpLT;
128 ( hit.
mEdge & 3 ) != 0;
133 view.ResetTextSelection();
150 const auto &mLabels = pTrack->GetLabels();
170 if (!(isPointLabel && evt.ShiftDown()))
200 const wxMouseEvent &
event = evt.
event;
206 *
mpHit, event,
mRect, viewInfo, viewInfo.selectedRegion);
208 if (!
mpHit->mIsAdjustingLabel )
227(
LabelTrackHit &hit,
int iLabel,
int iEdge,
bool bAllowSwapping,
double fNewTime)
232 const auto pTrack =
mpLT;
233 const auto &mLabels = pTrack->GetLabels();
234 auto labelStruct = mLabels[ iLabel ];
237 bool flipped = labelStruct.AdjustEdge( iEdge, fNewTime );
240 pTrack->SetLabel( iLabel, labelStruct );
246 if( !bAllowSwapping )
248 labelStruct.AdjustEdge( -iEdge, fNewTime );
249 pTrack->SetLabel( iLabel, labelStruct );
253 pTrack->SetLabel( iLabel, labelStruct );
265 const auto pTrack =
mpLT;
266 const auto &mLabels = pTrack->GetLabels();
267 auto labelStruct = mLabels[ iLabel ];
268 labelStruct.MoveLabel( iEdge, fNewTime );
269 pTrack->SetLabel( iLabel, labelStruct );
276 wxASSERT(
min <= max );
288 wxRect & r,
const ZoomInfo &zoomInfo,
291 const auto pTrack =
mpLT;
292 const auto &mLabels = pTrack->GetLabels();
295 bool updated =
false;
298 updated |= labelStruct.updated;
299 labelStruct.updated =
false;
304 updated |= labelStruct.updated;
305 labelStruct.updated =
false;
312 if (!labelStruct.updated)
315 newSel = labelStruct.selectedRegion;
322 bool done = tracks.Selected().any_of(
323 [&](
const Track* track) {
return track !=
static_cast<Track*
>(pTrack.get()); }
328 for (
auto t : tracks.Any())
329 selectionState.SelectTrack(*t,
true,
true);
334 selectionState.SelectTrack(*pTrack.get(),
true,
true);
344 labelStruct.updated =
false;
372 for (
auto i = 0, count =
static_cast<int>(mLabels.size()); i < count; ++i)
389 bool bAllowSwapping =
397 auto navigationIndex = view.GetNavigationIndex(project);
398 if(navigationIndex != -1 &&
405 newSel = mLabels[navigationIndex].selectedRegion;
407 pTrack->SortLabels();
418 const wxMouseEvent &
event = evt.
event;
421 *pProject, *
mpHit, event,
mRect, viewInfo, viewInfo.selectedRegion);
430 static wxCursor arrowCursor{ wxCURSOR_ARROW };
432 MakeCursor(wxCURSOR_HAND, RearrangeCursorXpm, 16, 16);
433 static auto handClosedCursor =
434 MakeCursor(wxCURSOR_HAND, RearrangingCursorXpm, 16, 16);
436 if (
mpHit->mMouseOverLabel != -1)
439 XO(
"Drag label. Hold shift and drag to move all labels on the same track."),
443 else if ((
mpHit->mEdge & 4) != 0)
444 return {
XO(
"Drag one or more label boundaries."), &arrowCursor };
446 return {
XO(
"Drag label boundary."), &arrowCursor };
455 const wxMouseEvent &
event = evt.
event;
458 *pProject, *
mpHit, event,
mRect, viewInfo, viewInfo.selectedRegion)) {
static auto 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.
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.