LMMS
Loading...
Searching...
No Matches
juce_HyperlinkButton.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
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.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 const URL& linkURL)
31 : Button (linkText),
32 url (linkURL),
33 font (14.0f, Font::underlined),
36{
38 setTooltip (linkURL.toString (false));
39}
40
49
53
54//==============================================================================
55void HyperlinkButton::setFont (const Font& newFont,
56 const bool resizeToMatchComponentHeight,
57 Justification justificationType)
58{
59 font = newFont;
60 resizeFont = resizeToMatchComponentHeight;
61 justification = justificationType;
62 repaint();
63}
64
65void HyperlinkButton::setURL (const URL& newURL) noexcept
66{
67 url = newURL;
68 setTooltip (newURL.toString (false));
69}
70
72{
73 if (resizeFont)
74 return font.withHeight ((float) getHeight() * 0.7f);
75
76 return font;
77}
78
80{
81 setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight());
82}
83
85{
86 if (justification != newJustification)
87 {
88 justification = newJustification;
89 repaint();
90 }
91}
92
97
98//==============================================================================
100{
101 if (url.isWellFormed())
102 url.launchInDefaultBrowser();
103}
104
106 bool shouldDrawButtonAsHighlighted,
107 bool shouldDrawButtonAsDown)
108{
109 const Colour textColour (findColour (textColourId));
110
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));
116
117 g.setFont (getFontToUse());
118
119 g.drawText (getButtonText(), getLocalBounds().reduced (1, 0),
120 justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
121 true);
122}
123
124} // namespace juce
Button(const String &buttonName)
Definition juce_Button.cpp:76
const String & getButtonText() const
Definition juce_Button.h:67
void setTooltip(const String &newTooltip) override
Definition juce_Button.cpp:105
Definition juce_Colour.h:38
JUCE_NODISCARD Colour darker(float amountDarker=0.4f) const noexcept
Definition juce_Colour.cpp:472
Colour withMultipliedAlpha(float alphaMultiplier) const noexcept
Definition juce_Colour.cpp:333
int getHeight() const noexcept
Definition juce_Component.h:274
void setMouseCursor(const MouseCursor &cursorType)
Definition juce_Component.cpp:1859
void repaint()
Definition juce_Component.cpp:1917
void setSize(int newWidth, int newHeight)
Definition juce_Component.cpp:1262
Colour findColour(int colourID, bool inheritFromParent=false) const
Definition juce_Component.cpp:2219
bool isEnabled() const noexcept
Definition juce_Component.cpp:3104
Rectangle< int > getLocalBounds() const noexcept
Definition juce_Component.cpp:2283
Definition juce_Font.h:42
Definition juce_GraphicsContext.h:45
Definition juce_Justification.h:41
@ verticallyCentred
Definition juce_Justification.h:126
@ PointingHandCursor
Definition juce_MouseCursor.h:56
Definition juce_String.h:53
Definition juce_URL.h:38
String toString(bool includeGetParameters) const
Definition juce_URL.cpp:200
int g
Definition inflate.c:1573
Definition carla_juce.cpp:31
#define true
Definition ordinals.h:82