1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    2
    Vote Rating
    0
    mariuscristea is on a distinguished road

      0  

    Default Unanswered: paperjs+sencha bug

    Unanswered: 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

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,065
    Answers
    3498
    Vote Rating
    852
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    I don't see anywhere where you tried to integrate with ST2
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    2
    Vote Rating
    0
    mariuscristea is on a distinguished road

      0  

    Default


    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>

Thread Participants: 1

Tags for this Thread