Qt3to4
[kdeartwork.git] / kscreensaver / kdesavers / firesaverwriter.h
blobeb5a0a451e9dba72b4ae86da6b44fbb3ab6c4071
1 /***************************************************************************
2 * Copyright (C) 2004 by E.Ros *
3 * rosenric@dei.unipd.it *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 ***************************************************************************/
12 #ifndef FIRESAVER_WRITER_H
13 #define FIRESAVER_WRITER_H
15 #include <qgl.h>
16 #include <q3ptrlist.h>
17 #include <qmap.h>
18 #include <qstring.h>
20 class Symbol
22 public:
23 Symbol( unsigned int textureNumber, float l, float t, float r, float b )
24 : scale((r - l) / (b - t)), texNum(textureNumber), L(l), T(1-t), R(r), B(1-b)
26 v1[0] = -scale; v1[1] = 1;
27 v2[0] = -scale; v2[1] = -1;
28 v3[0] = scale; v3[1] = 1;
29 v4[0] = scale; v4[1] = -1;
32 float scale;
34 inline void renderSymbol()
36 //draw the symbol and update "cursor"'s position
37 glBindTexture( GL_TEXTURE_2D, texNum );
38 glTranslatef( scale, 0, 0 );
39 glBegin( GL_TRIANGLE_STRIP );
40 glTexCoord2f( L, T );
41 glVertex2fv( v1 );
42 glTexCoord2f( L, B );
43 glVertex2fv( v2 );
44 glTexCoord2f( R, T );
45 glVertex2fv( v3 );
46 glTexCoord2f( R, B );
47 glVertex2fv( v4 );
48 glEnd();
49 glTranslatef( scale, 0, 0 );
52 private:
53 float v1[2], v2[2], v3[2], v4[2];
54 unsigned int texNum; //number of texture to activate
55 float L, T, R, B; //coordinates for mapping
59 class Word
61 friend class Writer;
62 public:
63 Word( const char * text, QMap<char, Symbol *> * map, float scale = 1.0 );
65 inline void renderWord( double dT );
66 inline bool isDead();
68 private:
69 float width, scale, cX, cY;
70 float vScale, vX, vY;
71 float activateTime, lifeTime, currentTime;
72 float color[4];
73 Q3PtrList<Symbol> symbolList;
79 **/
80 class Writer
82 public:
83 Writer( QString descFileName );
84 ~Writer();
86 //types of effects implemented
87 enum effectType { NoEffect = 0, Sequence, Fun1, Fun2 };
89 //call this function to add a sentence to the renderer
90 void spawnWords( QString phrase, effectType fx = NoEffect );
92 //called to get the words on screen using OpenGL
93 //Note: the context must be set up. Words are drawn on XY plane
94 //inside a rectangle with 10 units's side.
95 void render( double dT );
97 private:
98 //misc utility functions
99 bool loadMap( QString );
101 //texture 'references' used by GL to delete allocated textures
102 int numTextures;
103 unsigned int texArray[16];
105 //list of words and map of symbols
106 Q3PtrList<Word> wordList;
107 QMap<char, Symbol *> symbolMap;
109 //disables standard constructor
110 Writer();
113 #endif