The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

327 lines
12KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef NEWPROJECTWIZARDCOMPONENTS_H_INCLUDED
  18. #define NEWPROJECTWIZARDCOMPONENTS_H_INCLUDED
  19. /** The target platforms chooser for the chosen template. */
  20. class PlatformTargetsComp : public Component,
  21. private ListBoxModel
  22. {
  23. public:
  24. PlatformTargetsComp()
  25. {
  26. setOpaque (false);
  27. addAndMakeVisible (listBox);
  28. listBox.setRowHeight (360 / getNumRows());
  29. listBox.setModel (this);
  30. listBox.setOpaque (false);
  31. listBox.setMultipleSelectionEnabled (true);
  32. listBox.setClickingTogglesRowSelection (true);
  33. listBox.setColour (ListBox::ColourIds::backgroundColourId, Colours::white.withAlpha (0.0f));
  34. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconXcode_png, BinaryData::projectIconXcode_pngSize), "Create a new XCode target"));
  35. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconXcodeIOS_png, BinaryData::projectIconXcodeIOS_pngSize), "Create a new XCode IOS target"));
  36. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio13_png, BinaryData::projectIconVisualStudio13_pngSize), "Create a new Visual Studio 2013 target"));
  37. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio12_png, BinaryData::projectIconVisualStudio12_pngSize), "Create a new Visual Studio 2012 target"));
  38. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio10_png, BinaryData::projectIconVisualStudio10_pngSize), "Create a new Visual Studio 2010 target"));
  39. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio08_png, BinaryData::projectIconVisualStudio08_pngSize), "Create a new Visual Studio 2008 target"));
  40. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconVisualStudio05_png, BinaryData::projectIconVisualStudio05_pngSize), "Create a new Visual Studio 2005 target"));
  41. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconAndroid_png, BinaryData::projectIconAndroid_pngSize), "Create a new Android target"));
  42. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconCodeblocks_png, BinaryData::projectIconCodeblocks_pngSize), "Create a new Codeblocks target"));
  43. platforms.add (new PlatformType (ImageCache::getFromMemory (BinaryData::projectIconLinuxMakefile_png, BinaryData::projectIconLinuxMakefile_pngSize), "Create a new linux makefile target"));
  44. }
  45. ~PlatformTargetsComp()
  46. {
  47. }
  48. void resized()
  49. {
  50. listBox.setBounds (getLocalBounds());
  51. }
  52. // these add the ListBoxModel virtual functions
  53. int getNumRows()
  54. {
  55. return 10;
  56. }
  57. void paintListBoxItem (int rowNumber, Graphics& g,
  58. int width, int height, bool rowIsSelected)
  59. {
  60. Rectangle<float> dotSelect = Rectangle<float> (0, 0, height, height);
  61. dotSelect.reduce (12, 12);
  62. g.setColour (Colours::white);
  63. g.drawEllipse (dotSelect, 1);
  64. if (rowIsSelected)
  65. {
  66. g.fillAll (Colour(243, 145, 0));
  67. g.fillEllipse (dotSelect);
  68. }
  69. g.drawImageWithin (platforms.getUnchecked(rowNumber)->icon, 40, 0, height, height, RectanglePlacement::stretchToFit);
  70. g.setColour (Colours::black);
  71. g.drawText (platforms.getUnchecked (rowNumber)->name, 90, 0, width, height, Justification::left);
  72. }
  73. private:
  74. struct PlatformType {
  75. PlatformType (const Image& platformIcon, const String& platformName){
  76. icon = platformIcon;
  77. name = platformName;
  78. }
  79. Image icon;
  80. String name;
  81. };
  82. ListBox listBox;
  83. OwnedArray<PlatformType> platforms;
  84. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PlatformTargetsComp)
  85. };
  86. /**
  87. The Component for project creation.
  88. Features a file browser to select project destination and
  89. a list box of platform targets to generate.
  90. */
  91. //==============================================================================
  92. class WizardComp : public Component,
  93. private ButtonListener,
  94. private ComboBoxListener,
  95. private TextEditorListener
  96. {
  97. public:
  98. WizardComp()
  99. : projectName (TRANS("Project name")),
  100. nameLabel (String::empty, TRANS("Project Name") + ":"),
  101. typeLabel (String::empty, TRANS("Project Type") + ":"),
  102. fileBrowser (FileBrowserComponent::saveMode | FileBrowserComponent::canSelectDirectories,
  103. NewProjectWizardClasses::getLastWizardFolder(), nullptr, nullptr),
  104. fileOutline (String::empty, TRANS("Project Folder") + ":"),
  105. targetsOutline (String::empty, TRANS("Project Targets") + ":"),
  106. createButton (TRANS("Create") + "..."),
  107. cancelButton (TRANS("Cancel")),
  108. platformTargets()
  109. {
  110. setOpaque (false);
  111. addChildAndSetID (&projectName, "projectName");
  112. projectName.setText ("NewProject");
  113. projectName.setBounds ("120, 34, parent.width / 2 - 10, top + 22");
  114. nameLabel.attachToComponent (&projectName, true);
  115. projectName.addListener (this);
  116. addChildAndSetID (&projectType, "projectType");
  117. projectType.addItemList (getWizardNames(), 1);
  118. projectType.setSelectedId (1, dontSendNotification);
  119. projectType.setBounds ("120, projectName.bottom + 4, projectName.right, top + 22");
  120. typeLabel.attachToComponent (&projectType, true);
  121. projectType.addListener (this);
  122. addChildAndSetID (&fileOutline, "fileOutline");
  123. fileOutline.setColour (GroupComponent::outlineColourId, Colours::black.withAlpha (0.2f));
  124. fileOutline.setTextLabelPosition (Justification::centred);
  125. fileOutline.setBounds ("30, projectType.bottom + 20, projectType.right, parent.height - 30");
  126. addChildAndSetID (&targetsOutline, "targetsOutline");
  127. targetsOutline.setColour (GroupComponent::outlineColourId, Colours::black.withAlpha (0.2f));
  128. targetsOutline.setTextLabelPosition (Justification::centred);
  129. targetsOutline.setBounds ("fileOutline.right + 20, projectType.bottom + 20, parent.width - 30, parent.height - 70");
  130. addChildAndSetID (&platformTargets, "platformTargets");
  131. platformTargets.setBounds ("targetsOutline.left + 15, projectType.bottom + 45, parent.width - 40, parent.height - 90");
  132. addChildAndSetID (&fileBrowser, "fileBrowser");
  133. fileBrowser.setBounds ("fileOutline.left + 10, fileOutline.top + 20, fileOutline.right - 10, fileOutline.bottom - 32");
  134. fileBrowser.setFilenameBoxLabel ("Folder:");
  135. addChildAndSetID (&createButton, "createButton");
  136. createButton.setBounds ("right - 130, bottom - 34, parent.width - 30, parent.height - 30");
  137. createButton.addListener (this);
  138. addChildAndSetID (&cancelButton, "cancelButton");
  139. cancelButton.addShortcut (KeyPress (KeyPress::escapeKey));
  140. cancelButton.setBounds ("right - 130, createButton.top, createButton.left - 10, createButton.bottom");
  141. cancelButton.addListener (this);
  142. updateCustomItems();
  143. updateCreateButton();
  144. }
  145. void paint (Graphics& g) override
  146. {
  147. Rectangle<int> rect = getLocalBounds().reduced (10, 10);
  148. g.setColour (Colours::white.withAlpha(0.3f));
  149. g.fillRect (rect);
  150. g.fillRect (rect.reduced (10, 10));
  151. }
  152. void buttonClicked (Button* b) override
  153. {
  154. if (b == &createButton)
  155. {
  156. createProject();
  157. }
  158. else if (b == &cancelButton)
  159. {
  160. // returns to template icon page on cancel
  161. SlidingPanelComponent* parent = findParentComponentOfClass<SlidingPanelComponent>();
  162. if (parent->getNumTabs() > 0) parent->goToTab (parent->getCurrentTabIndex() - 1);
  163. }
  164. }
  165. void createProject()
  166. {
  167. MainWindow* mw = Component::findParentComponentOfClass<MainWindow>();
  168. jassert (mw != nullptr);
  169. ScopedPointer<NewProjectWizardClasses::NewProjectWizard> wizard (createWizard());
  170. if (wizard != nullptr)
  171. {
  172. Result result (wizard->processResultsFromSetupItems (*this));
  173. if (result.failed())
  174. {
  175. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  176. TRANS("Create Project"),
  177. result.getErrorMessage());
  178. return;
  179. }
  180. if (! wizard->selectJuceFolder())
  181. return;
  182. ScopedPointer<Project> project (wizard->runWizard (mw, projectName.getText(),
  183. fileBrowser.getSelectedFile (0)));
  184. if (project != nullptr)
  185. mw->setProject (project.release());
  186. }
  187. }
  188. void updateCustomItems()
  189. {
  190. customItems.clear();
  191. ScopedPointer<NewProjectWizardClasses::NewProjectWizard> wizard (createWizard());
  192. if (wizard != nullptr)
  193. wizard->addSetupItems (*this, customItems);
  194. }
  195. void comboBoxChanged (ComboBox*) override
  196. {
  197. updateCustomItems();
  198. }
  199. void textEditorTextChanged (TextEditor&) override
  200. {
  201. updateCreateButton();
  202. fileBrowser.setFileName (File::createLegalFileName (projectName.getText()));
  203. }
  204. // projectType box is public so it can be set by the introjucer front page icons
  205. ComboBox projectType;
  206. private:
  207. TextEditor projectName;
  208. Label nameLabel, typeLabel;
  209. FileBrowserComponent fileBrowser;
  210. GroupComponent fileOutline;
  211. GroupComponent targetsOutline;
  212. TextButton createButton, cancelButton;
  213. OwnedArray<Component> customItems;
  214. PlatformTargetsComp platformTargets;
  215. NewProjectWizardClasses::NewProjectWizard* createWizard()
  216. {
  217. return createWizardType (projectType.getSelectedItemIndex());
  218. }
  219. void updateCreateButton()
  220. {
  221. createButton.setEnabled (projectName.getText().trim().isNotEmpty());
  222. }
  223. };
  224. //==============================================================================
  225. static int getNumWizards()
  226. {
  227. return 5;
  228. }
  229. static NewProjectWizardClasses::NewProjectWizard* createWizardType (int index)
  230. {
  231. switch (index)
  232. {
  233. case 0: return new NewProjectWizardClasses::GUIAppWizard();
  234. case 1: return new NewProjectWizardClasses::ConsoleAppWizard();
  235. case 2: return new NewProjectWizardClasses::AudioPluginAppWizard();
  236. case 3: return new NewProjectWizardClasses::StaticLibraryWizard();
  237. case 4: return new NewProjectWizardClasses::DynamicLibraryWizard();
  238. default: jassertfalse; break;
  239. }
  240. return nullptr;
  241. }
  242. static StringArray getWizardNames()
  243. {
  244. StringArray s;
  245. for (int i = 0; i < getNumWizards(); ++i)
  246. {
  247. ScopedPointer<NewProjectWizardClasses::NewProjectWizard> wiz (createWizardType (i));
  248. s.add (wiz->getName());
  249. }
  250. return s;
  251. }
  252. #endif // NEWPROJECTWIZARDCOMPONENTS_H_INCLUDED