LMMS
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
33
37
42
44{
45 buttonSize = newSize;
46 resized();
47}
48
49//==============================================================================
51 const Drawable* icon,
52 const Drawable* overIcon,
53 const Drawable* downIcon)
54{
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);
64
65 resized();
66
67 if (currentPage == nullptr)
69}
70
71void PreferencesPanel::addSettingsPage (const String& title, const void* imageData, int imageDataSize)
72{
73 DrawableImage icon, iconOver, iconDown;
74 icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
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{
88 setSize (dialogWidth, dialogHeight);
89
91 o.content.setNonOwned (this);
92 o.dialogTitle = dialogTitle;
93 o.dialogBackgroundColour = backgroundColour;
95 o.useNativeTitleBar = true;
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 {
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
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
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_Colour.h:38
void addAndMakeVisible(Component *child, int zOrder=-1)
Definition juce_Component.cpp:1554
void setSize(int newWidth, int newHeight)
Definition juce_Component.cpp:1262
int getWidth() const noexcept
Definition juce_Component.h:271
Rectangle< int > getLocalBounds() const noexcept
Definition juce_Component.cpp:2283
Definition juce_DrawableButton.h:41
@ ImageAboveTextLabel
Definition juce_DrawableButton.h:49
Definition juce_Drawable.h:38
Definition juce_DrawableImage.h:38
void setOverlayColour(Colour newOverlayColour)
Definition juce_DrawableImage.cpp:69
void setImage(const Image &imageToUse)
Definition juce_DrawableImage.cpp:58
Definition juce_GraphicsContext.h:45
static Image getFromMemory(const void *imageData, int dataSize)
Definition juce_ImageCache.cpp:144
void paint(Graphics &) override
Definition juce_PreferencesPanel.cpp:111
void showInDialogBox(const String &dialogTitle, int dialogWidth, int dialogHeight, Colour backgroundColour=Colours::white)
Definition juce_PreferencesPanel.cpp:86
int getButtonSize() const noexcept
Definition juce_PreferencesPanel.cpp:38
OwnedArray< DrawableButton > buttons
Definition juce_PreferencesPanel.h:139
String currentPageName
Definition juce_PreferencesPanel.h:137
~PreferencesPanel() override
Definition juce_PreferencesPanel.cpp:34
void setCurrentPage(const String &pageName)
Definition juce_PreferencesPanel.cpp:117
void clickedPage()
Definition juce_PreferencesPanel.cpp:144
void resized() override
Definition juce_PreferencesPanel.cpp:102
virtual Component * createComponentForPage(const String &pageName)=0
std::unique_ptr< Component > currentPage
Definition juce_PreferencesPanel.h:138
void setButtonSize(int newSize)
Definition juce_PreferencesPanel.cpp:43
int buttonSize
Definition juce_PreferencesPanel.h:140
void addSettingsPage(const String &pageTitle, const Drawable *normalIcon, const Drawable *overIcon, const Drawable *downIcon)
Definition juce_PreferencesPanel.cpp:50
PreferencesPanel()
Definition juce_PreferencesPanel.cpp:29
Definition juce_String.h:53
int g
Definition inflate.c:1573
register unsigned i
Definition inflate.c:1575
static const char * title
Definition pugl.h:1747
const Colour grey
Definition juce_Colours.h:93
const Colour black
Definition juce_Colours.h:50
Definition carla_juce.cpp:31
@ dontSendNotification
Definition juce_NotificationType.h:33
@ button
Definition juce_AccessibilityRole.h:38
Definition juce_DialogWindow.h:90
Colour dialogBackgroundColour
Definition juce_DialogWindow.h:97
bool useNativeTitleBar
Definition juce_DialogWindow.h:115
OptionalScopedPointer< Component > content
Definition juce_DialogWindow.h:104
DialogWindow * launchAsync()
Definition juce_DialogWindow.cpp:116
bool resizable
Definition juce_DialogWindow.h:117
bool escapeKeyTriggersCloseButton
Definition juce_DialogWindow.h:113
String dialogTitle
Definition juce_DialogWindow.h:94
b
Definition crypt.c:628
#define const
Definition zconf.h:137