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.

128 lines
4.2KB

  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. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  21. : fadeOutLength (fadeOutLengthMs),
  22. deleteAfterUse (false)
  23. {
  24. }
  25. BubbleMessageComponent::~BubbleMessageComponent()
  26. {
  27. Desktop::getInstance().getAnimator().fadeOut (this, fadeOutLength);
  28. }
  29. void BubbleMessageComponent::showAt (int x, int y,
  30. const String& text,
  31. const int numMillisecondsBeforeRemoving,
  32. const bool removeWhenMouseClicked,
  33. const bool deleteSelfAfterUse)
  34. {
  35. textLayout.clear();
  36. textLayout.setText (text, Font (14.0f));
  37. textLayout.layout (256, Justification::centredLeft, true);
  38. setPosition (x, y);
  39. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  40. }
  41. void BubbleMessageComponent::showAt (Component* const component,
  42. const String& text,
  43. const int numMillisecondsBeforeRemoving,
  44. const bool removeWhenMouseClicked,
  45. const bool deleteSelfAfterUse)
  46. {
  47. textLayout.clear();
  48. textLayout.setText (text, Font (14.0f));
  49. textLayout.layout (256, Justification::centredLeft, true);
  50. setPosition (component);
  51. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  52. }
  53. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  54. const bool removeWhenMouseClicked,
  55. const bool deleteSelfAfterUse)
  56. {
  57. setVisible (true);
  58. deleteAfterUse = deleteSelfAfterUse;
  59. if (numMillisecondsBeforeRemoving > 0)
  60. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  61. else
  62. expiryTime = 0;
  63. startTimer (77);
  64. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  65. if (! (removeWhenMouseClicked && isShowing()))
  66. mouseClickCounter += 0xfffff;
  67. repaint();
  68. }
  69. void BubbleMessageComponent::getContentSize (int& w, int& h)
  70. {
  71. w = textLayout.getWidth() + 16;
  72. h = textLayout.getHeight() + 16;
  73. }
  74. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  75. {
  76. g.setColour (findColour (TooltipWindow::textColourId));
  77. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  78. }
  79. void BubbleMessageComponent::timerCallback()
  80. {
  81. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  82. {
  83. stopTimer();
  84. setVisible (false);
  85. if (deleteAfterUse)
  86. delete this;
  87. }
  88. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  89. {
  90. stopTimer();
  91. if (deleteAfterUse)
  92. delete this;
  93. else
  94. Desktop::getInstance().getAnimator().fadeOut (this, fadeOutLength);
  95. }
  96. }
  97. END_JUCE_NAMESPACE