OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
OpenXcom::Text Class Reference

Text string displayed on screen. More...

#include <Text.h>

Inheritance diagram for OpenXcom::Text:
OpenXcom::Surface OpenXcom::MedikitTitle OpenXcom::MedikitTxt

Public Member Functions

 Text (int width, int height, int x=0, int y=0)
 Creates a new text with the specified size and position. More...
 
 ~Text ()
 Cleans up the text.
 
void setBig ()
 Sets the text size to big. More...
 
void setSmall ()
 Sets the text size to small. More...
 
FontgetFont () const
 Gets the text's current font. More...
 
void initText (Font *big, Font *small, Language *lang)
 Initializes the resources for the text. More...
 
void setText (const std::wstring &text)
 Sets the text's string. More...
 
std::wstring getText () const
 Gets the text's string. More...
 
void setWordWrap (bool wrap, bool indent=false)
 Sets the text's wordwrap setting. More...
 
void setInvert (bool invert)
 Sets the text's color invert setting. More...
 
void setHighContrast (bool contrast)
 Sets the text's high contrast color setting. More...
 
void setAlign (TextHAlign align)
 Sets the text's horizontal alignment. More...
 
TextHAlign getAlign () const
 Gets the text's horizontal alignment. More...
 
void setVerticalAlign (TextVAlign valign)
 Sets the text's vertical alignment. More...
 
void setColor (Uint8 color)
 Sets the text's color. More...
 
Uint8 getColor () const
 Gets the text's color. More...
 
void setSecondaryColor (Uint8 color)
 Sets the text's secondary color. More...
 
Uint8 getSecondaryColor () const
 Gets the text's secondary color. More...
 
int getTextWidth (int line=-1) const
 Gets the rendered text's width. More...
 
int getTextHeight (int line=-1) const
 Gets the rendered text's height. More...
 
void draw ()
 Draws the text. More...
 
- Public Member Functions inherited from OpenXcom::Surface
 Surface (int width, int height, int x=0, int y=0, int bpp=8)
 Creates a new surface with the specified size and position. More...
 
 Surface (const Surface &other)
 Creates a new surface from an existing one. More...
 
virtual ~Surface ()
 Cleans up the surface. More...
 
void loadScr (const std::string &filename)
 Loads an X-Com SCR graphic. More...
 
void loadSpk (const std::string &filename)
 Loads an X-Com SPK graphic. More...
 
void loadBdy (const std::string &filename)
 Loads a TFTD BDY graphic. More...
 
void loadImage (const std::string &filename)
 Loads a general image file. More...
 
void clear ()
 Clears the surface's contents. More...
 
void offset (int off, int min=-1, int max=-1, int mul=1)
 Offsets the surface's colors by a set amount. More...
 
void invert (Uint8 mid)
 Inverts the surface's colors. More...
 
virtual void think ()
 Runs surface functionality every cycle. More...
 
virtual void blit (Surface *surface)
 Blits this surface onto another one. More...
 
void copy (Surface *surface)
 Copies a portion of another surface into this one. More...
 
void drawRect (SDL_Rect *rect, Uint8 color)
 Draws a filled rectangle on the surface. More...
 
void drawRect (Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 color)
 Draws a filled rectangle on the surface. More...
 
void drawLine (Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 color)
 Draws a line on the surface. More...
 
void drawCircle (Sint16 x, Sint16 y, Sint16 r, Uint8 color)
 Draws a filled circle on the surface. More...
 
void drawPolygon (Sint16 *x, Sint16 *y, int n, Uint8 color)
 Draws a filled polygon on the surface. More...
 
void drawTexturedPolygon (Sint16 *x, Sint16 *y, int n, Surface *texture, int dx, int dy)
 Draws a textured polygon on the surface. More...
 
void drawString (Sint16 x, Sint16 y, const char *s, Uint8 color)
 Draws a string on the surface. More...
 
