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 //==============================================================================
31 A speech-bubble component that displays a short message.
33 This can be used to show a message with the tail of the speech bubble
34 pointing to a particular component or location on the screen.
40 class JUCE_API BubbleMessageComponent
: public BubbleComponent
,
44 //==============================================================================
45 /** Creates a bubble component.
47 After creating one a BubbleComponent, do the following:
48 - add it to an appropriate parent component, or put it on the
49 desktop with Component::addToDesktop (0).
50 - use the showAt() method to show a message.
51 - it will make itself invisible after it times-out (and can optionally
52 also delete itself), or you can reuse it somewhere else by calling
55 BubbleMessageComponent (int fadeOutLengthMs
= 150);
58 ~BubbleMessageComponent() override
;
60 //==============================================================================
61 /** Shows a message bubble at a particular position.
63 This shows the bubble with its stem pointing to the given location
64 (coordinates being relative to its parent component).
66 @param position the coords of the object to point to
67 @param message the text to display
68 @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
69 from its parent component. If this is 0 or less, it
70 will stay there until manually removed.
71 @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
72 mouse button is pressed (anywhere on the screen)
73 @param deleteSelfAfterUse if true, then the component will delete itself after
76 void showAt (const Rectangle
<int>& position
,
77 const AttributedString
& message
,
78 int numMillisecondsBeforeRemoving
,
79 bool removeWhenMouseClicked
= true,
80 bool deleteSelfAfterUse
= false);
82 /** Shows a message bubble next to a particular component.
84 This shows the bubble with its stem pointing at the given component.
86 @param component the component that you want to point at
87 @param message the text to display
88 @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
89 from its parent component. If this is 0 or less, it
90 will stay there until manually removed.
91 @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
92 mouse button is pressed (anywhere on the screen)
93 @param deleteSelfAfterUse if true, then the component will delete itself after
96 void showAt (Component
* component
,
97 const AttributedString
& message
,
98 int numMillisecondsBeforeRemoving
,
99 bool removeWhenMouseClicked
= true,
100 bool deleteSelfAfterUse
= false);
103 //==============================================================================
105 void getContentSize (int& w
, int& h
) override
;
107 void paintContent (Graphics
& g
, int w
, int h
) override
;
109 void timerCallback() override
;
112 //==============================================================================
113 int fadeOutLength
, mouseClickCounter
;
114 TextLayout textLayout
;
118 void createLayout (const AttributedString
&);
119 void init (int, bool, bool);
120 void hide (bool fadeOut
);
122 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleMessageComponent
)