VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_gui_basics / buttons / juce_HyperlinkButton.cpp
blob1fdd25a23fd984c699763532a6b71c953a568b21
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 HyperlinkButton::HyperlinkButton (const String& linkText,
30 const URL& linkURL)
31 : Button (linkText),
32 url (linkURL),
33 font (14.0f, Font::underlined),
34 resizeFont (true),
35 justification (Justification::centred)
37 setMouseCursor (MouseCursor::PointingHandCursor);
38 setTooltip (linkURL.toString (false));
41 HyperlinkButton::HyperlinkButton()
42 : Button (String()),
43 font (14.0f, Font::underlined),
44 resizeFont (true),
45 justification (Justification::centred)
47 setMouseCursor (MouseCursor::PointingHandCursor);
50 HyperlinkButton::~HyperlinkButton()
54 //==============================================================================
55 void HyperlinkButton::setFont (const Font& newFont,
56 const bool resizeToMatchComponentHeight,
57 Justification justificationType)
59 font = newFont;
60 resizeFont = resizeToMatchComponentHeight;
61 justification = justificationType;
62 repaint();
65 void HyperlinkButton::setURL (const URL& newURL) noexcept
67 url = newURL;
68 setTooltip (newURL.toString (false));
71 Font HyperlinkButton::getFontToUse() const
73 if (resizeFont)
74 return font.withHeight ((float) getHeight() * 0.7f);
76 return font;
79 void HyperlinkButton::changeWidthToFitText()
81 setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight());
84 void HyperlinkButton::setJustificationType (Justification newJustification)
86 if (justification != newJustification)
88 justification = newJustification;
89 repaint();
93 void HyperlinkButton::colourChanged()
95 repaint();
98 //==============================================================================
99 void HyperlinkButton::clicked()
101 if (url.isWellFormed())
102 url.launchInDefaultBrowser();
105 void HyperlinkButton::paintButton (Graphics& g,
106 bool shouldDrawButtonAsHighlighted,
107 bool shouldDrawButtonAsDown)
109 const Colour textColour (findColour (textColourId));
111 if (isEnabled())
112 g.setColour ((shouldDrawButtonAsHighlighted) ? textColour.darker ((shouldDrawButtonAsDown) ? 1.3f : 0.4f)
113 : textColour);
114 else
115 g.setColour (textColour.withMultipliedAlpha (0.4f));
117 g.setFont (getFontToUse());
119 g.drawText (getButtonText(), getLocalBounds().reduced (1, 0),
120 justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
121 true);
124 } // namespace juce