-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanvas.cpp
More file actions
96 lines (83 loc) · 1.64 KB
/
Copy pathCanvas.cpp
File metadata and controls
96 lines (83 loc) · 1.64 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//23050111029 Medine Merve MARAL
#include "Canvas.h"
Canvas::Canvas(int X, int Y, int W, int H) : Fl_Widget(X, Y, W, H), X(X), Y(Y), W(W), H(H)
{
normalPen = new Pen(FL_BLACK);
colorfulPen = new ColorfulPen();
line = new Line(normalPen, 0, 0, 0, 0);
rectangle = new Rectangle(normalPen, 0, 0, 0, 0);
circle = new Circle(normalPen, 0, 0, 0, 0);
shape = line;
pen = normalPen;
}
int Canvas::handle(int event)
{
if (event == FL_PUSH)
{
if (clickCount == 0)
{
x1 = Fl::event_x();
y1 = Fl::event_y();
clickCount++;
}
else if (clickCount == 1)
{
x2 = Fl::event_x();
y2 = Fl::event_y();
clickCount = 0;
if (shape != nullptr || pen != nullptr)
{
setShapeCoordinates();
redraw();
}
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
}
return 1;
}
else
{
return Fl_Widget::handle(event);
}
}
void Canvas::draw()
{
fl_rect(X, Y, W, H, FL_WHITE);
shape->draw();
}
void Canvas::setShapeCoordinates()
{
shape->setCoordinates(x1, x2, y1, y2);
}
void Canvas::shapeLine()
{
shape = line;
}
void Canvas::shapeRectangle()
{
shape = rectangle;
}
void Canvas::shapeCircle()
{
shape = circle;
}
void Canvas::penPen()
{
pen = normalPen;
shape->setPen(pen);
}
void Canvas::penColorfulPen()
{
pen = colorfulPen;
shape->setPen(pen);
}
void Canvas::setBold(bool bold)
{
pen->setBold(bold);
}
void Canvas::setColor(Fl_Color color)
{
pen->setColor(color);
}