Add remaining files
[juce-lv2.git] / juce / source / src / gui / components / special / juce_PreferencesPanel.cpp
bloba8e7b41edb7d36222ef791c75eee5ad4512c5d12
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../../core/juce_StandardHeader.h"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_PreferencesPanel.h"
31 #include "../windows/juce_DialogWindow.h"
32 #include "../../graphics/imaging/juce_ImageCache.h"
33 #include "../../graphics/drawables/juce_DrawableImage.h"
36 //==============================================================================
37 PreferencesPanel::PreferencesPanel()
38 : buttonSize (70)
42 PreferencesPanel::~PreferencesPanel()
46 int PreferencesPanel::getButtonSize() const noexcept
48 return buttonSize;
51 void PreferencesPanel::setButtonSize (int newSize)
53 buttonSize = newSize;
54 resized();
57 //==============================================================================
58 void PreferencesPanel::addSettingsPage (const String& title,
59 const Drawable* icon,
60 const Drawable* overIcon,
61 const Drawable* downIcon)
63 DrawableButton* const button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
64 buttons.add (button);
66 button->setImages (icon, overIcon, downIcon);
67 button->setRadioGroupId (1);
68 button->addListener (this);
69 button->setClickingTogglesState (true);
70 button->setWantsKeyboardFocus (false);
71 addAndMakeVisible (button);
73 resized();
75 if (currentPage == nullptr)
76 setCurrentPage (title);
79 void PreferencesPanel::addSettingsPage (const String& title, const void* imageData, const int imageDataSize)
81 DrawableImage icon, iconOver, iconDown;
82 icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
84 iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
85 iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
87 iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
88 iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
90 addSettingsPage (title, &icon, &iconOver, &iconDown);
93 //==============================================================================
94 void PreferencesPanel::showInDialogBox (const String& dialogTitle, int dialogWidth, int dialogHeight, const Colour& backgroundColour)
96 setSize (dialogWidth, dialogHeight);
97 DialogWindow::showDialog (dialogTitle, this, 0, backgroundColour, false);
100 //==============================================================================
101 void PreferencesPanel::resized()
103 for (int i = 0; i < buttons.size(); ++i)
104 buttons.getUnchecked(i)->setBounds (i * buttonSize, 0, buttonSize, buttonSize);
106 if (currentPage != nullptr)
107 currentPage->setBounds (getLocalBounds().withTop (buttonSize + 5));
110 void PreferencesPanel::paint (Graphics& g)
112 g.setColour (Colours::grey);
113 g.fillRect (0, buttonSize + 2, getWidth(), 1);
116 void PreferencesPanel::setCurrentPage (const String& pageName)
118 if (currentPageName != pageName)
120 currentPageName = pageName;
122 currentPage = nullptr;
123 currentPage = createComponentForPage (pageName);
125 if (currentPage != nullptr)
127 addAndMakeVisible (currentPage);
128 currentPage->toBack();
129 resized();
132 for (int i = 0; i < buttons.size(); ++i)
134 if (buttons.getUnchecked(i)->getName() == pageName)
136 buttons.getUnchecked(i)->setToggleState (true, false);
137 break;
143 void PreferencesPanel::buttonClicked (Button*)
145 for (int i = 0; i < buttons.size(); ++i)
147 if (buttons.getUnchecked(i)->getToggleState())
149 setCurrentPage (buttons.getUnchecked(i)->getName());
150 break;
155 END_JUCE_NAMESPACE