Skip to content

Commit 03531e0

Browse files
committed
Finish simple GUI
1 parent b66f829 commit 03531e0

File tree

12 files changed

+131
-45
lines changed

12 files changed

+131
-45
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ juce_add_binary_data(BWUtilityBinaryData
7272
BinaryData
7373
SOURCES
7474
resources/fonts/Inter-Regular.otf
75+
resources/fonts/Inter-Italic.otf
76+
resources/fonts/Inter-Bold.otf
7577
resources/fonts/Inter-Black.otf)
7678

7779
target_link_libraries(BW_UTILITY

resources/fonts/Inter-Bold.otf

265 KB
Binary file not shown.

resources/fonts/Inter-Italic.otf

265 KB
Binary file not shown.

source/gui/BassMono.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ BassMono::BassMono()
1212
active.setText("ACTIVE", dontSendNotification);
1313
active.setJustificationType(Justification::centred);
1414
active.setColour(Label::textColourId, Colours::black);
15-
active.getProperties().set("gui_class", "label");
15+
active.getProperties().set("gui_class", "italic");
1616

1717
addAndMakeVisible(&checkbox);
1818

1919
addAndMakeVisible(&frequency);
2020
frequency.setText("FREQUENCY", dontSendNotification);
2121
frequency.setJustificationType(Justification::centred);
2222
frequency.setColour(Label::textColourId, Colours::black);
23-
frequency.getProperties().set("gui_class", "label");
2423

2524
addAndMakeVisible(&slider);
2625
slider.setSliderStyle(Slider::LinearBar);

source/gui/Channels.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ Channels::Channels()
1111

1212
addAndMakeVisible(&selector);
1313
selector.addItemList(CHANNELS_CHOICES, 0);
14+
selector.setColour(ComboBox::textColourId, Colours::black);
15+
selector.setJustificationType(Justification::centred);
1416

1517
addAndMakeVisible(&mono);
1618
mono.setText("MONO", dontSendNotification);
1719
mono.setJustificationType(juce::Justification::centred);
1820
mono.setColour(Label::textColourId, Colours::black);
19-
mono.getProperties().set("gui_class", "label");
21+
mono.getProperties().set("gui_class", "italic");
2022

2123
addAndMakeVisible(&checkbox);
2224
}

source/gui/Footer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ Footer::Footer()
99
version.getProperties().set("gui_class", "label");
1010

1111
addAndMakeVisible(&bw);
12-
bw.setText("BW", dontSendNotification);
12+
bw.setText("->BW", dontSendNotification);
1313
bw.setJustificationType(juce::Justification::right);
1414
bw.setColour(juce::Label::textColourId, juce::Colours::white);
15-
bw.getProperties().set("gui_class", "label");
1615

1716
addAndMakeVisible(&link);
1817
link.setURL(juce::URL("https://butchwarns.de/"));

source/gui/Look.cpp

+102-26
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,64 @@
11
#include "Look.h"
22

