# HG changeset patch # User wycc # Date 1281872649 -28800 # Node ID f95d58a8edd16af9432e8352543461d3cd2c0b1b # Parent 01d02382dea7202f1921509a1c3598090ce7a27e Add javascript-based animation test program. We should make it as module in the future. diff -r 01d02382dea7 -r f95d58a8edd1 nodejs/testsvg.js --- a/nodejs/testsvg.js Sun Aug 15 19:07:36 2010 +0800 +++ b/nodejs/testsvg.js Sun Aug 15 19:44:09 2010 +0800 @@ -7,17 +7,45 @@ lightbar = app.get("item_lightbar") item=1 lightbar[5] = app.get("item"+item)[5] + +function animated(app,obj) { + var d=obj.animated_loc - obj[5]; + var dd=d; + if (dd<0) dd = -dd; + + if (dd > 5) { + if (d > 0) d = 5; else d = -5; + } + + obj[5] += d; + sys.puts(d); + app.refresh() + if (dd > 1) { + setTimeout(function() { animated(app,obj);}, 20); + return; + } + app.animated_end = 1; +} +function animated_start(app,obj,target) { + if (obj.animated_end==0) + obj[5] = obj.animated_loc; + obj.animated_loc = target[5]; + obj.animated_end = 0; + animated(app,obj); +} +lightbar.animated_loc = 1; app.addKeyboardListener(6, function(evt) { if (evt.keycode == mbapp.KEY_UP) { item = item - 1; - if (item == 0) item = 9; - lightbar[5] = app.get("item"+item)[5] + if (item == 0) item = 1; + else + animated_start(app,lightbar,app.get("item"+item)); } else if (evt.keycode == mbapp.KEY_DOWN) { item = item + 1; if (item == 10) { - item = 1; - } - lightbar[5] = app.get("item"+item)[5] + item = 9; + } else + animated_start(app,lightbar,app.get("item"+item)); } }); app.loop();