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 29 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 34 of file textparticle.cpp.

37  :
38  Particle(),
39  mText(text),
40  mTextFont(font),
41  mColor(color),
42  mTextWidth(mTextFont != nullptr ? mTextFont->getWidth(mText) / 2 : 1),
43  mOutline(outline)
44 {
46 }
int getWidth(const std::string &text) const
Definition: font.cpp:334
Particle()
Definition: particle.cpp:59
ParticleTypeT mType
Definition: particle.h:271
std::string mText
Definition: textparticle.h:60
Font * mTextFont
Definition: textparticle.h:62
const Color * mColor
Definition: textparticle.h:64

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 48 of file textparticle.cpp.

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 }
#define CAST_S32
Definition: cast.h:30
#define CAST_U32
Definition: cast.h:31
Vector mPos
Definition: actor.h:140
Definition: color.h:76
unsigned int a
Definition: color.h:251
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:254
virtual void setColor(const Color &color)
Definition: graphics.h:320
int mFadeIn
Definition: particle.h:263
int mLifetimePast
Definition: particle.h:257
float mAlpha
Definition: particle.h:251
int mLifetimeLeft
Definition: particle.h:254
int mFadeOut
Definition: particle.h:260
bool isAlive() const
Definition: particle.h:206
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:136
if(!vert) return
#define restrict
Definition: localconsts.h:165
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
Theme * theme
Definition: theme.cpp:62

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 51 of file textparticle.h.

52  { return CAST_S32(mPos.y + mPos.z); }
float z
Definition: vector.h:209
float y
Definition: vector.h:209

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 55 of file textparticle.h.

56  { 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 64 of file textparticle.h.

◆ mOutline

bool TextParticle::mOutline
private

Definition at line 67 of file textparticle.h.

◆ mText

std::string TextParticle::mText
private

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

Definition at line 60 of file textparticle.h.

◆ mTextFont

Font* TextParticle::mTextFont
private

Color used for drawing the text.

Definition at line 62 of file textparticle.h.

◆ mTextWidth

int TextParticle::mTextWidth
private

Make the text better readable

Definition at line 65 of file textparticle.h.


The documentation for this class was generated from the following files: