-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageManager.cpp
More file actions
189 lines (134 loc) · 3.41 KB
/
ImageManager.cpp
File metadata and controls
189 lines (134 loc) · 3.41 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "stdafx.h"
#include "ImageManager.h"
ImageManager::ImageManager()
{
}
ImageManager::~ImageManager()
{
}
HRESULT ImageManager::init()
{
return S_OK;
}
void ImageManager::release()
{
deleteAll();
}
image* ImageManager::addImage(string strKey, int width, int height)
{
image* img = findImage(strKey);
//해당 이미지가 만약에 있으면 그냥 그 이미지를 써라
if (img) return img;
img = new image;
if (FAILED(img->init(width, height)))
{
SAFE_DELETE(img);
return nullptr;
}
_mImageList.insert(make_pair(strKey, img));
return img;
}
image* ImageManager::addImage(string strKey, const char* fileName, int width, int height, bool trans, COLORREF transColor)
{
image* img = findImage(strKey);
if (img) return img;
img = new image;
if (FAILED(img->init(fileName, width, height, trans, transColor)))
{
SAFE_DELETE(img);
return nullptr;
}
_mImageList.insert(make_pair(strKey, img));
return img;
}
image* ImageManager::addFrameImage(string strKey, const char* fileName, float x, float y, int width, int height, int frameX, int frameY, bool trans, COLORREF transColor)
{
image* img = findImage(strKey);
if (img) return img;
img = new image;
if (FAILED(img->init(fileName, x, y, width, height, frameX, frameY, trans, transColor)))
{
SAFE_DELETE(img);
return nullptr;
}
_mImageList.insert(make_pair(strKey, img));
return img;
}
image* ImageManager::addFrameImage(string strKey, const char* fileName, int width, int height, int frameX, int frameY, bool trans, COLORREF transColor)
{
image* img = findImage(strKey);
if (img) return img;
img = new image;
if (FAILED(img->init(fileName, width, height, frameX, frameY, trans, transColor)))
{
SAFE_DELETE(img);
return nullptr;
}
_mImageList.insert(make_pair(strKey, img));
return img;
}
image* ImageManager::findImage(string strKey)
{
mapImageIter key = _mImageList.find(strKey);
//찾았다!
if (key != _mImageList.end())
{
return key->second;
}
return nullptr;
}
BOOL ImageManager::deleteImage(string strKey)
{
mapImageIter key = _mImageList.find(strKey);
if (key != _mImageList.end())
{
key->second->release();
SAFE_DELETE(key->second);
_mImageList.erase(key);
return true;
}
return false;
}
BOOL ImageManager::deleteAll()
{
mapImageIter iter = _mImageList.begin();
for (; iter != _mImageList.end();)
{
//맵컨테이너안에 이미지가 있다면
if (iter->second != nullptr)
{
iter->second->release();
SAFE_DELETE(iter->second);
iter = _mImageList.erase(iter);
}
else ++iter;
}
_mImageList.clear();
return false;
}
/*
void imageManager::render(string strKey, HDC hdc)
{
image* img = findImage(strKey);
if (img) img->render(hdc);
}*/
void ImageManager::render(string strKey, HDC hdc, int destX, int destY)
{
image* img = findImage(strKey);
if (img) img->render(hdc, destX, destY);
}
void ImageManager::render(string strKey, HDC hdc, int destX, int destY, int sourX, int sourY, int sourWidth, int sourHeight)
{
image* img = findImage(strKey);
if (img) img->render(hdc, destX, destY, sourX, sourY, sourWidth, sourHeight);
}
void ImageManager::frameRender(string strKey, HDC hdc, int destX, int destY)
{
image* img = findImage(strKey);
if (img) img->frameRender(hdc, destX, destY);
}
void ImageManager::frameRender(string strKey, HDC hdc, int destX, int destY, int currentFrameX, int currentFrameY)
{
image* img = findImage(strKey);
if (img) img->frameRender(hdc, destX, destY, currentFrameX, currentFrameY);
}