-
Notifications
You must be signed in to change notification settings - Fork 5
/
tilebuffer.cpp
86 lines (75 loc) · 1.76 KB
/
tilebuffer.cpp
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
#include "tilebuffer.h"
TileBuffer::TileBuffer()
{
TileSizeY = 32;
TileSizeX = 32;
}
TileBuffer::~TileBuffer()
{
qDeleteAll(TileImages);
TileImages.clear();
}
int TileBuffer::LoadImage(QString FileName)
{
QPixmap Img;
Img.load(FileName);
TileImages.clear();
for (int j=0; j<Img.height()/TileSizeY;j++)
for (int i=0; i<Img.width()/TileSizeX;i++)
{
TileImages.append(
new QPixmap(Img.copy(i*TileSizeX,
j*TileSizeY,
TileSizeX,
TileSizeY) ));
}
return Img.width()/TileSizeX;
}
void TileBuffer::addLoadImage(QString FileName)
{
QPixmap Img;
Img.load(FileName);
for (int j=0; j<Img.height()/TileSizeY;j++)
for (int i=0; i<Img.width()/TileSizeX;i++)
{
TileImages.append(
new QPixmap(Img.copy(i*TileSizeX,
j*TileSizeY,
TileSizeX,
TileSizeY) ));
}
}
void TileBuffer::remove(int index)
{
TileImages.removeAt(index);
}
void TileBuffer::clear()
{
qDeleteAll(TileImages);
TileImages.clear();
}
int TileBuffer::getTileSizeX() const
{
return TileSizeX;
}
int TileBuffer::getTileSizeY() const
{
return TileSizeY;
}
void TileBuffer::setTileSize(int x, int y)
{
TileSizeX = x;
TileSizeY = y;
}
int TileBuffer::getCount()
{
return TileImages.size();
}
QPixmap *TileBuffer::getTilePixmapAt(int index)
{
if (index < 0 ) return NULL;
if (index < TileImages.size())
return TileImages.at(index);
else
return NULL;
}