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