virtual void setPalette (SDL_Color *colors, int firstcolor=0, int ncolors=256)
 Sets the surface's palette. More...
 
SDL_Color * getPalette () const
 Returns the surface's 8bpp palette. More...
 
virtual void setX (int x)
 Sets the X position of the surface. More...
 
int getX () const
 Returns the position of the surface in the X axis. More...
 
virtual void setY (int y)
 Sets the Y position of the surface. More...
 
int getY () const
 Returns the position of the surface in the Y axis. More...
 
void setVisible (bool visible)
 Sets the surface's visibility. More...
 
bool getVisible () const
 Gets the surface's visibility. More...
 
void resetCrop ()
 Resets the cropping rectangle for the surface. More...
 
SDL_Rect * getCrop ()
 Gets the cropping rectangle for the surface. More...
 
void setPixel (int x, int y, Uint8 pixel)
 Changes the color of a pixel in the surface, relative to the top-left corner of the surface. More...
 
void setPixelIterative (int *x, int *y, Uint8 pixel)
 Changes the color of a pixel in the surface and returns the next pixel position. More...
 
Uint8 getPixel (int x, int y) const
 Returns the color of a specified pixel in the surface. More...
 
SDL_Surface * getSurface () const
 Returns the internal SDL_Surface for SDL calls. More...
 
int getWidth () const
 Returns the width of the surface. More...
 
virtual void setWidth (int width)
 Sets the width of the surface. More...
 
int getHeight () const
 Returns the height of the surface. More...
 
virtual void setHeight (int height)
 Sets the height of the surface. More...
 
void setHidden (bool hidden)
 Sets the surface's special hidden flag. More...
 
void lock ()
 Locks the surface. More...
 
void unlock ()
 Unlocks the surface. More...
 
void blitNShade (Surface *surface, int x, int y, int off, bool half=false, int newBaseColor=0)
 Specific blit function to blit battlescape terrain data in different shades in a fast way. More...
 
void invalidate ()
 Invalidate the surface: force it to be redrawn. More...
 
std::string getTooltip () const
 Gets the tooltip of the surface. More...
 
void setTooltip (const std::string &tooltip)
 Sets the tooltip of the surface. More...
 

Static Public Member Functions

static std::wstring formatNumber (int value, std::wstring currency=L"")
 Formats an integer value as number with separators. More...
 
static std::wstring formatFunding (int funds)
 Formats an integer value as currency. More...
 
static std::wstring formatPercentage (int value)
 Formats an integer value as percentage. More...
 

Additional Inherited Members

- Protected Member Functions inherited from OpenXcom::Surface
void resize (int width, int height)
 Recreates the surface with a new size. More...
 

Detailed Description

Text string displayed on screen.

Takes the characters from a Font and puts them together on screen to display a string of text, taking care of any required aligning or wrapping.

Constructor & Destructor Documentation

OpenXcom::Text::Text ( int  width,
int  height,
int  x = 0,
int  y = 0 
)

Creates a new text with the specified size and position.

Sets up a blank text with the specified size and position.

Parameters
widthWidth in pixels.
heightHeight in pixels.
xX position in pixels.
yY position in pixels.

Member Function Documentation

void OpenXcom::Text::draw ( )
virtual

Draws the text.

Draws all the characters in the text with a really nasty complex gritty text rendering algorithm logic stuff.

Reimplemented from OpenXcom::Surface.

std::wstring OpenXcom::Text::formatFunding ( int  funds)
static

Formats an integer value as currency.

Takes an integer value and formats it as currency, spacing the thousands and adding a $ sign to the front.

Parameters
fundsThe funding value.
Returns
The formatted string.
std::wstring OpenXcom::Text::formatNumber ( int  value,
std::wstring  currency = L"" 
)
static

Formats an integer value as number with separators.

Takes an integer value and formats it as number with separators (spacing the thousands).

Parameters
valueThe value.
currencyCurrency symbol.
Returns
The formatted string.
std::wstring OpenXcom::Text::formatPercentage ( int  value)
static

