Commit 64ab5c4d authored by Joel Martin's avatar Joel Martin

Working with Raw rectangles and capital letter keys.

parent c8460b03
......@@ -2,7 +2,7 @@
<head><title>Canvas Experiments</title></head>
<body>
Canvas:<br>
<canvas id="tutorial" width="500" height="300">
<canvas id="tutorial" width="640" height="480">
Canvas not supported.
</canvas>
......@@ -16,6 +16,6 @@
<script src="canvas.js"></script>
<script>
window.onload = function() { init_canvas('tutorial'); }
window.onload = function() { init_canvas('tutorial', 640, 480); }
</script>
</html>
......@@ -28,8 +28,9 @@ c_x : 0,
c_y : 0,
c_wx : 0,
c_wy : 0,
ctx : null,
mousedown: function (e) {
mouseDown: function (e) {
evt = e.event || window.event;
e.stop();
debug('mouse ' + evt.which + '/' + evt.button + ' down:' +
......@@ -64,14 +65,21 @@ ctxDisable: function (e) {
},
init: function (canvas) {
init: function (canvas, width, height, keyDown, keyUp, mouseDown, mouseUp) {
debug(">> init_canvas");
if (! keyDown) keyDown = Canvas.keyDown;
if (! keyUp) keyUp = Canvas.keyUp;
if (! mouseDown) mouseDown = Canvas.mouseDown;
if (! mouseUp) mouseUp = Canvas.mouseUp;
c = $(canvas);
c.addEvent('mousedown', Canvas.mouseDown);
c.addEvent('mouseup', Canvas.mouseUp);
document.addEvent('keydown', Canvas.keyDown);
document.addEvent('keyup', Canvas.keyUp);
c.width = width;
c.height = height;
document.addEvent('keydown', keyDown);
document.addEvent('keyup', keyUp);
c.addEvent('mousedown', mouseDown);
c.addEvent('mouseup', mouseUp);
/* Work around right and middle click browser behaviors */
document.addEvent('click', Canvas.ctxDisable);
......@@ -83,22 +91,22 @@ init: function (canvas) {
Canvas.c_wy = c.getSize().y;
if (! c.getContext) return;
var ctx = c.getContext('2d');
Canvas.ctx = c.getContext('2d');
/* Border */
ctx.stroke();
ctx.rect(0, 0, Canvas.c_wx, Canvas.c_wy);
ctx.stroke();
Canvas.ctx.stroke();
Canvas.ctx.rect(0, 0, Canvas.c_wx, Canvas.c_wy);
Canvas.ctx.stroke();
/*
// Does not work in firefox
var himg = new Image();
himg.src = "head_ani2.gif"
ctx.drawImage(himg, 10, 10);
Canvas.ctx.drawImage(himg, 10, 10);
*/
/* Test array image data */
var img = ctx.createImageData(50, 50);
var img = Canvas.ctx.createImageData(50, 50);
for (y=0; y< 50; y++) {
for (x=0; x< 50; x++) {
img.data[(y*50 + x)*4 + 0] = 255 - parseInt((255 / 50) * y);
......@@ -107,9 +115,21 @@ init: function (canvas) {
img.data[(y*50 + x)*4 + 3] = 255;
}
}
ctx.putImageData(img, 100, 100);
Canvas.ctx.putImageData(img, 100, 100);
debug("<< init_canvas");
},
rfbImage: function(x, y, width, height, arr) {
var img = Canvas.ctx.createImageData(width, height);
for (var i=0; i < (width * height); i++) {
img.data[i*4 + 0] = arr[i*4 + 0];
img.data[i*4 + 1] = arr[i*4 + 1];
img.data[i*4 + 2] = arr[i*4 + 2];
img.data[i*4 + 3] = 255; // Set Alpha
}
Canvas.ctx.putImageData(img, x, y);
}
};
......
......@@ -17,6 +17,7 @@
<script src="include/mootools.js"></script>
<script src="include/mootools-more.js"></script>
<script src="include/base64a.js"></script>
<script src="include/des2.js"></script>
<script src="canvas.js"></script>
<script src="vnc.js"></script>
......@@ -30,12 +31,11 @@
debug("must set host and port");
return;
}
init_ws(host, port);
RFB.init_ws(host, port);
debug("<< connect");
}
window.onload = function() {
Canvas.init('vnc');
connect();
}
</script>
......
This diff is collapsed.
......@@ -4,6 +4,8 @@ import sys, os, socket, time, traceback
from base64 import b64encode, b64decode
from select import select
buffer_size = 65536
server_handshake = """HTTP/1.1 101 Web Socket Protocol Handshake\r
Upgrade: WebSocket\r
Connection: Upgrade\r
......@@ -35,30 +37,30 @@ def proxy(client, target):
if excepts: raise Exception("Socket exception")
if client in ins:
buf = client.recv(1024)
buf = client.recv(buffer_size)
if len(buf) == 0: raise Exception("Client closed")
tqueue.append(b64decode(buf[1:-1]))
print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf))
#traffic("}")
#print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf))
traffic("}")
if target in ins:
buf = target.recv(1024)
buf = target.recv(buffer_size)
if len(buf) == 0: raise Exception("Target closed")
cqueue.append("\x00" + b64encode(buf) + "\xff")
print "Target recv: %s (%d)" % (repr(buf), len(buf))
#traffic("{")
#print "Target recv: %s (%d)" % (repr(buf), len(buf))
traffic("{")
if cqueue and client in outs:
while cqueue:
print "Client send: %s" % repr(cqueue[0])
#print "Client send: %s" % repr(cqueue[0])
client.send(cqueue.pop(0))
#traffic("<")
traffic("<")
if tqueue and target in outs:
while tqueue:
print "Target send: %s" % repr(tqueue[0])
#print "Target send: %s" % repr(tqueue[0])
target.send(tqueue.pop(0))
#traffic(">")
traffic(">")
def start_server(listen_port, target_host, target_port):
lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment