1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-16 00:34:19 +00:00

Code clean-up

This commit is contained in:
jules 2014-10-20 17:00:34 +01:00
parent c397984fe9
commit 4fbb5358c4
8 changed files with 190 additions and 220 deletions

View file

@ -42,16 +42,13 @@ namespace TabbedComponentHelpers
//==============================================================================
SlidingPanelComponent::SlidingPanelComponent ()
SlidingPanelComponent::SlidingPanelComponent()
: currentTabIndex (0), dotSize (20)
{
dotSize = 20;
numTabs = 0;
currentTabIndex = 0;
addAndMakeVisible (&slide);
addAndMakeVisible (slide);
}
SlidingPanelComponent::~SlidingPanelComponent ()
SlidingPanelComponent::~SlidingPanelComponent()
{
for (int i = contentComponents.size(); --i >= 0;)
if (Component* c = contentComponents.getReference(i))
@ -59,12 +56,11 @@ SlidingPanelComponent::~SlidingPanelComponent ()
}
void SlidingPanelComponent::addTab (const String& tabName,
Component* const contentComponent,
const bool deleteComponentWhenNotNeeded,
const int insertIndex)
Component* const contentComponent,
const bool deleteComponentWhenNotNeeded,
const int insertIndex)
{
contentComponents.insert (insertIndex, WeakReference<Component> (contentComponent));
tabNames.insert (insertIndex, tabName);
if (deleteComponentWhenNotNeeded && contentComponent != nullptr)
@ -72,48 +68,46 @@ void SlidingPanelComponent::addTab (const String& tabName,
slide.addAndMakeVisible (contentComponent);
numTabs++;
resized();
}
void SlidingPanelComponent::goToTab (int targetTabIndex)
{
int xTranslation = (currentTabIndex - targetTabIndex) * getWidth();
const int xTranslation = (currentTabIndex - targetTabIndex) * getWidth();
currentTabIndex = targetTabIndex;
Desktop::getInstance().getAnimator().animateComponent (&slide, slide.getBounds().translated(xTranslation, 0), 1.0f, 600, false, 0.0, 0.0);
Desktop::getInstance().getAnimator()
.animateComponent (&slide, slide.getBounds().translated (xTranslation, 0),
1.0f, 600, false, 0.0, 0.0);
repaint();
}
void SlidingPanelComponent::paint (Graphics& g)
{
Rectangle<int> dotHolder = getLocalBounds();
dotHolder.reduce ((getWidth() - dotSize * numTabs)/2, 20);
dotHolder.reduce ((getWidth() - dotSize * getNumTabs()) / 2, 20);
dotHolder = dotHolder.removeFromBottom (dotSize);
g.setColour (Colours::white);
for (int i = 0; i < numTabs; i++)
for (int i = 0; i < getNumTabs(); ++i)
{
const Rectangle<float> r (dotHolder.removeFromLeft (dotSize).reduced (5, 5).toFloat());
if (i == currentTabIndex)
{
g.fillEllipse (dotHolder.removeFromLeft (dotSize).reduced (5, 5).toFloat());
}
g.fillEllipse (r);
else
{
g.drawEllipse (dotHolder.removeFromLeft (dotSize).reduced (5, 5).toFloat(), 1.0f);
}
g.drawEllipse (r, 1.0f);
}
}
void SlidingPanelComponent::resized()
{
slide.setBounds (-currentTabIndex*getWidth(), slide.getPosition().y, numTabs * getWidth(), getHeight());
slide.setBounds (-currentTabIndex * getWidth(), slide.getPosition().y,
getNumTabs() * getWidth(), getHeight());
Rectangle<int> content (getLocalBounds());
@ -121,5 +115,5 @@ void SlidingPanelComponent::resized()
for (int i = contentComponents.size(); --i >= 0;)
if (Component* c = contentComponents.getReference(i))
c->setBounds (content.translated (i*content.getWidth(), 0));
c->setBounds (content.translated (i * content.getWidth(), 0));
}

View file

@ -29,10 +29,11 @@
#include "../Application/jucer_Application.h"
class SlidingPanelComponent : public Component
//==============================================================================
class SlidingPanelComponent : public Component
{
public:
SlidingPanelComponent ();
SlidingPanelComponent();
~SlidingPanelComponent();
/** Adds a new tab to the panel slider. */
@ -45,10 +46,10 @@ public:
void removeTab (int tabIndex);
/** Gets index of current tab. */
int getCurrentTabIndex (){return currentTabIndex;};
int getCurrentTabIndex() const noexcept { return currentTabIndex; }
/** Returns the number of tabs. */
int getNumTabs (){return numTabs;};
int getNumTabs() const noexcept { return contentComponents.size(); }
/** Animates the window to the desired tab. */
void goToTab (int targetTabIndex);
@ -56,22 +57,19 @@ public:
//==============================================================================
/** @internal */
void paint (Graphics&);
void paint (Graphics&) override;
/** @internal */
void resized();
void resized() override;
private:
Array <WeakReference<Component>> contentComponents;
Array <String> tabNames;
Array<WeakReference<Component> > contentComponents;
StringArray tabNames;
Component slide;
int currentTabIndex, dotSize;
int currentTabIndex;
int numTabs;
int dotSize;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SlidingPanelComponent);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SlidingPanelComponent);
};
#endif // JUCER_SLIDINGPANELCOMPONENT_H_INCLUDED

View file

@ -25,7 +25,6 @@
#ifndef GUIAPPWIZARD_H_INCLUDED
#define GUIAPPWIZARD_H_INCLUDED
#include "jucer_NewProjectWizard.h"
//==============================================================================
struct GUIAppWizard : public NewProjectWizard

View file

@ -27,7 +27,7 @@
//==============================================================================
static inline void createFileCreationOptionComboBox (Component& setupComp,
static void createFileCreationOptionComboBox (Component& setupComp,
OwnedArray<Component>& itemsCreated,
const StringArray& fileOptions)
{
@ -45,7 +45,7 @@ static inline void createFileCreationOptionComboBox (Component& setupComp,
c->setBounds ("parent.width / 2 + 160, 30, parent.width - 30, top + 22");
}
static inline int getFileCreationComboResult (Component& setupComp)
static int getFileCreationComboResult (Component& setupComp)
{
if (ComboBox* cb = dynamic_cast<ComboBox*> (setupComp.findChildWithID ("filesToCreate")))
return cb->getSelectedItemIndex();
@ -54,19 +54,19 @@ static inline int getFileCreationComboResult (Component& setupComp)
return 0;
}
static inline void setExecutableNameForAllTargets (Project& project, const String& exeName)
static void setExecutableNameForAllTargets (Project& project, const String& exeName)
{
for (Project::ExporterIterator exporter (project); exporter.next();)
for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
config->getTargetBinaryName() = exeName;
}
static inline Project::Item createSourceGroup (Project& project)
static Project::Item createSourceGroup (Project& project)
{
return project.getMainGroup().addNewSubGroup ("Source", 0);
}
static inline File& getLastWizardFolder()
static File& getLastWizardFolder()
{
#if JUCE_WINDOWS
static File lastFolder (File::getSpecialLocation (File::userDocumentsDirectory));

View file

@ -27,56 +27,51 @@
/** The target platforms chooser for the chosen template. */
class PlatformTargetsComp : public Component,
private ListBoxModel
class PlatformTargetsComp : public Component,
private ListBoxModel
{
public:
PlatformTargetsComp()
{
setOpaque (false);
addAndMakeVisible (listBox);
listBox.setRowHeight (360 / getNumRows());
listBox.setModel (this);
listBox.setOpaque (false);
listBox.setMultipleSelectionEnabled (true);
listBox.setClickingTogglesRowSelection (true);
listBox.setColour (ListBox::ColourIds::backgroundColourId, Colours::white.withAlpha (0.0f));
addAndMakeVisible (listBox);
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconXcode_png, BinaryData::projectIconXcode_pngSize), "Create a new XCode target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconXcodeIOS_png, BinaryData::projectIconXcodeIOS_pngSize), "Create a new XCode IOS target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio13_png, BinaryData::projectIconVisualStudio13_pngSize), "Create a new Visual Studio 2013 target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio12_png, BinaryData::projectIconVisualStudio12_pngSize), "Create a new Visual Studio 2012 target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio10_png, BinaryData::projectIconVisualStudio10_pngSize), "Create a new Visual Studio 2010 target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio08_png, BinaryData::projectIconVisualStudio08_pngSize), "Create a new Visual Studio 2008 target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio05_png, BinaryData::projectIconVisualStudio05_pngSize), "Create a new Visual Studio 2005 target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconAndroid_png, BinaryData::projectIconAndroid_pngSize), "Create a new Android target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconCodeblocks_png, BinaryData::projectIconCodeblocks_pngSize), "Create a new Codeblocks target"));
platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconLinuxMakefile_png, BinaryData::projectIconLinuxMakefile_pngSize), "Create a new linux makefile target"));
addPlatformType (BinaryData::projectIconXcode_png, BinaryData::projectIconXcode_pngSize, "Create a new XCode target");
addPlatformType (BinaryData::projectIconXcodeIOS_png, BinaryData::projectIconXcodeIOS_pngSize, "Create a new XCode IOS target");
addPlatformType (BinaryData::projectIconVisualStudio13_png, BinaryData::projectIconVisualStudio13_pngSize, "Create a new Visual Studio 2013 target");
addPlatformType (BinaryData::projectIconVisualStudio12_png, BinaryData::projectIconVisualStudio12_pngSize, "Create a new Visual Studio 2012 target");
addPlatformType (BinaryData::projectIconVisualStudio10_png, BinaryData::projectIconVisualStudio10_pngSize, "Create a new Visual Studio 2010 target");
addPlatformType (BinaryData::projectIconVisualStudio08_png, BinaryData::projectIconVisualStudio08_pngSize, "Create a new Visual Studio 2008 target");
addPlatformType (BinaryData::projectIconVisualStudio05_png, BinaryData::projectIconVisualStudio05_pngSize, "Create a new Visual Studio 2005 target");
addPlatformType (BinaryData::projectIconAndroid_png, BinaryData::projectIconAndroid_pngSize, "Create a new Android target");
addPlatformType (BinaryData::projectIconCodeblocks_png, BinaryData::projectIconCodeblocks_pngSize, "Create a new Codeblocks target");
addPlatformType (BinaryData::projectIconLinuxMakefile_png, BinaryData::projectIconLinuxMakefile_pngSize, "Create a new linux makefile target");
}
~PlatformTargetsComp()
void addPlatformType (const void* imgData, int imgSize, const char* name)
{
platforms.add (new PlatformType (ImageCache::getFromMemory (imgData, imgSize), name));
}
void resized()
void resized() override
{
listBox.setBounds (getLocalBounds());
}
// these add the ListBoxModel virtual functions
int getNumRows()
int getNumRows() override
{
return 10;
}
void paintListBoxItem (int rowNumber, Graphics& g,
int width, int height, bool rowIsSelected)
int width, int height, bool rowIsSelected) override
{
Rectangle<float> dotSelect = Rectangle<float> (0, 0, height, height);
dotSelect.reduce (12, 12);
@ -97,32 +92,31 @@ public:
private:
struct PlatformType {
PlatformType (const Image& platformIcon, const String& platformName){
icon = platformIcon;
name = platformName;
struct PlatformType
{
PlatformType (const Image& platformIcon, const String& platformName)
: icon (platformIcon), name (platformName)
{
}
Image icon;
String name;
};
ListBox listBox;
OwnedArray<PlatformType> platforms;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PlatformTargetsComp)
};
/**
The Component for project creation.
Features a file browser to select project destination and
a list box of platform targets to generate.
*/
//==============================================================================
/**
The Component for project creation.
Features a file browser to select project destination and
a list box of platform targets to generate.
*/
class WizardComp : public Component,
private ButtonListener,
private ComboBoxListener,
@ -203,10 +197,20 @@ public:
}
else if (b == &cancelButton)
{
// returns to template icon page on cancel
SlidingPanelComponent* parent = findParentComponentOfClass<SlidingPanelComponent>();
returnToTemplatesPage();
}
}
if (parent->getNumTabs() > 0) parent->goToTab (parent->getCurrentTabIndex() - 1);
void returnToTemplatesPage()
{
if (SlidingPanelComponent* parent = findParentComponentOfClass<SlidingPanelComponent>())
{
if (parent->getNumTabs() > 0)
parent->goToTab (parent->getCurrentTabIndex() - 1);
}
else
{
jassertfalse;
}
}
@ -252,20 +256,19 @@ public:
void comboBoxChanged (ComboBox*) override
{
updateCustomItems();
updateCustomItems();
}
void textEditorTextChanged (TextEditor&) override
{
updateCreateButton();
fileBrowser.setFileName (File::createLegalFileName (projectName.getText()));
updateCreateButton();
fileBrowser.setFileName (File::createLegalFileName (projectName.getText()));
}
// projectType box is public so it can be set by the introjucer front page icons
ComboBox projectType;
private:
private:
TextEditor projectName;
Label nameLabel, typeLabel;
FileBrowserComponent fileBrowser;
@ -322,5 +325,4 @@ static StringArray getWizardNames()
}
#endif // NEWPROJECTWIZARDCOMPONENTS_H_INCLUDED

View file

@ -28,38 +28,30 @@
class StartPageComponent : public Component
{
public:
StartPageComponent()
{
setSize (800, 650);
StartPageComponent()
{
panel = new SlidingPanelComponent();
WizardComp* projectWizard = new WizardComp();
WizardComp* projectWizard = new WizardComp();
panel.addTab ("Create New Project", new TemplateTileBrowser (projectWizard), true);
panel.addTab ("New Project Options", projectWizard, true);
setSize (800, 650);
addAndMakeVisible (panel);
}
panel->addTab ("Create New Project", new TemplateTileBrowser (projectWizard), true);
panel->addTab ("New Project Options", projectWizard, true);
void paint (Graphics& g)
{
IntrojucerLookAndFeel::fillWithBackgroundTexture (*this, g);
}
addAndMakeVisible (panel);
}
~StartPageComponent()
{
panel = nullptr;
}
void paint (Graphics& g)
{
IntrojucerLookAndFeel::fillWithBackgroundTexture (*this, g);
}
void resized()
{
panel->setBounds (getBounds());
}
void resized()
{
panel.setBounds (getLocalBounds());
}
private:
ScopedPointer<SlidingPanelComponent> panel;
SlidingPanelComponent panel;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StartPageComponent)
};

View file

@ -21,6 +21,7 @@
==============================================================================
*/
#ifndef JUCER_STATICLIBRARYWIZARD_H_INCLUDED
#define JUCER_STATICLIBRARYWIZARD_H_INCLUDED