Formats an integer value as percentage.

Takes an integer value and formats it as percentage, adding a % sign.

Parameters
valueThe percentage value.
Returns
The formatted string.
TextHAlign OpenXcom::Text::getAlign ( ) const

Gets the text's horizontal alignment.

Returns the way the text is aligned horizontally relative to the drawing area.

Returns
Horizontal alignment.
Uint8 OpenXcom::Text::getColor ( ) const

Gets the text's color.

Returns the color used to render the text.

Returns
Color value.
Font * OpenXcom::Text::getFont ( ) const

Gets the text's current font.

Returns the font currently used by the text.

Returns
Pointer to font.
Uint8 OpenXcom::Text::getSecondaryColor ( ) const

Gets the text's secondary color.

Returns the secondary color used to render the text.

Returns
Color value.
std::wstring OpenXcom::Text::getText ( ) const

Gets the text's string.

Returns the string displayed on screen.

Returns
Text string.
int OpenXcom::Text::getTextHeight ( int  line = -1) const

Gets the rendered text's height.

Returns the rendered text's height.

Useful to check if wordwrap applies.

Parameters
lineLine to get the height, or -1 to get whole text height.
Returns
Height in pixels.
int OpenXcom::Text::getTextWidth ( int  line = -1) const

Gets the rendered text's width.

Returns the rendered text's width.

Parameters
lineLine to get the width, or -1 to get whole text width.
Returns
Width in pixels.
void OpenXcom::Text::initText ( Font big,
Font small,
Language lang 
)
virtual

Initializes the resources for the text.

Changes the various resources needed for text rendering.

The different fonts need to be passed in advance since the text size can change mid-text, and the language affects how the text is rendered.

Parameters
bigPointer to large-size font.
smallPointer to small-size font.
langPointer to current language.

Reimplemented from OpenXcom::Surface.

void OpenXcom::Text::setAlign ( TextHAlign  align)

Sets the text's horizontal alignment.

Changes the way the text is aligned horizontally relative to the drawing area.

Parameters
alignHorizontal alignment.
void OpenXcom::Text::setBig ( )

Sets the text size to big.

Changes the text to use the big-size font.

void OpenXcom::Text::setColor ( Uint8  color)

Sets the text's color.

Changes the color used to render the text.

Unlike regular graphics, fonts are greyscale so they need to be assigned a specific position in the palette to be displayed.

Parameters
colorColor value.
void OpenXcom::Text::setHighContrast ( bool  contrast)

Sets the text's high contrast color setting.

Enables/disables high contrast color.

Mostly used for Battlescape UI.

Parameters
contrastHigh contrast setting.
void OpenXcom::Text::setInvert ( bool  invert)

Sets the text's color invert setting.

Enables/disables color inverting.

Mostly used to make button text look pressed along with the button.

Parameters
invertInvert setting.
void OpenXcom::Text::setSecondaryColor ( Uint8  color)

Sets the text's secondary color.

Changes the secondary color used to render the text.

The text switches between the primary and secondary color whenever there's a 0x01 in the string.

Parameters
colorColor value.
void OpenXcom::Text::setSmall ( )

Sets the text size to small.

Changes the text to use the small-size font.

void OpenXcom::Text::setText ( const std::wstring &  text)

Sets the text's string.

Changes the string displayed on screen.

Parameters
textText string.
void OpenXcom::Text::setVerticalAlign ( TextVAlign  valign)

Sets the text's vertical alignment.

Changes the way the text is aligned vertically relative to the drawing area.

Parameters
valignVertical alignment.
void OpenXcom::Text::setWordWrap ( bool  wrap,
bool  indent = false 
)

Sets the text's wordwrap setting.

Enables/disables text wordwrapping.

When enabled, lines of text are automatically split to ensure they stay within the drawing area, otherwise they simply go off the edge.

Parameters
wrapWordwrapping setting.
indentIndent wrapped text.

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