~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/textparticle.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-09-17 10:35:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130917103551-az7p3nz9jgxwqjfn
Tags: 1.3.9.15-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  The ManaPlus Client
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
6
 
 *
7
 
 *  This file is part of The ManaPlus Client.
8
 
 *
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
12
 
 *  any later version.
13
 
 *
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.
18
 
 *
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/>.
21
 
 */
22
 
 
23
 
#include "textparticle.h"
24
 
 
25
 
#include "graphics.h"
26
 
 
27
 
#include "gui/theme.h"
28
 
 
29
 
#include <guichan/color.hpp>
30
 
#include <guichan/font.hpp>
31
 
 
32
 
#include "debug.h"
33
 
 
34
 
TextParticle::TextParticle(Map *const map, const std::string &text,
35
 
                           const gcn::Color *const color,
36
 
                           gcn::Font *const font, const bool outline) :
37
 
    Particle(map),
38
 
    mText(text),
39
 
    mTextFont(font),
40
 
    mColor(color),
41
 
    mTextWidth(mTextFont ? mTextFont->getWidth(mText) / 2 : 1),
42
 
    mOutline(outline)
43
 
{
44
 
}
45
 
 
46
 
bool TextParticle::draw(Graphics *const graphics,
47
 
                        const int offsetX, const int offsetY) const
48
 
{
49
 
    if (!mColor || !mTextFont)
50
 
        return false;
51
 
 
52
 
    BLOCK_START("TextParticle::draw")
53
 
    if (!isAlive())
54
 
    {
55
 
        BLOCK_END("TextParticle::draw")
56
 
        return false;
57
 
    }
58
 
 
59
 
    const int screenX = static_cast<int>(mPos.x) + offsetX;
60
 
    const int screenY = static_cast<int>(mPos.y) - static_cast<int>(mPos.z)
61
 
        + offsetY;
62
 
 
63
 
    float alpha = mAlpha * 255.0f;
64
 
 
65
 
    if (mFadeOut && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
66
 
    {
67
 
        alpha *= static_cast<float>(mLifetimeLeft)
68
 
                / static_cast<float>(mFadeOut);
69
 
    }
70
 
 
71
 
    if (mFadeIn && mLifetimePast < mFadeIn)
72
 
    {
73
 
        alpha *= static_cast<float>(mLifetimePast)
74
 
                / static_cast<float>(mFadeIn);
75
 
    }
76
 
 
77
 
    gcn::Color color = *mColor;
78
 
    color.a = static_cast<int>(alpha);
79
 
 
80
 
    graphics->setColor(color);
81
 
    if (mOutline)
82
 
    {
83
 
        graphics->setColor2(Theme::getThemeColor(
84
 
            Theme::OUTLINE, static_cast<int>(alpha)));
85
 
    }
86
 
    mTextFont->drawString(graphics, mText, screenX - mTextWidth, screenY);
87
 
    BLOCK_END("TextParticle::draw")
88
 
    return true;
89
 
}