Back to index

kdeartwork  4.3.2
firesaverwriter.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by E.Ros                                           *
00003  *   rosenric@dei.unipd.it                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #ifndef FIRESAVER_WRITER_H
00013 #define FIRESAVER_WRITER_H
00014 
00015 #include <qgl.h>
00016 #include <qlist.h>
00017 #include <qmap.h>
00018 #include <qstring.h>
00019 
00020 class Symbol
00021 {
00022     public:
00023        Symbol( unsigned int textureNumber, float l, float t, float r, float b )
00024            : scale((r - l) / (b - t)), texNum(textureNumber), L(l), T(1-t), R(r), B(1-b)
00025        {
00026            v1[0] = -scale;  v1[1] =  1;
00027            v2[0] = -scale;  v2[1] = -1;
00028            v3[0] = scale;   v3[1] =  1;
00029            v4[0] = scale;   v4[1] = -1;
00030        }
00031 
00032        float scale;
00033 
00034        inline void renderSymbol()
00035        {
00036            //draw the symbol and update "cursor"'s position
00037            glBindTexture( GL_TEXTURE_2D, texNum );
00038            glTranslatef( scale, 0, 0 );
00039            glBegin( GL_TRIANGLE_STRIP );
00040             glTexCoord2f( L, T );
00041             glVertex2fv( v1 );
00042             glTexCoord2f( L, B );
00043             glVertex2fv( v2 );
00044             glTexCoord2f( R, T );
00045             glVertex2fv( v3 );
00046             glTexCoord2f( R, B );
00047             glVertex2fv( v4 );
00048            glEnd();
00049            glTranslatef( scale, 0, 0 );
00050        }
00051 
00052     private:
00053        float v1[2], v2[2], v3[2], v4[2];
00054        unsigned int texNum; //number of texture to activate
00055        float L, T, R, B;    //coordinates for mapping
00056 };
00057 
00058 
00059 class Word
00060 {
00061     friend class Writer;
00062     public:
00063        Word( const char * text, QMap<char, Symbol *> * map, float scale = 1.0 );
00064 
00065        inline void renderWord( double dT );
00066        inline bool isDead();
00067 
00068     private:
00069        float width, scale, cX, cY;
00070        float vScale, vX, vY;
00071        float activateTime, lifeTime, currentTime;
00072        float color[4];
00073        Q3PtrList<Symbol> symbolList;
00074 };
00075 
00076 
00077 /*
00078  *
00079  **/
00080 class Writer
00081 {
00082     public:
00083        Writer( QString descFileName );
00084        ~Writer();
00085 
00086        //types of effects implemented
00087        enum effectType { NoEffect = 0, Sequence, Fun1, Fun2 };
00088 
00089        //call this function to add a sentence to the renderer
00090        void spawnWords( QString phrase, effectType fx = NoEffect );
00091 
00092        //called to get the words on screen using OpenGL
00093        //Note: the context must be set up. Words are drawn on XY plane
00094        //inside a rectangle with 10 units's side.
00095        void render( double dT );
00096 
00097     private:
00098        //misc utility functions
00099        bool loadMap( QString );
00100 
00101        //texture 'references' used by GL to delete allocated textures
00102        int numTextures;
00103        unsigned int texArray[16];
00104 
00105        //list of words and map of symbols
00106        QList<Word *> wordList;
00107        QMap<char, Symbol *> symbolMap;
00108 
00109        //disables standard constructor
00110        Writer();
00111 };
00112 
00113 #endif