JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_LookAndFeel.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29static Typeface::Ptr getTypefaceForFontFromLookAndFeel (const Font& font)
30{
32}
33
34using GetTypefaceForFont = Typeface::Ptr (*)(const Font&);
35extern GetTypefaceForFont juce_getTypefaceForFont;
36
37//==============================================================================
39{
40 /* if this fails it means you're trying to create a LookAndFeel object before
41 the static Colours have been initialised. That ain't gonna work. It probably
42 means that you're using a static LookAndFeel object and that your compiler has
43 decided to initialise it before the Colours class.
44 */
45 jassert (Colours::white == Colour (0xffffffff));
46
47 juce_getTypefaceForFont = getTypefaceForFontFromLookAndFeel;
48}
49
51{
52 /* This assertion is triggered if you try to delete a LookAndFeel object while something
53 is still using it!
54
55 Reasons may be:
56 - it's still being used as the default LookAndFeel; or
57 - it's set as a Component's current lookandfeel; or
58 - there's a WeakReference to it somewhere else in your code
59
60 Generally the fix for this will be to make sure you call
61 Component::setLookAndFeel (nullptr) on any components that were still using
62 it before you delete it, or call LookAndFeel::setDefaultLookAndFeel (nullptr)
63 if you had set it up to be the default one. This assertion can also be avoided by
64 declaring your LookAndFeel object before any of the Components that use it as
65 the Components will be destroyed before the LookAndFeel.
66
67 Deleting a LookAndFeel is unlikely to cause a crash since most things will use a
68 safe WeakReference to it, but it could cause some unexpected graphical behaviour,
69 so it's advisable to clear up any references before destroying them!
70 */
71 jassert (masterReference.getNumActiveWeakReferences() == 0
72 || (masterReference.getNumActiveWeakReferences() == 1
73 && this == &getDefaultLookAndFeel()));
74}
75
76//==============================================================================
77Colour LookAndFeel::findColour (int colourID) const noexcept
78{
79 const ColourSetting c = { colourID, Colour() };
80 auto index = colours.indexOf (c);
81
82 if (index >= 0)
83 return colours[index].colour;
84
86 return Colours::black;
87}
88
89void LookAndFeel::setColour (int colourID, Colour newColour) noexcept
90{
91 const ColourSetting c = { colourID, newColour };
92 auto index = colours.indexOf (c);
93
94 if (index >= 0)
95 colours.getReference (index).colour = newColour;
96 else
97 colours.add (c);
98}
99
100bool LookAndFeel::isColourSpecified (const int colourID) const noexcept
101{
102 const ColourSetting c = { colourID, Colour() };
103 return colours.contains (c);
104}
105
106//==============================================================================
111
116
117//==============================================================================
119{
121 {
122 if (defaultTypeface != nullptr)
123 return defaultTypeface;
124
125 if (defaultSans.isNotEmpty())
126 {
127 Font f (font);
128 f.setTypefaceName (defaultSans);
130 }
131 }
132
134}
135
137{
138 if (defaultTypeface != newDefaultTypeface)
139 {
140 defaultTypeface = newDefaultTypeface;
142 }
143}
144
146{
147 if (defaultSans != newName)
148 {
149 defaultTypeface.reset();
151 defaultSans = newName;
152 }
153}
154
155//==============================================================================
157{
158 auto cursor = component.getMouseCursor();
159
160 for (auto* parent = component.getParentComponent();
161 parent != nullptr && cursor == MouseCursor::ParentCursor;
162 parent = parent->getParentComponent())
163 {
164 cursor = parent->getMouseCursor();
165 }
166
167 return cursor;
168}
169
176
177//==============================================================================
182
184{
185 #if JUCE_LINUX || JUCE_BSD
186 return false; // not available currently..
187 #else
188 return useNativeAlertWindows;
189 #endif
190}
191
192} // namespace juce
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
The base class for all JUCE user-interface objects.
virtual MouseCursor getMouseCursor()
Returns the mouse cursor shape to use when the mouse is over this component.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
LookAndFeel & getDefaultLookAndFeel() noexcept
Returns the current default look-and-feel for components which don't have one explicitly set.
void setDefaultLookAndFeel(LookAndFeel *newDefaultLookAndFeel)
Changes the default look-and-feel.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
static Typeface::Ptr getDefaultTypefaceForFont(const Font &font)
Returns the default system typeface for the given font.
static const String & getDefaultSansSerifFontName()
Returns a typeface font family that represents the default sans-serif font.
String getTypefaceName() const noexcept
Returns the font family of the typeface that this font uses.
void setTypefaceName(const String &faceName)
Changes the font family of the typeface.
Holds a fixed-size bitmap.
Definition juce_Image.h:58
LookAndFeel objects define the appearance of all the JUCE widgets, and subclasses can be used to appl...
static LookAndFeel & getDefaultLookAndFeel() noexcept
Returns the current default look-and-feel for a component to use when it hasn't got one explicitly se...
LookAndFeel()
Creates the default JUCE look and feel.
void setDefaultSansSerifTypefaceName(const String &newName)
Allows you to change the default sans-serif font.
virtual Typeface::Ptr getTypefaceForFont(const Font &)
Returns the typeface that should be used for a given font.
virtual std::unique_ptr< LowLevelGraphicsContext > createGraphicsContext(const Image &imageToRenderOn, Point< int > origin, const RectangleList< int > &initialClip)
Creates a new graphics context object.
bool isUsingNativeAlertWindows()
Returns true if native alert windows will be used (if available).
virtual MouseCursor getMouseCursorFor(Component &)
Override this to get the chance to swap a component's mouse cursor for a customised one.
~LookAndFeel() override
Destructor.
void setUsingNativeAlertWindows(bool shouldUseNativeAlerts)
Sets whether native alert windows (if available) or standard JUCE AlertWindows drawn with AlertWindow...
bool isColourSpecified(int colourId) const noexcept
Returns true if the specified colour ID has been explicitly set using the setColour() method.
void setDefaultSansSerifTypeface(Typeface::Ptr newDefaultTypeface)
Allows you to supply a default typeface that will be returned as the default sans-serif font.
void setColour(int colourId, Colour colour) noexcept
Registers a colour to be used for a particular purpose.
static void setDefaultLookAndFeel(LookAndFeel *newDefaultLookAndFeel) noexcept
Changes the default look-and-feel.
Colour findColour(int colourId) const noexcept
Looks for a colour that has been registered with the given colour ID number.
Represents a mouse cursor image.
@ ParentCursor
Indicates that the component's parent's cursor should be used.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Maintains a set of rectangles as a complex region.
void reset() noexcept
Resets this object to a null pointer.
The JUCE String class!
Definition juce_String.h:53
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
static Ptr createSystemTypefaceFor(const Font &font)
Creates a new system typeface.
ReferenceCountedObjectPtr< Typeface > Ptr
A handy typedef for a pointer to a typeface.
static void clearTypefaceCache()
Clears any fonts that are currently cached in memory.
#define jassert(expression)
Platform-independent assertion macro.
#define jassertfalse
This will always cause an assertion failure.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88