DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


sample_code:drawing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
sample_code:drawing [2014/11/04 04:36]
stevegarman
sample_code:drawing [2014/12/06 21:07] (current)
stevegarman
Line 2: Line 2:
 <code JavaScript drawing.js>​ <code JavaScript drawing.js>​
 //​drawing.js //​drawing.js
-var lastev=[]; lastev.action="​Up";​ lastev.x=0; lastev.y=0;+var lastev = []; 
 +lastev.action = "​Up";​ 
 +lastev.x = 0; 
 +lastev.y = 0;
 var img var img
-//Called when application is started.  +  ​//Called when application is started.  
-function OnStart() {  +function OnStart() 
- //Create a layout with objects vertically centered.  +
- var lay = app.CreateLayout( "​Linear",​ "​FillXY"​ );   +  //Create a layout with objects vertically centered.  
-   +  var lay = app.CreateLayout("​Linear",​ "​FillXY"​);​ 
- //Create a blank image.  + 
- img = app.CreateImage( null, 0.8, 0.8 );  +  //Create a blank image.  
- lay.AddChild( img );  +  img = app.CreateImage(null,​ 0.8, 0.8); 
- var btn = app.CreateButton("​Save"​);​ +  lay.AddChild(img);​ 
-    btn.SetOnTouch(btn_OnTouch);​ +  var btn = app.CreateButton("​Save"​);​ 
-    lay.AddChild( btn ); +  btn.SetOnTouch(btn_OnTouch);​ 
- //Add layout to app.  +  lay.AddChild(btn);​ 
- app.AddLayout( lay );   +  //Add layout to app.  
- //Draw blank picture.  +  app.AddLayout(lay);​ 
- DrawPicture();​  +  //Draw blank picture.  
-+  DrawPicture();​ 
 +} 
 + 
 +function DrawPicture() 
 +
 +  //Fill image with solid white.  
 +  img.SetColor("#​ffffffff"​);​ 
 +  img.SetLineWidth(10);​ 
 +  img.SetPaintStyle("​Line"​);​ 
 +  img.SetPaintColor("#​ff8888ff"​);​ 
 +  img.SetOnTouch(img_OnTouch);​ 
 +
 + 
 +function img_OnTouch(ev) 
 +
 +  app.Debug("​=>"​ + ev.action + "<​="​);​ 
 +  if (ev.action == "​Up"​) 
 +  {
  
-function DrawPicture() {  
- //Fill image with solid white. ​ 
- img.SetColor( "#​ffffffff"​ );  
- img.SetLineWidth( 10 );  ​ 
- img.SetPaintStyle( "​Line"​ );  
- img.SetPaintColor( "#​ff8888ff"​ );  
- img.SetOnTouch( img_OnTouch ); 
- 
-function img_OnTouch( ev ){ 
-app.Debug("​=>"​+ev.action+"<​="​);​ 
-  if( ev.action == "​Up"​){ 
-        
   }   }
-  else if( ev.action=="​Down"​ ){ +  else if (ev.action == "​Down"​) 
-    img.DrawPoint( ev.x[0], ev.y[0] );+  ​
 +    img.DrawPoint(ev.x[0],​ ev.y[0]);
   }   }
-  else if( ev.action=="​Move"​ ){ +  else if (ev.action == "​Move"​) 
-      if( lastev.action != "​Up"​){ +  ​
-          img.DrawLine( lastev.x, lastev.y, ev.x[0], ev.y[0] ); +    if (lastev.action != "​Up"​) 
-      }+    ​
 +      img.DrawLine(lastev.x,​ lastev.y, ev.x[0], ev.y[0]); 
 +    }
   }   }
-  if(ev.action != ""​){+  if (ev.action != ""​) 
 +  ​{
     lastev.action = ev.action     lastev.action = ev.action
     lastev.x = ev.x[0];     lastev.x = ev.x[0];
Line 48: Line 60:
   }   }
 } }
-function btn_OnTouch(){ + 
-    img.Save("/​sdcard/​temptest.jpg"​);​+function btn_OnTouch() 
 +
 +  img.Save("/​sdcard/​temptest.jpg"​);​
 } }
 </​code>​ </​code>​
sample_code/drawing.txt · Last modified: 2014/12/06 21:07 by stevegarman