diff options
Diffstat (limited to 'examples/declarative')
-rw-r--r-- | examples/declarative/workerscript/workerscript.js | 16 | ||||
-rw-r--r-- | examples/declarative/workerscript/workerscript.qml | 6 |
2 files changed, 19 insertions, 3 deletions
diff --git a/examples/declarative/workerscript/workerscript.js b/examples/declarative/workerscript/workerscript.js index 060c04a..f76471f 100644 --- a/examples/declarative/workerscript/workerscript.js +++ b/examples/declarative/workerscript/workerscript.js @@ -1,5 +1,15 @@ -onmessage = function(message) { - print ("You clicked the " + message.rectangle + " rectangle."); - print ("The coordinates were: " + message.x + "," + message.y); +var lastx = 0; +var lasty = 0; + +WorkerScript.onMessage = function(message) { + var ydiff = message.y - lasty; + var xdiff = message.x - lastx; + + var total = Math.sqrt(ydiff * ydiff + xdiff * xdiff); + + lastx = message.x; + lasty = message.y; + + WorkerScript.sendMessage( {xmove: xdiff, ymove: ydiff, move: total} ); } diff --git a/examples/declarative/workerscript/workerscript.qml b/examples/declarative/workerscript/workerscript.qml index 3729022..e36d4d4 100644 --- a/examples/declarative/workerscript/workerscript.qml +++ b/examples/declarative/workerscript/workerscript.qml @@ -6,6 +6,12 @@ Rectangle { WorkerScript { id: myWorker source: "workerscript.js" + + onMessage: { + print("Moved " + messageObject.xmove + " along the X axis."); + print("Moved " + messageObject.ymove + " along the Y axis."); + print("Moved " + messageObject.move + " pixels."); + } } Rectangle { |