3
* Copyright (C) 2006-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "particle/textparticle.h"
25
#include "render/graphics.h"
27
#include "gui/theme.h"
29
#include <guichan/color.hpp>
30
#include <guichan/font.hpp>
34
TextParticle::TextParticle(Map *const map, const std::string &text,
35
const gcn::Color *const color,
36
gcn::Font *const font, const bool outline) :
41
mTextWidth(mTextFont ? mTextFont->getWidth(mText) / 2 : 1),
46
bool TextParticle::draw(Graphics *const graphics,
47
const int offsetX, const int offsetY) const
49
if (!mColor || !mTextFont)
52
BLOCK_START("TextParticle::draw")
55
BLOCK_END("TextParticle::draw")
59
const int screenX = static_cast<int>(mPos.x) + offsetX;
60
const int screenY = static_cast<int>(mPos.y) - static_cast<int>(mPos.z)
63
float alpha = mAlpha * 255.0f;
65
if (mFadeOut && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
67
alpha *= static_cast<float>(mLifetimeLeft)
68
/ static_cast<float>(mFadeOut);
71
if (mFadeIn && mLifetimePast < mFadeIn)
73
alpha *= static_cast<float>(mLifetimePast)
74
/ static_cast<float>(mFadeIn);
77
gcn::Color color = *mColor;
78
color.a = static_cast<int>(alpha);
80
graphics->setColor(color);
83
graphics->setColor2(Theme::getThemeColor(
84
Theme::OUTLINE, static_cast<int>(alpha)));
86
mTextFont->drawString(graphics, mText, screenX - mTextWidth, screenY);
87
BLOCK_END("TextParticle::draw")