2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
29 BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs
)
30 : fadeOutLength (fadeOutLengthMs
), mouseClickCounter (0),
31 expiryTime (0), deleteAfterUse (false)
35 BubbleMessageComponent::~BubbleMessageComponent()
39 void BubbleMessageComponent::showAt (const Rectangle
<int>& pos
,
40 const AttributedString
& text
,
41 const int numMillisecondsBeforeRemoving
,
42 const bool removeWhenMouseClicked
,
43 const bool deleteSelfAfterUse
)
47 init (numMillisecondsBeforeRemoving
, removeWhenMouseClicked
, deleteSelfAfterUse
);
50 void BubbleMessageComponent::showAt (Component
* const component
,
51 const AttributedString
& text
,
52 const int numMillisecondsBeforeRemoving
,
53 const bool removeWhenMouseClicked
,
54 const bool deleteSelfAfterUse
)
57 setPosition (component
);
58 init (numMillisecondsBeforeRemoving
, removeWhenMouseClicked
, deleteSelfAfterUse
);
61 void BubbleMessageComponent::createLayout (const AttributedString
& text
)
63 textLayout
.createLayoutWithBalancedLineLengths (text
, 256);
66 void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving
,
67 const bool removeWhenMouseClicked
,
68 const bool deleteSelfAfterUse
)
72 deleteAfterUse
= deleteSelfAfterUse
;
74 expiryTime
= numMillisecondsBeforeRemoving
> 0
75 ? (Time::getMillisecondCounter() + (uint32
) numMillisecondsBeforeRemoving
) : 0;
77 mouseClickCounter
= Desktop::getInstance().getMouseButtonClickCounter();
79 if (! (removeWhenMouseClicked
&& isShowing()))
80 mouseClickCounter
+= 0xfffff;
86 const float bubblePaddingX
= 20.0f
;
87 const float bubblePaddingY
= 14.0f
;
89 void BubbleMessageComponent::getContentSize (int& w
, int& h
)
91 w
= (int) (bubblePaddingX
+ textLayout
.getWidth());
92 h
= (int) (bubblePaddingY
+ textLayout
.getHeight());
95 void BubbleMessageComponent::paintContent (Graphics
& g
, int w
, int h
)
97 g
.setColour (findColour (TooltipWindow::textColourId
));
99 textLayout
.draw (g
, Rectangle
<float> (bubblePaddingX
/ 2.0f
, bubblePaddingY
/ 2.0f
,
100 (float) w
- bubblePaddingX
, (float) h
- bubblePaddingY
));
103 void BubbleMessageComponent::timerCallback()
105 if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter
)
107 else if (expiryTime
!= 0 && Time::getMillisecondCounter() > expiryTime
)
111 void BubbleMessageComponent::hide (const bool fadeOut
)
116 Desktop::getInstance().getAnimator().fadeOut (this, fadeOutLength
);