JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_BubbleMessageComponent.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 : fadeOutLength (fadeOutLengthMs), mouseClickCounter (0),
31 expiryTime (0), deleteAfterUse (false)
32{
33}
34
38
40 const AttributedString& text,
42 const bool removeWhenMouseClicked,
43 const bool deleteSelfAfterUse)
44{
45 createLayout (text);
46 setPosition (pos);
48}
49
51 const AttributedString& text,
53 const bool removeWhenMouseClicked,
54 const bool deleteSelfAfterUse)
55{
56 createLayout (text);
57 setPosition (component);
59}
60
61void BubbleMessageComponent::createLayout (const AttributedString& text)
62{
63 textLayout.createLayoutWithBalancedLineLengths (text, 256);
64}
65
66void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
67 const bool removeWhenMouseClicked,
68 const bool deleteSelfAfterUse)
69{
70 setAlpha (1.0f);
71 setVisible (true);
72 deleteAfterUse = deleteSelfAfterUse;
73
74 expiryTime = numMillisecondsBeforeRemoving > 0
76
78
80 mouseClickCounter += 0xfffff;
81
82 startTimer (77);
83 repaint();
84}
85
86const float bubblePaddingX = 20.0f;
87const float bubblePaddingY = 14.0f;
88
90{
91 w = (int) (bubblePaddingX + textLayout.getWidth());
92 h = (int) (bubblePaddingY + textLayout.getHeight());
93}
94
96{
98
99 textLayout.draw (g, Rectangle<float> (bubblePaddingX / 2.0f, bubblePaddingY / 2.0f,
100 (float) w - bubblePaddingX, (float) h - bubblePaddingY));
101}
102
104{
105 if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
106 hide (false);
107 else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
108 hide (true);
109}
110
111void BubbleMessageComponent::hide (const bool fadeOut)
112{
113 stopTimer();
114
115 if (fadeOut)
116 Desktop::getInstance().getAnimator().fadeOut (this, fadeOutLength);
117 else
118 setVisible (false);
119
120 if (deleteAfterUse)
121 delete this;
122}
123
124} // namespace juce
A text string with a set of colour/font settings that are associated with sub-ranges of the text.
void setPosition(Component *componentToPointTo, int distanceFromTarget=15, int arrowLength=10)
Moves and resizes the bubble to point at a given component.
void getContentSize(int &w, int &h) override
Subclasses should override this to return the size of the content they want to draw inside the bubble...
void showAt(const Rectangle< int > &position, const AttributedString &message, int numMillisecondsBeforeRemoving, bool removeWhenMouseClicked=true, bool deleteSelfAfterUse=false)
Shows a message bubble at a particular position.
BubbleMessageComponent(int fadeOutLengthMs=150)
Creates a bubble component.
void paintContent(Graphics &g, int w, int h) override
Subclasses should override this to draw their bubble's contents.
void timerCallback() override
The user-defined callback routine that actually gets called periodically.
void fadeOut(Component *component, int millisecondsToTake)
Begins a fade-out of this components alpha level.
The base class for all JUCE user-interface objects.
bool isShowing() const
Tests whether this component and all its parents are visible.
void setAlpha(float newAlpha)
Changes the transparency of this component.
void repaint()
Marks the whole component as needing to be redrawn.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
ComponentAnimator & getAnimator() noexcept
The Desktop object has a ComponentAnimator instance which can be used for performing your animations.
int getMouseButtonClickCounter() const noexcept
Returns the number of times the mouse button has been clicked since the app started.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
A graphics context, used for drawing a component or image.
void setColour(Colour newColour)
Changes the current drawing colour.
Manages a rectangle and allows geometric operations to be performed on it.
void createLayoutWithBalancedLineLengths(const AttributedString &, float maxWidth)
Creates a layout, attempting to choose a width which results in lines of a similar length.
float getWidth() const noexcept
Returns the maximum width of the content.
void draw(Graphics &, Rectangle< float > area) const
Draws the layout within the specified area.
float getHeight() const noexcept
Returns the maximum height of the content.
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
void stopTimer() noexcept
Stops the timer.
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
@ textColourId
The colour to use for the text.
typedef int
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
unsigned int uint32
A platform-independent 32-bit unsigned integer type.