| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/*!******************************************************************** |
| 3 |
|
| 4 |
Audacity: A Digital Audio Editor |
| 5 |
|
| 6 |
ClipOverflowButtonHandle.cpp |
| 7 |
|
| 8 |
Matthieu Hodgkinson |
| 9 |
|
| 10 |
**********************************************************************/ |
| 11 |
#include "ClipOverflowButtonHandle.h" |
| 12 |
#include "AllThemeResources.h" |
| 13 |
#include "HitTestResult.h" |
| 14 |
#include "LowlitClipButton.h" |
| 15 |
#include "ProjectHistory.h" |
| 16 |
#include "RefreshCode.h" |
| 17 |
#include "Theme.h" |
| 18 |
#include "TrackArt.h" |
| 19 |
#include "TrackPanelCell.h" |
| 20 |
#include "TrackPanelMouseEvent.h" |
| 21 |
#include "ViewInfo.h" |
| 22 |
#include "WaveClip.h" |
| 23 |
#include "WaveTrack.h" |
| 24 |
#include <wx/dc.h> |
| 25 |
#include <wx/event.h> |
| 26 |
|
| 27 |
namespace |
| 28 |
{ |
| 29 |
void SelectInterval( |
| 30 |
AudacityProject& project, const WaveTrack::Interval& interval) |
| 31 |
{ |
| 32 |
auto& viewInfo = ViewInfo::Get(project); |
| 33 |
viewInfo.selectedRegion.setTimes( |
| 34 |
interval.GetPlayStartTime(), interval.GetPlayEndTime()); |
| 35 |
ProjectHistory::Get(project).ModifyState(false); |
| 36 |
} |
| 37 |
} // namespace |
| 38 |
|
| 39 |
ClipOverflowButtonHandle::ClipOverflowButtonHandle( |
| 40 |
const std::shared_ptr<WaveTrack>& track, |
| 41 |
const std::shared_ptr<WaveTrack::Interval>& clip, |
| 42 |
std::weak_ptr<TrackPanelCell> cell) |
| 43 |
: HighlitClipButtonHandle { ClipButtonId::Overflow, track, clip } |
| 44 |
, mCell { std::move(cell) } |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
void ClipOverflowButtonHandle::DoDraw(const wxRect& rect, wxDC& dc) |
| 49 |
{ |
| 50 |
const ClipInterface& clip = *mClip; |
| 51 |
ClipButtonDrawingArgs args { rect, clip, dc }; |
| 52 |
ClipButtonSpecializations<ClipButtonId::Overflow>::DrawOnClip(args); |
| 53 |
} |
| 54 |
|
| 55 |
UIHandle::Result ClipOverflowButtonHandle::DoRelease( |
| 56 |
const TrackPanelMouseEvent& event, AudacityProject* pProject, |
| 57 |
wxWindow* pParent) |
| 58 |
{ |
| 59 |
if (const auto cell = mCell.lock()) |
| 60 |
{ |
| 61 |
SelectInterval(*pProject, *mClip); |
| 62 |
const wxPoint point { event.event.GetPosition() }; |
| 63 |
return cell->DoContextMenu(event.rect, pParent, &point, pProject); |
| 64 |
} |
| 65 |
return RefreshCode::RefreshNone; |
| 66 |
} |
| 67 |
|
| 68 |
HitTestPreview ClipOverflowButtonHandle::Preview( |
| 69 |
const TrackPanelMouseState& state, AudacityProject* pProject) |
| 70 |
{ |
| 71 |
return { XO("Click to open clip context menu."), nullptr }; |
| 72 |
} |
| 73 |
|
| 74 |
int ClipButtonSpecializations<ClipButtonId::Overflow>::GetWidth( |
| 75 |
const ClipInterface&) |
| 76 |
{ |
| 77 |
return 30; |
| 78 |
} |
| 79 |
|
| 80 |
bool ClipButtonSpecializations<ClipButtonId::Overflow>::NeedsDrawing( |
| 81 |
const ClipInterface&) |
| 82 |
{ |
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
void ClipButtonSpecializations<ClipButtonId::Overflow>::DrawOnClip( |
| 87 |
ClipButtonDrawingArgs& args) |
| 88 |
{ |
| 89 |
auto& dc = args.dc; |
| 90 |
const auto& rect = args.rect; |
| 91 |
constexpr auto penWidth = 0; |
| 92 |
wxDCPenChanger pen { args.dc, { wxPenInfo { theTheme.Colour(clrClipNameText), penWidth } } }; |
| 93 |
wxDCBrushChanger brush { dc, theTheme.Colour(clrClipNameText) }; |
| 94 |
constexpr auto numDots = 3; |
| 95 |
constexpr auto radius = 1; |
| 96 |
constexpr auto spacing = 4; |
| 97 |
constexpr auto totalWidth = numDots * 2 * radius + 2 * spacing; |
| 98 |
const auto dotY = rect.y + (rect.height + 1 - radius) / 2; |
| 99 |
for (auto i = 0; i < numDots; ++i) |
| 100 |
{ |
| 101 |
const auto dotX = rect.x + (rect.width + 1 - totalWidth) / 2 + |
| 102 |
i * (2 * radius + spacing); |
| 103 |
dc.DrawCircle(dotX, dotY, radius); |
| 104 |
} |
| 105 |
} |