summaryrefslogtreecommitdiffstats
path: root/kscreensaver/kdesavers/firesaverwriter.h
blob: e93f65be3daadbf3a8edf0f2ff40e1eb03a7a9c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
 *   Copyright (C) 2004 by E.Ros                                           *
 *   rosenric@dei.unipd.it                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef FIRESAVER_WRITER_H
#define FIRESAVER_WRITER_H

#include <tqgl.h>
#include <tqptrlist.h>
#include <tqmap.h>
#include <tqstring.h>

class Symbol
{
    public:
	Symbol( unsigned int textureNumber, float l, float t, float r, float b )
	    : scale((r - l) / (b - t)), texNum(textureNumber), L(l), T(1-t), R(r), B(1-b)
	{
	    v1[0] = -scale;	v1[1] =  1;
	    v2[0] = -scale;	v2[1] = -1;
	    v3[0] = scale;	v3[1] =  1;
	    v4[0] = scale;	v4[1] = -1;
	}

	float scale;

	inline void renderSymbol()
	{
	    //draw the symbol and update "cursor"'s position
	    glBindTexture( GL_TEXTURE_2D, texNum );
	    glTranslatef( scale, 0, 0 );
	    glBegin( GL_TRIANGLE_STRIP );
	     glTexCoord2f( L, T );
	     glVertex2fv( v1 );
	     glTexCoord2f( L, B );
	     glVertex2fv( v2 );
	     glTexCoord2f( R, T );
	     glVertex2fv( v3 );
	     glTexCoord2f( R, B );
	     glVertex2fv( v4 );
	    glEnd();
	    glTranslatef( scale, 0, 0 );
	}

    private:
	float v1[2], v2[2], v3[2], v4[2];
	unsigned int texNum;	//number of texture to activate
	float L, T, R, B;	//coordinates for mapping
};


class Word
{
    friend class Writer;
    public:
	Word( const char * text, TQMap<char, Symbol *> * map, float scale = 1.0 );

	inline void renderWord( double dT );
	inline bool isDead();

    private:
	float width, scale, cX, cY;
	float vScale, vX, vY;
	float activateTime, lifeTime, currentTime;
	float color[4];
	TQPtrList<Symbol> symbolList;
};


/*
 *
 **/
class Writer
{
    public:
	Writer( TQString descFileName );
	~Writer();

	//types of effects implemented
	enum effectType { NoEffect = 0, Sequence, Fun1, Fun2 };

	//call this function to add a sentence to the renderer
	void spawnWords( TQString phrase, effectType fx = NoEffect );

	//called to get the words on screen using OpenGL
	//Note: the context must be set up. Words are drawn on XY plane
	//inside a rectangle with 10 units's side.
	void render( double dT );

    private:
	//misc utility functions
	bool loadMap( TQString );

	//texture 'references' used by GL to delete allocated textures
	int numTextures;
	unsigned int texArray[16];

	//list of words and map of symbols
	TQPtrList<Word> wordList;
	TQMap<char, Symbol *> symbolMap;

	//disables standard constructor
	Writer();
};

#endif