Author: kpreisser Date: Wed Aug 19 09:06:50 2015 New Revision: 1696546 URL: http://svn.apache.org/r1696546 Log: Follow-Up commit to r1696404: - Remove the "lastInChain" flag in JavaScript as well as it is not used. - Because the flag has been removed, there is no need to generate a Path/DrawingMessage object when the mouse button is released while drawing a continuous path and the old and new mouse coordinates are the same.
Modified: tomcat/trunk/webapps/examples/websocket/drawboard.xhtml Modified: tomcat/trunk/webapps/examples/websocket/drawboard.xhtml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/drawboard.xhtml?rev=1696546&r1=1696545&r2=1696546&view=diff ============================================================================== --- tomcat/trunk/webapps/examples/websocket/drawboard.xhtml (original) +++ tomcat/trunk/webapps/examples/websocket/drawboard.xhtml Wed Aug 19 09:06:50 2015 @@ -267,7 +267,7 @@ this.id = id; } - function Path(type, color, thickness, x1, y1, x2, y2, lastInChain) { + function Path(type, color, thickness, x1, y1, x2, y2) { this.type = type; this.color = color; this.thickness = thickness; @@ -275,7 +275,6 @@ this.y1 = y1; this.x2 = x2; this.y2 = y2; - this.lastInChain = lastInChain; function ellipse(ctx, x, y, w, h) { /* Drawing a ellipse cannot be done directly in a @@ -495,8 +494,7 @@ parseFloat(elements[7]), parseFloat(elements[8]), parseFloat(elements[9]), - parseFloat(elements[10]), - elements[11] != "0"); + parseFloat(elements[10])); // Draw the path onto the last canvas. path.draw(canvasServerImageCtx); @@ -613,7 +611,7 @@ availableColors[currentColorIndex], availableThicknesses[currentThicknessIndex], currentMouseX, currentMouseY, mouseX, - mouseY, false); + mouseY); // Draw it on the background canvas. path.draw(canvasBackgroundCtx); @@ -658,19 +656,24 @@ var mouseY = e.pageY - canvasDisplay.offsetTop; var drawType = availableDrawTypes[currentDrawTypeIndex]; - var path = new Path(drawType.id, availableColors[currentColorIndex], - availableThicknesses[currentThicknessIndex], - currentMouseX, currentMouseY, mouseX, - mouseY, true); - // Draw it on the background canvas. - path.draw(canvasBackgroundCtx); - - // Send it to the sever. - pushPath(path); - - // Refresh old coordinates - currentMouseX = mouseX; - currentMouseY = mouseY; + // If we are drawing a continuous path and the previous mouse coordinates are the same as + // the new ones, there is no need to construct a new draw message as we don't need to + // "terminate" a path as every path element contains both the start and the end point. + if (!(drawType.continuous && mouseX == currentMouseX && mouseY == currentMouseY)) { + var path = new Path(drawType.id, availableColors[currentColorIndex], + availableThicknesses[currentThicknessIndex], + currentMouseX, currentMouseY, mouseX, + mouseY); + // Draw it on the background canvas. + path.draw(canvasBackgroundCtx); + + // Send it to the sever. + pushPath(path); + + // Refresh old coordinates + currentMouseX = mouseX; + currentMouseY = mouseY; + } refreshDisplayCanvas(); } @@ -807,8 +810,7 @@ + path.color[2] + "," + Math.round(path.color[3] * 255.0) + "," + path.thickness + "," + path.x1 + "," - + path.y1 + "," + path.x2 + "," + path.y2 + "," - + (path.lastInChain ? "1" : "0"); + + path.y1 + "," + path.x2 + "," + path.y2; socket.send("1" + message); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org