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