| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/*!******************************************************************** |
| 3 |
|
| 4 |
Audacity: A Digital Audio Editor |
| 5 |
|
| 6 |
LowlitClipButton.cpp |
| 7 |
|
| 8 |
Matthieu Hodgkinson |
| 9 |
|
| 10 |
**********************************************************************/ |
| 11 |
#include "LowlitClipButton.h" |
| 12 |
#include "ClipParameters.h" |
| 13 |
|
| 14 |
namespace |
| 15 |
{ |
| 16 |
constexpr auto widthReservedForTitle = 50; |
| 17 |
constexpr auto topMargin = 4; |
| 18 |
constexpr auto leftMargin = 0; |
| 19 |
constexpr auto bottomMargin = 1; |
| 20 |
|
| 21 |
wxRect RemoveSpaceReservedForTitle(const wxRect& rect) |
| 22 |
{ |
| 23 |
const auto toRemove = std::min(rect.width, widthReservedForTitle); |
| 24 |
return { rect.x + toRemove, rect.y, rect.width - toRemove, rect.height }; |
| 25 |
} |
| 26 |
|
| 27 |
int GetButtonWidth(ClipButtonId buttonId, const ClipInterface& clip) |
| 28 |
{ |
| 29 |
return buttonId == ClipButtonId::Overflow ? |
| 30 |
ClipButtonSpecializations<ClipButtonId::Overflow>::GetWidth(clip) : |
| 31 |
buttonId == ClipButtonId::Speed ? |
| 32 |
ClipButtonSpecializations<ClipButtonId::Speed>::GetWidth(clip) : |
| 33 |
ClipButtonSpecializations<ClipButtonId::Pitch>::GetWidth(clip); |
| 34 |
} |
| 35 |
} // namespace |
| 36 |
|
| 37 |
std::optional<wxRect> LowlitClipButton::Detail::GetButtonRectangle( |
| 38 |
ClipButtonId buttonId, const LowlitClipButton::RectangleArgs& args) |
| 39 |
{ |
| 40 |
const auto clipRect = ClipParameters::GetClipRect( |
| 41 |
args.clip, args.zoomInfo, args.trackAffordanceRect); |
| 42 |
const auto rect = |
| 43 |
RemoveSpaceReservedForTitle(clipRect.Intersect(args.trackAffordanceRect)); |
| 44 |
|
| 45 |
// In this order, from left to right: pitch (maybe), speed (maybe), overflow. |
| 46 |
auto offset = 0; |
| 47 |
if (buttonId != ClipButtonId::Overflow) |
| 48 |
{ |
| 49 |
offset += |
| 50 |
ClipButtonSpecializations<ClipButtonId::Overflow>::GetWidth(args.clip); |
| 51 |
if ( |
| 52 |
buttonId == ClipButtonId::Pitch && |
| 53 |
ClipButtonSpecializations<ClipButtonId::Speed>::NeedsDrawing( |
| 54 |
args.clip)) |
| 55 |
{ |
| 56 |
offset += |
| 57 |
ClipButtonSpecializations<ClipButtonId::Speed>::GetWidth(args.clip); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
const auto buttonWidth = GetButtonWidth(buttonId, args.clip); |
| 62 |
if (rect.width < buttonWidth + offset) |
| 63 |
return {}; |
| 64 |
const auto x = rect.x + rect.width - offset - buttonWidth; |
| 65 |
return std::make_optional<wxRect>(x, rect.y, buttonWidth, rect.height); |
| 66 |
} |
| 67 |
|
| 68 |
std::optional<wxRect> LowlitClipButton::Detail::GetButtonInnerRectangle( |
| 69 |
ClipButtonId buttonId, const LowlitClipButton::RectangleArgs& args) |
| 70 |
{ |
| 71 |
const auto outerRect = GetButtonRectangle(buttonId, args); |
| 72 |
if (!outerRect.has_value()) |
| 73 |
return {}; |
| 74 |
const auto rightMargin = buttonId == ClipButtonId::Overflow ? 5 : 2; |
| 75 |
return wxRect { outerRect->x + leftMargin, outerRect->y + topMargin, |
| 76 |
outerRect->width - leftMargin - rightMargin, |
| 77 |
outerRect->height - topMargin - bottomMargin }; |
| 78 |
} |