VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_gui_extra / misc / juce_BubbleMessageComponent.cpp
bloba8c10af92a2a90b091918caf5ab89c94e877af68
1 /*
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
8 licensing.
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
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
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)
45 createLayout (text);
46 setPosition (pos);
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)
56 createLayout (text);
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)
70 setAlpha (1.0f);
71 setVisible (true);
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;
82 startTimer (77);
83 repaint();
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)
106 hide (false);
107 else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
108 hide (true);
111 void BubbleMessageComponent::hide (const bool fadeOut)
113 stopTimer();
115 if (fadeOut)
116 Desktop::getInstance().getAnimator().fadeOut (this, fadeOutLength);
117 else
118 setVisible (false);
120 if (deleteAfterUse)
121 delete this;
124 } // namespace juce