-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
63 lines (53 loc) · 2.15 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
==============================================================================
utils.h - Utility functions
==============================================================================
*/
#pragma once
#include "JuceHeader.h"
namespace jux
{
[[maybe_unused]] static juce::Path getArrowPath (juce::Rectangle<float> arrowZone, const int direction, bool filled, const juce::Justification justification)
{
auto w = std::min<float> (arrowZone.getWidth(), (direction == 0 || direction == 2) ? 8.0f : filled ? 5.0f : 8.0f);
auto h = std::min<float> (arrowZone.getHeight(), (direction == 0 || direction == 2) ? 5.0f : filled ? 8.0f : 5.0f);
if (justification == juce::Justification::centred)
{
arrowZone.reduce ((arrowZone.getWidth() - w) / 2, (arrowZone.getHeight() - h) / 2);
}
else if (justification == juce::Justification::centredRight)
{
arrowZone.removeFromLeft (arrowZone.getWidth() - w);
arrowZone.reduce (0, (arrowZone.getHeight() - h) / 2);
}
else if (justification == juce::Justification::centredLeft)
{
arrowZone.removeFromRight (arrowZone.getWidth() - w);
arrowZone.reduce (0, (arrowZone.getHeight() - h) / 2);
}
else
{
jassertfalse; // currently only supports centred justifications
}
juce::Path path;
path.startNewSubPath (arrowZone.getX(), arrowZone.getBottom());
path.lineTo (arrowZone.getCentreX(), arrowZone.getY());
path.lineTo (arrowZone.getRight(), arrowZone.getBottom());
if (filled)
path.closeSubPath();
path.applyTransform (juce::AffineTransform::rotation (direction * juce::MathConstants<float>::halfPi,
arrowZone.getCentreX(),
arrowZone.getCentreY()));
return path;
}
[[maybe_unused]] static bool addDefaultColourIdIfNotSet (int colourId, juce::Colour defaultColourToSet)
{
auto& def = juce::LookAndFeel::getDefaultLookAndFeel();
if (! def.isColourSpecified (colourId))
{
def.setColour (colourId, defaultColourToSet);
return true;
}
return false;
}
} // namespace jux