Add an eraser tool.

This commit is contained in:
Ophir LOJKINE 2013-11-23 15:03:06 +01:00
parent 61244d1984
commit 1ecc676b2c
3 changed files with 89 additions and 4 deletions

View file

@ -44,6 +44,7 @@
<script type="text/javascript" src="js/board.js"></script>
<script type="text/javascript" src="tools/pencil/pencil.js"></script>
<script type="text/javascript" src="tools/text/text.js"></script>
<script type="text/javascript" src="tools/eraser/eraser.js"></script>
<script type="text/javascript" src="tools/hand/hand.js"></script>
</body>
</html>

View file

@ -0,0 +1,79 @@
/**
* WHITEBOPHIR
*********************************************************
* @licstart The following is the entire license notice for the
* JavaScript code in this page.
*
* Copyright (C) 2013 Ophir LOJKINE
*
*
* The JavaScript code in this page is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
* @licend
*/
(function eraser (){ //Code isolation
var erasing = false;
function startErasing () {
erasing = true;
}
var msg = {
"type" : "delete",
"id" : ""
};
function erase (x,y, evt){
/*evt.target is the element over which the mouse is.*/
if (erasing && evt.target !== Tools.svg) {
msg.id = evt.target.id;
Tools.drawAndSend(msg);
}
}
function stopErasing (){
erasing = false;
}
var renderingLine = {};
function draw(data) {
switch(data.type) {
//TODO: add the ability to erase only some points in a line
case "delete":
elem = svg.getElementById(data.id);
if (elem === null) console.error("Eraser: Tried to delete an element that does not exist.");
else svg.removeChild(elem);
break;
default:
console.error("Eraser: 'delete' instruction with unknown type. ", data);
break;
}
}
var svg = Tools.svg;
Tools.add({ //The new tool
"name" : "Eraser",
"listeners" : {
"press" : startErasing,
"move" : erase,
"release" : stopErasing,
},
"draw" : draw,
"mouseCursor" : "crosshair",
});
})(); //End of code isolation

View file

@ -3,10 +3,11 @@
"collaborative",
"whiteboard"
],
"version": "0.1.0-38",
"version": "0.1.0-40",
"dependencies": {
"node-static": "0.7.x",
"socket.io": "0.9.x"
"socket.io": "0.9.x",
"mongodb": "1.3.x"
},
"scripts": {
"start": "node ./server/server.js"
@ -16,6 +17,10 @@
"main": "./server/server.js",
"subdomain": "wbo",
"engines": {
"node": "0.10.x"
}
"node": "0.10.x"
},
"repository" : {
"type" : "git",
"url" : "http://github.com/lovasoa/whitebophir.git"
}
}