This shows you the differences between two versions of the page.
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> | ||
- | // | ||
- | var lastev=[]; lastev.action=" | ||
- | var img | ||
- | //Called when application is started. | ||
- | function OnStart() { | ||
- | //Create a layout with objects vertically centered. | ||
- | var lay = app.CreateLayout( " | ||
- | |||
- | //Create a blank image. | ||
- | img = app.CreateImage( null, 0.8, 0.8 ); | ||
- | lay.AddChild( img ); | ||
- | var btn = app.CreateButton(" | ||
- | 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( "# | ||
- | img.SetLineWidth( 10 ); | ||
- | img.SetPaintStyle( " | ||
- | img.SetPaintColor( "# | ||
- | img.SetOnTouch( img_OnTouch ); | ||
- | } | ||
- | function img_OnTouch( ev ){ | ||
- | app.Debug(" | ||
- | if( ev.action == " | ||
- | |||
- | } | ||
- | else if( ev.action==" | ||
- | img.DrawPoint( ev.x[0], ev.y[0] ); | ||
- | } | ||
- | else if( ev.action==" | ||
- | if( lastev.action != " | ||
- | 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("/ | ||
- | } | ||
- | </ |