Audacity 3.2.0
HighlitClipButtonHandle.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 HighlitClipButtonHandle.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
12#include "AllThemeResources.h"
13#include "ClipParameters.h"
14#include "HitTestResult.h"
15#include "LowlitClipButton.h"
16#include "ProjectHistory.h"
17#include "RefreshCode.h"
18#include "SelectionState.h"
19#include "Theme.h"
20#include "TrackArt.h"
21#include "TrackArtist.h"
24#include "ViewInfo.h"
25#include "WaveClip.h"
26#include "WaveTrack.h"
27#include <wx/dc.h>
28#include <wx/window.h>
29
31 ClipButtonId id, std::shared_ptr<WaveTrack> track,
32 std::shared_ptr<WaveTrack::Interval> clip)
33 : mButtonId { id }
34 , mTrack { std::move(track) }
35 , mClip { std::move(clip) }
36{
37}
38
40 TrackPanelDrawingContext& context, const wxRect& affordanceRect,
41 unsigned iPass)
42{
43 if (iPass != TrackArtist::PassSnapping)
44 return;
45 const auto artist = TrackArtist::Get(context);
46 const auto& zoomInfo = *artist->pZoomInfo;
48 mButtonId, { *mClip, zoomInfo, affordanceRect });
49 if (!rect)
50 return;
51 Highlight(*rect, context.dc);
52 DoDraw(*rect, context.dc);
53}
54
56 const TrackPanelMouseEvent& event, AudacityProject* pProject)
57{
58 mwCell = event.pCell;
59 return 0;
60}
61
63 const TrackPanelMouseEvent& event, AudacityProject* pProject)
64{
65 const auto cancelCode = RefreshCode::RefreshCell | RefreshCode::Cancelled;
66 if (event.pCell != mwCell.lock())
67 return cancelCode;
68
69 // It's the right cell; check that the mouse is still over the button.
71 mButtonId, { *mClip, ViewInfo::Get(*pProject), event.rect });
72 if (!buttonRect.has_value())
73 return cancelCode;
74
75 const auto mousePos = event.event.GetPosition();
76 if (!buttonRect->Contains(mousePos))
77 return cancelCode;
78
79 return 0;
80}
81
83 const TrackPanelMouseEvent& event, AudacityProject* pProject,
84 wxWindow* pParent)
85{
87 // Select before calling `DoRelease`.
88 const auto result = UpdateTrackSelection(event, pProject);
89 return result | DoRelease(event, pProject, pParent);
90}
91
93{
94 return 0;
95}
96
98 const TrackPanelMouseEvent& event, AudacityProject* pProject)
99{
100 auto& trackList = TrackList::Get(*pProject);
101
102 if (const auto track = trackList.Lock<Track>(mTrack))
103 {
104 auto& selectionState = SelectionState::Get(*pProject);
105 selectionState.SelectNone(trackList);
106 selectionState.SelectTrack(*track, true, true);
107
108 auto& viewInfo = ViewInfo::Get(*pProject);
109 viewInfo.selectedRegion.setTimes(
110 mClip->GetPlayStartTime(), mClip->GetPlayEndTime());
111
112 ProjectHistory::Get(*pProject).ModifyState(false);
113
115 }
116
118}
119
120std::shared_ptr<const Track> HighlitClipButtonHandle::FindTrack() const
121{
122 return mTrack;
123}
124
126{
128}
129
130void HighlitClipButtonHandle::Highlight(const wxRect& rect, wxDC& dc)
131{
132 constexpr auto penWidth = 0;
133 const auto col = theTheme.Colour(clrClipAffordanceStroke);
134 wxDCBrushChanger brush { dc, col };
135 wxDCPenChanger pen { dc, { wxPenInfo { col, penWidth } } };
136 constexpr auto radius = 3;
137 dc.DrawRoundedRectangle(rect, radius);
138}
ClipButtonId
Definition: ClipButtonId.h:14
THEME_API Theme theTheme
Definition: Theme.cpp:82
int id
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
HighlitClipButtonHandle(ClipButtonId id, std::shared_ptr< WaveTrack > track, std::shared_ptr< WaveTrack::Interval > clip)
virtual Result DoRelease(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
std::shared_ptr< WaveTrack > mTrack
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
static void Highlight(const wxRect &rect, wxDC &dc)
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
std::weak_ptr< TrackPanelCell > mwCell
std::shared_ptr< WaveTrack::Interval > mClip
void Enter(bool forward, AudacityProject *pProject) override
virtual void DoDraw(const wxRect &args, wxDC &dc)=0
std::shared_ptr< const Track > FindTrack() const override
Result Cancel(AudacityProject *pProject) override
UIHandle::Result UpdateTrackSelection(const TrackPanelMouseEvent &event, AudacityProject *pProject)
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static SelectionState & Get(AudacityProject &project)
wxColour & Colour(int iIndex)
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
Result mChangeHighlight
Definition: UIHandle.h:152
unsigned Result
Definition: UIHandle.h:40
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
std::optional< wxRect > GetButtonRectangle(ClipButtonId buttonId, const RectangleArgs &args)
std::optional< wxRect > GetButtonInnerRectangle(ClipButtonId buttonId, const RectangleArgs &args)
STL namespace.
std::shared_ptr< TrackPanelCell > pCell