Browse Source

small svg and js optimizations

dev_h
Ophir LOJKINE 4 years ago
parent
commit
516ff8f214

+ 3
- 15
client-data/tools/hand/delete.svg View File

@@ -1,17 +1,5 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<svg role="img" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
3
- <title>Instagram icon</title>
4
- <g transform="matrix(2.3668 2.3668 -2.3668 2.3668 13.98 -131.11)" fill="#ff002d">
5
-  <g transform="translate(-.5821 .16648)" fill="#f00">
6
-   <rect transform="scale(1,-1)" x="30.056" y="-33.755" width=".6819" height="6.5387" ry=".34186"/>
7
-   <rect transform="matrix(0,1,1,0,0,0)" x="30.145" y="27.128" width=".6819" height="6.5387" ry=".34186"/>
8
-  </g>
9
- </g>
10
- <metadata>
11
-  <rdf:RDF>
12
-   <cc:Work rdf:about="">
13
-    <dc:title>Delete icon</dc:title>
14
-   </cc:Work>
15
-  </rdf:RDF>
16
- </metadata>
2
+<svg role="img" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" id="root">
3
+    <title>Delete</title>
4
+    <path stroke="red" stroke-width="2" d="M 2 2 L 22 22 M 2 22 L 22 2"></path>
17 5
 </svg>

+ 6
- 15
client-data/tools/hand/duplicate.svg View File

@@ -1,17 +1,8 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<svg role="img" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
3
- <title>Instagram icon</title>
4
- <path d="m7.1549 7.1542v-3.5315c0-0.65725 0.52912-1.1864 1.1864-1.1864h11.991c0.65725 0 1.1864 0.52912 1.1864 1.1864v12.036c0 0.65725-0.52912 1.1864-1.1864 1.1864h-3.4867" fill="none" stroke="#000" stroke-linejoin="round" stroke-width=".3"/>
5
- <rect x="2.481" y="7.155" width="14.364" height="14.409" ry="1.1864" fill="none" stroke="#000" stroke-linejoin="round" stroke-width=".3"/>
6
- <g transform="translate(-20.734 -16.126)">
7
-  <rect transform="scale(1,-1)" x="30.056" y="-33.755" width=".6819" height="6.5387" ry=".34186"/>
8
-  <rect transform="matrix(0,1,1,0,0,0)" x="30.145" y="27.128" width=".6819" height="6.5387" ry=".34186"/>
9
- </g>
10
- <metadata>
11
-  <rdf:RDF>
12
-   <cc:Work rdf:about="">
13
-    <dc:title>Duplicate icon</dc:title>
14
-   </cc:Work>
15
-  </rdf:RDF>
16
- </metadata>
2
+<svg role="img" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" id="root">
3
+    <title>Duplicate</title>
4
+    <path d="m7.1549 7.1542v-3.5315c0-0.65725 0.52912-1.1864 1.1864-1.1864h11.991c0.65725 0 1.1864 0.52912 1.1864 1.1864v12.036c0 0.65725-0.52912 1.1864-1.1864 1.1864h-3.4867" fill="none" stroke="#000" stroke-linejoin="round" stroke-width=".3" />
5
+    <rect x="2.481" y="7.155" width="14.364" height="14.409" ry="1.1864" fill="none" stroke="#000" stroke-linejoin="round" stroke-width=".3" />
6
+    <rect transform="translate(-20.734 -16.126) scale(1,-1)" x="30.056" y="-33.755" width=".6819" height="6.5387" ry=".34186" />
7
+    <rect transform="translate(-20.734 -16.126) matrix(0,1,1,0,0,0)" x="30.145" y="27.128" width=".6819" height="6.5387" ry=".34186" />
17 8
 </svg>

+ 33
- 41
client-data/tools/hand/hand.js View File

@@ -39,43 +39,41 @@
39 39
 	var selectorState = selectorStates.pointing;
40 40
 	var last_sent = 0;
41 41
 	var blockedSelectionButtons = Tools.server_config.BLOCKED_SELECTION_BUTTONS;
