-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHexagon.cpp
161 lines (146 loc) · 3.92 KB
/
CHexagon.cpp
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
#include "CHexagon.h"
#include<fstream>
CHexagon::CHexagon(Point P1, GfxInfo FigureGfxInfo):CFigure(FigureGfxInfo)
{
Center = P1;
side = 100;
UpdateCorners();
pvid = ID;
}
CHexagon::CHexagon()
{
}
void CHexagon::Draw(Output* pOut) const
{
pOut->DrawHexa(Center, FigGfxInfo, Selected,side);
}
void CHexagon::PrintInfo(Output* pOut)
{
string c = to_string(Center.x)+","+to_string(Center.y);
string Id = to_string(ID);
string isselected = to_string(Selected);
pOut->PrintMessage("Figure type: Hexagon,Center: "+c+" ID: "+Id+" Is selected: "+isselected);
}
void CHexagon::MOVE(Point p)
{
C0=Center;
Center.x = p.x;
Center.y = p.y;
RightUp.x = Center.x + side;
RightUp.y = Center.y - ((0.866) * side);
RightDown.x = Center.x + side / 2;
RightDown.y = Center.y + ((0.866) * side);
Right.x = Center.x + side;
Right.y = Center.y;
LeftUp.x = Center.x - side / 2;
LeftUp.y = Center.y - ((0.866) * side);
LeftDown.x = Center.x - side/2;
LeftDown.y = Center.y + ((0.866) * side);
Left.x = Center.x - side;
Left.y = Center.y;
}
Point CHexagon::getcenter()
{
return C0;
}
void CHexagon::GetTheCorner(Point A)
{
}
void CHexagon::Resize(Point A)
{
side = CalcDistance(A, Center);
RightUp.x = Center.x + side / 2;
RightUp.y = Center.y - ((0.866) * side);
RightDown.x = Center.x + side / 2;
RightDown.y = Center.y + ((0.866) * side);
Right.x = Center.x + side;
Right.y = Center.y;
LeftUp.x = Center.x - side / 2;
LeftUp.y = Center.y - ((0.866) * side);
LeftDown.x = Center.x - side / 2;
LeftDown.y = Center.y + ((0.866) * side);
Left.x = Center.x - side;
Left.y = Center.y;
}
float CHexagon::area(int x1, int y1, int x2, int y2, int x3, int y3) const
{
return abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0;
}
bool CHexagon::IsOnFig(int x, int y) //Checks to deciding the click is on figure or not //BISHOY
{
UpdateCorners();
if (x >= LeftUp.x && x <= RightUp.x && y >= LeftUp.y && y <= LeftDown.y)
{
return true;
}
float A = area(RightDown.x, RightDown.y, RightUp.x, RightUp.y, Right.x, Right.y);
float A1 = area(x, y, RightUp.x, RightUp.y, Right.x, Right.y);
float A2 = area(RightDown.x, RightDown.y, x, y, Right.x, Right.y);
float A3 = area(RightDown.x, RightDown.y, RightUp.x, RightUp.y, x, y);
if (A == A1 + A2 + A3)
{
return true;
}
A1 = area(x, y, LeftUp.x, LeftUp.y, Left.x, Left.y);
A2 = area(LeftDown.x, LeftDown.y, x, y, Left.x, Left.y);
A3 = area(LeftDown.x, LeftDown.y, LeftUp.x, LeftUp.y, x, y);
if (A == A1 + A2 + A3)
{
return true;
}
return false;
}
void CHexagon::UpdateCorners()
{
RightUp.x = Center.x + side / 2;
RightUp.y = Center.y - ((0.866) * side);
RightDown.x = Center.x + side / 2;
RightDown.y = Center.y + ((0.866) * side);
Right.x = Center.x + side;
Right.y = Center.y;
LeftUp.x = Center.x - side / 2;
LeftUp.y = Center.y - ((0.866) * side);
LeftDown.x = Center.x - side / 2;
LeftDown.y = Center.y + ((0.866) * side);
Left.x = Center.x - side;
Left.y = Center.y;
}
ShapesMenuItem CHexagon::Returnshapestype()
{
return ITM_HEX;
}
void CHexagon::Save(ofstream& OutFile)
{
OutFile << "HEXAGON\t" << pvid << "\t" << Center.x << "\t" << Center.y << "\t"<<side << "\t" << ConvertColorToString(FigGfxInfo.DrawClr) << "\t";
if (FigGfxInfo.isFilled)
{
OutFile << ConvertColorToString(FigGfxInfo.FillClr) << endl;
}
else
{
OutFile << "NOCOLOR" << endl;
}
}
void CHexagon::Load(ifstream& InFile)
{
string DrawClr;
string FillClr;
InFile >> pvid >> Center.x >> Center.y>>side;
InFile >> DrawClr;
FigGfxInfo.DrawClr = ConvertStringToColor(DrawClr);
InFile >> FillClr;
if (FillClr == "NOCOLOR")
{
FigGfxInfo.isFilled = false;
}
else {
FigGfxInfo.isFilled = true;
FigGfxInfo.FillClr = ConvertStringToColor(FillClr);
}
FigGfxInfo.BorderWdth = UI.PenWidth;
Selected = false;
}
int CHexagon::iffigtype()
{
return 4;
}