home *** CD-ROM | disk | FTP | other *** search
- #include "FontObject2D.h"
- #include "Sequences.h"
- #include "Scene2D.h"
- #include "AutoPtr.h"
- #include "ResourceManagerPtr.h"
-
- FontObject2D::FontObject2D(Scene2D * scene, int layer, const String & name )
- : Object2D( scene, layer ),
- sequences( Sequences::load( name, scene ) ),
- alpha( 255 )
- {
- AutoPtr<Resource> res = ResourceManagerPtr()->create_resource( name + ".font" );
- if( !res )
- return;
- unsigned table_size = res->get_size() / 9;
-
- for( unsigned n = 0; n < table_size; ++n )
- {
- unsigned char font_desc[9] = { 0,0,0,0,0,0,0,0 };
- res->read( font_desc, 9 );
- unsigned char sym = font_desc[0];
- unsigned seq = (font_desc[2] - '0')*10 + (font_desc[3] - '0');
- unsigned fr = (font_desc[5] - '0')*10 + (font_desc[6] - '0');
- font_table[ sym ] = SeqFr( seq, fr );
- }
- }
-
- FontObject2D::~FontObject2D()
- {
- Sequences::unload( sequences );
- }
-
- void FontObject2D::render()
- {
- unsigned pos_x = 0;
- for( unsigned i = 0; i < text.size(); ++i )
- {
- FontTable::const_iterator it = font_table.find( text[i] );
- if( it == font_table.end() )
- continue;
- int seq = it->second.seq;
- int fr = it->second.fr;
-
- scene->push_shift_add( pos_x, 0 );
- {
- sequences->render_frame( seq, fr, alpha );
- }
- scene->pop_shift();
-
- pos_x += sequences->get_width( seq, fr );
- }
- }
-
- void FontObject2D::set_transparency(unsigned alpha)
- {
- this->alpha = alpha;
- }
-
- void FontObject2D::change_text(const String & text)
- {
- this->text = text;
- }
-