View file

@ -27,14 +27,14 @@
//=====================================================================================================
/**
Template option tile button.
the drawable button object class for the tile icons and buttons in the TemplateTileBrowser
Template option tile button.
The drawable button object class for the tile icons and buttons in the TemplateTileBrowser
*/
class TemplateOptionButton : public DrawableButton
{
public:
explicit TemplateOptionButton (const String& buttonName, ButtonStyle buttonStyle, const char* thumbSvg)
: DrawableButton (buttonName, buttonStyle)
TemplateOptionButton (const String& buttonName, ButtonStyle buttonStyle, const char* thumbSvg)
: DrawableButton (buttonName, buttonStyle)
{
// svg for thumbnail icon
ScopedPointer<XmlElement> svg (XmlDocument::parse (thumbSvg));
@ -55,35 +55,37 @@ public:
void paintButton (Graphics& g, bool isMouseOverButton, bool /*isButtonDown*/) override
{
const Rectangle<float> bounds (getLocalBounds().toFloat());
const Colour buttonColour (0xfff29300);
if (isMouseOverButton)
{
if (getStyle() == ButtonStyle::ImageFitted)
{
hoverBackground->drawWithin (g, getLocalBounds().toFloat(), RectanglePlacement::centred, 1.0);
thumb->drawWithin (g, getLocalBounds().toFloat(), RectanglePlacement::centred, 1.0);
hoverBackground->drawWithin (g, bounds, RectanglePlacement::centred, 1.0);
thumb->drawWithin (g, bounds, RectanglePlacement::centred, 1.0);
}
else
{
g.setColour (Colour (243, 146, 0).withAlpha (0.3f));
g.fillRoundedRectangle (getLocalBounds().toFloat().reduced (2, 2), 10.0f);
g.setColour (Colour (243, 146, 0).withAlpha (1.0f));
g.drawRoundedRectangle (getLocalBounds().toFloat().reduced (2, 2), 10.0f, 2.0f);
g.setColour (buttonColour.withAlpha (0.3f));
g.fillRoundedRectangle (bounds.reduced (2.0f, 2.0f), 10.0f);
g.setColour (buttonColour);
g.drawRoundedRectangle (bounds.reduced (2.0f, 2.0f), 10.0f, 2.0f);
}
}
else
{
if (getStyle() == ButtonStyle::ImageFitted)
{
thumb->drawWithin (g, getLocalBounds().toFloat(), RectanglePlacement::centred, 1.0);
thumb->drawWithin (g, bounds, RectanglePlacement::centred, 1.0);
}
else
{
g.setColour (Colour (243, 146, 0).withAlpha (1.0f));
g.drawRoundedRectangle (getLocalBounds().toFloat().reduced (2,2), 10.0f, 2.0f);
g.setColour (buttonColour);
g.drawRoundedRectangle (bounds.reduced (2.0f, 2.0f), 10.0f, 2.0f);
}
}
Rectangle<float> textTarget;
// center the text for the text buttons or position the text in the image buttons
@ -93,38 +95,32 @@ public:
}
else
{
textTarget = RectanglePlacement (RectanglePlacement::centred).appliedTo(thumb->getDrawableBounds(), getLocalBounds().toFloat());
textTarget = textTarget.removeFromBottom(textTarget.getHeight() * 0.3);
textTarget = RectanglePlacement (RectanglePlacement::centred).appliedTo (thumb->getDrawableBounds(), bounds);
textTarget = textTarget.removeFromBottom (textTarget.getHeight() * 0.3f);
}
g.setColour (Colours::white);
g.drawText (name, textTarget, Justification::centred, true);
}
void resized()
void resized() override
{
thumb->setBoundsToFit (0, 0, getWidth(), getHeight(), Justification::centred, false);
}
void setDescription (String descript)
void setDescription (String descript) noexcept
{
description = descript;
}
String getDescription()
String getDescription() const noexcept
{
return description;
}
private:
ScopedPointer<Drawable> thumb;
ScopedPointer<Drawable> hoverBackground;
String name;
String description;
ScopedPointer<Drawable> thumb, hoverBackground;
String name, description;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TemplateOptionButton)
};
@ -133,42 +129,29 @@ private:
//=====================================================================================================
/**
Project Template Component for front page.
Features multiple icon buttons to select the type of project template
Project Template Component for front page.
Features multiple icon buttons to select the type of project template
*/
class TemplateTileBrowser : public Component,
private Button::Listener
private Button::Listener
{
public:
TemplateTileBrowser (NewProjectWizardComponents::WizardComp* projectWizard)
{
addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("GUI Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconGui_svg)));
addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Audio Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconAudio_svg)));
addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Audio Plug-in", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconPlugin_svg)));
addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Animated Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconAnimation_svg)));
addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Opengl Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconOpengl_svg)));
addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Console Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconConsole_svg)));
addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Static Library", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconStatic_svg)));
addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Dynamic Library", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconDynamic_svg)));
// Add the descriptions for each button
optionButtons.getUnchecked(0)->setDescription ("Creates a blank JUCE application with a single window component.");
optionButtons.getUnchecked(1)->setDescription ("Creates a blank JUCE application with a single window component and Audio and MIDI in/out functions.");
optionButtons.getUnchecked(2)->setDescription ("Creates a VST or AU audio plug-in for use within a host program. This template features a single window component and Audio/MIDI IO functions");
optionButtons.getUnchecked(3)->setDescription ("Creates a blank JUCE application with a single window component that updates and draws at 60fps.");
optionButtons.getUnchecked(4)->setDescription ("Creates a blank JUCE application with a single window component. This component supports all OPENGL drawing features including 3D model import and glsl shaders.");
optionButtons.getUnchecked(5)->setDescription ("Creates a blank console application with support for all JUCE features.");
optionButtons.getUnchecked(6)->setDescription ("Creates a Static Library template with support for all JUCE features");
optionButtons.getUnchecked(7)->setDescription ("Creates a Dynamic Library template with support for all JUCE features");
addOptionButton ("GUI Application", BinaryData::iconGui_svg, "Creates a blank JUCE application with a single window component.");
addOptionButton ("Audio Application", BinaryData::iconAudio_svg, "Creates a blank JUCE application with a single window component and Audio and MIDI in/out functions.");
addOptionButton ("Audio Plug-in", BinaryData::iconPlugin_svg, "Creates a VST or AU audio plug-in for use within a host program. This template features a single window component and Audio/MIDI IO functions");
addOptionButton ("Animated Application", BinaryData::iconAnimation_svg, "Creates a blank JUCE application with a single window component that updates and draws at 60fps.");
addOptionButton ("Opengl Application", BinaryData::iconOpengl_svg, "Creates a blank JUCE application with a single window component. This component supports all OPENGL drawing features including 3D model import and glsl shaders.");
addOptionButton ("Console Application", BinaryData::iconConsole_svg, "Creates a blank console application with support for all JUCE features.");
addOptionButton ("Static Library", BinaryData::iconStatic_svg, "Creates a Static Library template with support for all JUCE features");
addOptionButton ("Dynamic Library", BinaryData::iconDynamic_svg, "Creates a Dynamic Library template with support for all JUCE features");
// Handle Open Project button functionality
ApplicationCommandManager& commandManager = IntrojucerApp::getCommandManager();
blankProjectButton = new TemplateOptionButton ("Create Blank Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
openProjectButton = new TemplateOptionButton ("Open Existing Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
openProjectButton = new TemplateOptionButton ("Open Existing Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
openProjectButton->setCommandToTrigger (&commandManager, CommandIDs::open, true);
exampleProjectButton = new TemplateOptionButton ("Open Example Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
@ -178,15 +161,17 @@ public:
addAndMakeVisible (openProjectButton);
addAndMakeVisible (exampleProjectButton);
for (TemplateOptionButton* t : optionButtons)
{
t->addListener (this);
}
newProjectWizard = projectWizard;
}
void addOptionButton (const char* name, const char* svg, const char* desc)
{
TemplateOptionButton* b = new TemplateOptionButton (name, TemplateOptionButton::ButtonStyle::ImageFitted, svg);
optionButtons.add (b);
addAndMakeVisible (b);
b->setDescription (desc);
b->addListener (this);
}
void paint (Graphics& g) override
{
@ -203,40 +188,33 @@ public:
descriptionBox = descriptionBox.removeFromBottom (50);
g.setColour (Colours::white.withAlpha (0.4f));
g.setFont(15);
g.setFont (15);
for ( int i = 0; i < 8; i++ )
{
if (optionButtons.getUnchecked (i)->getState() == TemplateOptionButton::ButtonState::buttonOver)
{
g.drawFittedText (optionButtons.getUnchecked (i)->getDescription(), descriptionBox, Justification::centred, 5, 1.0f);
}
}
for (int i = 0; i < 8; ++i)
if (optionButtons.getUnchecked(i)->getState() == TemplateOptionButton::ButtonState::buttonOver)
g.drawFittedText (optionButtons.getUnchecked(i)->getDescription(), descriptionBox, Justification::centred, 5, 1.0f);
}
void resized()
void resized() override
{
Rectangle<int> allOpts = getBounds().reduced (40, 60);
allOpts.removeFromBottom (allOpts.getHeight() * 0.25);
int numHorizIcons = 4;
const int numHorizIcons = 4;
const int optStep = allOpts.getWidth()/numHorizIcons;
int optStep = allOpts.getWidth()/numHorizIcons;
for (int i = 0; i < 8; i++)
for (int i = 0; i < optionButtons.size(); ++i)
{
int yShift = i < numHorizIcons ? 0 : 1;
const int yShift = i < numHorizIcons ? 0 : 1;
Rectangle<int> bounds;
bounds = Rectangle<int> (allOpts.getX() + i%numHorizIcons*optStep, allOpts.getY() + yShift * allOpts.getHeight() / 2, optStep, allOpts.getHeight() / 2);
bounds.reduce (10, 10);
optionButtons.getUnchecked (i)->setBounds (bounds);
optionButtons.getUnchecked(i)->setBounds (Rectangle<int> (allOpts.getX() + (i % numHorizIcons) * optStep,
allOpts.getY() + yShift * allOpts.getHeight() / 2,
optStep, allOpts.getHeight() / 2)
.reduced (10, 10));
}
Rectangle<int> openButtonBounds = getBounds();
openButtonBounds.removeFromBottom (getHeight() * 0.12);
openButtonBounds.removeFromBottom (proportionOfHeight (0.12f));
openButtonBounds = openButtonBounds.removeFromBottom (120);
openButtonBounds.reduce (50, 40);
@ -245,44 +223,50 @@ public:
openProjectButton->setBounds (openButtonBounds.reduced (18, 0));
}
void buttonClicked (Button* b) override
static int getIndexOfButton (const String& buttonText)
{
if (b->getButtonText() == "GUI Application") newProjectWizard->projectType.setSelectedItemIndex (0);
if (b->getButtonText() == "Console Application") newProjectWizard->projectType.setSelectedItemIndex (1);
if (b->getButtonText() == "Audio Plug-in") newProjectWizard->projectType.setSelectedItemIndex (2);
if (b->getButtonText() == "Static Library") newProjectWizard->projectType.setSelectedItemIndex (3);
if (b->getButtonText() == "Dynamic Library") newProjectWizard->projectType.setSelectedItemIndex (4);
if (buttonText == "GUI Application") return 0;
if (buttonText == "Console Application") return 1;
if (buttonText == "Audio Plug-in") return 2;
if (buttonText == "Static Library") return 3;
if (buttonText == "Dynamic Library") return 4;
//new templates without actual templates yet
if (b->getButtonText() == "Animated Application") newProjectWizard->projectType.setSelectedItemIndex (0);
if (b->getButtonText() == "Audio Application") newProjectWizard->projectType.setSelectedItemIndex (0);
if (b->getButtonText() == "Opengl Application") newProjectWizard->projectType.setSelectedItemIndex (0);
// new templates without actual templates yet
if (buttonText == "Animated Application") return 0;
if (buttonText == "Audio Application") return 0;
if (buttonText == "Opengl Application") return 0;
SlidingPanelComponent* parent = findParentComponentOfClass<SlidingPanelComponent>();
jassert (parent != nullptr);
if (parent->getNumTabs() > 0 && b->getButtonText() != "Open Existing Project") parent->goToTab (parent->getCurrentTabIndex() + 1);
jassertfalse;
return 0;
}
void buttonStateChanged (Button*)
void buttonClicked (Button* b) override
{
newProjectWizard->projectType.setSelectedItemIndex (getIndexOfButton (b->getButtonText()));
if (SlidingPanelComponent* parent = findParentComponentOfClass<SlidingPanelComponent>())
{
if (parent->getNumTabs() > 0 && b->getButtonText() != "Open Existing Project")
parent->goToTab (parent->getCurrentTabIndex() + 1);
}
else
{
jassertfalse;
}
}
void buttonStateChanged (Button*) override
{
repaint();
}
private:
private:
OwnedArray<TemplateOptionButton> optionButtons;
NewProjectWizardComponents::WizardComp* newProjectWizard;
ScopedPointer<TemplateOptionButton> blankProjectButton, openProjectButton, exampleProjectButton;
ScopedPointer<TemplateOptionButton> blankProjectButton;
ScopedPointer<TemplateOptionButton> openProjectButton;
ScopedPointer<TemplateOptionButton> exampleProjectButton;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TemplateTileBrowser)
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TemplateTileBrowser)
};
#endif // JUCER_TEMPLATETHUMBNAILSCOMPONENT_H_INCLUDED