home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 April / Game.EXE_04_2002.iso / Alawar / FontObject2D.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-02  |  1.5 KB  |  63 lines

  1. #include "FontObject2D.h"
  2. #include "Sequences.h"
  3. #include "Scene2D.h"
  4. #include "AutoPtr.h"
  5. #include "ResourceManagerPtr.h"
  6.  
  7. FontObject2D::FontObject2D(Scene2D * scene, int layer, const String & name  )
  8. :    Object2D( scene, layer ),
  9.     sequences( Sequences::load( name, scene ) ),
  10.     alpha( 255 )
  11. {
  12.     AutoPtr<Resource> res = ResourceManagerPtr()->create_resource( name + ".font" );
  13.     if( !res )
  14.         return;
  15.     unsigned table_size = res->get_size() / 9;
  16.  
  17.     for( unsigned n = 0; n < table_size; ++n )
  18.     {
  19.         unsigned char font_desc[9] = { 0,0,0,0,0,0,0,0 };
  20.         res->read( font_desc, 9 );
  21.         unsigned char sym = font_desc[0];
  22.         unsigned seq = (font_desc[2] - '0')*10 + (font_desc[3] - '0');
  23.         unsigned fr = (font_desc[5] - '0')*10 + (font_desc[6] - '0');
  24.         font_table[ sym ] = SeqFr( seq, fr );
  25.     }
  26. }
  27.  
  28. FontObject2D::~FontObject2D()
  29. {
  30.     Sequences::unload( sequences );
  31. }
  32.  
  33. void FontObject2D::render()
  34. {
  35.     unsigned pos_x = 0;
  36.     for( unsigned i = 0; i < text.size(); ++i )
  37.     {
  38.         FontTable::const_iterator it = font_table.find( text[i] );
  39.         if( it == font_table.end() )
  40.             continue;
  41.         int seq = it->second.seq;
  42.         int fr = it->second.fr;
  43.  
  44.         scene->push_shift_add( pos_x, 0 );
  45.         {
  46.             sequences->render_frame( seq, fr, alpha );
  47.         }
  48.         scene->pop_shift();
  49.  
  50.         pos_x += sequences->get_width( seq, fr );
  51.     }
  52. }
  53.  
  54. void FontObject2D::set_transparency(unsigned alpha)
  55. {
  56.     this->alpha = alpha;
  57. }
  58.  
  59. void FontObject2D::change_text(const String & text)
  60. {
  61.     this->text = text;
  62. }
  63.