-
paperjs+sencha bug
i'm creating a sencha application which draw a line on a picture inside a paperjs canvas. The line is drawn using mouseup event from paperjs. i use the event.downPoint and event.point for the extremities of the line. The user can draw only one single line on the canvas. After he draw it he can move the extremities clicking again on the canvas. The code i'm using is this:
Code:
var path = new Path();
path.strokeColor = 'black';
path.strokeWidth = 5;
var ok = false;
function onMouseUp(event) {
if(ok){
var point = path.getNearestPoint(event.downPoint);
if(point.x == path.segments[0].point.x && point.y == path.segments[0].point.y ){
path.segments[0].point = event.downPoint;
}else{
path.segments[1].point = event.downPoint;
}
}else{
path.add(event.downPoint);
path.add(event.point);
ok = true;
}
}
you can find an working example of what i want to accomplish here
http://jsfiddle.net/NwwEv/
I need yo integrate this into a sencha touch 2.0 application
what i've tried to do is to add the paper.js code at the end of the head section from the index file of the sencha application.
Code:
<script type="text/javascript" src="paper.js"></script>
<script type="text/paperscript" canvas="largeImage" id="paperscope">
var path = new Path();
path.strokeColor = 'black';
path.strokeWidth = 5;
var ok = false;
function onMouseUp(event) {
if(ok){
var point = path.getNearestPoint(event.downPoint);
if(point.x == path.segments[0].point.x && point.y == path.segments[0].point.y ){
path.segments[0].point = event.downPoint;
}else{
path.segments[1].point = event.downPoint;
}
}else{
path.add(event.downPoint);
path.add(event.point);
ok = true;
}
}
</script>
My problem is that the extremities points are not updated when try to do that. It's drawing another line starting from one of the extremities points to the point where i've clicked every time when i click on the canvas after i draw the line.
It's like the variable path isnt stored and each time is creating a new line.
Thanks
-
I don't see anywhere where you tried to integrate with ST2
-
paper.js is included directly in the index.html of the sencha application. the canvas of paperjs is present in a tabpanel of the application.
Code:
<!DOCTYPE HTML>h
<html manifest="" lang="en-US">
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" href="./resources/icons/favicon.ico">
<script type="text/javascript" src="sdk/microloader/development.js"></script>
<script type="text/javascript" src="paper.js"></script>
<script type="text/paperscript" canvas="largeImage" id="paperscope">
var path = new Path();
path.strokeColor = 'black';
path.strokeWidth = 5;
var ok = false;
function onMouseUp(event) {
if(ok){
var point = path.getNearestPoint(event.downPoint);
if(point.x == path.segments[0].point.x && point.y == path.segments[0].point.y ){
path.segments[0].point = event.downPoint;
}else{
path.segments[1].point = event.downPoint;
}
}else{
path.add(event.downPoint);
path.add(event.point);
ok = true;
}
}
</script>
</head>
<body onload="onLoad()">
<div id="appLoadingIndicator">
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>