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_PreferencesPanel.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
30 : buttonSize (70)
31{
32}
33
37
39{
40 return buttonSize;
41}
42
44{
45 buttonSize = newSize;
46 resized();
47}
48
49//==============================================================================
51 const Drawable* icon,
52 const Drawable* overIcon,
53 const Drawable* downIcon)
54{
55 auto* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
56 buttons.add (button);
57
58 button->setImages (icon, overIcon, downIcon);
59 button->setRadioGroupId (1);
60 button->onClick = [this] { clickedPage(); };
61 button->setClickingTogglesState (true);
62 button->setWantsKeyboardFocus (false);
63 addAndMakeVisible (button);
64
65 resized();
66
67 if (currentPage == nullptr)
68 setCurrentPage (title);
69}
70
71void PreferencesPanel::addSettingsPage (const String& title, const void* imageData, int imageDataSize)
72{
75
76 iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
77 iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
78
79 iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
80 iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
81
82 addSettingsPage (title, &icon, &iconOver, &iconDown);
83}
84
85//==============================================================================
86void PreferencesPanel::showInDialogBox (const String& dialogTitle, int dialogWidth, int dialogHeight, Colour backgroundColour)
87{
89
91 o.content.setNonOwned (this);
92 o.dialogTitle = dialogTitle;
93 o.dialogBackgroundColour = backgroundColour;
94 o.escapeKeyTriggersCloseButton = false;
95 o.useNativeTitleBar = false;
96 o.resizable = false;
97
98 o.launchAsync();
99}
100
101//==============================================================================
103{
104 for (int i = 0; i < buttons.size(); ++i)
105 buttons.getUnchecked (i)->setBounds (i * buttonSize, 0, buttonSize, buttonSize);
106
107 if (currentPage != nullptr)
108 currentPage->setBounds (getLocalBounds().withTop (buttonSize + 5));
109}
110
112{
113 g.setColour (Colours::grey);
114 g.fillRect (0, buttonSize + 2, getWidth(), 1);
115}
116
118{
119 if (currentPageName != pageName)
120 {
121 currentPageName = pageName;
122
123 currentPage.reset();
124 currentPage.reset (createComponentForPage (pageName));
125
126 if (currentPage != nullptr)
127 {
128 addAndMakeVisible (currentPage.get());
129 currentPage->toBack();
130 resized();
131 }
132
133 for (auto* b : buttons)
134 {
135 if (b->getName() == pageName)
136 {
137 b->setToggleState (true, dontSendNotification);
138 break;
139 }
140 }
141 }
142}
143
144void PreferencesPanel::clickedPage()
145{
146 for (auto* b : buttons)
147 {
148 if (b->getToggleState())
149 {
150 setCurrentPage (b->getName());
151 break;
152 }
153 }
154}
155
156} // namespace juce
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
int getWidth() const noexcept
Returns the component's width in pixels.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
A button that displays a Drawable.
@ ImageAboveTextLabel
Draws the button as a text label across the bottom with the image resized and scaled to fit above it.
A drawable object which is a bitmap image.
void setImage(const Image &imageToUse)
Sets the image that this drawable will render.
The base class for objects which can draw themselves, e.g.
A graphics context, used for drawing a component or image.
void fillRect(Rectangle< int > rectangle) const
Fills a rectangle with the current colour or brush.
void setColour(Colour newColour)
Changes the current drawing colour.
static Image getFromMemory(const void *imageData, int dataSize)
Loads an image from an in-memory image file, (or just returns the image if it's already cached).
void paint(Graphics &) override
Components can override this method to draw their content.
void showInDialogBox(const String &dialogTitle, int dialogWidth, int dialogHeight, Colour backgroundColour=Colours::white)
Utility method to display this panel in a DialogWindow.
int getButtonSize() const noexcept
Returns the size of the buttons shown along the top.
~PreferencesPanel() override
Destructor.
void setCurrentPage(const String &pageName)
Changes the current page being displayed.
void resized() override
Called when this component's size has been changed.
virtual Component * createComponentForPage(const String &pageName)=0
Subclasses must override this to return a component for each preferences page.
void setButtonSize(int newSize)
Changes the size of the buttons shown along the top.
void addSettingsPage(const String &pageTitle, const Drawable *normalIcon, const Drawable *overIcon, const Drawable *downIcon)
Creates a page using a set of drawables to define the page's icon.
PreferencesPanel()
Creates an empty panel.
The JUCE String class!
Definition juce_String.h:53
JUCE Namespace.
@ dontSendNotification
No notification message should be sent.
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
This class defines a collection of settings to be used to open a DialogWindow.
OptionalScopedPointer< Component > content
The content component to show in the window.