TextObject Class Reference

A text object intended for scripts that want to tell a story. More...

#include <text_object.hpp>

Inherits GameObject, scripting::Text, and ScriptInterface.

List of all members.

Public Member Functions

 TextObject (std::string name="")
virtual ~TextObject ()
void expose (HSQUIRRELVM vm, SQInteger table_idx)
void unexpose (HSQUIRRELVM vm, SQInteger table_idx)
void set_text (const std::string &text)
void set_font (const std::string &name)
void fade_in (float fadetime)
void fade_out (float fadetime)
void set_visible (bool visible)
void set_centered (bool centered)
bool is_visible ()
void set_anchor_point (AnchorPoint anchor)
AnchorPoint get_anchor_point () const
void set_pos (const Vector &pos)
void set_pos (float x, float y)
const Vectorget_pos () const
float get_pos_x ()
float get_pos_y ()
void set_anchor_point (int anchor)
int get_anchor_point ()
void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.
void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.

Private Member Functions

 TextObject (const TextObject &)
TextObjectoperator= (const TextObject &)

Private Attributes

FontPtr font
std::string text
float fading
float fadetime
bool visible
bool centered
AnchorPoint anchor
Vector pos

Static Private Attributes

static Color default_color


Detailed Description

A text object intended for scripts that want to tell a story.

Definition at line 28 of file text_object.hpp.


Constructor & Destructor Documentation

TextObject::TextObject ( std::string  name = ""  ) 

Definition at line 24 of file text_object.cpp.

References centered, font, and Resources::normal_font.

00024                                      :
00025   font(),
00026   text(),
00027   fading(0), 
00028   fadetime(0), 
00029   visible(false), 
00030   centered(),
00031   anchor(ANCHOR_MIDDLE),
00032   pos(0, 0)
00033 {
00034   this->name = name;
00035   font = Resources::normal_font;
00036   centered = false;
00037 }

TextObject::~TextObject (  )  [virtual]

Definition at line 39 of file text_object.cpp.

00040 {
00041 }

TextObject::TextObject ( const TextObject  )  [private]


Member Function Documentation

void TextObject::expose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 44 of file text_object.cpp.

References scripting::expose_object(), and GameObject::name.

00045 {
00046   if (name.empty())
00047     return;
00048 
00049   scripting::expose_object(vm, table_idx, dynamic_cast<scripting::Text *>(this), name, false);
00050 }

void TextObject::unexpose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 53 of file text_object.cpp.

References GameObject::name, and scripting::unexpose_object().

00054 {
00055   if (name.empty())
00056     return;
00057 
00058   scripting::unexpose_object(vm, table_idx, name);
00059 }

void TextObject::set_text ( const std::string &  text  )  [virtual]

Implements scripting::Text.

Definition at line 77 of file text_object.cpp.

00078 {
00079   this->text = text;
00080 }

void TextObject::set_font ( const std::string &  name  )  [virtual]

Implements scripting::Text.

Definition at line 62 of file text_object.cpp.

References Resources::big_font, font, log_warning, Resources::normal_font, and Resources::small_font.

00063 {
00064   if(name == "normal") {
00065     font = Resources::normal_font;
00066   } else if(name == "big") {
00067     font = Resources::big_font;
00068   } else if(name == "small") {
00069     font = Resources::small_font;
00070   } else {
00071     log_warning << "Unknown font '" << name << "'." << std::endl;
00072     font = Resources::normal_font;
00073   }
00074 }

void TextObject::fade_in ( float  fadetime  )  [virtual]

Implements scripting::Text.

Definition at line 83 of file text_object.cpp.

References fading.

00084 {
00085   this->fadetime = fadetime;
00086   fading = fadetime;
00087 }

void TextObject::fade_out ( float  fadetime  )  [virtual]

Implements scripting::Text.

Definition at line 90 of file text_object.cpp.

References fading.

00091 {
00092   this->fadetime = fadetime;
00093   fading = -fadetime;
00094 }

void TextObject::set_visible ( bool  visible  )  [virtual]

Implements scripting::Text.

Definition at line 97 of file text_object.cpp.

References fading.

00098 {
00099   this->visible = visible;
00100   fading = 0;
00101 }

void TextObject::set_centered ( bool  centered  )  [virtual]

Implements scripting::Text.

Definition at line 104 of file text_object.cpp.

00105 {
00106   this->centered = centered;
00107 }

bool TextObject::is_visible (  ) 

void TextObject::set_anchor_point ( AnchorPoint  anchor  )  [inline]

Definition at line 48 of file text_object.hpp.

Referenced by set_anchor_point().

00048                                             {
00049     this->anchor = anchor;
00050   }

AnchorPoint TextObject::get_anchor_point (  )  const [inline]

Definition at line 51 of file text_object.hpp.

References anchor.

Referenced by get_anchor_point().

00051                                        {
00052     return anchor;
00053   }

void TextObject::set_pos ( const Vector pos  )  [inline]

Definition at line 55 of file text_object.hpp.

