Audio plugin host https://kx.studio/carla
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.

juce_HyperlinkButton.cpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. HyperlinkButton::HyperlinkButton (const String& linkText,
  21. const URL& linkURL)
  22. : Button (linkText),
  23. url (linkURL),
  24. font (14.0f, Font::underlined),
  25. resizeFont (true),
  26. justification (Justification::centred)
  27. {
  28. setMouseCursor (MouseCursor::PointingHandCursor);
  29. setTooltip (linkURL.toString (false));
  30. }
  31. HyperlinkButton::HyperlinkButton()
  32. : Button (String()),
  33. font (14.0f, Font::underlined),
  34. resizeFont (true),
  35. justification (Justification::centred)
  36. {
  37. setMouseCursor (MouseCursor::PointingHandCursor);
  38. }
  39. HyperlinkButton::~HyperlinkButton()
  40. {
  41. }
  42. //==============================================================================
  43. void HyperlinkButton::setFont (const Font& newFont,
  44. const bool resizeToMatchComponentHeight,
  45. Justification justificationType)
  46. {
  47. font = newFont;
  48. resizeFont = resizeToMatchComponentHeight;
  49. justification = justificationType;
  50. repaint();
  51. }
  52. void HyperlinkButton::setURL (const URL& newURL) noexcept
  53. {
  54. url = newURL;
  55. setTooltip (newURL.toString (false));
  56. }
  57. Font HyperlinkButton::getFontToUse() const
  58. {
  59. if (resizeFont)
  60. return font.withHeight ((float) getHeight() * 0.7f);
  61. return font;
  62. }
  63. void HyperlinkButton::changeWidthToFitText()
  64. {
  65. setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight());
  66. }
  67. void HyperlinkButton::setJustificationType (Justification newJustification)
  68. {
  69. if (justification != newJustification)
  70. {
  71. justification = newJustification;
  72. repaint();
  73. }
  74. }
  75. void HyperlinkButton::colourChanged()
  76. {
  77. repaint();
  78. }
  79. //==============================================================================
  80. void HyperlinkButton::clicked()
  81. {
  82. if (url.isWellFormed())
  83. url.launchInDefaultBrowser();
  84. }
  85. void HyperlinkButton::paintButton (Graphics& g,
  86. bool shouldDrawButtonAsHighlighted,
  87. bool shouldDrawButtonAsDown)
  88. {
  89. const Colour textColour (findColour (textColourId));
  90. if (isEnabled())
  91. g.setColour ((shouldDrawButtonAsHighlighted) ? textColour.darker ((shouldDrawButtonAsDown) ? 1.3f : 0.4f)
  92. : textColour);
  93. else
  94. g.setColour (textColour.withMultipliedAlpha (0.4f));
  95. g.setFont (getFontToUse());
  96. g.drawText (getButtonText(), getLocalBounds().reduced (1, 0),
  97. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  98. true);
  99. }
  100. } // namespace juce