ManaPlus
Public Member Functions | Private Attributes
TextParticle Class Reference

#include <textparticle.h>

Inheritance diagram for TextParticle:
Particle Actor

Public Member Functions

 TextParticle (const std::string &text, const Color *const color, Font *const font, const bool outline)
 
void draw (Graphics *const graphics, const int offsetX, const int offsetY) const
 
int getPixelY () const
 
int getSortPixelY () const
 
- Public Member Functions inherited from Particle
 Particle ()
 
 ~Particle ()
 
void clear ()
 
bool update ()
 
ParticleaddEffect (const std::string &particleEffectFile, const int pixelX, const int pixelY, const int rotation)
 
void addEmitter (ParticleEmitter *const emitter)
 
void moveTo (const Vector &pos)
 
void moveTo (const float x, const float y)
 
void moveBy (const Vector &change)
 
void setLifetime (const int lifetime)
 
void setFadeOut (const int fadeOut)
 
void setFadeIn (const int fadeIn)
 
void setVelocity (const float x, const float y, const float z)
 
void setGravity (const float gravity)
 
void setRandomness (const int r)
 
void setBounce (const float bouncieness)
 
void setFollow (const bool follow)
 
bool doesFollow () const
 
void setDestination (Particle *const target, const float accel, const float moment)
 
void setDieDistance (const float dist)
 
void adjustEmitterSize (const int w, const int h)
 
void setAllowSizeAdjust (const bool adjust)
 
bool isAlive () const
 
void prepareToDie ()
 
bool isExtinct () const
 
void kill ()
 
void disableAutoDelete ()
 
int getNumberOfLayers () const
 
float getAlpha () const
 
void setAlpha (const float alpha)
 
virtual void setDeathEffect (const std::string &effectFile, const signed char conditions)
 
void setActor (const BeingId actor)
 
- Public Member Functions inherited from Actor
virtual ~Actor ()
 
virtual int getWidth () const
 
virtual int getHeight () const
 
const VectorgetPixelPositionF () const
 
virtual void setPixelPositionF (const Vector &pos)
 
int getPixelX () const
 
virtual int getTileX () const
 
virtual int getTileY () const
 
virtual void setMap (Map *const map)
 
const MapgetMap () const
 

Private Attributes

std::string mText
 
FontmTextFont
 
const ColormColor
 
int mTextWidth
 
bool mOutline
 

Additional Inherited Members

- Data Fields inherited from Actor
int mPixelX
 
int mPixelY
 
- Protected Member Functions inherited from Particle
void updateSelf ()
 
- Protected Member Functions inherited from Actor
 Actor ()
 
- Protected Attributes inherited from Particle
float mAlpha
 
int mLifetimeLeft
 
int mLifetimePast
 
int mFadeOut
 
int mFadeIn
 
Vector mVelocity
 
AliveStatusT mAlive
 
ParticleTypeT mType
 
SimpleAnimationmAnimation
 
ImagemImage
 
BeingId mActor
 
- Protected Attributes inherited from Actor
MapmMap
 
Vector mPos
 
int mYDiff
 

Detailed Description

Definition at line 28 of file textparticle.h.

Constructor & Destructor Documentation

◆ TextParticle()

TextParticle::TextParticle ( const std::string &  text,
const Color *const  color,
Font *const  font,
const bool  outline 
)

Constructor.

Definition at line 33 of file textparticle.cpp.

36  :
37  Particle(),
38  mText(text),
39  mTextFont(font),
40  mColor(color),
41  mTextWidth(mTextFont != nullptr ? mTextFont->getWidth(mText) / 2 : 1),
42  mOutline(outline)
43 {
45 }

References Particle::mType, and ParticleType::Text.

Member Function Documentation

◆ draw()

void TextParticle::draw ( Graphics *const  graphics,
const int  offsetX,
const int  offsetY 
) const
virtual

Draws the particle image.

Reimplemented from Particle.

Definition at line 47 of file textparticle.cpp.

