ManaPlus
src
particle
textparticle.cpp
Go to the documentation of this file.
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-2019 The ManaPlus Developers
6
* Copyright (C) 2019-2021 Andrei Karas
7
*
8
* This file is part of The ManaPlus Client.
9
*
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*/
23
24
#include "
particle/textparticle.h
"
25
26
#include "gui/theme.h"
27
28
#include "
gui/fonts/font.h
"
29
30
#include "render/graphics.h"
31
32
#include "
debug.h
"
33
34
TextParticle::TextParticle
(
const
std::string &
restrict
text,
35
const
Color
*
restrict
const
color,
36
Font
*
restrict
const
font,
37
const
bool
outline) :
38
Particle
(),
39
mText(text),
40
mTextFont(font),
41
mColor(color),
42
mTextWidth(mTextFont !=
nullptr
? mTextFont->getWidth(mText) / 2 : 1),
43
mOutline(outline)
44
{
45
mType
=
ParticleType::Text
;
46
}
47
48
void
TextParticle::draw
(
Graphics
*
restrict
const
graphics,
49
const
int
offsetX,
50
const
int
offsetY)
const
restrict2
51
{
52
BLOCK_START
(
"TextParticle::draw"
)
53
if
(!isAlive())
54
{
55
BLOCK_END
(
"TextParticle::draw"
)
56
return
;
57
}
58
59
const
int
screenX =
CAST_S32
(
mPos
.x) + offsetX;
60
const
int
screenY =
CAST_S32
(
mPos
.y) -
CAST_S32
(
mPos
.z)
61
+ offsetY;
62
63
float
alpha = mAlpha * 255.0F;
64
65
if
((mFadeOut != 0) && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
66
{
67
alpha *=
static_cast<
float
>
(mLifetimeLeft)
68
/
static_cast<
float
>
(mFadeOut);
69
}
70
71
if
((mFadeIn != 0) && mLifetimePast < mFadeIn)
72
{
73
alpha *=
static_cast<
float
>
(mLifetimePast)
74
/
static_cast<
float
>
(mFadeIn);
75
}
76
77
Color
color = *mColor;
78
color.
a
=
CAST_U32
(alpha);
79
80
graphics->setColor(color);
81
if
(mOutline)
82
{
83
const
Color
&
restrict
color2 =
theme
->
getColor
(ThemeColorId::OUTLINE,
84
CAST_S32
(alpha));
85
mTextFont->drawString(graphics,
86
color, color2,
87
mText,
88
screenX - mTextWidth, screenY);
89
}
90
else
91
{
92
mTextFont->drawString(graphics,
93
color, color,
94
mText, screenX - mTextWidth, screenY);
95
}
96
BLOCK_END
(
"TextParticle::draw"
)
97
}
CAST_S32
#define CAST_S32
Definition:
cast.h:30
CAST_U32
#define CAST_U32
Definition:
cast.h:31
Color
Definition:
color.h:76
Color::a
unsigned int a
Definition:
color.h:251
Font
Definition:
font.h:90
Graphics
Definition:
graphics.h:109
Particle
Definition:
particle.h:46
Particle::mType
ParticleTypeT mType
Definition:
particle.h:271
TextParticle::draw
void draw(Graphics *const graphics, const int offsetX, const int offsetY) const
Definition:
textparticle.cpp:48
TextParticle::TextParticle
TextParticle(const std::string &text, const Color *const color, Font *const font, const bool outline)
Definition:
textparticle.cpp:34
Theme::getColor
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition:
theme.h:136
debug.h
font.h
restrict
#define restrict
Definition:
localconsts.h:165
restrict2
#define restrict2
Definition:
localconsts.h:166
nullptr
#define nullptr
Definition:
localconsts.h:45
ParticleType::Text
@ Text
Definition:
particletype.h:33
anonymous_namespace{mrand.cpp}::mPos
int mPos
Definition:
mrand.cpp:31
BLOCK_END
#define BLOCK_END(name)
Definition:
perfomance.h:80
BLOCK_START
#define BLOCK_START(name)
Definition:
perfomance.h:79
textparticle.h
theme
Theme * theme
Definition:
theme.cpp:62
Generated on Wed Mar 17 2021 19:19:09 for ManaPlus by
1.9.1