-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDependentShape.cpp
More file actions
330 lines (281 loc) · 8.41 KB
/
DependentShape.cpp
File metadata and controls
330 lines (281 loc) · 8.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#include "stdafx.h"
#include "DependentShape.h"
#include "ShapeHandler.h"
CDependentShape::CDependentShape(int nId, int nX, int nY, int nWidth, int nHeight)
: CComponentShape(nId, nX, nY, nWidth, nHeight)
{
m_nLocaInfo = LOCA_DEFAULT;
m_nType = TYPE_DEPENDENT;
}
CDependentShape::~CDependentShape()
{
}
// 기본 기능
bool CDependentShape::AddShape()
{
CShapeHandler *tmpShapeHandler = CShapeHandler::GetInstance();
if (tmpShapeHandler->m_CaShape.size() == 0)
return FALSE;
//////////////////////////////////////////////////////////////////////////
// 마지막 검사, 기준 재조정
if (nX > nWidth)
{
swap(nX, nWidth);
}
if (nY > nHeight)
{
swap(nY, nHeight);
}
// Copy 할 때 또 대입 되는것을 방지 함!
if (m_nLocaInfo <= 0)
m_nLocaInfo = tmpShapeHandler->m_RememberLocationForDoorWindow;
if (m_pInContainerShapeID < 0)
m_pInContainerShapeID = tmpShapeHandler->m_pRememberRoomIDForDoorWindow; // 자신이 속해있는 Room의 ID
/// 삽입!
tmpShapeHandler->m_CaShape.push_back(this);
dynamic_cast<CBasicContainerShape*>(tmpShapeHandler->GetShapeByID(m_pInContainerShapeID))->m_CaDependent.push_back(this);
return TRUE;
}
bool CDependentShape::DeleteShape()
{
// 선택된 방 안의 문의 벡터를 받아 둠
// 주솟 값을 받아야함!!!! 저기 있는 벡터는 포인터 변수가 아님 꼭 기억해 놓을 것!
auto tmpDependentPtr = &dynamic_cast<CBasicContainerShape*>(CShapeHandler::GetInstance()->GetShapeByID(m_pInContainerShapeID))->m_CaDependent;
// 선택된 문의 포인터, 즉 나 자신
auto tmpSelectedDoorPtr = this;
tmpSelectedDoorPtr->SetId(-600000);
//////////////////////////////////////////////////////////////////////////
// 전체 CShape 벡터에서는 아이디 값이 쓰레기 값인 것을 삭제
for (long i = CShapeHandler::GetInstance()->m_CaShape.size() - 1; i >= 0; i--)
{
int nWasteValue = CShapeHandler::GetInstance()->m_CaShape[i]->GetId();
if (nWasteValue < -50000)
{
CShapeHandler::GetInstance()->m_CaShape.erase(CShapeHandler::GetInstance()->m_CaShape.begin() + i);
break;
}
}
//////////////////////////////////////////////////////////////////////////
// Dependent 벡터에서는 아이디 값이 쓰레기 값인 것을 삭제
for (long i = tmpDependentPtr->size() - 1; i >= 0; i--)
{
int nWasteValue = tmpDependentPtr->at(i)->GetId();
if (nWasteValue < -50000)
{
tmpDependentPtr->erase(tmpDependentPtr->begin() + i);
break;
}
}
SAFE_DELETE(tmpSelectedDoorPtr);// 선택된 문 삭제, delete
return TRUE;
}
bool CDependentShape::CopyShape()
{
int nRandLocation = static_cast<int>((rand() % 15)) + 1;
CBasicContainerShape *tmpBasicContainerShape = dynamic_cast<CBasicContainerShape*>(CShapeHandler::GetInstance()->GetShapeByID(m_pInContainerShapeID));
if (GetLocaInfo() == LOCA_LEFT || GetLocaInfo() == LOCA_RIGHT) //왼쪽 혹은 오른쪽에 있다면
{
// X 축은 고정하고, Y축만 RoomShape의 범위 밖을 나가지 않게 고정함
nY += 10 + nRandLocation;
nHeight += 10 + nRandLocation;
if (nY < tmpBasicContainerShape->nY)
{
nY = tmpBasicContainerShape->nY;
}
else if (nHeight > tmpBasicContainerShape->nHeight)
{
nHeight = tmpBasicContainerShape->nHeight;
}
}
else if (GetLocaInfo() == LOCA_DOWN || GetLocaInfo() == LOCA_UP) //위쪽 혹은 아래쪽에 있다면
{
// Y 축은 고정하고, X축만 RoomShape의 범위 밖을 나가지 않게 고정함
nX += 10 + nRandLocation;
nWidth += 10 + nRandLocation;
if (nX < tmpBasicContainerShape->nX)
{
nX = tmpBasicContainerShape->nX;
}
else if (nWidth > tmpBasicContainerShape->nWidth)
{
nWidth = tmpBasicContainerShape->nWidth;
}
}
else
{
cout << "창문, 문 단일 Copy Error\n";
return FALSE;
}
SetOwnColor();
CShapeHandler::GetInstance()->SetRange(nX, nY, nWidth, nHeight);
CShapeHandler::GetInstance()->AddShape(this);
return TRUE;
}
bool CDependentShape::MoveShape(CPoint point)
{
// 창문 문만 클릭했을 시!!!
CBasicContainerShape *tmpBasicContainerShape = dynamic_cast<CBasicContainerShape*>(CShapeHandler::GetInstance()->GetShapeByID(m_pInContainerShapeID));
int tmpX, tmpY, tmpWidth, tmpHeight;
if (GetLocaInfo() == LOCA_LEFT || GetLocaInfo() == LOCA_RIGHT) //왼쪽 혹은 오른쪽에 있다면
{
//cout << "왼오\n";
//////////////////////////////////////////////////////////////////////////
// X 축은 고정하고, Y축만 RoomShape의 범위 밖을 나가지 않게 고정함
tmpY = point.y + m_nMoveSubVal[1];
tmpHeight = point.y + m_nMoveSubVal[3];
if (tmpY <= tmpBasicContainerShape->nY || tmpHeight >= tmpBasicContainerShape->nHeight)
{
return FALSE;
}
else
{
nY = tmpY;
nHeight = tmpHeight;
}
}
else if (GetLocaInfo() == LOCA_UP || GetLocaInfo() == LOCA_DOWN) //위쪽 혹은 아래쪽에 있다면
{
//cout << "위아래\n";
//////////////////////////////////////////////////////////////////////////
// Y 축은 고정하고, X축만 RoomShape의 범위 밖을 나가지 않게 고정함
tmpX = point.x + m_nMoveSubVal[0];
tmpWidth = point.x + m_nMoveSubVal[2];
if (tmpX <= tmpBasicContainerShape->nX || tmpWidth >= tmpBasicContainerShape->nWidth)
{
return FALSE;
}
else
{
nX = tmpX;
nWidth = tmpWidth;
}
}
else
{
ASSERT(0);
return FALSE;
}
return TRUE;
}
bool CDependentShape::MagneticShape() // 얘는 마그네틱이 필요 없음!
{
return FALSE;
}
bool CDependentShape::EditShape(int nX, int nY, int nWidth, int nHeight, int *m_nSubShapeStatus, int *m_nRememberShapeStatus)
{
CBasicContainerShape *tmpBasicContainerShape = dynamic_cast<CBasicContainerShape*>(CShapeHandler::GetInstance()->GetShapeByID(m_pInContainerShapeID));;
int tmpSub = MY_ERROR;
if (GetLocaInfo() == LOCA_UP || GetLocaInfo() == LOCA_DOWN)
{
if (m_nSubShapeStatus[0] != MY_ERROR) //change X
{
if (nX <= tmpBasicContainerShape->nX) //작아질 때
{
tmpSub = m_nRememberShapeStatus[0] - tmpBasicContainerShape->nX;
nX = tmpBasicContainerShape->nX;
nWidth = m_nRememberShapeStatus[0] + m_nRememberShapeStatus[2] - tmpSub;
}
if (nX + m_nRememberShapeStatus[2] >= tmpBasicContainerShape->nWidth) //커질 때
{
tmpSub = tmpBasicContainerShape->nWidth - (m_nRememberShapeStatus[0] + m_nRememberShapeStatus[2]);
nWidth = tmpBasicContainerShape->nWidth;
nX = m_nRememberShapeStatus[0] + tmpSub;
}
}
if (m_nSubShapeStatus[2] != MY_ERROR) //change Width
{
if (nWidth >= tmpBasicContainerShape->nWidth)
nWidth = tmpBasicContainerShape->nWidth;
}
}
else if (GetLocaInfo() == LOCA_RIGHT || GetLocaInfo() == LOCA_LEFT)
{
if (m_nSubShapeStatus[1] != MY_ERROR) //change Y
{
if (nY <= tmpBasicContainerShape->nY) //작아질 때
{
tmpSub = m_nRememberShapeStatus[1] - tmpBasicContainerShape->nY;
nY = tmpBasicContainerShape->nY;
nHeight = m_nRememberShapeStatus[1] + m_nRememberShapeStatus[3] - tmpSub;
}
if (nY + m_nRememberShapeStatus[3] >= tmpBasicContainerShape->nHeight) //커질 때
{
tmpSub = tmpBasicContainerShape->nHeight - (m_nRememberShapeStatus[1] + m_nRememberShapeStatus[3]);
nHeight = tmpBasicContainerShape->nHeight;
nY = m_nRememberShapeStatus[1] + tmpSub;
}
}
if (m_nSubShapeStatus[3] != MY_ERROR) //change Height
{
if (nHeight >= tmpBasicContainerShape->nHeight)
nHeight = tmpBasicContainerShape->nHeight;
}
}
SetRect(nX, nY, nWidth, nHeight);
return TRUE;
}
bool CDependentShape::WheelShape(short zDelta)
{
// 내가 속해있는 방!
CBasicContainerShape *tmpBasicContainerShape =
dynamic_cast<CBasicContainerShape*>(CShapeHandler::GetInstance()->GetShapeByID(m_pInContainerShapeID));
if (GetLocaInfo() == LOCA_LEFT || GetLocaInfo() == LOCA_RIGHT) //왼쪽 혹은 오른쪽에 있다면
{
//////////////////////////////////////////////////////////////////////////
// X 축은 고정하고, Y축만 RoomShape의 범위 밖을 나가지 않게 고정함
if (zDelta > 100)
{
if (!(nY - 2 < tmpBasicContainerShape->nY))
{
nY -= 2;
}
if (!(nHeight + 2 > tmpBasicContainerShape->nHeight))
{
nHeight += 2;
}
}
else
{
if (!(nHeight - nY < 28))
{
nY += 2;
nHeight -= 2;
}
}
}
else if (GetLocaInfo() == LOCA_UP || GetLocaInfo() == LOCA_DOWN) //위쪽 혹은 아래쪽에 있다면
{
//////////////////////////////////////////////////////////////////////////
// Y 축은 고정하고, X축만 RoomShape의 범위 밖을 나가지 않게 고정함
if (zDelta > 100)
{
if (!(nX - 2 < tmpBasicContainerShape->nX))
{
nX -= 2;
}
if (!(nWidth + 2 > tmpBasicContainerShape->nWidth))
{
nWidth += 2;
}
}
else
{
if (!(nWidth - nX < 28))
{
nX += 2;
nWidth -= 2;
}
}
}
else
{
cout << "창문, 문 단일 Copy Error\n";
return FALSE;
}
return TRUE;
}
// 추가 기능
int CDependentShape::GetLocaInfo()
{
return m_nLocaInfo;
}