forked from clickteam-plugin/TileMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tileset.h
85 lines (71 loc) · 2.11 KB
/
Tileset.h
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
#pragma once
#include "HWASurface.h"
class Tileset {
char path[256];
public:
cSurface * surface;
cSurface * texture;
COLORREF transpCol;
int renderMode;
Tileset() : surface(0), texture(0), transpCol(0xFF00FF), renderMode(SD_DIB) { path[0] = 0; }
~Tileset()
{
delete surface;
#ifdef HWABETA
delete texture;
#endif
}
Tileset(const Tileset & src) : surface(0), texture(0)
{
int n = min(254, strlen(src.path));
strncpy(path, src.path, n);
path[n] = 0;
transpCol = src.transpCol;
if (src.surface) {
surface = new cSurface;
surface->Clone(*src.surface);
texture = 0;
updateTexture();
}
}
inline bool isValid() { return surface != 0 && surface->IsValid(); }
// For HWA: Need texture and bitmap surface...
void updateTexture()
{
#ifdef HWABETA
if (texture) {
delete texture;
texture = 0;
}
if (surface) {
texture = new cSurface;
texture->Create(surface->GetWidth(), surface->GetHeight(),
getPrototype(surface->GetDepth(), renderMode));
copyBlit(*surface, *texture);
texture->SetTransparentColor(surface->GetTransparentColor());
}
#else
texture = surface;
#endif
}
void setRenderMode(int mode)
{
renderMode = mode;
}
void setPathFromRelative(const char * sourcePath, const char * relativePath)
{
// Try to make this path absolute
if (!PathCombine(path, sourcePath, relativePath)) {
// Last chance: Copy path directly
strcpy_s(path, 256, relativePath);
}
}
void setPath(const char * source) { strcpy_s(path, 256, source); }
const char * getPath() const { return (const char *)&path[0]; }
bool getPathRelativeTo(const char * sourcePath, char * outputBuffer, bool sourceIsFile = false) const
{
return outputBuffer &&
PathRelativePathTo(outputBuffer, sourcePath,
sourceIsFile ? 0 : FILE_ATTRIBUTE_DIRECTORY, path, 0);
}
};