User Tools

Site Tools


sample_code:drawing

Differences

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

Link to this comparison view

sample_code:drawing [2014/11/04 04:35]
stevegarman created
sample_code:drawing [2014/12/07 05:07]
Line 1: Line 1:
-====== Drawing ====== 
-<code JavaScript drawing.js> 
-//drawing.js 
-var lastev=[]; lastev.action="Up"; lastev.x=0; lastev.y=0; 
-var img 
-//Called when application is started.  
-function OnStart() {  
- //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 );  
- lay.AddChild( img );  
- var btn = app.CreateButton("Save"); 
-    btn.SetOnTouch(btn_OnTouch); 
-    lay.AddChild( btn ); 
- //Add layout to app.   
- app.AddLayout( lay );   
- //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"){ 
-        
-  } 
-  else if( ev.action=="Down" ){ 
-    img.DrawPoint( ev.x[0], ev.y[0] ); 
-  } 
-  else if( ev.action=="Move" ){ 
-      if( lastev.action != "Up"){ 
-          img.DrawLine( lastev.x, lastev.y, ev.x[0], ev.y[0] ); 
-      } 
-  } 
-  if(ev.action != ""){ 
-    lastev.action = ev.action 
-    lastev.x = ev.x[0]; 
-    lastev.y = ev.y[0] 
-  } 
-} 
-function btn_OnTouch(){ 
-    img.Save("/sdcard/temptest.jpg"); 
-} 
-</code> 
sample_code/drawing.txt ยท Last modified: 2014/12/07 05:07 (external edit)