3+
Font Look::getFontInterRegular(float height)
4+
{
5+
static auto font = Font(Typeface::createSystemTypefaceFor(BinaryData::InterRegular_otf, BinaryData::InterRegular_otfSize));
6+
return font.withHeight(height).withExtraKerningFactor(KERNING_FACTOR);
7+
}
8+
9+
Font Look::getFontInterItalic(float height)
10+
{
11+
static auto font = Font(Typeface::createSystemTypefaceFor(BinaryData::InterItalic_otf, BinaryData::InterItalic_otfSize));
12+
return font.withHeight(height).withExtraKerningFactor(KERNING_FACTOR);
13+
}
14+
15+
Font Look::getFontInterBold(float height)
16+
{
17+
static auto font = Font(Typeface::createSystemTypefaceFor(BinaryData::InterBold_otf, BinaryData::InterBold_otfSize));
18+
return font.withHeight(height).withExtraKerningFactor(KERNING_FACTOR);
19+
}
20+
21+
Font Look::getFontInterBlack(float height)
22+
{
23+
static auto font = Font(Typeface::createSystemTypefaceFor(BinaryData::InterBlack_otf, BinaryData::InterBlack_otfSize));
24+
return font.withHeight(height).withExtraKerningFactor(KERNING_FACTOR);
25+
}
26+
327
void Look::drawLinearSlider(Graphics &g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const Slider::SliderStyle slider_style, Slider &slider)
428
{
29+
ignoreUnused(x, y, width, height, minSliderPos, maxSliderPos, slider_style);
30+
531
// Background
632
g.fillAll(BEIGE);
733

8-
// Outline
9-
g.setColour(juce::Colours::black);
10-
g.drawRect(slider.getLocalBounds(), 2);
11-
1234
// Indicator region
1335
const auto bounds = slider.getLocalBounds();
14-
g.setColour(GREY);
36+
g.setColour(GREY_TRANSPARENT);
1537
g.fillRect(bounds.getX(), bounds.getY(), (int)(sliderPos), bounds.getHeight());
38+
39+
// Outline
40+
g.setColour(juce::Colours::black);
41+
g.drawRect(slider.getLocalBounds(), 2);
1642
}
1743

