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.

759 lines
30KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include <typeinfo>
  20. #include "JuceDemoHeader.h"
  21. //==============================================================================
  22. struct AlphabeticDemoSorter
  23. {
  24. static int compareElements (const JuceDemoTypeBase* first, const JuceDemoTypeBase* second)
  25. {
  26. return first->name.compare (second->name);
  27. }
  28. };
  29. JuceDemoTypeBase::JuceDemoTypeBase (const String& demoName) : name (demoName)
  30. {
  31. AlphabeticDemoSorter sorter;
  32. getDemoTypeList().addSorted (sorter, this);
  33. }
  34. JuceDemoTypeBase::~JuceDemoTypeBase()
  35. {
  36. getDemoTypeList().removeFirstMatchingValue (this);
  37. }
  38. Array<JuceDemoTypeBase*>& JuceDemoTypeBase::getDemoTypeList()
  39. {
  40. static Array<JuceDemoTypeBase*> list;
  41. return list;
  42. }
  43. //==============================================================================
  44. #if JUCE_WINDOWS || JUCE_LINUX || JUCE_MAC
  45. // Just add a simple icon to the Window system tray area or Mac menu bar..
  46. struct DemoTaskbarComponent : public SystemTrayIconComponent,
  47. private Timer
  48. {
  49. DemoTaskbarComponent()
  50. {
  51. setIconImage (ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize));
  52. setIconTooltip ("Juce Demo App!");
  53. }
  54. void mouseDown (const MouseEvent&) override
  55. {
  56. // On OSX, there can be problems launching a menu when we're not the foreground
  57. // process, so just in case, we'll first make our process active, and then use a
  58. // timer to wait a moment before opening our menu, which gives the OS some time to
  59. // get its act together and bring our windows to the front.
  60. Process::makeForegroundProcess();
  61. startTimer (50);
  62. }
  63. // This is invoked when the menu is clicked or dismissed
  64. static void menuInvocationCallback (int chosenItemID, DemoTaskbarComponent*)
  65. {
  66. if (chosenItemID == 1)
  67. JUCEApplication::getInstance()->systemRequestedQuit();
  68. }
  69. void timerCallback() override
  70. {
  71. stopTimer();
  72. PopupMenu m;
  73. m.addItem (1, "Quit the Juce demo");
  74. // It's always better to open menus asynchronously when possible.
  75. m.showMenuAsync (PopupMenu::Options(),
  76. ModalCallbackFunction::forComponent (menuInvocationCallback, this));
  77. }
  78. };
  79. #endif
  80. bool juceDemoRepaintDebuggingActive = false;
  81. //==============================================================================
  82. class ContentComponent : public Component,
  83. public ListBoxModel,
  84. public ApplicationCommandTarget
  85. {
  86. public:
  87. ContentComponent()
  88. {
  89. // set lookAndFeel colour properties
  90. lookAndFeelV3.setColour (Label::textColourId, Colours::white);
  91. lookAndFeelV3.setColour (Label::textColourId, Colours::white);
  92. lookAndFeelV3.setColour (ToggleButton::textColourId, Colours::white);
  93. LookAndFeel::setDefaultLookAndFeel (&lookAndFeelV4);
  94. demoList.setModel (this);
  95. updateDemoListColours();
  96. demoList.selectRow (0);
  97. if (Desktop::getInstance().getMainMouseSource().isTouch())
  98. demoList.getViewport()->setScrollOnDragEnabled (true);
  99. addAndMakeVisible (demoList);
  100. }
  101. void clearCurrentDemo()
  102. {
  103. currentDemo = nullptr;
  104. }
  105. void resized() override
  106. {
  107. auto r = getLocalBounds();
  108. if (r.getWidth() > 600)
  109. {
  110. demoList.setBounds (r.removeFromLeft (210));
  111. demoList.setRowHeight (20);
  112. }
  113. else
  114. {
  115. demoList.setBounds (r.removeFromLeft (130));
  116. demoList.setRowHeight (30);
  117. }
  118. if (currentDemo != nullptr)
  119. currentDemo->setBounds (r);
  120. }
  121. int getNumRows() override
  122. {
  123. return JuceDemoTypeBase::getDemoTypeList().size();
  124. }
  125. void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected) override
  126. {
  127. if (rowIsSelected)
  128. g.fillAll (Colours::deepskyblue);
  129. if (auto* type = JuceDemoTypeBase::getDemoTypeList() [rowNumber])
  130. {
  131. auto name = type->name.trimCharactersAtStart ("0123456789").trimStart();
  132. AttributedString a;
  133. a.setJustification (Justification::centredLeft);
  134. String category;
  135. if (name.containsChar (':'))
  136. {
  137. category = name.upToFirstOccurrenceOf (":", true, false);
  138. name = name.fromFirstOccurrenceOf (":", false, false).trim();
  139. if (height > 20)
  140. category << "\n";
  141. else
  142. category << " ";
  143. }
  144. auto categoryColour = demoList.findColour (ListBox::outlineColourId);
  145. auto nameColour = demoList.findColour (ListBox::textColourId);
  146. if (category.isNotEmpty())
  147. a.append (category, Font (10.0f), categoryColour);
  148. a.append (name, Font (13.0f), nameColour);
  149. a.draw (g, Rectangle<int> (width + 10, height).reduced (6, 0).toFloat());
  150. }
  151. }
  152. void selectedRowsChanged (int lastRowSelected) override
  153. {
  154. if (auto* selectedDemoType = JuceDemoTypeBase::getDemoTypeList() [lastRowSelected])
  155. {
  156. currentDemo = nullptr;
  157. addAndMakeVisible (currentDemo = selectedDemoType->createComponent());
  158. currentDemo->setName (selectedDemoType->name);
  159. resized();
  160. }
  161. }
  162. MouseCursor getMouseCursorForRow (int /*row*/) override
  163. {
  164. return MouseCursor::PointingHandCursor;
  165. }
  166. int getCurrentPageIndex() const noexcept
  167. {
  168. if (currentDemo == nullptr)
  169. return -1;
  170. auto& demos = JuceDemoTypeBase::getDemoTypeList();
  171. for (int i = demos.size(); --i >= 0;)
  172. if (demos.getUnchecked (i)->name == currentDemo->getName())
  173. return i;
  174. return -1;
  175. }
  176. void moveDemoPages (int numPagesToMove)
  177. {
  178. demoList.selectRow (negativeAwareModulo (getCurrentPageIndex() + numPagesToMove,
  179. JuceDemoTypeBase::getDemoTypeList().size()));
  180. }
  181. bool isShowingOpenGLDemo() const
  182. {
  183. return currentDemo != nullptr
  184. && currentDemo->getName().contains ("OpenGL")
  185. && ! isShowingOpenGL2DDemo();
  186. }
  187. bool isShowingOpenGL2DDemo() const
  188. {
  189. return currentDemo != nullptr && currentDemo->getName().contains ("OpenGL 2D");
  190. }
  191. private:
  192. ListBox demoList;
  193. ScopedPointer<Component> currentDemo;
  194. LookAndFeel_V1 lookAndFeelV1;
  195. LookAndFeel_V2 lookAndFeelV2;
  196. LookAndFeel_V3 lookAndFeelV3;
  197. LookAndFeel_V4 lookAndFeelV4;
  198. //==============================================================================
  199. // The following methods implement the ApplicationCommandTarget interface, allowing
  200. // this window to publish a set of actions it can perform, and which can be mapped
  201. // onto menus, keypresses, etc.
  202. ApplicationCommandTarget* getNextCommandTarget() override
  203. {
  204. // this will return the next parent component that is an ApplicationCommandTarget (in this
  205. // case, there probably isn't one, but it's best to use this method in your own apps).
  206. return findFirstTargetParentComponent();
  207. }
  208. void getAllCommands (Array<CommandID>& commands) override
  209. {
  210. // this returns the set of all commands that this target can perform..
  211. const CommandID ids[] = { MainAppWindow::showPreviousDemo,
  212. MainAppWindow::showNextDemo,
  213. MainAppWindow::welcome,
  214. MainAppWindow::componentsAnimation,
  215. MainAppWindow::componentsDialogBoxes,
  216. MainAppWindow::componentsKeyMappings,
  217. MainAppWindow::componentsMDI,
  218. MainAppWindow::componentsPropertyEditors,
  219. MainAppWindow::componentsTransforms,
  220. MainAppWindow::componentsWebBrowsers,
  221. MainAppWindow::componentsWidgets,
  222. MainAppWindow::useLookAndFeelV1,
  223. MainAppWindow::useLookAndFeelV2,
  224. MainAppWindow::useLookAndFeelV3,
  225. MainAppWindow::useLookAndFeelV4Dark,
  226. MainAppWindow::useLookAndFeelV4Midnight,
  227. MainAppWindow::useLookAndFeelV4Grey,
  228. MainAppWindow::useLookAndFeelV4Light,
  229. MainAppWindow::toggleRepaintDebugging,
  230. #if ! JUCE_LINUX
  231. MainAppWindow::goToKioskMode,
  232. #endif
  233. MainAppWindow::useNativeTitleBar
  234. };
  235. commands.addArray (ids, numElementsInArray (ids));
  236. const CommandID engineIDs[] = { MainAppWindow::renderingEngineOne,
  237. MainAppWindow::renderingEngineTwo,
  238. MainAppWindow::renderingEngineThree };
  239. auto renderingEngines = MainAppWindow::getMainAppWindow()->getRenderingEngines();
  240. commands.addArray (engineIDs, renderingEngines.size());
  241. }
  242. void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result) override
  243. {
  244. const String generalCategory ("General");
  245. const String demosCategory ("Demos");
  246. switch (commandID)
  247. {
  248. case MainAppWindow::showPreviousDemo:
  249. result.setInfo ("Previous Demo", "Shows the previous demo in the list", demosCategory, 0);
  250. result.addDefaultKeypress ('-', ModifierKeys::commandModifier);
  251. break;
  252. case MainAppWindow::showNextDemo:
  253. result.setInfo ("Next Demo", "Shows the next demo in the list", demosCategory, 0);
  254. result.addDefaultKeypress ('=', ModifierKeys::commandModifier);
  255. break;
  256. case MainAppWindow::welcome:
  257. result.setInfo ("Welcome Demo", "Shows the 'Welcome' demo", demosCategory, 0);
  258. result.addDefaultKeypress ('1', ModifierKeys::commandModifier);
  259. break;
  260. case MainAppWindow::componentsAnimation:
  261. result.setInfo ("Animation Demo", "Shows the 'Animation' demo", demosCategory, 0);
  262. result.addDefaultKeypress ('2', ModifierKeys::commandModifier);
  263. break;
  264. case MainAppWindow::componentsDialogBoxes:
  265. result.setInfo ("Dialog Boxes Demo", "Shows the 'Dialog Boxes' demo", demosCategory, 0);
  266. result.addDefaultKeypress ('3', ModifierKeys::commandModifier);
  267. break;
  268. case MainAppWindow::componentsKeyMappings:
  269. result.setInfo ("Key Mappings Demo", "Shows the 'Key Mappings' demo", demosCategory, 0);
  270. result.addDefaultKeypress ('4', ModifierKeys::commandModifier);
  271. break;
  272. case MainAppWindow::componentsMDI:
  273. result.setInfo ("Multi-Document Demo", "Shows the 'Multi-Document' demo", demosCategory, 0);
  274. result.addDefaultKeypress ('5', ModifierKeys::commandModifier);
  275. break;
  276. case MainAppWindow::componentsPropertyEditors:
  277. result.setInfo ("Property Editor Demo", "Shows the 'Property Editor' demo", demosCategory, 0);
  278. result.addDefaultKeypress ('6', ModifierKeys::commandModifier);
  279. break;
  280. case MainAppWindow::componentsTransforms:
  281. result.setInfo ("Component Transforms Demo", "Shows the 'Transforms' demo", demosCategory, 0);
  282. result.addDefaultKeypress ('7', ModifierKeys::commandModifier);
  283. break;
  284. case MainAppWindow::componentsWebBrowsers:
  285. result.setInfo ("Web Browser Demo", "Shows the 'Web Browser' demo", demosCategory, 0);
  286. result.addDefaultKeypress ('8', ModifierKeys::commandModifier);
  287. break;
  288. case MainAppWindow::componentsWidgets:
  289. result.setInfo ("Widgets Demo", "Shows the 'Widgets' demo", demosCategory, 0);
  290. result.addDefaultKeypress ('9', ModifierKeys::commandModifier);
  291. break;
  292. case MainAppWindow::renderingEngineOne:
  293. case MainAppWindow::renderingEngineTwo:
  294. case MainAppWindow::renderingEngineThree:
  295. {
  296. auto& mainWindow = *MainAppWindow::getMainAppWindow();
  297. auto engines = mainWindow.getRenderingEngines();
  298. const int index = commandID - MainAppWindow::renderingEngineOne;
  299. result.setInfo ("Use " + engines[index], "Uses the " + engines[index] + " engine to render the UI", generalCategory, 0);
  300. result.setTicked (mainWindow.getActiveRenderingEngine() == index);
  301. result.addDefaultKeypress ('1' + index, ModifierKeys::noModifiers);
  302. break;
  303. }
  304. case MainAppWindow::useLookAndFeelV1:
  305. result.setInfo ("Use LookAndFeel_V1", String(), generalCategory, 0);
  306. result.addDefaultKeypress ('i', ModifierKeys::commandModifier);
  307. result.setTicked (isLookAndFeelSelected<LookAndFeel_V1>());
  308. break;
  309. case MainAppWindow::useLookAndFeelV2:
  310. result.setInfo ("Use LookAndFeel_V2", String(), generalCategory, 0);
  311. result.addDefaultKeypress ('o', ModifierKeys::commandModifier);
  312. result.setTicked (isLookAndFeelSelected<LookAndFeel_V2>());
  313. break;
  314. case MainAppWindow::useLookAndFeelV3:
  315. result.setInfo ("Use LookAndFeel_V3", String(), generalCategory, 0);
  316. result.addDefaultKeypress ('p', ModifierKeys::commandModifier);
  317. result.setTicked (isLookAndFeelSelected<LookAndFeel_V3>());
  318. break;
  319. case MainAppWindow::useLookAndFeelV4Dark:
  320. result.setInfo ("Use LookAndFeel_V4 Dark", String(), generalCategory, 0);
  321. result.addDefaultKeypress ('k', ModifierKeys::commandModifier);
  322. result.setTicked (isColourSchemeActive (LookAndFeel_V4::getDarkColourScheme()));
  323. break;
  324. case MainAppWindow::useLookAndFeelV4Midnight:
  325. result.setInfo ("Use LookAndFeel_V4 Midnight", String(), generalCategory, 0);
  326. result.setTicked (isColourSchemeActive (LookAndFeel_V4::getMidnightColourScheme()));
  327. break;
  328. case MainAppWindow::useLookAndFeelV4Grey:
  329. result.setInfo ("Use LookAndFeel_V4 Grey", String(), generalCategory, 0);
  330. result.setTicked (isColourSchemeActive (LookAndFeel_V4::getGreyColourScheme()));
  331. break;
  332. case MainAppWindow::useLookAndFeelV4Light:
  333. result.setInfo ("Use LookAndFeel_V4 Light", String(), generalCategory, 0);
  334. result.setTicked (isColourSchemeActive (LookAndFeel_V4::getLightColourScheme()));
  335. break;
  336. case MainAppWindow::toggleRepaintDebugging:
  337. result.setInfo ("Toggle repaint display", String(), generalCategory, 0);
  338. result.addDefaultKeypress ('r', ModifierKeys());
  339. result.setTicked (juceDemoRepaintDebuggingActive);
  340. break;
  341. case MainAppWindow::useNativeTitleBar:
  342. {
  343. result.setInfo ("Use native window title bar", String(), generalCategory, 0);
  344. result.addDefaultKeypress ('n', ModifierKeys::commandModifier);
  345. bool nativeTitlebar = false;
  346. if (auto* mainWindow = MainAppWindow::getMainAppWindow())
  347. nativeTitlebar = mainWindow->isUsingNativeTitleBar();
  348. result.setTicked (nativeTitlebar);
  349. break;
  350. }
  351. #if ! JUCE_LINUX
  352. case MainAppWindow::goToKioskMode:
  353. result.setInfo ("Show full-screen kiosk mode", String(), generalCategory, 0);
  354. result.addDefaultKeypress ('f', ModifierKeys::commandModifier);
  355. result.setTicked (Desktop::getInstance().getKioskModeComponent() != 0);
  356. break;
  357. #endif
  358. default:
  359. break;
  360. }
  361. }
  362. bool perform (const InvocationInfo& info) override
  363. {
  364. if (auto* mainWindow = MainAppWindow::getMainAppWindow())
  365. {
  366. switch (info.commandID)
  367. {
  368. case MainAppWindow::showPreviousDemo: moveDemoPages (-1); break;
  369. case MainAppWindow::showNextDemo: moveDemoPages ( 1); break;
  370. case MainAppWindow::welcome:
  371. case MainAppWindow::componentsAnimation:
  372. case MainAppWindow::componentsDialogBoxes:
  373. case MainAppWindow::componentsKeyMappings:
  374. case MainAppWindow::componentsMDI:
  375. case MainAppWindow::componentsPropertyEditors:
  376. case MainAppWindow::componentsTransforms:
  377. case MainAppWindow::componentsWebBrowsers:
  378. case MainAppWindow::componentsWidgets:
  379. demoList.selectRow (info.commandID - MainAppWindow::welcome);
  380. break;
  381. case MainAppWindow::renderingEngineOne:
  382. case MainAppWindow::renderingEngineTwo:
  383. case MainAppWindow::renderingEngineThree:
  384. mainWindow->setRenderingEngine (info.commandID - MainAppWindow::renderingEngineOne);
  385. break;
  386. case MainAppWindow::useLookAndFeelV1:
  387. LookAndFeel::setDefaultLookAndFeel (&lookAndFeelV1);
  388. updateDemoListColours();
  389. break;
  390. case MainAppWindow::useLookAndFeelV2:
  391. LookAndFeel::setDefaultLookAndFeel (&lookAndFeelV2);
  392. updateDemoListColours();
  393. break;
  394. case MainAppWindow::useLookAndFeelV3:
  395. LookAndFeel::setDefaultLookAndFeel (&lookAndFeelV3);
  396. updateDemoListColours();
  397. break;
  398. case MainAppWindow::useLookAndFeelV4Dark:
  399. lookAndFeelV4.setColourScheme (LookAndFeel_V4::getDarkColourScheme());
  400. LookAndFeel::setDefaultLookAndFeel (&lookAndFeelV4);
  401. updateDemoListColours();
  402. break;
  403. case MainAppWindow::useLookAndFeelV4Midnight:
  404. lookAndFeelV4.setColourScheme (LookAndFeel_V4::getMidnightColourScheme());
  405. LookAndFeel::setDefaultLookAndFeel (&lookAndFeelV4);
  406. updateDemoListColours();
  407. break;
  408. case MainAppWindow::useLookAndFeelV4Grey:
  409. lookAndFeelV4.setColourScheme (LookAndFeel_V4::getGreyColourScheme());
  410. LookAndFeel::setDefaultLookAndFeel (&lookAndFeelV4);
  411. updateDemoListColours();
  412. break;
  413. case MainAppWindow::useLookAndFeelV4Light:
  414. lookAndFeelV4.setColourScheme (LookAndFeel_V4::getLightColourScheme());
  415. LookAndFeel::setDefaultLookAndFeel (&lookAndFeelV4);
  416. updateDemoListColours();
  417. break;
  418. case MainAppWindow::toggleRepaintDebugging:
  419. juceDemoRepaintDebuggingActive = ! juceDemoRepaintDebuggingActive;
  420. mainWindow->repaint();
  421. break;
  422. case MainAppWindow::useNativeTitleBar:
  423. mainWindow->setUsingNativeTitleBar (! mainWindow->isUsingNativeTitleBar());
  424. break;
  425. #if ! JUCE_LINUX
  426. case MainAppWindow::goToKioskMode:
  427. {
  428. auto& desktop = Desktop::getInstance();
  429. if (desktop.getKioskModeComponent() == nullptr)
  430. desktop.setKioskModeComponent (getTopLevelComponent());
  431. else
  432. desktop.setKioskModeComponent (nullptr);
  433. break;
  434. }
  435. #endif
  436. default:
  437. return false;
  438. }
  439. }
  440. return true;
  441. }
  442. template <typename LookAndFeelType>
  443. bool isLookAndFeelSelected()
  444. {
  445. LookAndFeel& lf = getLookAndFeel();
  446. return typeid (LookAndFeelType) == typeid (lf);
  447. }
  448. bool isColourSchemeActive (LookAndFeel_V4::ColourScheme scheme)
  449. {
  450. if (auto* v4 = dynamic_cast<LookAndFeel_V4*> (&LookAndFeel::getDefaultLookAndFeel()))
  451. if (v4->getCurrentColourScheme() == scheme)
  452. return true;
  453. return false;
  454. }
  455. void updateDemoListColours()
  456. {
  457. demoList.setColour (ListBox::backgroundColourId,
  458. getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::widgetBackground, Colour::greyLevel (0.2f)));
  459. demoList.setColour (ListBox::textColourId,
  460. getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText,
  461. Colours::white.withAlpha (0.9f)));
  462. demoList.setColour (ListBox::outlineColourId,
  463. getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText,
  464. Colour::greyLevel (0.5f)).interpolatedWith (Colours::red, 0.4f));
  465. }
  466. };
  467. //==============================================================================
  468. static ScopedPointer<ApplicationCommandManager> applicationCommandManager;
  469. static ScopedPointer<AudioDeviceManager> sharedAudioDeviceManager;
  470. MainAppWindow::MainAppWindow()
  471. : DocumentWindow (JUCEApplication::getInstance()->getApplicationName(),
  472. LookAndFeel::getDefaultLookAndFeel().findColour (ResizableWindow::backgroundColourId),
  473. DocumentWindow::allButtons)
  474. {
  475. setUsingNativeTitleBar (true);
  476. setResizable (true, false);
  477. setResizeLimits (400, 400, 10000, 10000);
  478. #if JUCE_IOS || JUCE_ANDROID
  479. setFullScreen (true);
  480. #else
  481. setBounds ((int) (0.1f * getParentWidth()),
  482. (int) (0.1f * getParentHeight()),
  483. jmax (850, (int) (0.5f * getParentWidth())),
  484. jmax (600, (int) (0.7f * getParentHeight())));
  485. #endif
  486. contentComponent = new ContentComponent();
  487. setContentNonOwned (contentComponent, false);
  488. setVisible (true);
  489. // this lets the command manager use keypresses that arrive in our window to send out commands
  490. addKeyListener (getApplicationCommandManager().getKeyMappings());
  491. #if JUCE_WINDOWS || JUCE_LINUX || JUCE_MAC
  492. taskbarIcon = new DemoTaskbarComponent();
  493. #endif
  494. #if JUCE_ANDROID
  495. setOpenGLRenderingEngine();
  496. #endif
  497. triggerAsyncUpdate();
  498. }
  499. MainAppWindow::~MainAppWindow()
  500. {
  501. contentComponent->clearCurrentDemo();
  502. clearContentComponent();
  503. contentComponent = nullptr;
  504. applicationCommandManager = nullptr;
  505. sharedAudioDeviceManager = nullptr;
  506. #if JUCE_OPENGL
  507. openGLContext.detach();
  508. #endif
  509. }
  510. void MainAppWindow::closeButtonPressed()
  511. {
  512. JUCEApplication::getInstance()->systemRequestedQuit();
  513. }
  514. ApplicationCommandManager& MainAppWindow::getApplicationCommandManager()
  515. {
  516. if (applicationCommandManager == nullptr)
  517. applicationCommandManager = new ApplicationCommandManager();
  518. return *applicationCommandManager;
  519. }
  520. AudioDeviceManager& MainAppWindow::getSharedAudioDeviceManager()
  521. {
  522. if (sharedAudioDeviceManager == nullptr)
  523. {
  524. sharedAudioDeviceManager = new AudioDeviceManager();
  525. RuntimePermissions::request (RuntimePermissions::recordAudio, runtimePermissionsCallback);
  526. }
  527. return *sharedAudioDeviceManager;
  528. }
  529. void MainAppWindow::runtimePermissionsCallback (bool wasGranted)
  530. {
  531. int numInputChannels = wasGranted ? 2 : 0;
  532. sharedAudioDeviceManager->initialise (numInputChannels, 2, nullptr, true, String(), nullptr);
  533. }
  534. MainAppWindow* MainAppWindow::getMainAppWindow()
  535. {
  536. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  537. if (auto* maw = dynamic_cast<MainAppWindow*> (TopLevelWindow::getTopLevelWindow (i)))
  538. return maw;
  539. return nullptr;
  540. }
  541. void MainAppWindow::handleAsyncUpdate()
  542. {
  543. // This registers all of our commands with the command manager but has to be done after the window has
  544. // been created so we can find the number of rendering engines available
  545. auto& commandManager = MainAppWindow::getApplicationCommandManager();
  546. commandManager.registerAllCommandsForTarget (contentComponent);
  547. commandManager.registerAllCommandsForTarget (JUCEApplication::getInstance());
  548. }
  549. void MainAppWindow::showMessageBubble (const String& text)
  550. {
  551. currentBubbleMessage = new BubbleMessageComponent (500);
  552. getContentComponent()->addChildComponent (currentBubbleMessage);
  553. AttributedString attString;
  554. attString.append (text, Font (15.0f));
  555. currentBubbleMessage->showAt ({ getLocalBounds().getCentreX(), 10, 1, 1 },
  556. attString,
  557. 500, // numMillisecondsBeforeRemoving
  558. true, // removeWhenMouseClicked
  559. false); // deleteSelfAfterUse
  560. }
  561. static const char* openGLRendererName = "OpenGL Renderer";
  562. StringArray MainAppWindow::getRenderingEngines() const
  563. {
  564. StringArray renderingEngines;
  565. if (auto* peer = getPeer())
  566. renderingEngines = peer->getAvailableRenderingEngines();
  567. #if JUCE_OPENGL
  568. renderingEngines.add (openGLRendererName);
  569. #endif
  570. return renderingEngines;
  571. }
  572. void MainAppWindow::setRenderingEngine (int index)
  573. {
  574. showMessageBubble (getRenderingEngines()[index]);
  575. #if JUCE_OPENGL
  576. if (getRenderingEngines()[index] == openGLRendererName
  577. && contentComponent != nullptr
  578. && ! contentComponent->isShowingOpenGLDemo())
  579. {
  580. openGLContext.attachTo (*getTopLevelComponent());
  581. return;
  582. }
  583. openGLContext.detach();
  584. #endif
  585. if (auto* peer = getPeer())
  586. peer->setCurrentRenderingEngine (index);
  587. }
  588. void MainAppWindow::setOpenGLRenderingEngine()
  589. {
  590. setRenderingEngine (getRenderingEngines().indexOf (openGLRendererName));
  591. }
  592. int MainAppWindow::getActiveRenderingEngine() const
  593. {
  594. #if JUCE_OPENGL
  595. if (openGLContext.isAttached())
  596. return getRenderingEngines().indexOf (openGLRendererName);
  597. #endif
  598. if (auto* peer = getPeer())
  599. return peer->getCurrentRenderingEngine();
  600. return 0;
  601. }
  602. Path MainAppWindow::getJUCELogoPath()
  603. {
  604. return Drawable::parseSVGPath (
  605. "M250,301.3c-37.2,0-67.5-30.3-67.5-67.5s30.3-67.5,67.5-67.5s67.5,30.3,67.5,67.5S287.2,301.3,250,301.3zM250,170.8c-34.7,0-63,28.3-63,63s28.3,63,63,63s63-28.3,63-63S284.7,170.8,250,170.8z"
  606. "M247.8,180.4c0-2.3-1.8-4.1-4.1-4.1c-0.2,0-0.3,0-0.5,0c-10.6,1.2-20.6,5.4-29,12c-1,0.8-1.5,1.8-1.6,2.9c-0.1,1.2,0.4,2.3,1.3,3.2l32.5,32.5c0.5,0.5,1.4,0.1,1.4-0.6V180.4z"
  607. "M303.2,231.6c1.2,0,2.3-0.4,3.1-1.2c0.9-0.9,1.3-2.1,1.1-3.3c-1.2-10.6-5.4-20.6-12-29c-0.8-1-1.9-1.6-3.2-1.6c-1.1,0-2.1,0.5-3,1.3l-32.5,32.5c-0.5,0.5-0.1,1.4,0.6,1.4L303.2,231.6z"
  608. "M287.4,191.3c-0.1-1.1-0.6-2.2-1.6-2.9c-8.4-6.6-18.4-10.8-29-12c-0.2,0-0.3,0-0.5,0c-2.3,0-4.1,1.9-4.1,4.1v46c0,0.7,0.9,1.1,1.4,0.6l32.5-32.5C287,193.6,287.5,192.5,287.4,191.3z"
  609. "M252.2,287.2c0,2.3,1.8,4.1,4.1,4.1c0.2,0,0.3,0,0.5,0c10.6-1.2,20.6-5.4,29-12c1-0.8,1.5-1.8,1.6-2.9c0.1-1.2-0.4-2.3-1.3-3.2l-32.5-32.5c-0.5-0.5-1.4-0.1-1.4,0.6V287.2z"
  610. "M292.3,271.2L292.3,271.2c1.2,0,2.4-0.6,3.2-1.6c6.6-8.4,10.8-18.4,12-29c0.1-1.2-0.3-2.4-1.1-3.3c-0.8-0.8-1.9-1.2-3.1-1.2l-45.9,0c-0.7,0-1.1,0.9-0.6,1.4l32.5,32.5C290.2,270.8,291.2,271.2,292.3,271.2z"
  611. "M207.7,196.4c-1.2,0-2.4,0.6-3.2,1.6c-6.6,8.4-10.8,18.4-12,29c-0.1,1.2,0.3,2.4,1.1,3.3c0.8,0.8,1.9,1.2,3.1,1.2l45.9,0c0.7,0,1.1-0.9,0.6-1.4l-32.5-32.5C209.8,196.8,208.8,196.4,207.7,196.4z"
  612. "M242.6,236.1l-45.9,0c-1.2,0-2.3,0.4-3.1,1.2c-0.9,0.9-1.3,2.1-1.1,3.3c1.2,10.6,5.4,20.6,12,29c0.8,1,1.9,1.6,3.2,1.6c1.1,0,2.1-0.5,3-1.3c0,0,0,0,0,0l32.5-32.5C243.7,236.9,243.4,236.1,242.6,236.1z"
  613. "M213.8,273.1L213.8,273.1c-0.9,0.9-1.3,2-1.3,3.2c0.1,1.1,0.6,2.2,1.6,2.9c8.4,6.6,18.4,10.8,29,12c0.2,0,0.3,0,0.5,0h0c1.2,0,2.3-0.5,3.1-1.4c0.7-0.8,1-1.8,1-2.9v-45.9c0-0.7-0.9-1.1-1.4-0.6l-13.9,13.9L213.8,273.1z"
  614. "M197.2,353c-4.1,0-7.4-1.5-10.4-5.4l4-3.5c2,2.6,3.9,3.6,6.4,3.6c4.4,0,7.4-3.3,7.4-8.3v-24.7h5.6v24.7C210.2,347.5,204.8,353,197.2,353z"
  615. "M232.4,353c-8.1,0-15-6-15-15.8v-22.5h5.6v22.2c0,6.6,3.9,10.8,9.5,10.8c5.6,0,9.5-4.3,9.5-10.8v-22.2h5.6v22.5C247.5,347,240.5,353,232.4,353z"
  616. "M272,353c-10.8,0-19.5-8.6-19.5-19.3c0-10.8,8.8-19.3,19.5-19.3c4.8,0,9,1.6,12.3,4.4l-3.3,4.1c-3.4-2.4-5.7-3.2-8.9-3.2c-7.7,0-13.8,6.2-13.8,14.1c0,7.9,6.1,14.1,13.8,14.1c3.1,0,5.6-1,8.8-3.2l3.3,4.1C280.1,351.9,276.4,353,272,353z"
  617. "M290.4,352.5v-37.8h22.7v5H296v11.2h16.5v5H296v11.6h17.2v5H290.4z");
  618. };