-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMyRect.cpp
More file actions
35 lines (33 loc) · 996 Bytes
/
CMyRect.cpp
File metadata and controls
35 lines (33 loc) · 996 Bytes
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
#include "pch.h"
#include "CMyRect.h"
CMyRect::CMyRect(CPoint p1, CPoint p2) {
m_p1 = p1;
m_p2 = p2;
}
void CMyRect::draw(CDC& dc) {
CBrush fillBrush(m_fillColor);
CBrush* pOldBrush = dc.SelectObject(&fillBrush);
int left = min(m_p1.x, m_p2.x);
int top = min(m_p1.y, m_p2.y);
int right = max(m_p1.x, m_p2.x);
int bottom = max(m_p1.y, m_p2.y);
dc.Rectangle(left, top, right, bottom);
dc.SelectObject(pOldBrush);
}
CRect CMyRect::getBoundingRect() const {
return CRect(min(m_p1.x, m_p2.x), min(m_p1.y, m_p2.y),
max(m_p1.x, m_p2.x), max(m_p1.y, m_p2.y));
}
bool CMyRect::isInRect(const CRect& selectRect) const {
return selectRect.PtInRect(m_p1) || selectRect.PtInRect(m_p2);
}
bool CMyRect::isInPoint(CPoint point)
{
CRect rect(min(m_p1.x, m_p2.x), min(m_p1.y, m_p2.y),
max(m_p1.x, m_p2.x), max(m_p1.y, m_p2.y));
return rect.PtInRect(point);
}
void CMyRect::moveBy(int dx, int dy) {
m_p1.x += dx; m_p1.y += dy;
m_p2.x += dx; m_p2.y += dy;
}