User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:drawing

This is an old revision of the document!


Drawing demo

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");
}
sample_code/drawing.1415075770.txt.gz · Last modified: 2014/11/04 12:36 (external edit)