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
6.0KB

  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 "../JuceLibraryCode/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. 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. //==============================================================================
  60. class DemoRunnerApplication : public JUCEApplication
  61. {
  62. public:
  63. //==============================================================================
  64. DemoRunnerApplication() {}
  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. void backButtonPressed() override { mainWindow->getMainComponent().getSidePanel().showOrHide (false); }
  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)