-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpainter.cpp
More file actions
49 lines (41 loc) · 1.2 KB
/
painter.cpp
File metadata and controls
49 lines (41 loc) · 1.2 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
#include "painter.h"
Painter::Painter(HDC hdc) {
m_hdc = hdc;
m_pen = CreatePen(m_penStyle, m_nPenWidth, m_penColor);
m_brush = CreateSolidBrush(m_brushColor);
}
Painter::~Painter() {
DeleteObject(m_pen);
DeleteObject(m_brush);
}
void Painter::drawLine(int x1, int y1, int x2, int y2) {
HPEN oldPen = (HPEN)SelectObject(m_hdc, m_pen);
HBRUSH oldBrush = (HBRUSH)SelectObject(m_hdc, m_brush);
MoveToEx(m_hdc, x1, y1, NULL);
LineTo(m_hdc, x2, y2);
SelectObject(m_hdc, oldPen);
SelectObject(m_hdc, oldBrush);
}
void Painter::drawRect(int x1, int y1, int x2, int y2) {
HPEN oldPen = (HPEN)SelectObject(m_hdc, m_pen);
HBRUSH oldBrush = (HBRUSH)SelectObject(m_hdc, m_brush);
Rectangle(m_hdc, x1, y1, x2, y2);
SelectObject(m_hdc, oldPen);
SelectObject(m_hdc, oldBrush);
}
void Painter::drawText(LPCTSTR text, RECT rect, UINT format /*= DT_CENTER*/)
{
HPEN oldPen = (HPEN)SelectObject(m_hdc, m_pen);
DrawText(m_hdc, text, -1, &rect, format);
SelectObject(m_hdc, oldPen);
}
void Painter::changePen(int style, int width, COLORREF color)
{
DeleteObject(m_pen);
m_pen = CreatePen(style, width, color);
}
void Painter::changeBursh(COLORREF color)
{
DeleteObject(m_brush);
m_brush = CreateSolidBrush(color);
}