Repository navigation
Expand file tree
/
Copy pathConnector.cpp
More file actions
80 lines (64 loc) · 2.15 KB
/
Copy pathConnector.cpp
File metadata and controls
80 lines (64 loc) · 2.15 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
#include "Connector.h"
Connector::Connector(Statement* Src, Statement* Dst, Point start, Point end,char arrowDir , char outletDir):Selected(false),Start(start),End(end), arrowDir(arrowDir), SrcStat(Src), DstStat(Dst), outletDir(outletDir)
//When a connector is created, it must have a source statement and a destination statement
//There are NO FREE connectors in the flowchart
{
}
void Connector::setSrcStat(Statement *Src)
{ SrcStat = Src; }
Statement* Connector::getSrcStat()
{ return SrcStat; }
void Connector::setDstStat(Statement *Dst)
{ DstStat = Dst; }
Statement* Connector::getDstStat()
{ return DstStat; }
void Connector::setStartPoint(Point P)
{ Start = P; }
Point Connector::getStartPoint()
{ return Start; }
void Connector::setEndPoint(Point P)
{ End = P; }
Point Connector::getEndPoint()
{ return End; }
void Connector::Draw(Output* pOut) const
{
pOut->DrawConnector(Start,End, outletDir, arrowDir, Selected);
}
bool Connector::IsPointOnMe(Point p)
{
int x2 = Start.x;
if (arrowDir == 'L') {
x2 = Start.x + 60;
}
else if (arrowDir == 'R') {
x2 = Start.x - 60;
}
switch (Start.y < End.y) {
case 1:
return ((Start.x < p.x && p.x <= End.x) || (Start.x >= p.x && p.x >= End.x)) //this algrothim to follow the line and return if
&& Start.y + ((End.y - Start.y) / 10) - 5 <= p.y && Start.y + ((End.y - Start.y) / 10) + 5 >= p.y//you clicked on it
|| //or a region near it and retrun true
(End.x - 5 <= p.x && p.x <= End.x + 5)
&& Start.y + ((End.y - Start.y) / 10) <= p.y && End.y > p.y
||
(Start.x - 5 <= p.x && p.x <= Start.x + 5)
&& Start.y + ((End.y - Start.y) / 10) >= p.y && Start.y < p.y;
case 0:
return ((Start.x < p.x && p.x <= x2) || (Start.x >= p.x && p.x >= x2)) //this algrothim to follow the line and return if
&& Start.y - 5 >= p.y && Start.y + 5 <= p.y//you clicked on it
|| //or a region near it and retrun true
(x2 - 5 <= p.x && p.x <= x2 + 5)
&& Start.y>= p.y && End.y <= p.y
||
(x2 <= p.x && p.x <= End.x)
&& End.y-5 >= p.y && End.y-5 <= p.y;
}
}
void Connector::SetSelected(bool s)
{
Selected = s;
}
bool Connector::IsSelected() const
{
return Selected;
}