mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Refactored Path::addBubble, BubbleMessageComponent and BubbleComponent classes to work better and avoid duplicated code.
This commit is contained in:
parent
fb29acf1fa
commit
27f1901fe6
11 changed files with 160 additions and 292 deletions
|
|
@ -31,17 +31,16 @@ BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
|
|||
|
||||
BubbleMessageComponent::~BubbleMessageComponent()
|
||||
{
|
||||
Desktop::getInstance().getAnimator().fadeOut (this, fadeOutLength);
|
||||
}
|
||||
|
||||
void BubbleMessageComponent::showAt (int x, int y,
|
||||
void BubbleMessageComponent::showAt (const Rectangle<int>& pos,
|
||||
const AttributedString& text,
|
||||
const int numMillisecondsBeforeRemoving,
|
||||
const bool removeWhenMouseClicked,
|
||||
const bool deleteSelfAfterUse)
|
||||
{
|
||||
createLayout (text);
|
||||
setPosition (x, y);
|
||||
setPosition (pos);
|
||||
init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
|
||||
}
|
||||
|
||||
|
|
@ -65,55 +64,56 @@ void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
|
|||
const bool removeWhenMouseClicked,
|
||||
const bool deleteSelfAfterUse)
|
||||
{
|
||||
setAlpha (1.0f);
|
||||
setVisible (true);
|
||||
|
||||
deleteAfterUse = deleteSelfAfterUse;
|
||||
|
||||
if (numMillisecondsBeforeRemoving > 0)
|
||||
expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
|
||||
else
|
||||
expiryTime = 0;
|
||||
|
||||
startTimer (77);
|
||||
expiryTime = numMillisecondsBeforeRemoving > 0
|
||||
? (Time::getMillisecondCounter() + numMillisecondsBeforeRemoving) : 0;
|
||||
|
||||
mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
|
||||
|
||||
if (! (removeWhenMouseClicked && isShowing()))
|
||||
mouseClickCounter += 0xfffff;
|
||||
|
||||
startTimer (77);
|
||||
repaint();
|
||||
}
|
||||
|
||||
const float bubblePaddingX = 20.0f;
|
||||
const float bubblePaddingY = 14.0f;
|
||||
|
||||
void BubbleMessageComponent::getContentSize (int& w, int& h)
|
||||
{
|
||||
w = 20 + (int) textLayout.getWidth();
|
||||
h = 20 + (int) textLayout.getHeight();
|
||||
w = (int) (bubblePaddingX + textLayout.getWidth());
|
||||
h = (int) (bubblePaddingY + textLayout.getHeight());
|
||||
}
|
||||
|
||||
void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
|
||||
{
|
||||
g.setColour (findColour (TooltipWindow::textColourId));
|
||||
|
||||
textLayout.draw (g, Rectangle<float> (6.0f, 6.0f, w - 12.0f, h - 12.0f));
|
||||
textLayout.draw (g, Rectangle<float> (bubblePaddingX / 2.0f, bubblePaddingY / 2.0f,
|
||||
w - bubblePaddingX, h - bubblePaddingY));
|
||||
}
|
||||
|
||||
void BubbleMessageComponent::timerCallback()
|
||||
{
|
||||
if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
|
||||
{
|
||||
stopTimer();
|
||||
hide (false);
|
||||
else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
|
||||
hide (true);
|
||||
}
|
||||
|
||||
void BubbleMessageComponent::hide (const bool fadeOut)
|
||||
{
|
||||
stopTimer();
|
||||
|
||||
if (fadeOut)
|
||||
Desktop::getInstance().getAnimator().fadeOut (this, fadeOutLength);
|
||||
else
|
||||
setVisible (false);
|
||||
|
||||
if (deleteAfterUse)
|
||||
delete this;
|
||||
}
|
||||
else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
|
||||
{
|
||||
stopTimer();
|
||||
|
||||
if (deleteAfterUse)
|
||||
delete this;
|
||||
else
|
||||
Desktop::getInstance().getAnimator().fadeOut (this, fadeOutLength);
|
||||
}
|
||||
if (deleteAfterUse)
|
||||
delete this;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue