#include <text_object.hpp>
Inherits GameObject, scripting::Text, and ScriptInterface.
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 Vector & | get_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 &) | |
TextObject & | operator= (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 |
Definition at line 28 of file text_object.hpp.
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] |
TextObject::TextObject | ( | const TextObject & | ) | [private] |
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] |
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] |
void TextObject::fade_out | ( | float | fadetime | ) | [virtual] |
void TextObject::set_visible | ( | bool | visible | ) | [virtual] |
void TextObject::set_centered | ( | bool | centered | ) | [virtual] |
bool TextObject::is_visible | ( | ) |
void TextObject::set_anchor_point | ( | AnchorPoint | anchor | ) | [inline] |
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] |
void TextObject::set_pos | ( | float | x, | |
float | y | |||
) | [inline, virtual] |
const Vector& TextObject::get_pos | ( | ) | const [inline] |
float TextObject::get_pos_x | ( | ) | [inline, virtual] |
Implements scripting::Text.
Definition at line 64 of file text_object.hpp.
References pos, and Vector::x.
float TextObject::get_pos_y | ( | ) | [inline, virtual] |
Implements scripting::Text.
Definition at line 67 of file text_object.hpp.
References pos, and Vector::y.
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] |
Color TextObject::default_color [static, private] |
FontPtr TextObject::font [private] |
std::string TextObject::text [private] |
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] |
bool TextObject::visible [private] |
bool TextObject::centered [private] |
AnchorPoint TextObject::anchor [private] |
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().