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.

158 lines
5.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - 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 this technical preview, this file is not subject to commercial licensing.
  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_WINDOWS || JUCE_LINUX || JUCE_MAC
  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
  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. private:
  87. class MainAppWindow : public DocumentWindow
  88. {
  89. public:
  90. MainAppWindow (const String& name)
  91. : DocumentWindow (name, Desktop::getInstance().getDefaultLookAndFeel()
  92. .findColour (ResizableWindow::backgroundColourId),
  93. DocumentWindow::allButtons)
  94. {
  95. setUsingNativeTitleBar (true);
  96. setResizable (true, false);
  97. setResizeLimits (400, 400, 10000, 10000);
  98. #if JUCE_IOS || JUCE_ANDROID
  99. setFullScreen (true);
  100. Desktop::getInstance().setOrientationsEnabled (Desktop::rotatedClockwise | Desktop::rotatedAntiClockwise);
  101. #else
  102. setBounds ((int) (0.1f * getParentWidth()),
  103. (int) (0.1f * getParentHeight()),
  104. jmax (850, (int) (0.5f * getParentWidth())),
  105. jmax (600, (int) (0.7f * getParentHeight())));
  106. #endif
  107. setContentOwned (new MainComponent(), false);
  108. setVisible (true);
  109. #if JUCE_WINDOWS || JUCE_LINUX || JUCE_MAC
  110. taskbarIcon.reset (new DemoTaskbarComponent());
  111. #endif
  112. }
  113. void closeButtonPressed() override { JUCEApplication::getInstance()->systemRequestedQuit(); }
  114. //==============================================================================
  115. MainComponent& getMainComponent() { return *dynamic_cast<MainComponent*> (getContentComponent()); }
  116. private:
  117. std::unique_ptr<Component> taskbarIcon;
  118. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainAppWindow)
  119. };
  120. std::unique_ptr<MainAppWindow> mainWindow;
  121. };
  122. //==============================================================================
  123. // This macro generates the main() routine that launches the app.
  124. START_JUCE_APPLICATION (DemoRunnerApplication)