1844
void Look::drawRotarySlider(Graphics &g, int x, int y, int width, int height, float sliderPos, const float rotaryStartAngle, const float rotaryEndAngle, Slider &slider)
1945
{
46+
ignoreUnused(slider);
47+
2048
const auto centre_x = ((float)x + (float)width) / 2.0f;
21-
const auto centre_y = ((float)x + (float)height) / 2.0f;
49+
const auto centre_y = ((float)y + (float)height) / 2.0f;
50+
51+
const auto half_outline = OUTLINE / 2.0f;
2252

2353
// Knob
2454

2555
const auto knob_radius = KNOB_DIM / 2.0f;
2656
Path k;
27-
k.addEllipse(centre_x - knob_radius, centre_y - knob_radius, KNOB_DIM, KNOB_DIM);
57+
k.addEllipse(centre_x - knob_radius, centre_y - knob_radius, KNOB_DIM - OUTLINE, KNOB_DIM - OUTLINE);
2858

29-
g.setColour(Colours::white);
59+
g.setColour(BEIGE);
3060
g.fillPath(k);
31-
g.setColour(GREY);
61+
g.setColour(GREY_TRANSPARENT);
3262
g.fillPath(k);
3363

3464
g.setColour(Colours::black);
@@ -37,15 +67,15 @@ void Look::drawRotarySlider(Graphics &g, int x, int y, int width, int height, fl
3767
// Pointer
3868

3969
const auto pointer_radius = POINTER_DIM / 2.0f;
40-
const auto knob_offset = (width - KNOB_DIM) / 2.0f;
70+
const auto knob_offset = ((float)width - (float)KNOB_DIM) / 2.0f;
4171
Path p;
42-
p.addEllipse(x - pointer_radius, y - pointer_radius, POINTER_DIM, POINTER_DIM);
72+
p.addEllipse(Rectangle<float>(-pointer_radius, -pointer_radius, POINTER_DIM, POINTER_DIM).reduced(OUTLINE));
4373

4474
AffineTransform pointer_transform;
4575
pointer_transform = pointer_transform
46-
.translated(0.0f, -knob_radius + (pointer_radius + POINTER_OFFSET))
76+
.translated(0.0f, -(knob_radius + half_outline) + (pointer_radius + POINTER_OFFSET))
4777
.rotated((sliderPos - 0.5f) * (rotaryEndAngle - rotaryStartAngle))
48-
.translated(knob_radius + knob_offset, knob_radius + knob_offset);
78+
.translated(knob_radius + knob_offset - half_outline, knob_radius + knob_offset - half_outline);
4979
p.applyTransform(pointer_transform);
5080

5181
g.setColour(Colours::white);
@@ -62,17 +92,22 @@ void Look::drawTickBox(Graphics &g, Component &component,
6292
const bool shouldDrawButtonAsHighlighted,
6393
const bool shouldDrawButtonAsDown)
6494
{
95+
ignoreUnused(x, y, w, h, isEnabled, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
96+
97+
auto bounds = component.getLocalBounds();
98+
6599
// Background
66100
g.fillAll(BEIGE);
67101

68102
// Outline
69103
g.setColour(juce::Colours::black);
70-
g.drawRect(component.getLocalBounds(), 2);
104+
g.drawRect(bounds, (int)OUTLINE);
71105

72106
if (ticked)
73107
{
108+
g.setColour(Colours::black);
74109
g.setFont(Look::getFontInterBlack(FONT_SIZE));
75-
g.drawFittedText("X", component.getLocalBounds(), juce::Justification::centred, 1, 1.0f);
110+
g.drawFittedText("X", bounds, juce::Justification::centred, 1, 1.0f);
76111
}
77112
}
78113

@@ -96,32 +131,73 @@ void Look::drawLabel(Graphics &g, Label &label)
96131

97132
Font Look::getLabelFont(Label &label)
98133
{
99-
if ((label.getProperties()["gui_class"] == "label") || dynamic_cast<Slider *>(label.getParentComponent()))
134+
if (label.getProperties()["gui_class"] == "bold")
100135
{
101-
return getFontInterRegular(FONT_SIZE);
136+
return getFontInterBold(FONT_SIZE);
102137
}
103-
else if (label.getProperties()["gui_class"] == "bold")
138+
if (label.getProperties()["gui_class"] == "black")
104139
{
105140
return getFontInterBlack(FONT_SIZE);
106141
}
142+
else if (label.getProperties()["gui_class"] == "italic")
143+
{
144+
return getFontInterItalic(FONT_SIZE);
145+
}
107146
else if (label.getProperties()["gui_class"] == "title")
108147
{
109148
return getFontInterBlack(FONT_SIZE_TITLE);
110149
}
111150
else
112151
{
113-
return label.getFont();
152+
return getFontInterRegular(FONT_SIZE);
114153
}
115154
}
116155

117-
Font Look::getFontInterRegular(float height)
156+
void Look::drawComboBox(Graphics &g, int width, int height, bool, int, int, int, int, ComboBox &box)
118157
{
119-
static auto font = Font(Typeface::createSystemTypefaceFor(BinaryData::InterRegular_otf, BinaryData::InterRegular_otfSize));
120-
return font.withHeight(height).withExtraKerningFactor(KERNING_FACTOR);
158+
ignoreUnused(width, height);
159+
160+
auto bounds = box.getLocalBounds();
161+
162+
g.setColour(BEIGE);
163+
g.fillRect(bounds);
164+
165+
g.setColour(Colours::black);
166+
g.drawRect(bounds, 2.0f);
121167
}
122168

123-
Font Look::getFontInterBlack(float height)
169+
void Look::positionComboBoxText(ComboBox &box, Label &label)
124170
{
125-
static auto font = Font(Typeface::createSystemTypefaceFor(BinaryData::InterBlack_otf, BinaryData::InterBlack_otfSize));
126-
return font.withHeight(height).withExtraKerningFactor(KERNING_FACTOR);
127-
}
171+
label.setBounds(box.getLocalBounds());
172+
}
173+
174+
void Look::drawPopupMenuItem(Graphics &g, const Rectangle<int> &area,
175+
const bool isSeparator, const bool isActive,
176+
const bool isHighlighted, const bool isTicked,
177+
const bool hasSubMenu, const String &text,
178+
const String &shortcutKeyText,
179+
const Drawable *icon, const Colour *const textColourToUse)
180+
{
181+
ignoreUnused(isSeparator, isActive, isTicked, hasSubMenu, shortcutKeyText, icon, textColourToUse);
182+
183+
g.setColour(BEIGE);
184+
g.fillRect(area);
185+
if (isHighlighted)
186+
{
187+
g.setColour(GREY_TRANSPARENT);
188+
g.fillRect(area);
189+
}
190+
g.setColour(Colours::black);
191+
g.drawRect(area, (int)OUTLINE);
192+
193+
auto font = Look::getFontInterRegular(FONT_SIZE);
194+
g.setFont(font);
195+
g.setColour(Colours::black);
196+
g.drawFittedText(text, area, Justification::centred, 1.0f);
197+
}
198+
199+
void Look::drawPopupMenuBackground(Graphics &g, int width, int height)
200+
{
201+
ignoreUnused(width, height);
202+
g.fillAll(Colours::black);
203+
}

source/gui/Look.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ class Look : public juce::LookAndFeel_V4
88
{
99
public:
1010
Look() = default;
11-
~Look() = default;
1211

1312
static Font getFontInterRegular(float height);
13+
static Font getFontInterItalic(float height);
14+
static Font getFontInterBold(float height);
1415
static Font getFontInterBlack(float height);
1516

1617
private:
@@ -25,6 +26,16 @@ class Look : public juce::LookAndFeel_V4
2526
const bool shouldDrawButtonAsHighlighted,
2627
const bool shouldDrawButtonAsDown) override;
2728

28-
virtual void drawLabel(Graphics &g, Label &label) override;
29+
void drawLabel(Graphics &g, Label &label) override;
2930
Font getLabelFont(Label &label) override;
31+
32+
void drawComboBox(Graphics &g, int width, int height, bool, int, int, int, int, ComboBox &box) override;
33+
void positionComboBoxText(ComboBox &box, Label &label) override;
34+
void drawPopupMenuItem(Graphics &g, const Rectangle<int> &area,
35+
const bool isSeparator, const bool isActive,
36+
const bool isHighlighted, const bool isTicked,
37+
const bool hasSubMenu, const String &text,
38+
const String &shortcutKeyText,
39+
const Drawable *icon, const Colour *const textColourToUse) override;
40+
void drawPopupMenuBackground(Graphics &g, int width, int height) override;
3041
};

source/gui/Spacer.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include "Spacer.h"
22

3-
Spacer::Spacer()
4-
{
5-
}
6-
73
void Spacer::paint(juce::Graphics &g)
84
{
95
g.drawRect(0, PAD, getLocalBounds().getWidth(), SPACER_LINE, 1);

source/gui/Spacer.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
class Spacer : public juce::Component
77
{
88
public:
9-
Spacer();
10-
~Spacer() = default;
9+
Spacer() = default;
1110

1211
private:
1312
void paint(juce::Graphics &g) override;

source/gui/colours.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <JuceHeader.h>
44

5-
const auto BLACK = juce::Colour(0x40, 0x40, 0x40);
6-
const auto RED = juce::Colour(0xC3, 0x73, 0x73);
7-
const auto BEIGE = juce::Colour(0xD9, 0xD9, 0xD9);
8-
const auto GREY = juce::Colour(juce::uint8(0x00), juce::uint8(0x00), juce::uint8(0x00), juce::uint8(0x66));
5+
const auto BLACK = Colour(0x40, 0x40, 0x40);
6+
const auto RED = Colour(0xC3, 0x73, 0x73);
7+
const auto BEIGE = Colour(0xD9, 0xD9, 0xD9);
8+
const auto GREY_TRANSPARENT = Colour((uint8)0x00, (uint8)0x00, (uint8)0x00, (uint8)0x64);

source/gui/sizes.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#pragma once
22

3+
constexpr float OUTLINE = 2.0f;
4+
35
constexpr float KERNING_FACTOR = 0.1f;
46

57
constexpr int PAD = 5;
68

79
constexpr int HEADER_HEIGHT = 35;
810
constexpr int FOOTER_HEIGHT = 35;
911

10-
constexpr float FONT_SIZE = 11.0f;
11-
constexpr float FONT_SIZE_TITLE = 15.0f;
12+
constexpr float FONT_SIZE = 13.0f;
13+
constexpr float FONT_SIZE_TITLE = 17.0f;
1214

1315
constexpr int LABEL_HEIGHT = 20;
1416

0 commit comments

Comments
 (0)