Back to index

kdeartwork  4.3.2
Public Types | Public Member Functions | Private Member Functions | Private Attributes
Writer Class Reference

#include <firesaverwriter.h>

List of all members.

Public Types

enum  effectType { NoEffect = 0, Sequence, Fun1, Fun2 }

Public Member Functions

 Writer (QString descFileName)
 ~Writer ()
void spawnWords (QString phrase, effectType fx=NoEffect)
void render (double dT)

Private Member Functions

bool loadMap (QString)
 Writer ()

Private Attributes

int numTextures
unsigned int texArray [16]
QList< Word * > wordList
QMap< char, Symbol * > symbolMap

Detailed Description

Definition at line 80 of file firesaverwriter.h.


Member Enumeration Documentation

Enumerator:
NoEffect 
Sequence 
Fun1 
Fun2 

Definition at line 87 of file firesaverwriter.h.

{ NoEffect = 0, Sequence, Fun1, Fun2 };

Constructor & Destructor Documentation

Writer::Writer ( QString  descFileName)

Definition at line 90 of file firesaverwriter.cpp.

    : numTextures(0)
{
       wordList.setAutoDelete( true );

       if ( !loadMap( descFileName ) )
              return;

       QString welcomeString = i18n("Welcome to KDE %1.%2.%3",
            KDE_VERSION_MAJOR,
            KDE_VERSION_MINOR,
            KDE_VERSION_RELEASE);
       spawnWords(welcomeString, Fun1);
}

Here is the call graph for this function:

Definition at line 105 of file firesaverwriter.cpp.

{
       glDeleteTextures( numTextures, texArray );
       wordList.clear();
       QMap<char, Symbol *>::Iterator it = symbolMap.begin();
       for ( ; it != symbolMap.end(); ++it )
              delete (Symbol *)it.data();
}
Writer::Writer ( ) [private]

Member Function Documentation

bool Writer::loadMap ( QString  descFile) [private]

Definition at line 188 of file firesaverwriter.cpp.

{
    QFile desc( locate("data","kfiresaver/"+descFile) );
    if ( !desc.open( QIODevice::ReadOnly ) )
       return false;

    unsigned int currentNumber;
    float xres = 0, yres = 0;
    bool generatedFirst = false;

    while ( !desc.atEnd() )
    {
       QString line;
       int count = desc.readLine( line, 100 );
       //skip comments / invalid lines
       if ( count < 6 || line.at(0) == '#')
           continue;
       //load texture maps
       if ( line.at(0) == '"' && numTextures < 15 )
       {
           //load and generate texture
           QString fileName = line.section("\"", 1,1 );
           QImage tmp;
           if ( !tmp.load( locate("data","kfiresaver/"+fileName) ) ) {
              kWarning() << "can't load filename:" << fileName ;
              generatedFirst = false;
              continue;
           }
           glGenTextures( 1, &currentNumber );
           texArray[ numTextures++ ] = currentNumber;
           glBindTexture(GL_TEXTURE_2D, currentNumber);
           glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
           glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
           QImage texture = QGLWidget::convertToGLFormat( tmp );
           xres = (float)texture.width();
           yres = (float)texture.height();
           glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (int)xres, (int)yres, 0,
              GL_RGBA, GL_UNSIGNED_BYTE, texture.bits());
           generatedFirst = true;
           continue;
       }
       if  ( !generatedFirst )
           continue;
       if ( line.contains(' ') != 4 ) {
           kWarning() << "wrong line on symbols.desc (4 spaces expected):" ;
           kWarning() << " '" << line << "'" ;
           continue;
       }
       //parse the line describing a symbol and create it
       char p = *(line.latin1());
       if ( symbolMap.contains(p) )
           continue;
       float left = (float)(line.section(' ',1,1).toInt())/xres,
             top = (float)(line.section(' ',2,2).toInt())/yres,
             right = (float)(line.section(' ',3,3).toInt() + 1)/xres,
             bottom = (float)(line.section(' ',4,4).toInt() + 1)/yres;
       symbolMap[p] = new Symbol( currentNumber, left,top,right,bottom );
    }

    return symbolMap.size() > 0;
}

Here is the caller graph for this function:

void Writer::render ( double  dT)

Definition at line 163 of file firesaverwriter.cpp.

{
    if ( !numTextures )
       return;

    glEnable( GL_TEXTURE_2D );

    glPushMatrix();
    glScalef( 0.6, 0.6, 1.0 );
    Word * word = wordList.first();
    while( word ) {
       word->renderWord( dT );
       if ( word->isDead() ) {
              wordList.remove();
              word = wordList.current();
       } else
              word = wordList.next();
    }
    glPopMatrix();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Writer::spawnWords ( QString  phrase,
effectType  fx = NoEffect 
)

Definition at line 114 of file firesaverwriter.cpp.

{
       int wordCount = 0;
       float xCenter = 0,
             yCenter = drand48()*40 - 20,
             wordsWidth = 0;
       QList<Word *> localWords;
       while ( phrase.length() > 0 )
       {
              QString letters = phrase.section(' ',0,0);
              Word * word = new Word( letters.latin1(), &symbolMap );
              wordList.append( word );
              localWords.append( word );
              word->cX = xCenter;
              word->cY = yCenter;
              switch ( fX ) {
                  case Fun1:{
                     float  angle = 2*M_PI * drand48(),
                            module = 0.25 * (drand48() + drand48());
                     word->vX = module * cos( angle );
                     word->vY = module * sin( angle );
                     word->vScale = 0.6;
                     word->scale = 0.7 + 0.3*(drand48() + drand48());}
                     word->activateTime = 0.3 * wordCount;
                     //fall to the case below for word spacing
                  default:
                  case NoEffect:
                     wordsWidth += word->width;
                     word->cX += wordsWidth;
                     wordsWidth += word->width + 1;
                     break;
                  case Sequence:
                     word->lifeTime = 1.2;
                     word->activateTime = 0.6 + 0.9 * wordCount;
//                   word->vY = -5;
                     break;
              }
              wordCount ++;
              phrase.remove(0, letters.length() + 1);
       }
       if ( localWords.count() < 1 )
              return;
       //some computations to 'center' the string
       float displace = -(wordsWidth - 1) / 2;
       Word * word = localWords.first();
       for( ; word; word = localWords.next() )
              word->cX += displace;
}

Here is the caller graph for this function:


Member Data Documentation

int Writer::numTextures [private]

Definition at line 102 of file firesaverwriter.h.

QMap<char, Symbol *> Writer::symbolMap [private]

Definition at line 107 of file firesaverwriter.h.

unsigned int Writer::texArray[16] [private]

Definition at line 103 of file firesaverwriter.h.

QList<Word *> Writer::wordList [private]

Definition at line 106 of file firesaverwriter.h.


The documentation for this class was generated from the following files: