1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- function start(wsrpc){
- // attach on windows resize
- var canvas = document.getElementById("screen")
- var ctx = canvas.getContext("2d");
- ctx.lineWidth = 2;
- function handleResize(evt){
- if (ctx.canvas.width != window.innerWidth ||
- ctx.canvas.height != window.innerHeight) {
-
- console.log("Readapt canvas");
- ctx.canvas.width = window.innerWidth;
- ctx.canvas.height = window.innerHeight;
- }
- wsrpc.call("OnResize",ctx.canvas.width,ctx.canvas.height);
- }
- window.onresize = handleResize
- handleResize();
- // Get Canvas ctx
- console.log("Connected");
- wsrpc.export({
- ping: function() {
- console.log("Client sent ping");
- },
- DrawArc: function(response, x,y,radius,startAngle,endAngle) {
- //console.log("Drawing arc",x,y,radius,startAngle,endAngle);
- x = x - canvas.offsetLeft
- y = y - canvas.offsetTop
- ctx.beginPath();
- ctx.arc(x,y,radius,startAngle,endAngle,false);
- ctx.stroke();
- },
- Line: function(response, x1,y1,x2,y2) {
- x1 = x1 - canvas.offsetLeft
- y1 = y1 - canvas.offsetTop
- x2 = x2 - canvas.offsetLeft
- y2 = y2 - canvas.offsetTop
- ctx.beginPath();
- ctx.moveTo(x1,y1);
- ctx.lineTo(x2,y2);
- ctx.stroke();
- },
- Clear: function(response) {
- ctx.clearRect(0,0,ctx.canvas.width,ctx.canvas.height);
- }
- // Canvas stuff
- //
-
- })
- // Events
- window.onmousemove = function(evt) {
- wsrpc.call("OnMouseMove",evt.pageX,evt.pageY);
- }
- }
- window.onload = function() {
- wsrpc = new WsRpc();
- wsrpc.onopen = start;
- wsrpc.connect("ws://" + location.host + "/wsrpc");
- }
|