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
|
/* -------------------------------------------------------------
KDE Tuberling
Object to draw on the game board
mailto:e.bischoff@noos.fr
------------------------------------------------------------- */
#include <tqbitmap.h>
#include <tqpainter.h>
#include "todraw.h"
// Constructor with no arguments
ToDraw::ToDraw()
: position()
{
number = -1;
}
// Copy constructor
ToDraw::ToDraw(const ToDraw &model)
: position(model.position)
{
number = model.number;
}
// Constructor with arguments
ToDraw::ToDraw(int declaredNumber, const TQRect &declaredPosition)
: position(declaredPosition)
{
number = declaredNumber;
}
// Affectation operator
ToDraw &ToDraw::operator=(const ToDraw &model)
{
if (&model == this) return *this;
position = model.position;
number = model.number;
return *this;
}
// Draw an object previously laid down on the game board
void ToDraw::draw(TQPainter &artist, const TQRect &area,
const TQRect *objectsLayout,
const TQPixmap *gameboard, const TQBitmap *masks) const
{
if (!position.intersects(area)) return;
TQPixmap objectPixmap(objectsLayout[number].size());
TQBitmap shapeBitmap(objectsLayout[number].size());
bitBlt(&objectPixmap, TQPoint(0, 0), gameboard, objectsLayout[number], TQt::CopyROP);
bitBlt(&shapeBitmap, TQPoint(0, 0), masks, objectsLayout[number], TQt::CopyROP);
objectPixmap.setMask(shapeBitmap);
artist.drawPixmap(position.topLeft(), objectPixmap);
}
// Load an object from a file
bool ToDraw::load(FILE *fp, int decorations, bool &eof)
{
int nitems;
int pl, pt, pr, pb;
nitems = fscanf(fp, "%d\t%d %d %d %d\n", &number, &pl, &pt, &pr, &pb);
if (nitems == EOF)
{
eof = true;
return true;
}
eof = false;
if (nitems != 5) return false;
if (number < 0 || number >= decorations) return false;
position.setCoords(pl, pt, pr, pb);
return true;
}
// Save an object to a file
void ToDraw::save(FILE *fp) const
{
fprintf(fp, "%d\t%d %d %d %d\n",
number,
position.left(), position.top(), position.right(), position.bottom());
}
|