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.3KB

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