/* ============================================================================== This file is part of the JUCE library. Copyright (c) 2015 - ROLI Ltd. Permission is granted to use this software under the terms of either: a) the GPL v2 (or any later version) b) the Affero GPL v3 Details of these licenses can be found at: www.gnu.org/licenses JUCE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ------------------------------------------------------------------------------ To release a closed-source product which uses JUCE, commercial licenses are available: visit www.juce.com for more information. ============================================================================== */ struct IconButton : public Button { IconButton (String name, const Path* p) : Button (name), icon (p, Colours::transparentBlack) { lookAndFeelChanged(); setTooltip (name); } void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) override { auto alpha = 1.0f; if (! isEnabled()) { isMouseOverButton = false; isButtonDown = false; alpha = 0.2f; } auto backgroundColour = isIDEButton ? Colours::white : isUserButton ? findColour (userButtonBackgroundColourId) : findColour (defaultButtonBackgroundColourId); backgroundColour = isButtonDown ? backgroundColour.darker (0.5f) : isMouseOverButton ? backgroundColour.darker (0.2f) : backgroundColour; auto bounds = getLocalBounds().toFloat(); if (isButtonDown) bounds.reduce (2, 2); Path ellipse; ellipse.addEllipse (bounds); g.reduceClipRegion(ellipse); g.setColour (backgroundColour.withAlpha (alpha)); g.fillAll(); if (iconImage != Image()) { if (isIDEButton) bounds.reduce (7, 7); g.setOpacity (alpha); g.drawImage (iconImage, bounds, RectanglePlacement::fillDestination, false); } else { icon.withColour (findColour (defaultIconColourId).withAlpha (alpha)).draw (g, bounds.reduced (2, 2), false); } } Icon icon; Image iconImage; bool isIDEButton = false; bool isUserButton = false; }; //============================================================================== class UserSettingsPopup : public Component #if ! JUCER_ENABLE_GPL_MODE , private Button::Listener, private LicenseController::StateChangedCallback #endif { public: UserSettingsPopup (bool isShownInsideWebview) #if ! JUCER_ENABLE_GPL_MODE : isInsideWebview (isShownInsideWebview) #endif { #if JUCER_ENABLE_GPL_MODE ignoreUnused (isShownInsideWebview); #endif auto standardFont = Font (12.0f); addAndMakeVisible (loggedInUsernameLabel = new Label ("Username Label")); loggedInUsernameLabel->setFont (standardFont); loggedInUsernameLabel->setJustificationType (Justification::centred); loggedInUsernameLabel->setMinimumHorizontalScale (0.75f); #if JUCER_ENABLE_GPL_MODE loggedInUsernameLabel->setText ("GPL Mode: Re-compile with JUCER_ENABLE_GPL_MODE=0 to enable login!", NotificationType::dontSendNotification); #else addAndMakeVisible (licenseTypeLabel = new Label ("License Type Label")); licenseTypeLabel->setFont (standardFont); licenseTypeLabel->setJustificationType (Justification::centred); licenseTypeLabel->setMinimumHorizontalScale (1.0f); addAndMakeVisible (logoutButton = new TextButton (isInsideWebview ? "Select different account..." : "Logout")); logoutButton->addListener (this); logoutButton->setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId)); if (! isInsideWebview) { addAndMakeVisible (switchLicenseButton = new TextButton ("Switch License")); switchLicenseButton->addListener (this); } if (LicenseController* controller = ProjucerApplication::getApp().licenseController) licenseStateChanged (controller->getState()); #endif } void paint (Graphics& g) override { g.fillAll (findColour (secondaryBackgroundColourId)); } void resized() override { auto bounds = getLocalBounds().reduced (10, 20); #if JUCER_ENABLE_GPL_MODE loggedInUsernameLabel->setBounds (bounds); #else loggedInUsernameLabel->setBounds (bounds.removeFromTop (25)); if (hasLicenseType) { bounds.removeFromTop (10); licenseTypeLabel->setBounds (bounds.removeFromTop (25)); } bounds.removeFromBottom (5); auto buttonArea = bounds.removeFromBottom (30); if (! isInsideWebview) switchLicenseButton->setBounds (buttonArea.removeFromRight (buttonArea.getWidth() / 2).reduced (2)); logoutButton->setBounds (buttonArea.reduced (2)); #endif } private: //============================================================================== #if ! JUCER_ENABLE_GPL_MODE void buttonClicked (Button* b) override { if (b == logoutButton) { dismissCalloutBox(); ProjucerApplication::getApp().doLogout(); } else if (b == switchLicenseButton) { dismissCalloutBox(); if (LicenseController* controller = ProjucerApplication::getApp().licenseController) controller->chooseNewLicense(); } } void licenseStateChanged (const LicenseState& state) override { hasLicenseType = (state.type != LicenseState::Type::noLicenseChosenYet); licenseTypeLabel->setVisible (hasLicenseType); loggedInUsernameLabel->setText (state.username, NotificationType::dontSendNotification); licenseTypeLabel->setText (LicenseState::licenseTypeToString (state.type), NotificationType::dontSendNotification); } void dismissCalloutBox() { if (auto* parent = findParentComponentOfClass()) parent->dismiss(); } void lookAndFeelChanged() override { if (logoutButton != nullptr) logoutButton->setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId)); } #endif //============================================================================== ScopedPointer