-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMyGroup.cpp
More file actions
111 lines (97 loc) · 2.89 KB
/
CMyGroup.cpp
File metadata and controls
111 lines (97 loc) · 2.89 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
#include "pch.h"
#include "CMyGroup.h"
CMyGroup::CMyGroup() : CMyShape(){}
CMyGroup::~CMyGroup()
{
clearShapes(); // 그룹이 삭제될 때 포함된 도형들도 삭제
}
void CMyGroup::draw(CDC& dc)
{
// 그룹에 포함된 모든 도형들을 그림
for (CMyShape* shape : m_shapes) {
if (shape != nullptr) {
shape->draw(dc);
}
}
}
CRect CMyGroup::getBoundingRect() const
{
if (m_shapes.empty()) {
return CRect(0, 0, 0, 0);
}
// 첫 번째 도형의 바운딩 박스로 초기화
CRect boundingRect = m_shapes[0]->getBoundingRect();
// 나머지 도형들의 바운딩 박스와 합집합 계산
for (size_t i = 1; i < m_shapes.size(); ++i) {
if (m_shapes[i] != nullptr) {
CRect shapeRect = m_shapes[i]->getBoundingRect();
boundingRect.UnionRect(boundingRect, shapeRect);
}
}
return boundingRect;
}
bool CMyGroup::isInRect(const CRect& selectRect) const
{
// 그룹 내 모든 도형이 선택 영역에 포함되어야 그룹이 선택됨
for (CMyShape* shape : m_shapes) {
if (shape != nullptr && !shape->isInRect(selectRect)) {
return false;
}
}
return !m_shapes.empty(); // 비어있지 않은 그룹만 선택 가능
}
bool CMyGroup::isInPoint(CPoint point)
{
// 그룹 내 어느 도형이라도 클릭되면 그룹이 선택됨
for (CMyShape* shape : m_shapes) {
if (shape != nullptr && shape->isInPoint(point)) {
return true;
}
}
return false;
}
void CMyGroup::moveBy(int dx, int dy)
{
// 그룹 내 모든 도형을 이동
for (CMyShape* shape : m_shapes) {
if (shape != nullptr) {
shape->moveBy(dx, dy);
}
}
}
void CMyGroup::addShape(CMyShape* shape)
{
if (shape != nullptr) {
m_shapes.push_back(shape);
}
}
void CMyGroup::removeShape(CMyShape* shape)
{
auto it = std::find(m_shapes.begin(), m_shapes.end(), shape);
if (it != m_shapes.end()) {
m_shapes.erase(it);
}
}
void CMyGroup::clearShapes()
{
// 그룹에서 도형들을 제거하지만 메모리는 해제하지 않음
// (메모리 관리는 상위 레벨에서 처리)
m_shapes.clear();
}
void CMyGroup::getAllShapes(std::vector<CMyShape*>& allShapes) const
{
// 재귀적으로 모든 개별 도형들을 수집
for (CMyShape* shape : m_shapes) {
if (shape != nullptr) {
CMyGroup* group = dynamic_cast<CMyGroup*>(shape);
if (group != nullptr) {
// 중첩된 그룹인 경우 재귀 호출
group->getAllShapes(allShapes);
}
else {
// 개별 도형인 경우 리스트에 추가
allShapes.push_back(shape);
}
}
}
}