-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
squarepine_graphics.h
205 lines (176 loc) · 7.06 KB
/
squarepine_graphics.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef SQUAREPINE_GRAPHICS_H
#define SQUAREPINE_GRAPHICS_H
/** BEGIN_JUCE_MODULE_DECLARATION
ID: squarepine_graphics
vendor: SquarePine
version: 0.0.1
name: SquarePine Graphics
description: A grouping of reusable graphics classes, image formats, and other utilities.
website: https://www.squarepine.io
license: Beerware
minimumCppStandard: 17
dependencies: squarepine_core juce_gui_extra
END_JUCE_MODULE_DECLARATION
*/
//==============================================================================
#include <squarepine_core/squarepine_core.h>
#include <juce_gui_extra/juce_gui_extra.h>
//==============================================================================
/** Config: SQUAREPINE_USE_AVIR_RESIZER
A high-quality image resizer.
By default, this is enabled when building against Intel CPU systems.
*/
#ifndef SQUAREPINE_USE_AVIR_RESIZER
#define SQUAREPINE_USE_AVIR_RESIZER JUCE_INTEL
#endif
/** Config: SQUAREPINE_USE_CUESDK
If you're a fan of controlling RGB peripherals and want to control
Corsair's devices, enable this to play around on mainstream desktops.
Only available for 64-bit Windows and macOS (Intel only).
*/
#ifndef SQUAREPINE_USE_CUESDK
#define SQUAREPINE_USE_CUESDK 0
#endif
/** Config: SQUAREPINE_LOG_OPENGL_INFO
*/
#ifndef SQUAREPINE_LOG_OPENGL_INFO
#define SQUAREPINE_LOG_OPENGL_INFO 0
#endif
//==============================================================================
namespace sp
{
using namespace juce;
/** */
class WaitCursorAutoHider final
{
public:
WaitCursorAutoHider() { MouseCursor::showWaitCursor(); }
~WaitCursorAutoHider() { MouseCursor::hideWaitCursor(); }
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WaitCursorAutoHider)
};
/** */
class ScreenSaverAutoDisabler final
{
public:
ScreenSaverAutoDisabler() { Desktop::getInstance().setScreenSaverEnabled (false); }
~ScreenSaverAutoDisabler() { Desktop::getInstance().setScreenSaverEnabled (true); }
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScreenSaverAutoDisabler)
};
namespace helpers
{
/** */
inline void addAndMakeVisible (Component& parent, const Array<Component*>& children)
{
for (auto* c : children)
parent.addAndMakeVisible (c);
}
/** */
inline void addChildComponents (Component& parent, const Array<Component*>& children)
{
for (auto* c : children)
parent.addChildComponent (c);
}
}
/** */
inline void drawFittedText (Graphics& g,
const String& text,
const juce::Rectangle<float>& area,
Justification justification = Justification::centredLeft,
int maximumNumberOfLines = 1,
float minimumHorizontalScale = 1.0f)
{
if (text.isNotEmpty()
&& ! area.isEmpty()
&& g.clipRegionIntersects (area.getSmallestIntegerContainer()))
{
GlyphArrangement arr;
arr.addFittedText (g.getCurrentFont(), text,
area.getX(), area.getY(),
area.getWidth(), area.getHeight(),
justification,
maximumNumberOfLines,
minimumHorizontalScale);
arr.draw (g);
}
}
/** */
inline void drawFittedText (Graphics& g,
const String& text,
const juce::Rectangle<int>& area,
Justification justification = Justification::centredLeft,
int maximumNumberOfLines = 1,
float minimumHorizontalScale = 1.0f)
{
drawFittedText (g, text, area.toFloat(), justification, maximumNumberOfLines, minimumHorizontalScale);
}
/** */
class ValidPathCompatibleInputFilter final : public TextEditor::InputFilter
{
public:
/** */
ValidPathCompatibleInputFilter (int maxStringLength = 128) :
maxLength (maxStringLength)
{
}
/** @internal */
String filterNewText (TextEditor& ed, const String& newInput) override
{
auto t = newInput;
// Anything but path-related stuff listed here:
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
// And no escape char junk, nor path dividers.
for (const auto c : U"<>:/|?*\"\\\'\?\a\b\f\n\r\t\v")
t = t.replaceCharacter ((juce_wchar) c, ' ');
return t.substring (0, maxLength - (ed.getTotalNumChars() - ed.getHighlightedRegion().getLength()));
}
private:
const int maxLength = 128;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ValidPathCompatibleInputFilter)
};
//==============================================================================
/** Why waste memory and cycles reallocating a RectangleList when you can just
forcibly set all of the rectangles to a new height instead?
*/
template<typename ValueType>
inline void updateWithNewHeight (RectangleList<ValueType>& rectList, ValueType newHeight) noexcept
{
for (auto& r : rectList)
const_cast<juce::Rectangle<ValueType>&> (r).setHeight (newHeight);
}
/** Why waste memory and cycles reallocating a RectangleList when you can just
forcibly set all of the rectangles to a new width instead?
*/
template<typename ValueType>
inline void updateWithNewWidth (RectangleList<ValueType>& rectList, ValueType newWidth) noexcept
{
for (auto& r : rectList)
const_cast<juce::Rectangle<ValueType>&> (r).setWidth (newWidth);
}
//==============================================================================
#include "application/SimpleApplication.h"
#include "components/PropertyComponents.h"
#include "components/ComponentViewer.h"
#include "components/ComponentWindow.h"
#include "components/GoogleAnalyticsAttachment.h"
#include "components/JavascriptEditor.h"
#include "components/HighPerformanceRendererConfigurator.h"
#include "components/ValueTreeEditor.h"
#include "images/BlendingEffects.h"
#include "images/BMPImageFormat.h"
#include "images/DrawableHelpers.h"
#include "images/ImageEffects.h"
#include "images/ImageFormatManager.h"
#include "images/Resizer.h"
#include "images/SVGParser.h"
#include "images/TGAImageFormat.h"
//#include "images/WebPImageFormat.h"
#include "linkers/CueSDKIncluder.h"
#include "lookandfeels/Windows10LookAndFeel.h"
//#include "tokenisers/JavascriptCodeTokeniser.h"
#include "utilities/Fonts.h"
#include "utilities/Particles.h"
#include "utilities/Resolution.h"
}
#endif //SQUAREPINE_GRAPHICS_H