42
-	var selectionButtons = {};
43
-
44
-	selectionButtons["delete"] = createButton("delete", "delete", 22, 22,
45
-		function (me, bbox, s) {
46
-			me.width.baseVal.value = me.origWidth / s;
47
-			me.height.baseVal.value = me.origHeight / s;
48
-			me.x.baseVal.value = bbox.r[0];
49
-			me.y.baseVal.value = bbox.r[1] - (me.origHeight + 3) / s;
50
-			me.style.display = "";
51
-		},
52
-		deleteSelection);
53
-
54
-	selectionButtons["duplicate"] = createButton("duplicate", "duplicate", 22, 22,
55
-		function (me, bbox, s) {
56
-			me.width.baseVal.value = me.origWidth / s;
57
-			me.height.baseVal.value = me.origHeight / s;
58
-			me.x.baseVal.value = bbox.r[0] + (me.origWidth + 2) / s;
59
-			me.y.baseVal.value = bbox.r[1] - (me.origHeight + 3) / s;
60
-			me.style.display = "";
61
-		},
62
-		duplicateSelection);
63
-	selectionButtons["scale"] = createButton("scaleHandle", "handle", 14, 14,
64
-		function (me, bbox, s) {
65
-			me.width.baseVal.value = me.origWidth / s;
66
-			me.height.baseVal.value = me.origHeight / s;
67
-			me.x.baseVal.value = bbox.r[0] + bbox.a[0] - me.origWidth / (2 * s);
68
-			me.y.baseVal.value = bbox.r[1] + bbox.b[1] - me.origHeight / (2 * s);
69
-			me.style.display = "";
70
-		},
71
-		startScalingTransform);
42
+	var selectionButtons = [
43
+		createButton("delete", "delete", 24, 24,
44
+			function (me, bbox, s) {
45
+				me.width.baseVal.value = me.origWidth / s;
46
+				me.height.baseVal.value = me.origHeight / s;
47
+				me.x.baseVal.value = bbox.r[0];
48
+				me.y.baseVal.value = bbox.r[1] - (me.origHeight + 3) / s;
49
+				me.style.display = "";
50
+			},
51
+			deleteSelection),
52
+
53
+		createButton("duplicate", "duplicate", 24, 24,
54
+			function (me, bbox, s) {
55
+				me.width.baseVal.value = me.origWidth / s;
56
+				me.height.baseVal.value = me.origHeight / s;
57
+				me.x.baseVal.value = bbox.r[0] + (me.origWidth + 2) / s;
58
+				me.y.baseVal.value = bbox.r[1] - (me.origHeight + 3) / s;
59
+				me.style.display = "";
60
+			},
61
+			duplicateSelection),
62
+
63
+		createButton("scaleHandle", "handle", 14, 14,
64
+			function (me, bbox, s) {
65
+				me.width.baseVal.value = me.origWidth / s;
66
+				me.height.baseVal.value = me.origHeight / s;
67
+				me.x.baseVal.value = bbox.r[0] + bbox.a[0] - me.origWidth / (2 * s);
68
+				me.y.baseVal.value = bbox.r[1] + bbox.b[1] - me.origHeight / (2 * s);
69
+				me.style.display = "";
70
+			},
71
+			startScalingTransform)
72
+	];
72 73
 
73 74
 	for (i in blockedSelectionButtons) {
74 75
 		delete selectionButtons[blockedSelectionButtons[i]];
75 76
 	}
76
-	selectionButtons = Object.keys(selectionButtons).map(function (k) {
77
-		return selectionButtons[k];
78
-	});
79 77
 
80 78
 	var getScale = Tools.getScale;
81 79
 
@@ -149,12 +147,7 @@
149 147
 	}
150 148
 
151 149
 	function createButton(name, icon, width, height, drawCallback, clickCallback) {
152
-		var shape = Tools.createSVGElement("image", {
153
-			id: name + "Icon",
154
-			href: "tools/hand/" + icon + ".svg",
155
-			width: width,
156
-			height: height,
157
-		});
150
+		var shape = Tools.createSVGElement("use", {href: "tools/hand/" + icon + ".svg#root"});
158 151
 		shape.style.display = "none";
159 152
 		shape.origWidth = width;
160 153
 		shape.origHeight = height;
@@ -405,10 +398,9 @@
405 398
 
406 399
 	function clickSelector(x, y, evt) {
407 400
 		selectionRect = selectionRect || createSelectorRect();
408
-		var button = null;
409 401
 		for (var i = 0; i < selectionButtons.length; i++) {
410 402
 			if (selectionButtons[i].contains(evt.target)) {
411
-				button = selectionButtons[i];
403
+				var button = selectionButtons[i];
412 404
 			}
413 405
 		}
414 406
 		if (button) {

Loading…
Cancel
Save