Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

board.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /**
  2. * WHITEBOPHIR
  3. *********************************************************
  4. * @licstart The following is the entire license notice for the
  5. * JavaScript code in this page.
  6. *
  7. * Copyright (C) 2013 Ophir LOJKINE
  8. *
  9. *
  10. * The JavaScript code in this page is free software: you can
  11. * redistribute it and/or modify it under the terms of the GNU
  12. * General Public License (GNU GPL) as published by the Free Software
  13. * Foundation, either version 3 of the License, or (at your option)
  14. * any later version. The code is distributed WITHOUT ANY WARRANTY;
  15. * without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  17. *
  18. * As additional permission under GNU GPL version 3 section 7, you
  19. * may distribute non-source (e.g., minimized or compacted) forms of
  20. * that code without the copy of the GNU GPL normally required by
  21. * section 4, provided you include this license notice and a URL
  22. * through which recipients can access the Corresponding Source.
  23. *
  24. * @licend
  25. */
  26. var Tools = {};
  27. Tools.i18n = (function i18n() {
  28. var translations = JSON.parse(document.getElementById("translations").text);
  29. return {
  30. "t": function translate(s) {
  31. var key = s.toLowerCase().replace(/ /g, '_');
  32. return translations[key] || s;
  33. }
  34. };
  35. })();
  36. Tools.server_config = JSON.parse(document.getElementById("configuration").text);
  37. Tools.board = document.getElementById("board");
  38. Tools.svg = document.getElementById("canvas");
  39. Tools.drawingArea = Tools.svg.getElementById("drawingArea");
  40. //Initialization
  41. Tools.curTool = null;
  42. Tools.drawingEvent = true;
  43. Tools.showMarker = true;
  44. Tools.showOtherCursors = true;
  45. Tools.showMyCursor = true;
  46. Tools.isIE = /MSIE|Trident/.test(window.navigator.userAgent);
  47. Tools.socket = null;
  48. Tools.connect = function () {
  49. var self = this;
  50. // Destroy socket if one already exists
  51. if (self.socket) {
  52. self.socket.destroy();
  53. delete self.socket;
  54. self.socket = null;
  55. }
  56. this.socket = io.connect('', {
  57. "path": window.location.pathname.split("/boards/")[0] + "/socket.io",
  58. "reconnection": true,
  59. "reconnectionDelay": 100, //Make the xhr connections as fast as possible
  60. "timeout": 1000 * 60 * 20 // Timeout after 20 minutes
  61. });
  62. //Receive draw instructions from the server
  63. this.socket.on("broadcast", function (msg) {
  64. handleMessage(msg).finally(function afterload() {
  65. var loadingEl = document.getElementById("loadingMessage");
  66. loadingEl.classList.add("hidden");
  67. });
  68. });
  69. this.socket.on("reconnect", function onReconnection() {
  70. Tools.socket.emit('joinboard', Tools.boardName);
  71. });
  72. };
  73. Tools.connect();
  74. Tools.boardName = (function () {
  75. var path = window.location.pathname.split("/");
  76. return decodeURIComponent(path[path.length - 1]);
  77. })();
  78. //Get the board as soon as the page is loaded
  79. Tools.socket.emit("getboard", Tools.boardName);
  80. Tools.HTML = {
  81. template: new Minitpl("#tools > .tool"),
  82. addShortcut: function addShortcut(key, callback) {
  83. window.addEventListener("keydown", function (e) {
  84. if (e.key === key && !e.target.matches("input[type=text], textarea")) {
  85. callback();
  86. }
  87. });
  88. },
  89. addTool: function (toolName, toolIcon, toolIconHTML, toolShortcut, oneTouch) {
  90. var callback = function () {
  91. Tools.change(toolName);
  92. };
  93. this.addShortcut(toolShortcut, function () {
  94. Tools.change(toolName);
  95. document.activeElement.blur && document.activeElement.blur();
  96. });
  97. return this.template.add(function (elem) {
  98. elem.addEventListener("click", callback);
  99. elem.id = "toolID-" + toolName;
  100. elem.getElementsByClassName("tool-name")[0].textContent = Tools.i18n.t(toolName);
  101. var toolIconElem = elem.getElementsByClassName("tool-icon")[0];
  102. toolIconElem.src = toolIcon;
  103. toolIconElem.alt = toolIcon;
  104. if (oneTouch) elem.classList.add("oneTouch");
  105. elem.title =
  106. Tools.i18n.t(toolName) + " (" +
  107. Tools.i18n.t("keyboard shortcut") + ": " +
  108. toolShortcut + ")" +
  109. (Tools.list[toolName].secondary ? " [" + Tools.i18n.t("click_to_toggle") + "]" : "");
  110. });
  111. },
  112. changeTool: function (oldToolName, newToolName) {
  113. var oldTool = document.getElementById("toolID-" + oldToolName);
  114. var newTool = document.getElementById("toolID-" + newToolName);
  115. if (oldTool) oldTool.classList.remove("curTool");
  116. if (newTool) newTool.classList.add("curTool");
  117. },
  118. toggle: function (toolName, name, icon) {
  119. var elem = document.getElementById("toolID-" + toolName);
  120. elem.getElementsByClassName("tool-icon")[0].src = icon;
  121. elem.getElementsByClassName("tool-name")[0].textContent = Tools.i18n.t(name);
  122. },
  123. addStylesheet: function (href) {
  124. //Adds a css stylesheet to the html or svg document
  125. var link = document.createElement("link");
  126. link.href = href;
  127. link.rel = "stylesheet";
  128. link.type = "text/css";
  129. document.head.appendChild(link);
  130. },
  131. colorPresetTemplate: new Minitpl("#colorPresetSel .colorPresetButton"),
  132. addColorButton: function (button) {
  133. var setColor = Tools.setColor.bind(Tools, button.color);
  134. if (button.key) this.addShortcut(button.key, setColor);
  135. return this.colorPresetTemplate.add(function (elem) {
  136. elem.addEventListener("click", setColor);
  137. elem.id = "color_" + button.color.replace(/^#/, '');
  138. elem.style.backgroundColor = button.color;
  139. if (button.key) {
  140. elem.title = Tools.i18n.t("keyboard shortcut") + ": " + button.key;
  141. }
  142. });
  143. }
  144. };
  145. Tools.list = {}; // An array of all known tools. {"toolName" : {toolObject}}
  146. Tools.isBlocked = function toolIsBanned(tool) {
  147. if (tool.name.includes(",")) throw new Error("Tool Names must not contain a comma");
  148. return Tools.server_config.BLOCKED_TOOLS.includes(tool.name);
  149. };
  150. /**
  151. * Register a new tool, without touching the User Interface
  152. */
  153. Tools.register = function registerTool(newTool) {
  154. if (Tools.isBlocked(newTool)) return;
  155. if (newTool.name in Tools.list) {
  156. console.log("Tools.add: The tool '" + newTool.name + "' is already" +
  157. "in the list. Updating it...");
  158. }
  159. //Format the new tool correctly
  160. Tools.applyHooks(Tools.toolHooks, newTool);
  161. //Add the tool to the list
  162. Tools.list[newTool.name] = newTool;
  163. // Register the change handlers
  164. if (newTool.onSizeChange) Tools.sizeChangeHandlers.push(newTool.onSizeChange);
  165. //There may be pending messages for the tool
  166. var pending = Tools.pendingMessages[newTool.name];
  167. if (pending) {
  168. console.log("Drawing pending messages for '%s'.", newTool.name);
  169. var msg;
  170. while (msg = pending.shift()) {
  171. //Transmit the message to the tool (precising that it comes from the network)
  172. newTool.draw(msg, false);
  173. }
  174. }
  175. };
  176. /**
  177. * Add a new tool to the user interface
  178. */
  179. Tools.add = function (newTool) {
  180. if (Tools.isBlocked(newTool)) return;
  181. Tools.register(newTool);
  182. if (newTool.stylesheet) {
  183. Tools.HTML.addStylesheet(newTool.stylesheet);
  184. }
  185. //Add the tool to the GUI
  186. Tools.HTML.addTool(newTool.name, newTool.icon, newTool.iconHTML, newTool.shortcut, newTool.oneTouch);
  187. };
  188. Tools.change = function (toolName) {
  189. var newTool = Tools.list[toolName];
  190. var oldTool = Tools.curTool;
  191. if (!newTool) throw new Error("Trying to select a tool that has never been added!");
  192. if (newTool === oldTool) {
  193. if (newTool.secondary) {
  194. newTool.secondary.active = !newTool.secondary.active;
  195. var props = newTool.secondary.active ? newTool.secondary : newTool;
  196. Tools.HTML.toggle(newTool.name, props.name, props.icon);
  197. if (newTool.secondary.switch) newTool.secondary.switch();
  198. }
  199. return;
  200. }
  201. if (!newTool.oneTouch) {
  202. //Update the GUI
  203. var curToolName = (Tools.curTool) ? Tools.curTool.name : "";
  204. try {
  205. Tools.HTML.changeTool(curToolName, toolName);
  206. } catch (e) {
  207. console.error("Unable to update the GUI with the new tool. " + e);
  208. }
  209. Tools.svg.style.cursor = newTool.mouseCursor || "auto";
  210. Tools.board.title = Tools.i18n.t(newTool.helpText || "");
  211. //There is not necessarily already a curTool
  212. if (Tools.curTool !== null) {
  213. //It's useless to do anything if the new tool is already selected
  214. if (newTool === Tools.curTool) return;
  215. //Remove the old event listeners
  216. Tools.removeToolListeners(Tools.curTool);
  217. //Call the callbacks of the old tool
  218. Tools.curTool.onquit(newTool);
  219. }
  220. //Add the new event listeners
  221. Tools.addToolListeners(newTool);
  222. Tools.curTool = newTool;
  223. }
  224. //Call the start callback of the new tool
  225. newTool.onstart(oldTool);
  226. };
  227. Tools.addToolListeners = function addToolListeners(tool) {
  228. for (var event in tool.compiledListeners) {
  229. var listener = tool.compiledListeners[event];
  230. var target = listener.target || Tools.board;
  231. target.addEventListener(event, listener, { 'passive': false });
  232. }
  233. };
  234. Tools.removeToolListeners = function removeToolListeners(tool) {
  235. for (var event in tool.compiledListeners) {
  236. var listener = tool.compiledListeners[event];
  237. var target = listener.target || Tools.board;
  238. target.removeEventListener(event, listener);
  239. // also attempt to remove with capture = true in IE
  240. if (Tools.isIE) target.removeEventListener(event, listener, true);
  241. }
  242. };
  243. (function () {
  244. // Handle secondary tool switch with shift (key code 16)
  245. function handleShift(active, evt) {
  246. if (evt.keyCode === 16 && Tools.curTool.secondary && Tools.curTool.secondary.active !== active) {
  247. Tools.change(Tools.curTool.name);
  248. }
  249. }
  250. window.addEventListener("keydown", handleShift.bind(null, true));
  251. window.addEventListener("keyup", handleShift.bind(null, false));
  252. })();
  253. Tools.send = function (data, toolName) {
  254. toolName = toolName || Tools.curTool.name;
  255. var d = data;
  256. d.tool = toolName;
  257. Tools.applyHooks(Tools.messageHooks, d);
  258. var message = {
  259. "board": Tools.boardName,
  260. "data": d
  261. };
  262. Tools.socket.emit('broadcast', message);
  263. };
  264. Tools.drawAndSend = function (data, tool) {
  265. if (tool == null) tool = Tools.curTool;
  266. tool.draw(data, true);
  267. Tools.send(data, tool.name);
  268. };
  269. //Object containing the messages that have been received before the corresponding tool
  270. //is loaded. keys : the name of the tool, values : array of messages for this tool
  271. Tools.pendingMessages = {};
  272. // Send a message to the corresponding tool
  273. function messageForTool(message) {
  274. var name = message.tool,
  275. tool = Tools.list[name];
  276. if (tool) {
  277. Tools.applyHooks(Tools.messageHooks, message);
  278. tool.draw(message, false);
  279. } else {
  280. ///We received a message destinated to a tool that we don't have
  281. //So we add it to the pending messages
  282. if (!Tools.pendingMessages[name]) Tools.pendingMessages[name] = [message];
  283. else Tools.pendingMessages[name].push(message);
  284. }
  285. if (message.tool !== 'Hand' && message.deltax != null && message.deltay != null) {
  286. //this message has special info for the mover
  287. messageForTool({ tool: 'Hand', type: 'update', deltax: message.deltax || 0, deltay: message.deltay || 0, id: message.id });
  288. }
  289. }
  290. // Apply the function to all arguments by batches
  291. function batchCall(fn, args) {
  292. var BATCH_SIZE = 1024;
  293. if (args.length === 0) {
  294. return Promise.resolve();
  295. } else {
  296. var batch = args.slice(0, BATCH_SIZE);
  297. var rest = args.slice(BATCH_SIZE);
  298. return Promise.all(batch.map(fn))
  299. .then(function () {
  300. return new Promise(requestAnimationFrame);
  301. }).then(batchCall.bind(null, fn, rest));
  302. }
  303. }
  304. // Call messageForTool recursively on the message and its children
  305. function handleMessage(message) {
  306. //Check if the message is in the expected format
  307. if (!message.tool && !message._children) {
  308. console.error("Received a badly formatted message (no tool). ", message);
  309. }
  310. if (message.tool) messageForTool(message);
  311. if (message._children) return batchCall(handleMessage, message._children);
  312. else return Promise.resolve();
  313. }
  314. Tools.unreadMessagesCount = 0;
  315. Tools.newUnreadMessage = function () {
  316. Tools.unreadMessagesCount++;
  317. updateDocumentTitle();
  318. };
  319. window.addEventListener("focus", function () {
  320. Tools.unreadMessagesCount = 0;
  321. updateDocumentTitle();
  322. });
  323. function updateDocumentTitle() {
  324. document.title =
  325. (Tools.unreadMessagesCount ? '(' + Tools.unreadMessagesCount + ') ' : '') +
  326. Tools.boardName +
  327. " | WBO";
  328. }
  329. (function () {
  330. // Scroll and hash handling
  331. var scrollTimeout, lastStateUpdate = Date.now();
  332. window.addEventListener("scroll", function onScroll() {
  333. var x = document.documentElement.scrollLeft / Tools.getScale(),
  334. y = document.documentElement.scrollTop / Tools.getScale();
  335. clearTimeout(scrollTimeout);
  336. scrollTimeout = setTimeout(function updateHistory() {
  337. var hash = '#' + (x | 0) + ',' + (y | 0) + ',' + Tools.getScale().toFixed(1);
  338. if (Date.now() - lastStateUpdate > 5000 && hash !== window.location.hash) {
  339. window.history.pushState({}, "", hash);
  340. lastStateUpdate = Date.now();
  341. } else {
  342. window.history.replaceState({}, "", hash);
  343. }
  344. }, 100);
  345. });
  346. function setScrollFromHash() {
  347. var coords = window.location.hash.slice(1).split(',');
  348. var x = coords[0] | 0;
  349. var y = coords[1] | 0;
  350. var scale = parseFloat(coords[2]);
  351. resizeCanvas({ x: x, y: y });
  352. Tools.setScale(scale);
  353. window.scrollTo(x * scale, y * scale);
  354. }
  355. window.addEventListener("hashchange", setScrollFromHash, false);
  356. window.addEventListener("popstate", setScrollFromHash, false);
  357. window.addEventListener("DOMContentLoaded", setScrollFromHash, false);
  358. })();
  359. //List of hook functions that will be applied to messages before sending or drawing them
  360. function resizeCanvas(m) {
  361. //Enlarge the canvas whenever something is drawn near its border
  362. var x = m.x | 0, y = m.y | 0
  363. var MAX_BOARD_SIZE = 65536; // Maximum value for any x or y on the board
  364. if (x > Tools.svg.width.baseVal.value - 2000) {
  365. Tools.svg.width.baseVal.value = Math.min(x + 2000, MAX_BOARD_SIZE);
  366. }
  367. if (y > Tools.svg.height.baseVal.value - 2000) {
  368. Tools.svg.height.baseVal.value = Math.min(y + 2000, MAX_BOARD_SIZE);
  369. }
  370. }
  371. function updateUnreadCount(m) {
  372. if (document.hidden && ["child", "update"].indexOf(m.type) === -1) {
  373. Tools.newUnreadMessage();
  374. }
  375. }
  376. Tools.messageHooks = [resizeCanvas, updateUnreadCount];
  377. Tools.scale = 1.0;
  378. var scaleTimeout = null;
  379. Tools.setScale = function setScale(scale) {
  380. if (isNaN(scale)) scale = 1;
  381. scale = Math.max(0.1, Math.min(10, scale));
  382. Tools.svg.style.willChange = 'transform';
  383. Tools.svg.style.transform = 'scale(' + scale + ')';
  384. clearTimeout(scaleTimeout);
  385. scaleTimeout = setTimeout(function () {
  386. Tools.svg.style.willChange = 'auto';
  387. }, 1000);
  388. Tools.scale = scale;
  389. return scale;
  390. }
  391. Tools.getScale = function getScale() {
  392. return Tools.scale;
  393. }
  394. //List of hook functions that will be applied to tools before adding them
  395. Tools.toolHooks = [
  396. function checkToolAttributes(tool) {
  397. if (typeof (tool.name) !== "string") throw "A tool must have a name";
  398. if (typeof (tool.listeners) !== "object") {
  399. tool.listeners = {};
  400. }
  401. if (typeof (tool.onstart) !== "function") {
  402. tool.onstart = function () { };
  403. }
  404. if (typeof (tool.onquit) !== "function") {
  405. tool.onquit = function () { };
  406. }
  407. },
  408. function compileListeners(tool) {
  409. //compile listeners into compiledListeners
  410. var listeners = tool.listeners;
  411. //A tool may provide precompiled listeners
  412. var compiled = tool.compiledListeners || {};
  413. tool.compiledListeners = compiled;
  414. function compile(listener) { //closure
  415. return (function listen(evt) {
  416. var x = evt.pageX / Tools.getScale(),
  417. y = evt.pageY / Tools.getScale();
  418. return listener(x, y, evt, false);
  419. });
  420. }
  421. function compileTouch(listener) { //closure
  422. return (function touchListen(evt) {
  423. //Currently, we don't handle multitouch
  424. if (evt.changedTouches.length === 1) {
  425. //evt.preventDefault();
  426. var touch = evt.changedTouches[0];
  427. var x = touch.pageX / Tools.getScale(),
  428. y = touch.pageY / Tools.getScale();
  429. return listener(x, y, evt, true);
  430. }
  431. return true;
  432. });
  433. }
  434. function wrapUnsetHover(f, toolName) {
  435. return (function unsetHover(evt) {
  436. document.activeElement && document.activeElement.blur && document.activeElement.blur();
  437. return f(evt);
  438. });
  439. }
  440. if (listeners.press) {
  441. compiled["mousedown"] = wrapUnsetHover(compile(listeners.press), tool.name);
  442. compiled["touchstart"] = wrapUnsetHover(compileTouch(listeners.press), tool.name);
  443. }
  444. if (listeners.move) {
  445. compiled["mousemove"] = compile(listeners.move);
  446. compiled["touchmove"] = compileTouch(listeners.move);
  447. }
  448. if (listeners.release) {
  449. var release = compile(listeners.release),
  450. releaseTouch = compileTouch(listeners.release);
  451. compiled["mouseup"] = release;
  452. if (!Tools.isIE) compiled["mouseleave"] = release;
  453. compiled["touchleave"] = releaseTouch;
  454. compiled["touchend"] = releaseTouch;
  455. compiled["touchcancel"] = releaseTouch;
  456. }
  457. }
  458. ];
  459. Tools.applyHooks = function (hooks, object) {
  460. //Apply every hooks on the object
  461. hooks.forEach(function (hook) {
  462. hook(object);
  463. });
  464. };
  465. // Utility functions
  466. Tools.generateUID = function (prefix, suffix) {
  467. var uid = Date.now().toString(36); //Create the uids in chronological order
  468. uid += (Math.round(Math.random() * 36)).toString(36); //Add a random character at the end
  469. if (prefix) uid = prefix + uid;
  470. if (suffix) uid = uid + suffix;
  471. return uid;
  472. };
  473. Tools.createSVGElement = function createSVGElement(name, attrs) {
  474. var elem = document.createElementNS(Tools.svg.namespaceURI, name);
  475. if (typeof (attrs) !== "object") return elem;
  476. Object.keys(attrs).forEach(function (key, i) {
  477. elem.setAttributeNS(null, key, attrs[key]);
  478. });
  479. return elem;
  480. };
  481. Tools.positionElement = function (elem, x, y) {
  482. elem.style.top = y + "px";
  483. elem.style.left = x + "px";
  484. };
  485. Tools.colorPresets = [
  486. { color: "#001f3f", key: '1' },
  487. { color: "#FF4136", key: '2' },
  488. { color: "#0074D9", key: '3' },
  489. { color: "#FF851B", key: '4' },
  490. { color: "#FFDC00", key: '5' },
  491. { color: "#3D9970", key: '6' },
  492. { color: "#91E99B", key: '7' },
  493. { color: "#90468b", key: '8' },
  494. { color: "#7FDBFF", key: '9' },
  495. { color: "#AAAAAA", key: '0' },
  496. { color: "#E65194" }
  497. ];
  498. Tools.color_chooser = document.getElementById("chooseColor");
  499. Tools.setColor = function (color) {
  500. Tools.color_chooser.value = color;
  501. };
  502. Tools.getColor = (function color() {
  503. var color_index = (Math.random() * Tools.colorPresets.length) | 0;
  504. var initial_color = Tools.colorPresets[color_index].color;
  505. Tools.setColor(initial_color);
  506. return function () { return Tools.color_chooser.value; };
  507. })();
  508. Tools.colorPresets.forEach(Tools.HTML.addColorButton.bind(Tools.HTML));
  509. Tools.sizeChangeHandlers = [];
  510. Tools.setSize = (function size() {
  511. var chooser = document.getElementById("chooseSize");
  512. function update() {
  513. var size = Math.max(1, Math.min(50, chooser.value | 0));
  514. chooser.value = size;
  515. Tools.sizeChangeHandlers.forEach(function (handler) {
  516. handler(size);
  517. });
  518. }
  519. update();
  520. chooser.onchange = chooser.oninput = update;
  521. return function (value) {
  522. if (value !== null && value !== undefined) { chooser.value = value; update(); }
  523. return parseInt(chooser.value);
  524. };
  525. })();
  526. Tools.getSize = (function () { return Tools.setSize() });
  527. Tools.getOpacity = (function opacity() {
  528. var chooser = document.getElementById("chooseOpacity");
  529. var opacityIndicator = document.getElementById("opacityIndicator");
  530. function update() {
  531. opacityIndicator.setAttribute("opacity", chooser.value);
  532. }
  533. update();
  534. chooser.onchange = chooser.oninput = update;
  535. return function () {
  536. return Math.max(0.1, Math.min(1, chooser.value));
  537. };
  538. })();
  539. //Scale the canvas on load
  540. Tools.svg.width.baseVal.value = document.body.clientWidth;
  541. Tools.svg.height.baseVal.value = document.body.clientHeight;
  542. /**
  543. What does a "tool" object look like?
  544. newtool = {
  545. "name" : "SuperTool",
  546. "listeners" : {
  547. "press" : function(x,y,evt){...},
  548. "move" : function(x,y,evt){...},
  549. "release" : function(x,y,evt){...},
  550. },
  551. "draw" : function(data, isLocal){
  552. //Print the data on Tools.svg
  553. },
  554. "onstart" : function(oldTool){...},
  555. "onquit" : function(newTool){...},
  556. "stylesheet" : "style.css",
  557. }
  558. */