Middle Europe Productions Library  alpha 1.3.3
Public Types | Public Member Functions | Friends | List of all members
MEP::Text Class Reference

A basic Text class. More...

#include <TextObject.h>

Inheritance diagram for MEP::Text:
MEP::Drawable MEP::Following

Public Types

enum  PositionTag { PositionTag::Non, PositionTag::XMiddle, PositionTag::YMiddle, PositionTag::Middle }
 
- Public Types inherited from MEP::Following
enum  FollowType {
  FollowType::NotInit = 0, FollowType::Objects = 1, FollowType::X_Scale = 2, FollowType::Y_Scale = 3,
  FollowType::X_Pos = 4, FollowType::Y_Pos = 5, FollowType::Color = 6
}
 

Public Member Functions

 Text (const std::string &content, sf::Font &font, unsigned int fontSize=40, sf::Vector2f position={ 0, 0 }, PositionTag tag=PositionTag::Non)
 
 Text (const std::string &content, sf::Font &font, const Following &follow, unsigned int fontSize=40, PositionTag tag=PositionTag::Non)
 
Textoperator<< (const Sprite &x)
 
Textoperator<< (const Text &x)
 
void onResize () override
 
void update (sf::Time &) override
 
void changePositionTag (const PositionTag &x)
 
bool draw (sf::RenderWindow &window) override
 
const std::string & getString () const
 
sf::Text & getText ()
 
void setText (const std::string &in)
 
void setColor (const sf::Color &in)
 
virtual void debugOutput (std::ostream &out) const
 
- Public Member Functions inherited from MEP::Drawable
void _link (std::shared_ptr< bool > _li)
 
std::shared_ptr< bool > _linkAddr ()
 
const std::shared_ptr< bool > _linkAddr () const
 
bool _isLinked () const
 
U_int32 getDrawTag () const
 
void setDrawTag (const U_int32 tag)
 
bool addDrawTag (const U_int32 tag)
 
bool removeDrawTag (const U_int32 tag)
 
 Drawable ()=default
 
virtual void entryUpdate (sf::Time &currentTime, bool low=false)
 
virtual void exitUpdate (sf::Time &currentTime, bool low=false)
 
virtual bool isActive () const
 
virtual ~Drawable ()
 
- Public Member Functions inherited from MEP::Following
 Following (const FollowType &followType, sf::Vector2f pos={ 0.f, 0.f }, sf::Vector2f posFixed={ 0.f, 0.f }, sf::Vector2f scale={ 1.f, 1.f }, sf::Vector2f scaleFixed={ 1.f, 1.f })
 
 Following (sf::Vector2f pos={ 0.f, 0.f }, sf::Vector2f posFixed={ 0.f, 0.f }, sf::Vector2f scale={ 1.f, 1.f }, sf::Vector2f scaleFixed={ 1.f, 1.f })
 
 Following (const Following &x)
 
void updatePosition ()
 
void addMethodPos (std::function< sf::Vector2f()> method)
 
void updateScale ()
 
void addMethodScale (std::function< sf::Vector2f()> method)
 
Followingoperator<< (const Following &x)
 
void setFollow (const AnimationPosition &base, const FollowType type, MEP::U_int32 group=-1)
 
void setFollow (const AnimationColor &base, MEP::U_int32 toFollow=MEP::ColorChannel::ALL, MEP::U_int32 group=-1)
 
void muteFollowGroup (MEP::U_int32 group)
 
void unMuteFollowGroup (MEP::U_int32 group)
 
void fullMuteFollow ()
 
void fullUnMuteFollow ()
 
virtual void setPosition (const sf::Vector2f pos)
 
virtual void setPosition (const Following &x)
 
virtual void movePosition (const sf::Vector2f pos)
 
virtual void setScale (const sf::Vector2f scale)
 
virtual void setScale (const Following &x)
 
virtual const sf::Color & getColor () const
 
sf::Vector2f getPosition () const
 
sf::Vector2f getScale () const
 
sf::Vector2f getOriginPosition () const
 
sf::Vector2f getOriginScale () const
 
bool isFollowerActive () const
 
void followingDebug (std::ostream &out, const char *skipLines="") const
 
void clearFollow ()
 

Friends

std::ostream & operator<< (std::ostream &out, const Text &x)
 

Additional Inherited Members

- Protected Member Functions inherited from MEP::Drawable
void notify ()
 
void drawTagDebug (std::ostream &out) const
 
- Protected Attributes inherited from MEP::Following
std::function< sf::Vector2f()> calc_position = [this]()->sf::Vector2f { return m_pos; }
 
