This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sample_code:drawing [2014/11/04 04:35] stevegarman created |
sample_code:drawing [2014/12/07 05:07] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Drawing ====== | + | ====== Drawing |
<code JavaScript drawing.js> | <code JavaScript drawing.js> | ||
// | // | ||
- | var lastev=[]; lastev.action=" | + | var lastev = []; |
+ | lastev.action = " | ||
+ | lastev.x = 0; | ||
+ | lastev.y = 0; | ||
var img | var img | ||
- | //Called when application is started. | + | |
- | function OnStart() { | + | function OnStart() |
- | //Create a layout with objects vertically centered. | + | { |
- | var lay = app.CreateLayout( " | + | //Create a layout with objects vertically centered. |
- | + | var lay = app.CreateLayout(" | |
- | //Create a blank image. | + | |
- | img = app.CreateImage( null, 0.8, 0.8 ); | + | //Create a blank image. |
- | lay.AddChild( img ); | + | img = app.CreateImage(null, |
- | var btn = app.CreateButton(" | + | lay.AddChild(img); |
- | btn.SetOnTouch(btn_OnTouch); | + | var btn = app.CreateButton(" |
- | 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("# | ||
+ | img.SetLineWidth(10); | ||
+ | img.SetPaintStyle(" | ||
+ | img.SetPaintColor("# | ||
+ | img.SetOnTouch(img_OnTouch); | ||
+ | } | ||
+ | |||
+ | function img_OnTouch(ev) | ||
+ | { | ||
+ | app.Debug(" | ||
+ | if (ev.action == " | ||
+ | { | ||
- | 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==" | + | else if (ev.action == " |
- | img.DrawPoint( ev.x[0], ev.y[0] ); | + | |
+ | img.DrawPoint(ev.x[0], | ||
} | } | ||
- | else if( ev.action==" | + | else if (ev.action == " |
- | if( lastev.action != " | + | |
- | img.DrawLine( lastev.x, lastev.y, ev.x[0], ev.y[0] ); | + | if (lastev.action != " |
- | } | + | |
+ | img.DrawLine(lastev.x, | ||
+ | } | ||
} | } | ||
- | 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("/ | + | function btn_OnTouch() |
+ | { | ||
+ | img.Save("/ | ||
} | } | ||
</ | </ |