forked from nathantoannguyen/ZotBoard-FrontEnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.js
137 lines (113 loc) · 3.12 KB
/
canvas.js
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
const URL = "http://localhost:5000";
const socket = io(URL, { autoConnect: true });
window.onload = function() {
// var canvas = new fabric.Canvas('c', { isDrawingMode: true });
//canvas.backgroundColor = 'rgb(255, 255, 255)'
var canvas = new fabric.Canvas('c', {backgroundColor: 'rgb(255, 255, 255)', isDrawingMode: true})
window.canvas = canvas
canvas.on('path:created', function (event) {
console.log(event)
let drawing_path = event.path
let send_json = JSON.stringify(drawing_path)
socket.send(send_json)
return true
})
socket.on("message", function (event) {
console.log("message", event);
let json_resp = JSON.parse(event);
fabric.Path.fromObject(json_resp, function (share_path) {
canvas.add(share_path);
})
})
}
function add_text_button() {
canvas.isDrawingMode = false
var text = new fabric.Textbox("Insert text", {
fontSize: 18,
width: 100,
cursorColor: "black",
top: 50,
left: 50,
editable: true
});
canvas.add(text)
text.set('selectable', true)
}
function draw_button() {
canvas.isDrawingMode = true
}
function stop_drawing_button() {
canvas.isDrawingMode = false
}
function insert_rectangle_button() {
canvas.isDrawingMode = false
var rect = new fabric.Rect( {
width: 200,
height: 100,
fill: "white",
stroke: "black",
strokeWidth: 2,
left: 100,
top: 100,
});
canvas.add(rect)
rect.set('selectable', true)
}
function insert_circle_button() {
canvas.isDrawingMode = false
var circ = new fabric.Ellipse( {
rx: 50,
ry: 50,
raidus: 50,
fill: "white",
stroke: "black",
strokeWidth: 2,
left: 100,
top: 100,
});
canvas.add(circ)
circ.set('selectable', true)
}
function insert_triangle_button() {
canvas.isDrawingMode = false
var tri = new fabric.Triangle( {
width: 150,
height: 100,
angle: 0,
fill: "white",
stroke: "black",
strokeWidth: 2,
left: 100,
top: 100,
});
canvas.add(tri)
tri.set('selectable', true)
}
function like_idea_emote_button()
{
fabric.Image.fromURL('https://appstickers-cdn.appadvice.com/1410106976/827828369/67d24884a1cb520f7e200c823fc8a543-3.png', function(myImg) {
var newImg = myImg.set({left: 100, top: 100, scaleX: 0.15, scaleY: 0.15});
canvas.add(newImg)
} )
}
function love_idea_emote_button()
{
fabric.Image.fromURL('https://appstickers-cdn.appadvice.com/1410106976/827828369/d7a76df54e1521ccf29d8007eac18023-2.png', function(myImg) {
var newImg = myImg.set({left: 100, top: 100, scaleX: 0.15, scaleY: 0.15});
canvas.add(newImg)
} )
}
function hate_idea_emote_button()
{
fabric.Image.fromURL('https://appstickers-cdn.appadvice.com/1410106976/827828369/73b37fbb039a1be67a7ddb88da6f3cc7-11.png', function(myImg) {
var newImg = myImg.set({left: 100, top: 100, scaleX: 0.15, scaleY: 0.15});
canvas.add(newImg)
} )
}
function dislike_idea_emote_button()
{
fabric.Image.fromURL('https://appstickers-cdn.appadvice.com/1410106976/827828369/51fbce8a2551813be61ce4c2bc72a60a-7.png', function(myImg) {
var newImg = myImg.set({left: 100, top: 100, scaleX: 0.15, scaleY: 0.15});
canvas.add(newImg)
} )
}