| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/*!******************************************************************** |
| 3 |
|
| 4 |
Audacity: A Digital Audio Editor |
| 5 |
|
| 6 |
LowlitClipButton.h |
| 7 |
|
| 8 |
Describes the buttons that appear on the audio clips in their "lowlit" state, |
| 9 |
i.e., the opposite of the "highlit", or "highlighted", state. These buttons |
| 10 |
are highlit when the mouse hovers over them, and lowlit otherwise. |
| 11 |
|
| 12 |
Matthieu Hodgkinson |
| 13 |
|
| 14 |
**********************************************************************/ |
| 15 |
#pragma once |
| 16 |
|
| 17 |
#include "ClipButtonId.h" |
| 18 |
#include "ClipParameters.h" |
| 19 |
#include "UIHandle.h" |
| 20 |
#include "WaveTrack.h" |
| 21 |
|
| 22 |
class wxRect; |
| 23 |
class wxPoint; |
| 24 |
class wxDC; |
| 25 |
class ClipInterface; |
| 26 |
class ZoomInfo; |
| 27 |
|
| 28 |
struct ClipButtonDrawingArgs |
| 29 |
{ |
| 30 |
const wxRect& rect; |
| 31 |
const ClipInterface& clip; |
| 32 |
wxDC& dc; |
| 33 |
}; |
| 34 |
|
| 35 |
template <ClipButtonId id> struct ClipButtonSpecializations |
| 36 |
{ |
| 37 |
static bool NeedsDrawing(const ClipInterface&); |
| 38 |
static void DrawOnClip(ClipButtonDrawingArgs&); |
| 39 |
static int GetWidth(const ClipInterface& clip); |
| 40 |
}; |
| 41 |
|
| 42 |
template<> |
| 43 |
struct ClipButtonSpecializations<ClipButtonId::Overflow> |
| 44 |
{ |
| 45 |
static bool NeedsDrawing(const ClipInterface& clip); |
| 46 |
static void DrawOnClip(ClipButtonDrawingArgs&); |
| 47 |
static int GetWidth(const ClipInterface& clip); |
| 48 |
}; |
| 49 |
|
| 50 |
template<> |
| 51 |
struct ClipButtonSpecializations<ClipButtonId::Pitch> |
| 52 |
{ |
| 53 |
static bool NeedsDrawing(const ClipInterface& clip); |
| 54 |
static void DrawOnClip(ClipButtonDrawingArgs&); |
| 55 |
static int GetWidth(const ClipInterface& clip); |
| 56 |
}; |
| 57 |
|
| 58 |
template<> |
| 59 |
struct ClipButtonSpecializations<ClipButtonId::Speed> |
| 60 |
{ |
| 61 |
static bool NeedsDrawing(const ClipInterface& clip); |
| 62 |
static void DrawOnClip(ClipButtonDrawingArgs&); |
| 63 |
static int GetWidth(const ClipInterface& clip); |
| 64 |
}; |
| 65 |
|
| 66 |
namespace LowlitClipButton |
| 67 |
{ |
| 68 |
struct RectangleArgs |
| 69 |
{ |
| 70 |
const ClipInterface& clip; |
| 71 |
const ZoomInfo& zoomInfo; |
| 72 |
// The upper ribbon of a track's rectangle, where the affordances of one or |
| 73 |
// more clips are drawn. |
| 74 |
const wxRect& trackAffordanceRect; |
| 75 |
}; |
| 76 |
|
| 77 |
namespace Detail |
| 78 |
{ |
| 79 |
std::optional<wxRect> |
| 80 |
GetButtonRectangle(ClipButtonId buttonId, const RectangleArgs& args); |
| 81 |
|
| 82 |
std::optional<wxRect> |
| 83 |
GetButtonInnerRectangle(ClipButtonId buttonId, const RectangleArgs& args); |
| 84 |
} // namespace Detail |
| 85 |
|
| 86 |
template <ClipButtonId id> |
| 87 |
bool HitTest(const RectangleArgs& args, const wxPoint& mousePos) |
| 88 |
{ |
| 89 |
if (!ClipButtonSpecializations<id>::NeedsDrawing(args.clip)) |
| 90 |
return false; |
| 91 |
const auto buttonRect = Detail::GetButtonRectangle(id, args); |
| 92 |
return buttonRect.has_value() && buttonRect->Contains(mousePos); |
| 93 |
} |
| 94 |
|
| 95 |
template <ClipButtonId id> |
| 96 |
std::optional<wxRect> DrawOnClip(const RectangleArgs& args, wxDC& dc) |
| 97 |
{ |
| 98 |
if (!ClipButtonSpecializations<id>::NeedsDrawing(args.clip)) |
| 99 |
return {}; |
| 100 |
const auto rect = Detail::GetButtonInnerRectangle(id, args); |
| 101 |
if (!rect) |
| 102 |
return {}; |
| 103 |
ClipButtonDrawingArgs drawingArgs { *rect, args.clip, dc }; |
| 104 |
ClipButtonSpecializations<id>::DrawOnClip(drawingArgs); |
| 105 |
return rect; |
| 106 |
} |
| 107 |
} // namespace LowlitClipButton |