Krotos Modules 3
Loading...
Searching...
No Matches
SampleBrowserButton.cpp
Go to the documentation of this file.
1namespace krotos
2{
4 : TextButton(buttonText), m_previousButton("Previous", DrawableButton::ButtonStyle::ImageFitted),
5 m_nextButton("Next", DrawableButton::ButtonStyle::ImageFitted), m_sampleCounter("SampleCounter", "0 of 0")
6 {
7 addAndMakeVisible(m_mouseBlocker);
8 addAndMakeVisible(m_previousButton);
9 addAndMakeVisible(m_nextButton);
10 addAndMakeVisible(m_sampleCounter);
11
12 m_dropdownIcon = Drawable::createFromImageData(KrotosBinaryData::SampleBrowser_Dropdown_Icon_svg,
13 KrotosBinaryData::SampleBrowser_Dropdown_Icon_svgSize);
14 m_rightArrow = Drawable::createFromImageData(KrotosBinaryData::Icon_Button_Right_svg,
15 KrotosBinaryData::Icon_Button_Right_svgSize);
16 m_leftArrow = Drawable::createFromImageData(KrotosBinaryData::Icon_Button_Left_svg,
17 KrotosBinaryData::Icon_Button_Left_svgSize);
18
19 m_nextButton.setImages(m_rightArrow.get());
20 m_previousButton.setImages(m_leftArrow.get());
21
22 m_nextButton.toFront(false);
23 m_previousButton.toFront(false);
24
25 m_nextButton.onClick = [&] {
28 };
29
30 m_previousButton.onClick = [&] {
33 };
34
35 m_sampleCounter.setColour(Label::ColourIds::textColourId,
36 findColour(Label::ColourIds::textColourId).withAlpha(0.5f));
37
38 m_sampleCounter.setFont(m_sampleCounter.getFont().withHeight(15.0f));
39 m_sampleCounter.setMinimumHorizontalScale(0.75f);
40 m_sampleCounter.setJustificationType(Justification::centredRight);
41 }
42
43 void SampleBrowserButton::paintButton(Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
44 {
45 // Draw background
46 auto cornerSize = 2.0f;
47 auto boxBounds = getLocalBounds();
48 Path p;
49 p.addRoundedRectangle(boxBounds.toFloat().getX(), boxBounds.toFloat().getY(), boxBounds.toFloat().getWidth(),
50 boxBounds.toFloat().getHeight(), cornerSize, cornerSize, false, false, true, true);
51 g.setColour(findColour(ComboBox::ColourIds::backgroundColourId));
52 g.fillPath(p);
53
54 // Draw button text
55 auto textBounds = getLocalBounds();
56 textBounds.removeFromLeft(m_textXOffset);
57 textBounds.removeFromRight(getWidth() - m_sampleCounter.getX());
58 float textOpacity = isOver() || getToggleState() ? 1.0f : 0.7f;
59 Colour textColour = findColour(TextButton::ColourIds::textColourOnId).withAlpha(textOpacity);
60 g.setColour(textColour);
61 g.setFont(Font(15.0f).withExtraKerningFactor(0.027f));
62 g.drawFittedText(getButtonText(), textBounds, Justification::centredLeft, 1);
63
64 // Draw dropdown icon
65 auto bounds = getLocalBounds();
66 bounds.removeFromLeft(3);
67 m_dropdownIconBounds = bounds.removeFromLeft(m_iconWidth).withSizeKeepingCentre(m_iconWidth, m_iconWidth);
68 m_dropdownIcon->drawWithin(g, m_dropdownIconBounds.toFloat(), RectanglePlacement::centred, 1.0f);
69 }
70
72 {
73 auto bounds = getLocalBounds();
74
75 m_nextButton.setBounds(
76 bounds.removeFromRight(m_nextPrevButtonSize).withSizeKeepingCentre(m_iconWidth, m_iconWidth));
77 m_previousButton.setBounds(
78 bounds.removeFromRight(m_nextPrevButtonSize).withSizeKeepingCentre(m_iconWidth, m_iconWidth));
79
80 bounds.removeFromRight(4);
81 m_sampleCounter.setBounds(bounds.removeFromRight(m_sampleCounterLabelWidth));
82
83 // Prevent text button from picking up the mouse around the extra components
84 m_mouseBlocker.setBounds(
85 getLocalBounds().removeFromRight(getLocalBounds().getWidth() - m_sampleCounter.getX()));
86 }
87
89 {
90 // one-indexed, clamped to sampleCount (0 of 0, 1 of 1, etc)
91 index = m_sampleCount == 0 ? 0 : index + 1;
92 m_sampleIndex = jlimit(0, (int)m_sampleCount, index);
94 }
95
97 {
98 m_sampleCount = count;
100 }
101
103 {
104 m_sampleCounter.setText(String(m_sampleIndex) + " of " + String(m_sampleCount),
105 NotificationType::dontSendNotification);
106 }
107} // namespace krotos
DrawableButton m_previousButton
Definition SampleBrowserButton.h:65
Component m_mouseBlocker
Definition SampleBrowserButton.h:69
SampleBrowserButton(const String &buttonText)
Creates a SampleBrowserButton, which is a essentially just a TextButton with some extra components on...
Definition SampleBrowserButton.cpp:3
void paintButton(Graphics &g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
Definition SampleBrowserButton.cpp:43
const int m_iconWidth
Definition SampleBrowserButton.h:56
std::unique_ptr< Drawable > m_dropdownIcon
Definition SampleBrowserButton.h:64
const int m_nextPrevButtonSize
Definition SampleBrowserButton.h:55
size_t m_sampleCount
Definition SampleBrowserButton.h:62
const int m_sampleCounterLabelWidth
Definition SampleBrowserButton.h:59
const int m_textXOffset
Definition SampleBrowserButton.h:58
void resized() override
Definition SampleBrowserButton.cpp:71
void setSampleIndex(int index)
Sets the number of the sample counter indicator e.g. "<index> of 10".
Definition SampleBrowserButton.cpp:88
DrawableButton m_nextButton
Definition SampleBrowserButton.h:65
std::function< void()> onNextButtonClick
Callback for when the "next" sample button is clicked.
Definition SampleBrowserButton.h:22
void updateSampleCounter()
Definition SampleBrowserButton.cpp:102
void setSampleCount(size_t count)
Sets the number of samples loaded in the sampler to display in the sample counter e....
Definition SampleBrowserButton.cpp:96
std::unique_ptr< Drawable > m_leftArrow
Definition SampleBrowserButton.h:64
int m_sampleIndex
Definition SampleBrowserButton.h:61
std::function< void()> onPreviousButtonClick
Callback for when the "previous" sample button is clicked.
Definition SampleBrowserButton.h:27
Label m_sampleCounter
Definition SampleBrowserButton.h:66
Rectangle< int > m_dropdownIconBounds
Definition SampleBrowserButton.h:67
std::unique_ptr< Drawable > m_rightArrow
Definition SampleBrowserButton.h:64
Definition AirAbsorptionFilter.cpp:2