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.

177 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #include <JuceHeader.h>
  19. #include "../../Assets/DemoUtilities.h"
  20. #include "UI/MainComponent.h"
  21. //==============================================================================
  22. #if JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD
  23. // Just add a simple icon to the Window system tray area or Mac menu bar..
  24. struct DemoTaskbarComponent : public SystemTrayIconComponent,
  25. private Timer
  26. {
  27. DemoTaskbarComponent()
  28. {
  29. setIconImage (getImageFromAssets ("juce_icon.png"),
  30. getImageFromAssets ("juce_icon_template.png"));
  31. setIconTooltip ("JUCE demo runner!");
  32. }
  33. void mouseDown (const MouseEvent&) override
  34. {
  35. // On OSX, there can be problems launching a menu when we're not the foreground
  36. // process, so just in case, we'll first make our process active, and then use a
  37. // timer to wait a moment before opening our menu, which gives the OS some time to
  38. // get its act together and bring our windows to the front.
  39. Process::makeForegroundProcess();
  40. startTimer (50);
  41. }
  42. // This is invoked when the menu is clicked or dismissed
  43. static void menuInvocationCallback (int chosenItemID, DemoTaskbarComponent*)
  44. {
  45. if (chosenItemID == 1)
  46. JUCEApplication::getInstance()->systemRequestedQuit();
  47. }
  48. void timerCallback() override
  49. {
  50. stopTimer();
  51. PopupMenu m;
  52. m.addItem (1, "Quit");
  53. // It's always better to open menus asynchronously when possible.
  54. m.showMenuAsync (PopupMenu::Options(),
  55. ModalCallbackFunction::forComponent (menuInvocationCallback, this));
  56. }
  57. };
  58. #endif
  59. std::unique_ptr<AudioDeviceManager> sharedAudioDeviceManager;
  60. //==============================================================================
  61. class DemoRunnerApplication : public JUCEApplication
  62. {
  63. public:
  64. //==============================================================================
  65. DemoRunnerApplication() {}
  66. ~DemoRunnerApplication() override
  67. {
  68. sharedAudioDeviceManager.reset();
  69. }
  70. const String getApplicationName() override { return ProjectInfo::projectName; }
  71. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  72. bool moreThanOneInstanceAllowed() override { return true; }
  73. //==============================================================================
  74. void initialise (const String& commandLine) override
  75. {
  76. registerAllDemos();
  77. #if JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD
  78. // (This function call is for one of the demos, which involves launching a child process)
  79. if (invokeChildProcessDemo (commandLine))
  80. return;
  81. #else
  82. ignoreUnused (commandLine);
  83. #endif
  84. mainWindow.reset (new MainAppWindow (getApplicationName()));
  85. }
  86. bool backButtonPressed() override { mainWindow->getMainComponent().getSidePanel().showOrHide (false); return true; }
  87. void shutdown() override { mainWindow = nullptr; }
  88. //==============================================================================
  89. void systemRequestedQuit() override { quit(); }
  90. void anotherInstanceStarted (const String&) override {}
  91. ApplicationCommandManager& getGlobalCommandManager() { return commandManager; }
  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. auto& desktop = Desktop::getInstance();
  107. desktop.setOrientationsEnabled (Desktop::allOrientations);
  108. desktop.setKioskModeComponent (this);
  109. #else
  110. setBounds ((int) (0.1f * (float) getParentWidth()),
  111. (int) (0.1f * (float) getParentHeight()),
  112. jmax (850, (int) (0.5f * (float) getParentWidth())),
  113. jmax (600, (int) (0.7f * (float) getParentHeight())));
  114. #endif
  115. setContentOwned (new MainComponent(), false);
  116. setVisible (true);
  117. #if JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD
  118. taskbarIcon.reset (new DemoTaskbarComponent());
  119. #endif
  120. }
  121. void closeButtonPressed() override { JUCEApplication::getInstance()->systemRequestedQuit(); }
  122. //==============================================================================
  123. MainComponent& getMainComponent() { return *dynamic_cast<MainComponent*> (getContentComponent()); }
  124. private:
  125. std::unique_ptr<Component> taskbarIcon;
  126. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainAppWindow)
  127. };
  128. std::unique_ptr<MainAppWindow> mainWindow;
  129. ApplicationCommandManager commandManager;
  130. };
  131. ApplicationCommandManager& getGlobalCommandManager()
  132. {
  133. return dynamic_cast<DemoRunnerApplication*> (JUCEApplication::getInstance())->getGlobalCommandManager();
  134. }
  135. //==============================================================================
  136. // This macro generates the main() routine that launches the app.
  137. START_JUCE_APPLICATION (DemoRunnerApplication)