References pos.

Referenced by set_pos().

00055                                   {
00056     this->pos = pos; 
00057   } 

void TextObject::set_pos ( float  x,
float  y 
) [inline, virtual]

Implements scripting::Text.

Definition at line 58 of file text_object.hpp.

References set_pos().

00058                                  {
00059     set_pos(Vector(x, y));
00060   }

const Vector& TextObject::get_pos (  )  const [inline]

Definition at line 61 of file text_object.hpp.

References pos.

00061                                 {
00062     return pos; 
00063   }

float TextObject::get_pos_x (  )  [inline, virtual]

Implements scripting::Text.

Definition at line 64 of file text_object.hpp.

References pos, and Vector::x.

00064                     {
00065     return pos.x;
00066   }

float TextObject::get_pos_y (  )  [inline, virtual]

Implements scripting::Text.

Definition at line 67 of file text_object.hpp.

References pos, and Vector::y.

00067                     {
00068     return pos.y;
00069   }

void TextObject::set_anchor_point ( int  anchor  )  [inline, virtual]

Implements scripting::Text.

Definition at line 71 of file text_object.hpp.

References set_anchor_point().

00071                                     {
00072     set_anchor_point((AnchorPoint) anchor);
00073   }

int TextObject::get_anchor_point (  )  [inline, virtual]

Implements scripting::Text.

Definition at line 74 of file text_object.hpp.

References get_anchor_point().

00074                          {
00075     return (int) get_anchor_point();
00076   }

void TextObject::draw ( DrawingContext context  )  [virtual]

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Implements GameObject.

Definition at line 110 of file text_object.cpp.

References ALIGN_LEFT, anchor, centered, default_color, DrawingContext::draw_center_text(), DrawingContext::draw_filled_rect(), DrawingContext::draw_text(), fadetime, fading, font, get_anchor_pos(), LAYER_GUI, DrawingContext::pop_transform(), pos, DrawingContext::push_transform(), SCREEN_HEIGHT, SCREEN_WIDTH, DrawingContext::set_alpha(), DrawingContext::set_translation(), text, and visible.

00111 {
00112   context.push_transform();
00113   context.set_translation(Vector(0, 0));
00114   if(fading > 0) {
00115     context.set_alpha((fadetime-fading) / fadetime);
00116   } else if(fading < 0) {
00117     context.set_alpha(-fading / fadetime);
00118   } else if(!visible) {
00119     context.pop_transform();
00120     return;
00121   }
00122 
00123   float width  = 500;
00124   float height = 70;
00125   Vector spos = pos + get_anchor_pos(Rectf(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
00126                                      width, height, anchor);
00127 
00128   context.draw_filled_rect(spos, Vector(width, height),
00129                            Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI-50);
00130   if (centered) {
00131     context.draw_center_text(font, text, spos, LAYER_GUI-40, TextObject::default_color);
00132   } else {
00133     context.draw_text(font, text, spos + Vector(10, 10), ALIGN_LEFT, LAYER_GUI-40, TextObject::default_color);
00134   }
00135 
00136   context.pop_transform();
00137 }

void TextObject::update ( float  elapsed_time  )  [virtual]

This function is called once per frame and allows the object to update it's state.

The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)

Implements GameObject.

Definition at line 140 of file text_object.cpp.

References fading, and visible.

00141 {
00142   if(fading > 0) {
00143     fading -= elapsed_time;
00144     if(fading <= 0) {
00145       fading = 0;
00146       visible = true;
00147     }
00148   } else if(fading < 0) {
00149     fading += elapsed_time;
00150     if(fading >= 0) {
00151       fading = 0;
00152       visible = false;
00153     }
00154   }
00155 }

TextObject& TextObject::operator= ( const TextObject  )  [private]


Member Data Documentation

Color TextObject::default_color [static, private]

Definition at line 32 of file text_object.hpp.

Referenced by draw().

FontPtr TextObject::font [private]

Definition at line 82 of file text_object.hpp.

Referenced by draw(), set_font(), and TextObject().

std::string TextObject::text [private]

Definition at line 83 of file text_object.hpp.

Referenced by draw().

float TextObject::fading [private]

Definition at line 84 of file text_object.hpp.

Referenced by draw(), fade_in(), fade_out(), set_visible(), and update().

float TextObject::fadetime [private]

Definition at line 85 of file text_object.hpp.

Referenced by draw().

bool TextObject::visible [private]

Definition at line 86 of file text_object.hpp.

Referenced by draw(), and update().

bool TextObject::centered [private]

Definition at line 87 of file text_object.hpp.

Referenced by draw(), and TextObject().

AnchorPoint TextObject::anchor [private]

Definition at line 88 of file text_object.hpp.

Referenced by draw(), and get_anchor_point().

Vector TextObject::pos [private]

Definition at line 89 of file text_object.hpp.

Referenced by draw(), get_pos(), get_pos_x(), get_pos_y(), and set_pos().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:37 2014 for SuperTux by  doxygen 1.5.1