Skip to content

Commit 4b97124

Browse files
authored
Fix Link-in-Out: Read actual state on window open (#97)
Fix Link-in-Out - Read the actual state on the window open
1 parent 5967c1f commit 4b97124

File tree

2 files changed

+125
-130
lines changed

2 files changed

+125
-130
lines changed

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class PeakEater(ConanFile):
77
name = "peakeater"
8-
version = "0.8.0"
8+
version = "0.8.1"
99
user = "vvvar"
1010
channel = "testing"
1111
company = "T-Audio"

source/GUIv2/linkinout/LinkInOut.cpp

Lines changed: 124 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -5,155 +5,150 @@
55

66
#include <BinaryData.h>
77

8-
namespace pe
8+
namespace pe::gui
99
{
10-
namespace gui
10+
namespace
1111
{
12-
namespace
12+
auto constexpr gParamName = "LinkInOut";
13+
}
14+
LinkInOut::LinkInOut (std::shared_ptr<juce::AudioProcessorValueTreeState> parameters)
15+
: mParameters (parameters), mIsOn (1.0f == mParameters->getParameter (gParamName)->getValue())
16+
{
17+
mParameters->getParameter (gParamName)->addListener (this);
18+
setMouseCursor (juce::MouseCursor::PointingHandCursor);
19+
}
20+
21+
LinkInOut::~LinkInOut()
22+
{
23+
mParameters->getParameter (gParamName)->removeListener (this);
24+
setLookAndFeel (nullptr);
25+
}
26+
27+
void LinkInOut::resized() {}
28+
29+
void LinkInOut::paint (juce::Graphics& g)
30+
{
31+
auto const paddingTopFactor = 0.2f;
32+
auto const paddingLeftFactor = 0.1f;
33+
auto const paddingRightFactor = 0.9f;
34+
35+
auto const bounds = getLocalBounds().toFloat();
36+
auto const width = bounds.getWidth();
37+
auto const height = bounds.getHeight();
38+
auto const centreX = bounds.getCentreX();
39+
auto const centreY = bounds.getCentreY() + (height * paddingTopFactor);
40+
41+
// Set color for lines and icon
42+
juce::Colour mainColour;
43+
juce::Colour labelTextColour;
44+
if (mIsOn)
1345
{
14-
auto constexpr gParamName = "LinkInOut";
46+
mainColour = colourscheme::ForegroundTertiary.withAlpha (0.9f);
47+
labelTextColour = colourscheme::ForegroundTertiary.withAlpha (0.9f);
1548
}
16-
LinkInOut::LinkInOut (std::shared_ptr<juce::AudioProcessorValueTreeState> parameters)
17-
: mParameters (parameters), mIsOn (false)
49+
else
1850
{
19-
mParameters->getParameter (gParamName)->addListener (this);
20-
setMouseCursor (juce::MouseCursor::PointingHandCursor);
51+
mainColour = colourscheme::BackgroundTertiary.withAlpha (0.9f);
52+
labelTextColour = colourscheme::TextFocusLevel1.withAlpha (0.9f);
2153
}
22-
23-
LinkInOut::~LinkInOut()
54+
if (isMouseOver())
2455
{
25-
mParameters->getParameter (gParamName)->removeListener (this);
26-
setLookAndFeel (nullptr);
56+
mainColour = mainColour.withAlpha (1.0f);
57+
labelTextColour = labelTextColour.withAlpha (1.0f);
2758
}
28-
29-
void LinkInOut::resized()
59+
if (! isEnabled())
3060
{
61+
mainColour = mainColour.withAlpha (0.5f);
62+
labelTextColour = labelTextColour.withAlpha (0.5f);
3163
}
32-
33-
void LinkInOut::paint (juce::Graphics& g)
64+
g.setColour (mainColour);
65+
66+
// Draw icon
67+
auto const icon = juce::ImageCache::getFromMemory (BinaryData::link_png, BinaryData::link_pngSize);
68+
auto const imgWidth = 14;
69+
auto const imgHeight = 14;
70+
auto const destX = static_cast<int> (centreX) - imgWidth / 2;
71+
auto const destY = static_cast<int> (centreY) - imgHeight / 2;
72+
g.drawImage (icon, destX, destY, imgWidth, imgHeight, 0, 0, icon.getWidth(), icon.getHeight(), true);
73+
74+
// Draw curved line
75+
auto const topY = height * paddingTopFactor;
76+
// Left line part
77+
juce::Point<float> p1 (width * paddingLeftFactor, topY);
78+
juce::Point<float> p2 (width * paddingLeftFactor, centreY);
79+
juce::Point<float> p3 (width * 0.2f, centreY);
80+
juce::Point<float> p4 (centreX - imgWidth, centreY);
81+
juce::Path path1;
82+
path1.startNewSubPath (p1);
83+
path1.quadraticTo (p2, p3);
84+
path1.lineTo (p4);
85+
g.strokePath (path1, juce::PathStrokeType (1.0));
86+
// Right line part
87+
juce::Point<float> p5 (centreX + imgWidth, centreY);
88+
juce::Point<float> p6 (width * 0.8f, centreY);
89+
juce::Point<float> p7 (width * paddingRightFactor, centreY);
90+
juce::Point<float> p8 (width * paddingRightFactor, topY);
91+
juce::Path path2;
92+
path2.startNewSubPath (p5);
93+
path2.lineTo (p6);
94+
path2.quadraticTo (p7, p8);
95+
g.strokePath (path2, juce::PathStrokeType (1.0));
96+
97+
// Draw label
98+
g.setColour (labelTextColour);
99+
auto const fontSize = calculatePrimaryTextSize (getTopLevelComponent()->getBounds().getWidth(),
100+
getTopLevelComponent()->getBounds().getHeight());
101+
g.setFont (fontSize);
102+
g.drawText (juce::String ("Link Input with Output").toUpperCase(),
103+
0,
104+
static_cast<int> (topY),
105+
static_cast<int> (width),
106+
static_cast<int> (height),
107+
juce::Justification::centredTop,
108+
true);
109+
}
110+
111+
void LinkInOut::mouseDown (juce::MouseEvent const&)
112+
{
113+
if (isEnabled()) // handle click only when component is enabled
34114
{
35-
auto const paddingTopFactor = 0.2f;
36-
auto const paddingLeftFactor = 0.1f;
37-
auto const paddingRightFactor = 0.9f;
38-
39-
auto const bounds = getLocalBounds().toFloat();
40-
auto const width = bounds.getWidth();
41-
auto const height = bounds.getHeight();
42-
auto const centreX = bounds.getCentreX();
43-
auto const centreY = bounds.getCentreY() + (height * paddingTopFactor);
44-
45-
// Set color for lines and icon
46-
juce::Colour mainColour;
47-
juce::Colour labelTextColour;
48-
if (mIsOn)
49-
{
50-
mainColour = colourscheme::ForegroundTertiary.withAlpha (0.9f);
51-
labelTextColour = colourscheme::ForegroundTertiary.withAlpha (0.9f);
52-
}
53-
else
54-
{
55-
mainColour = colourscheme::BackgroundTertiary.withAlpha (0.9f);
56-
labelTextColour = colourscheme::TextFocusLevel1.withAlpha (0.9f);
57-
}
58-
if (isMouseOver())
59-
{
60-
mainColour = mainColour.withAlpha (1.0f);
61-
labelTextColour = labelTextColour.withAlpha (1.0f);
62-
}
63-
if (! isEnabled())
64-
{
65-
mainColour = mainColour.withAlpha (0.5f);
66-
labelTextColour = labelTextColour.withAlpha (0.5f);
67-
}
68-
g.setColour (mainColour);
69-
70-
// Draw icon
71-
auto const icon = juce::ImageCache::getFromMemory (BinaryData::link_png, BinaryData::link_pngSize);
72-
auto const imgWidth = 14;
73-
auto const imgHeight = 14;
74-
auto const destX = static_cast<int> (centreX) - imgWidth / 2;
75-
auto const destY = static_cast<int> (centreY) - imgHeight / 2;
76-
g.drawImage (icon, destX, destY, imgWidth, imgHeight, 0, 0, icon.getWidth(), icon.getHeight(), true);
77-
78-
// Draw curved line
79-
auto const topY = height * paddingTopFactor;
80-
// Left line part
81-
juce::Point<float> p1 (width * paddingLeftFactor, topY);
82-
juce::Point<float> p2 (width * paddingLeftFactor, centreY);
83-
juce::Point<float> p3 (width * 0.2f, centreY);
84-
juce::Point<float> p4 (centreX - imgWidth, centreY);
85-
juce::Path path1;
86-
path1.startNewSubPath (p1);
87-
path1.quadraticTo (p2, p3);
88-
path1.lineTo (p4);
89-
g.strokePath (path1, juce::PathStrokeType (1.0));
90-
// Right line part
91-
juce::Point<float> p5 (centreX + imgWidth, centreY);
92-
juce::Point<float> p6 (width * 0.8f, centreY);
93-
juce::Point<float> p7 (width * paddingRightFactor, centreY);
94-
juce::Point<float> p8 (width * paddingRightFactor, topY);
95-
juce::Path path2;
96-
path2.startNewSubPath (p5);
97-
path2.lineTo (p6);
98-
path2.quadraticTo (p7, p8);
99-
g.strokePath (path2, juce::PathStrokeType (1.0));
100-
101-
// Draw label
102-
g.setColour (labelTextColour);
103-
auto const fontSize = calculatePrimaryTextSize (getTopLevelComponent()->getBounds().getWidth(), getTopLevelComponent()->getBounds().getHeight());
104-
g.setFont (fontSize);
105-
g.drawText (
106-
juce::String ("Link Input with Output").toUpperCase(),
107-
0,
108-
static_cast<int> (topY),
109-
static_cast<int> (width),
110-
static_cast<int> (height),
111-
juce::Justification::centredTop,
112-
true);
115+
mParameters->getParameter (gParamName)->setValueNotifyingHost (! mIsOn);
113116
}
117+
}
114118

115-
void LinkInOut::mouseDown (juce::MouseEvent const&)
119+
void LinkInOut::mouseEnter (juce::MouseEvent const&)
120+
{
121+
if (isEnabled())
116122
{
117-
if (isEnabled()) // handle click only when component is enabled
118-
{
119-
mParameters->getParameter (gParamName)->setValueNotifyingHost (! mIsOn);
120-
}
123+
setMouseCursor (juce::MouseCursor::PointingHandCursor);
121124
}
122-
123-
void LinkInOut::mouseEnter (juce::MouseEvent const&)
125+
else
124126
{
125-
if (isEnabled())
126-
{
127-
setMouseCursor (juce::MouseCursor::PointingHandCursor);
128-
}
129-
else
130-
{
131-
setMouseCursor (juce::MouseCursor::NormalCursor);
132-
}
127+
setMouseCursor (juce::MouseCursor::NormalCursor);
133128
}
129+
}
134130

135-
void LinkInOut::mouseExit (juce::MouseEvent const&)
131+
void LinkInOut::mouseExit (juce::MouseEvent const&)
132+
{
133+
if (isEnabled())
136134
{
137-
if (isEnabled())
138-
{
139-
setMouseCursor (juce::MouseCursor::PointingHandCursor);
140-
}
141-
else
142-
{
143-
setMouseCursor (juce::MouseCursor::NormalCursor);
144-
}
135+
setMouseCursor (juce::MouseCursor::PointingHandCursor);
145136
}
146-
147-
void LinkInOut::parameterValueChanged (int, float)
137+
else
148138
{
149-
mIsOn = (mParameters->getParameter (gParamName)->getValue() != 0.0f);
150-
repaint();
139+
setMouseCursor (juce::MouseCursor::NormalCursor);
151140
}
141+
}
152142

153-
void LinkInOut::parameterGestureChanged (int, bool)
154-
{
155-
mIsOn = (mParameters->getParameter (gParamName)->getValue() != 0.0f);
156-
repaint();
157-
}
158-
} // namespace gui
159-
} // namespace pe
143+
void LinkInOut::parameterValueChanged (int, float)
144+
{
145+
mIsOn = (mParameters->getParameter (gParamName)->getValue() != 0.0f);
146+
repaint();
147+
}
148+
149+
void LinkInOut::parameterGestureChanged (int, bool)
150+
{
151+
mIsOn = (mParameters->getParameter (gParamName)->getValue() != 0.0f);
152+
repaint();
153+
}
154+
} // namespace pe::gui

0 commit comments

Comments
 (0)