std::function< sf::Vector2f()> calc_scale = [this]()->sf::Vector2f { return m_scale; }
 
MEPtools::GroupManager< Follow, std::unique_ptr< Follow >, std::list< std::unique_ptr< Follow > > > followingListv2
 
sf::Vector2f m_pos = {0.f, 0.f}
 
sf::Vector2f m_posMove = { 0.f, 0.f }
 
sf::Vector2f m_posFixed = { 0.f, 0.f }
 
sf::Vector2f m_scale = { 1.f, 1.f }
 
sf::Vector2f m_scaleFixed = { 1.f, 1.f }
 
sf::Color m_color
 
sf::Color m_colorFixed
 

Detailed Description

A basic Text class.

Type only very important feature here is the ability of displaying the text with a position tag. The tricky part in here is that we are not able to tell the size of a Text before rendering it on a screen in order to solve the issue MEP::Text has an ability of skiping the frame. But keep in mind that this is a very costly operation.

Member Enumeration Documentation

◆ PositionTag

Enumerator
Non 

Position.x and Position.y are the top left corner of the text.

XMiddle 

Position.y is not changed while Position.x is in the middle of the text.

YMiddle 

Position.x is not changed while Position.y is in the middle of the text.

Middle 

Both Postition.x and Position.y are exactly in the middle of the text.

Constructor & Destructor Documentation

◆ Text() [1/2]

MEP::Text::Text ( const std::string &  content,
sf::Font &  font,
unsigned int  fontSize = 40,
sf::Vector2f  position = { 0, 0 },
PositionTag  tag = PositionTag::Non 
)
inline

Constructor of a text.

Parameters
[in]context: This goes on your screen.
[in]font: Font of a Text.
[in]fontSize: Size of the font.
[in]position: Position on the screen.
[in]tag: MEP::TextOboject::PositionTag

◆ Text() [2/2]

MEP::Text::Text ( const std::string &  content,
sf::Font &  font,
const Following follow,
unsigned int  fontSize = 40,
PositionTag  tag = PositionTag::Non 
)
inline

Constructor of a text.

Parameters
[in]context: This goes on your screen.
[in]font: Font of a Text.
[in]fontSize: Size of the font.
[in]position: Position on the screen.
[in]tag: MEP::TextOboject::PositionTag

Member Function Documentation

◆ changePositionTag()

void MEP::Text::changePositionTag ( const PositionTag x)
inline

◆ debugOutput()

virtual void MEP::Text::debugOutput ( std::ostream &  out) const
inlinevirtual

Debug output of the class.

Reimplemented from MEP::Drawable.

◆ draw()

bool MEP::Text::draw ( sf::RenderWindow &  window)
inlineoverridevirtual

The implementation of this draw method is slightly different than the other ones. It does some update job. The reason for that is rather straightforward, in order to get text bound we do need to render it. MEP::Text provides operation based on that that is why I needed to implement some user friendly solution. I would highly recommend you to avoid using the PositionTag beacause in order to use it you need to 'loose first frame of the execution'. why? Text is being rendered than we calculate the bound and after all of that we do need to request frame rebuild to avoid text without MEP::TextObject::PositionTag applied.

Parameters
[in]window: Classic sf::RenderWindow

Reimplemented from MEP::Drawable.

◆ getString()

const std::string& MEP::Text::getString ( ) const
inline

Outputs the content of a string of the text

Returns
: Text as std::string

◆ getText()

sf::Text& MEP::Text::getText ( )
inline

Outputs the content of a sf::Text

Returns
: sf::Text

◆ onResize()

void MEP::Text::onResize ( )
inlineoverridevirtual

On resize we want to update the position.

Reimplemented from MEP::Drawable.

◆ operator<<() [1/2]

Text& MEP::Text::operator<< ( const Sprite x)
inline

◆ operator<<() [2/2]

Text& MEP::Text::operator<< ( const Text x)
inline

◆ setColor()

void MEP::Text::setColor ( const sf::Color &  in)
inlinevirtual

Changes the main string.

Parameters
[in]in: New string.

Reimplemented from MEP::Following.

◆ setText()

void MEP::Text::setText ( const std::string &  in)
inline

Changes the main string.

Parameters
[in]in: New string.

◆ update()

void MEP::Text::update ( sf::Time &  )
inlineoverridevirtual

Override of a MEP::Drawable update.

Reimplemented from MEP::Drawable.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const Text x 
)
friend

Overrdie of the << operator for diagnostic purposes.