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.

166 lines
6.2KB

  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 <JuceHeader.h>
  20. #include "../../Assets/DemoUtilities.h"
  21. #include "UI/MainComponent.h"
  22. //==============================================================================
  23. #if JUCE_WINDOWS || JUCE_LINUX || JUCE_MAC
  24. // Just add a simple icon to the Window system tray area or Mac menu bar..
  25. struct DemoTaskbarComponent : public SystemTrayIconComponent,
  26. private Timer
  27. {
  28. DemoTaskbarComponent()
  29. {
  30. setIconImage (getImageFromAssets ("juce_icon.png"),
  31. getImageFromAssets ("juce_icon_template.png"));
  32. setIconTooltip ("JUCE demo runner!");
  33. }
  34. void mouseDown (const MouseEvent&) override
  35. {
  36. // On OSX, there can be problems launching a menu when we're not the foreground
  37. // process, so just in case, we'll first make our process active, and then use a
  38. // timer to wait a moment before opening our menu, which gives the OS some time to
  39. // get its act together and bring our windows to the front.
  40. Process::makeForegroundProcess();
  41. startTimer (50);
  42. }
  43. // This is invoked when the menu is clicked or dismissed
  44. static void menuInvocationCallback (int chosenItemID, DemoTaskbarComponent*)
  45. {
  46. if (chosenItemID == 1)
  47. JUCEApplication::getInstance()->systemRequestedQuit();
  48. }
  49. void timerCallback() override
  50. {
  51. stopTimer();
  52. PopupMenu m;
  53. m.addItem (1, "Quit");
  54. // It's always better to open menus asynchronously when possible.
  55. m.showMenuAsync (PopupMenu::Options(),
  56. ModalCallbackFunction::forComponent (menuInvocationCallback, this));
  57. }
  58. };
  59. #endif
  60. std::unique_ptr<AudioDeviceManager> sharedAudioDeviceManager;
  61. //==============================================================================
  62. class DemoRunnerApplication : public JUCEApplication
  63. {
  64. public:
  65. //==============================================================================
  66. DemoRunnerApplication() {}
  67. ~DemoRunnerApplication() override
  68. {
  69. sharedAudioDeviceManager.reset();
  70. }
  71. const String getApplicationName() override { return ProjectInfo::projectName; }
  72. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  73. bool moreThanOneInstanceAllowed() override { return true; }
  74. //==============================================================================
  75. void initialise (const String& commandLine) override
  76. {
  77. registerAllDemos();
  78. #if JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX
  79. // (This function call is for one of the demos, which involves launching a child process)
  80. if (invokeChildProcessDemo (commandLine))
  81. return;
  82. #else
  83. ignoreUnused (commandLine);
  84. #endif
  85. mainWindow.reset (new MainAppWindow (getApplicationName()));
  86. }
  87. bool backButtonPressed() override { mainWindow->getMainComponent().getSidePanel().showOrHide (false); return true; }
  88. void shutdown() override { mainWindow = nullptr; }
  89. //==============================================================================
  90. void systemRequestedQuit() override { quit(); }
  91. void anotherInstanceStarted (const String&) override {}
  92. private:
  93. class MainAppWindow : public DocumentWindow
  94. {
  95. public:
  96. MainAppWindow (const String& name)
  97. : DocumentWindow (name, Desktop::getInstance().getDefaultLookAndFeel()
  98. .findColour (ResizableWindow::backgroundColourId),
  99. DocumentWindow::allButtons)
  100. {
  101. setUsingNativeTitleBar (true);
  102. setResizable (true, false);
  103. setResizeLimits (400, 400, 10000, 10000);
  104. #if JUCE_IOS || JUCE_ANDROID
  105. setFullScreen (true);
  106. Desktop::getInstance().setOrientationsEnabled (Desktop::rotatedClockwise | Desktop::rotatedAntiClockwise);
  107. #else
  108. setBounds ((int) (0.1f * getParentWidth()),
  109. (int) (0.1f * getParentHeight()),
  110. jmax (850, (int) (0.5f * getParentWidth())),
  111. jmax (600, (int) (0.7f * getParentHeight())));
  112. #endif
  113. setContentOwned (new MainComponent(), false);
  114. setVisible (true);
  115. #if JUCE_WINDOWS || JUCE_LINUX || JUCE_MAC
  116. taskbarIcon.reset (new DemoTaskbarComponent());
  117. #endif
  118. }
  119. void closeButtonPressed() override { JUCEApplication::getInstance()->systemRequestedQuit(); }
  120. //==============================================================================
  121. MainComponent& getMainComponent() { return *dynamic_cast<MainComponent*> (getContentComponent()); }
  122. private:
  123. std::unique_ptr<Component> taskbarIcon;
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainAppWindow)
  125. };
  126. std::unique_ptr<MainAppWindow> mainWindow;
  127. };
  128. //==============================================================================
  129. // This macro generates the main() routine that launches the app.
  130. START_JUCE_APPLICATION (DemoRunnerApplication)