The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

111 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. BEGIN_JUCE_NAMESPACE
  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. {
  33. }
  34. //==============================================================================
  35. void HyperlinkButton::setFont (const Font& newFont,
  36. const bool resizeToMatchComponentHeight,
  37. const Justification& justificationType)
  38. {
  39. font = newFont;
  40. resizeFont = resizeToMatchComponentHeight;
  41. justification = justificationType;
  42. repaint();
  43. }
  44. void HyperlinkButton::setURL (const URL& newURL) noexcept
  45. {
  46. url = newURL;
  47. setTooltip (newURL.toString (false));
  48. }
  49. Font HyperlinkButton::getFontToUse() const
  50. {
  51. Font f (font);
  52. if (resizeFont)
  53. f.setHeight (getHeight() * 0.7f);
  54. return f;
  55. }
  56. void HyperlinkButton::changeWidthToFitText()
  57. {
  58. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  59. }
  60. void HyperlinkButton::colourChanged()
  61. {
  62. repaint();
  63. }
  64. //==============================================================================
  65. void HyperlinkButton::clicked()
  66. {
  67. if (url.isWellFormed())
  68. url.launchInDefaultBrowser();
  69. }
  70. void HyperlinkButton::paintButton (Graphics& g,
  71. bool isMouseOverButton,
  72. bool isButtonDown)
  73. {
  74. const Colour textColour (findColour (textColourId));
  75. if (isEnabled())
  76. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  77. : textColour);
  78. else
  79. g.setColour (textColour.withMultipliedAlpha (0.4f));
  80. g.setFont (getFontToUse());
  81. g.drawText (getButtonText(),
  82. 2, 0, getWidth() - 2, getHeight(),
  83. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  84. true);
  85. }
  86. END_JUCE_NAMESPACE