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.

170 lines
6.3KB

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