-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigure.h
119 lines (99 loc) · 1.71 KB
/
Figure.h
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
#pragma once
#include "Point.h"
#include <Windows.h>
class Figure
{
protected:
static HDC hdc;
void SetPen(COLORREF c, int width = 3)
{
SelectObject(hdc, CreatePen(PS_SOLID, width, c));
}
void SetBrush(COLORREF c)
{
SelectObject(hdc, CreateSolidBrush(c));
}
public:
enum SHAPE_COLOR { BLACK, RED, GREEN, BLUE, WHITE, YELLOW, NONE };
protected:
Point tl;
unsigned short width;
unsigned short height;
COLORREF color;
COLORREF SHAPECOLOR_to_COLORREF(SHAPE_COLOR c)
{
switch (c)
{
case BLACK:
return RGB(0, 0, 0);
case RED:
return RGB(255, 0, 0);
case GREEN:
return RGB(0, 255, 0);
case BLUE:
return RGB(0, 0, 255);
case WHITE:
return RGB(255, 255, 255);
case YELLOW:
return RGB(255, 255, 0);
case NONE:
return 0;
}
}
public:
Figure()
{
color = RGB(255, 255, 255);
}
Figure(int X, int Y, unsigned short _width, unsigned short _height, COLORREF c = RGB(255, 0, 0)) :tl(X, Y)
{
width = _width;
height = _height;
color = c;
}
const Point& GetPointTopleft() const
{
return tl;
}
unsigned short GetWidth() const
{
return width;
}
unsigned short GetHeight() const
{
return height;
}
COLORREF GetColor() const
{
return color;
}
void SetPointTopLeft(const Point& p)
{
tl = p;
}
void SetWidth(unsigned short value)
{
width = value;
}
void SetHeight(unsigned short value)
{
height = value;
}
void SetColor(COLORREF color)
{
this->color = color;
}
void SetColor(unsigned char red, unsigned char green, unsigned char blue)
{
color = RGB(red, green, blue);
}
void SetColor(SHAPE_COLOR c)
{
color = SHAPECOLOR_to_COLORREF(c);
}
void MoveTo(int X, int Y)
{
tl = { X, Y };
}
};
HDC Figure::hdc = GetDC(GetConsoleWindow());