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
114
115
116
117
118
119
120
121
|
#ifndef AA_FRAME_H
#define AA_FRAME_H
#include <tqstring.h>
#include <tqvaluevector.h>
#include <tqpixmap.h>
#include "screen.h"
/**
* Represents a single frame of a sprite's animation.
*
* @see Sprite
*/
class Frame
{
/**
* Two-dimensional array of Pixels, which represent the appearance of this
* frame. This is used to create m_pixmap and m_erasePixmap when they are
* needed.
*
* @see Pixel
*/
TQValueVector<TQValueVector<Screen::Pixel> > m_data;
/// Masked pixmap of the animation frame. Created by convertDataToPixmap().
TQPixmap m_pixmap;
/// Masked pixmap used to clear frame. Created by convertDataToPixmap().
TQPixmap m_erasePixmap;
/// Height of this frame of animation in logical coordinates.
int m_height;
/// Width of this frame of animation in logical coordinates.
int m_width;
/// Character to be used as a special 'transparent' character. Normally is
/// the '?' character.
TQChar m_transparentChar;
public:
/**
* Constructs an empty animation Frame. Do not insert this into a Sprite.
*/
Frame() : m_height(0), m_width(0)
{
}
/**
* Constructs an animation frame.
*
* @param text Newline-separated text used to construct the Pixel arrays.
* The lines do not have to be equal length, any extra needed
* characters will automatically be filled with transparency.
* Any whitespace at the beginning of a line is converted to
* transparency as well.
*
* @param mask Newline-separated text used to mask \p text's colors. This
* can be empty or null in which case no masking is performed.
* However, if present, there should be the same number of
* lines in \p mask as in \p text, although individual lines
* can be shorter or empty as convienient. You can use letters
* to stand for colors, e.g. 'r' will make the letter in \p
* text at the same position dark red.
*
* @param defaultColor The default color to apply to characters. This
* color is used for all characters in \p text that are
* not altered by \p mask.
*
* @param transparent The character to use to represent transparent areas
* in \p text. This can be useful when the
* auto-transparency feature can't detect transparent
* areas.
*/
Frame(TQString text, TQString mask, TQRgb defaultColor, TQChar transparent = '?');
/**
* Paints this Frame into the given screen.
*
* @param scr The Screen to draw into.
* @param x The logical x coordinate of the left edge of the update region.
* @param y The logical y coordinate of the top edge of the update region.
*/
void paint(Screen* scr, int x, int y);
/**
* Erases this Frame from the given screen.
*
* @param scr The Screen to draw into.
* @param x The logical x coordinate of the left edge of the update region.
* @param y The logical y coordinate of the top edge of the update region.
*/
void erase(Screen* scr, int x, int y);
/// Returns the logical width of this frame.
int width() const
{
return m_width;
}
/// Returns the logical height of this frame.
int height() const
{
return m_height;
}
protected:
/**
* This function converts the Pixel data in m_data to setup m_pixmap
* and m_erasePixmap, which are not setup until this function is called.
*
* m_data is not valid after this call is performed to save memory.
*
* @param screen The Screen we will be drawing into later.
*/
void convertDataToPixmap(const Screen *screen);
};
#endif
|