Audacity 3.2.0
LowlitClipButton.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 LowlitClipButton.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "LowlitClipButton.h"
12#include "ClipParameters.h"
13
14namespace
15{
16constexpr auto widthReservedForTitle = 50;
17constexpr auto topMargin = 4;
18constexpr auto leftMargin = 0;
19constexpr auto bottomMargin = 1;
20
21wxRect 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
27int GetButtonWidth(ClipButtonId buttonId, const ClipInterface& clip)
28{
29 return buttonId == ClipButtonId::Overflow ?
31 buttonId == ClipButtonId::Speed ?
34}
35} // namespace
36
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 +=
51 if (
52 buttonId == ClipButtonId::Pitch &&
54 args.clip))
55 {
56 offset +=
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
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}
ClipButtonId
Definition: ClipButtonId.h:14
int min(int a, int b)
std::optional< wxRect > GetButtonRectangle(ClipButtonId buttonId, const RectangleArgs &args)
std::optional< wxRect > GetButtonInnerRectangle(ClipButtonId buttonId, const RectangleArgs &args)
wxRect RemoveSpaceReservedForTitle(const wxRect &rect)
int GetButtonWidth(ClipButtonId buttonId, const ClipInterface &clip)
static int GetWidth(const ClipInterface &clip)
static wxRect GetClipRect(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)