-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
224 lines (163 loc) · 6.06 KB
/
index.html
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html lang="en">
<head>
<title>Canvas-Events5 Example</title>
<meta charset="utf-8">
<link rel="icon" type="image/x-icon" href="https://mahmoudhegazi.github.io/canvas-events.io/canvas_events_logo.JPG">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<style>
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Old versions of Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
supported by Chrome, Edge, Opera and Firefox */
}
</style>
</head>
<body>
<img class="icon_image" id="scream" width="35" height="35"
src="https://i.ibb.co/wYyc259/iconimage.png" alt="The Scream">
<img id="project_image" width="450" height="300"
src="https://i.ibb.co/sK5HtQy/bulding-image.png">
<button onclick="drawProject()">Redraw things</button>
<div id="currentStamp">
</div>
<canvas id="myCanvas" width="450" height="300"
style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<script src="https://mahmoudhegazi.github.io/canvas-events.io/canvas-events.js"></script>
<script>
/*how to use this library*/
let painter;
const projectStamps = [{
title: 'repear',
image_id: 'scream',
x: 100,
y: 100,
w: 35,
h: 35,
id: 1
}, {
title: 'repear2',
image_id: 'scream',
x: 100,
y: 100,
w: 35,
h: 35,
id: 122
}, {
title: 'fix',
image_id: 'scream',
x: 200,
y: 100,
w: 35,
h: 35,
id: 2
}, {
title: 'development',
image_id: 'scream',
x: 50,
y: 0,
w: 35,
h: 35,
id: 3
}, {
title: 'guarding',
image_id: 'scream',
x: 170,
y: 0,
w: 35,
h: 35,
id: 4
}];
window.onload = function() {
/* Use Canvas Events Library wrong name mouseDragStartGenerator, use startCanvasEvents to start and add all existing marks (important for load old marks) */
painter = startCanvasEvents('#myCanvas', projectStamps);
};
/* Drag Events Listener STarts (developer work) */
$(document).on('CanvasDragStart', function(e, eventInfo) {
console.log("My First Drag Event listener.", eventInfo);
});
$(document).on('CanvasDragOver', function(e, eventInfo) {
console.log("Reciveing Datatransfer shape from drag event listener ", eventInfo);
//console.log("\n\n\n\n", eventInfo, '\n\n\n');
});
$(document).on('CanvasDrop', function(e, eventInfo) {
if (!eventInfo || !eventInfo.dropEvent || !eventInfo.transferObjState || !eventInfo.transferObjState.getData || !eventInfo.transferObjState.getData.data || !eventInfo.transferObjState.getData.data.id || !eventInfo.elmSelector) {
console.log("this flash message, unknown error unable to move the icon");
return false;
}
console.log("Reciveing Datatransfer shape from drop event listener ", eventInfo);
/*easy as developer now control any shape*/
//MoveStampIcon(eventInfo.transferObjState.data, eventInfo.transferObjState);
const canvasElm = document.querySelector(eventInfo.elmSelector);
const shape = eventInfo.transferObjState.getData.data;
if (canvasElm) {
const rect = canvasElm.getBoundingClientRect();
const x = eventInfo.dropEvent.clientX - rect.left; /*x position within the element */
const y = eventInfo.dropEvent.clientY - rect.top; /*y position within the element.*/
const newX = x - (shape.w / 2);
const newY = y - (shape.h / 2);
let success = painter.MoveStampIcon(shape.id, newX, newY);
console.log("\n\n\n\n", eventInfo, newX, newY, '\n\n\n');
}
});
$(document).on('CanvasRelaseCancel', function(e, eventInfo) {
console.log("Reciveing Datatransfer from drag relase cancel this new event data just info and used for back any changes made if drag faliure also let u able even to make changes using data transfer when event cancled on canvas shape for example game and user not able to drop this item in required place so hide this item for example important event", eventInfo);
console.log("\n\n\n\n", eventInfo, '\n\n\n');
});
$(document).on('canvasStampClick', function(e, eventInfo) {
if (!painter.stampEventsOn) {
return false;
}
//subscribers = $('.subscribers-testEvent');
console.log("hi canvasStampClick AI event listener CanvasEvents", e, eventInfo);
$("#currentStamp").html(`<span class="badge badge-secondary">${eventInfo.shape.title}</span>`);
});
$(document).on('canvasGroupStampClick', function(e, eventInfo) {
if (!painter.stampEventsOn) {
return false;
}
$("#currentStamp").html('');
//subscribers = $('.subscribers-testEvent');
console.log("hi canvasGroupStampClick AI event listener CanvasEvents", e, eventInfo);
if (eventInfo && eventInfo.shapes && eventInfo.shapes.length) {
eventInfo.shapes.forEach((clickedShape) => {
$("#currentStamp").append(`<span class="badge badge-secondary">${clickedShape.title}</span>`);
});
}
});
/* onStampMouseEnter (1 time called only when enter stamp) */
$(document).on('stampMouseEnter', function(e, eventInfo) {
if (!eventInfo){
return false;
}
if (!painter.stampEventsMouseOn) {
return false;
}
painter.CanvasHoverEffect(eventInfo.shape);
console.log("stamp stampMouseEnter event listener");
});
$(document).on('stampMouseOut', function(e, eventInfo) {
if (!painter.stampEventsMouseOn) {
return false;
}
/*relational database point */
painter.removeBorder(eventInfo.shape.id);
console.log("stamp stampMouseOut event listener");
});
/*remove stamp event listener */
$(document).on('canvasStampRemove', function(e, eventInfo) {
console.log("hi canvasStampRemove AI event listener", e, eventInfo);
});
</script>
</body>
</html>