50 {
51  BLOCK_START("TextParticle::draw")
52  if (!isAlive())
53  {
54  BLOCK_END("TextParticle::draw")
55  return;
56  }
57 
58  const int screenX = CAST_S32(mPos.x) + offsetX;
59  const int screenY = CAST_S32(mPos.y) - CAST_S32(mPos.z)
60  + offsetY;
61 
62  float alpha = mAlpha * 255.0F;
63 
64  if ((mFadeOut != 0) && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
65  {
66  alpha *= static_cast<float>(mLifetimeLeft)
67  / static_cast<float>(mFadeOut);
68  }
69 
70  if ((mFadeIn != 0) && mLifetimePast < mFadeIn)
71  {
72  alpha *= static_cast<float>(mLifetimePast)
73  / static_cast<float>(mFadeIn);
74  }
75 
76  Color color = *mColor;
77  color.a = CAST_U32(alpha);
78 
79  graphics->setColor(color);
80  if (mOutline)
81  {
82  const Color &restrict color2 = theme->getColor(ThemeColorId::OUTLINE,
83  CAST_S32(alpha));
84  mTextFont->drawString(graphics,
85  color, color2,
86  mText,
87  screenX - mTextWidth, screenY);
88  }
89  else
90  {
91  mTextFont->drawString(graphics,
92  color, color,
93  mText, screenX - mTextWidth, screenY);
94  }
95  BLOCK_END("TextParticle::draw")
96 }

References Color::a, BLOCK_END, BLOCK_START, CAST_S32, CAST_U32, Theme::getColor(), anonymous_namespace{mrand.cpp}::mPos, restrict, and theme.

◆ getPixelY()

int TextParticle::getPixelY ( ) const
inlinevirtual

Necessary for sorting with the other sprites.

Reimplemented from Particle.

Definition at line 50 of file textparticle.h.

51  { return CAST_S32(mPos.y + mPos.z); }

References CAST_S32, Actor::mPos, Vector::y, and Vector::z.

◆ getSortPixelY()

int TextParticle::getSortPixelY ( ) const
inlinevirtual

Necessary for sorting with the other sprites for sorting only.

Reimplemented from Particle.

Definition at line 54 of file textparticle.h.

55  { return CAST_S32(mPos.y + mPos.z); }

References CAST_S32, Actor::mPos, Vector::y, and Vector::z.

Field Documentation

◆ mColor

const Color* TextParticle::mColor
private

Definition at line 63 of file textparticle.h.

◆ mOutline

bool TextParticle::mOutline
private

Definition at line 66 of file textparticle.h.

◆ mText

std::string TextParticle::mText
private

< Text of the particle. Font used for drawing the text.

Definition at line 59 of file textparticle.h.

◆ mTextFont

Font* TextParticle::mTextFont
private

Color used for drawing the text.

Definition at line 61 of file textparticle.h.

◆ mTextWidth

int TextParticle::mTextWidth
private

Make the text better readable

Definition at line 64 of file textparticle.h.


The documentation for this class was generated from the following files:
TextParticle::mTextFont
Font * mTextFont
Definition: textparticle.h:61
TextParticle::mTextWidth
int mTextWidth
Definition: textparticle.h:64
Actor::mPos
Vector mPos
Definition: actor.h:139
Particle::mType
ParticleTypeT mType
Definition: particle.h:270
ParticleType::Text
@ Text
Definition: particletype.h:32
Particle::mFadeIn
int mFadeIn
Definition: particle.h:262
CAST_U32
#define CAST_U32
Definition: cast.h:30
Vector::z
float z
Definition: vector.h:208
Theme::getColor
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:135
if
if(!vert) return
Font::drawString
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:253
theme
Theme * theme
Definition: theme.cpp:61
x
x
Definition: graphics_calcImageRect.hpp:72
Particle::mLifetimeLeft
int mLifetimeLeft
Definition: particle.h:253
Particle::mFadeOut
int mFadeOut
Definition: particle.h:259
Font::getWidth
int getWidth(const std::string &text) const
Definition: font.cpp:333
Particle::mAlpha
float mAlpha
Definition: particle.h:250
Graphics::setColor
virtual void setColor(const Color &color)
Definition: graphics.h:319
restrict
#define restrict
Definition: localconsts.h:164
Vector::y
float y
Definition: vector.h:208
Particle::mLifetimePast
int mLifetimePast
Definition: particle.h:256
BLOCK_START
#define BLOCK_START(name)
Definition: perfomance.h:78
BLOCK_END
#define BLOCK_END(name)
Definition: perfomance.h:79
CAST_S32
#define CAST_S32
Definition: cast.h:29
TextParticle::mColor
const Color * mColor
Definition: textparticle.h:63
TextParticle::mText
std::string mText
Definition: textparticle.h:59
TextParticle::mOutline
bool mOutline
Definition: textparticle.h:66
Color
Definition: color.h:74
y
y
Definition: graphics_calcImageRect.hpp:72
Particle::isAlive
bool isAlive() const
Definition: particle.h:205
Particle::Particle
Particle()
Definition: particle.cpp:58
Color::a
unsigned int a
Definition: color.h:250