diff --git a/parts/scenes/app_console.lua b/parts/scenes/app_console.lua index 4b15c356..188eaddc 100644 --- a/parts/scenes/app_console.lua +++ b/parts/scenes/app_console.lua @@ -647,6 +647,11 @@ local commands={}do scene='app_triple', description="A Match-3 Game. Original idea from Sanlitun / Triple Town" }, + { + code="sw", + scene='app_stopwatch', + description="A stopwatch" + }, { code="spin", scene='app_spin', diff --git a/parts/scenes/app_stopwatch.lua b/parts/scenes/app_stopwatch.lua new file mode 100644 index 00000000..bd041414 --- /dev/null +++ b/parts/scenes/app_stopwatch.lua @@ -0,0 +1,70 @@ +local state +local pressTime +local releaseTime +local time1,time2 + +local function press() + if state==0 then + state=1 + pressTime=TIME() + releaseTime=false + time2=STRING.time(0) + elseif state==2 then + state=0 + end +end + +local function release() + if state==1 then + state=2 + releaseTime=TIME() + end +end + +local scene={} + +function scene.sceneInit() + state=0 + time1=STRING.time(0) + time2=STRING.time(0) +end + +function scene.mouseDown() + press() +end +function scene.mouseUp() + release() +end +function scene.keyDown(key,isRep) + if isRep then return end + if key=='escape'then + SCN.back() + else + press() + end +end +function scene.keyUp() + release() +end + +function scene.update() + if state~=0 then + time1=STRING.time(TIME()-pressTime) + if releaseTime then + time2=STRING.time(TIME()-releaseTime) + end + end +end + +function scene.draw() + FONT.set(60) + mStr(CHAR.icon.import,340,230) + mStr(CHAR.icon.export,940,230) + mStr(time1,340,300) + mStr(time2,940,300) +end + +scene.widgetList={ + WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=60,fText=CHAR.icon.back,code=backScene}, +} +return scene