From 006c4e6960e726daabfa3976023157ee9ec24836 Mon Sep 17 00:00:00 2001 From: Dimitri Gigot Date: Wed, 8 Apr 2020 16:42:47 +0000 Subject: [PATCH] Improve the perf --- apps.json | 2 +- apps/toucher/ChangeLog | 3 ++- apps/toucher/app.js | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps.json b/apps.json index e250da0f6..02c6364aa 100644 --- a/apps.json +++ b/apps.json @@ -1035,7 +1035,7 @@ "name": "Touch Launcher", "shortName":"Menu", "icon": "app.png", - "version":"0.04", + "version":"0.05", "description": "Touch enable left to right launcher.", "tags": "tool,system,launcher", "type":"launch", diff --git a/apps/toucher/ChangeLog b/apps/toucher/ChangeLog index c536d1a5b..a2a709ee3 100644 --- a/apps/toucher/ChangeLog +++ b/apps/toucher/ChangeLog @@ -1,4 +1,5 @@ 0.01: New App! 0.02: Add swipe support and doucle tap to run application 0.03: Close launcher when lcd turn off -0.04: Complete rewrite to add animation and loop ( issue #210 ) \ No newline at end of file +0.04: Complete rewrite to add animation and loop ( issue #210 ) +0.05: Improve perf \ No newline at end of file diff --git a/apps/toucher/app.js b/apps/toucher/app.js index 5c3703129..b67e5b26c 100644 --- a/apps/toucher/app.js +++ b/apps/toucher/app.js @@ -19,7 +19,7 @@ function getApps(){ const HEIGHT = g.getHeight(); const WIDTH = g.getWidth(); const HALF = WIDTH/2; -const ANIMATION_FRAME = 3; +const ANIMATION_FRAME = 4; const ANIMATION_STEP = HALF / ANIMATION_FRAME; function getPosition(index){ @@ -35,6 +35,8 @@ const back = { back: true }; +let icons = {}; + const apps = [back].concat(getApps()); apps.push(back); @@ -54,6 +56,12 @@ function drawIcons(offset){ const y = HALF - (HALF*0.3);//-(HALF*0.7); let diff = (x - HALF); if(diff < 0) diff *=-1; + + const dontRender = x+(HALF/2)<0 || x-(HALF/2)>120; + if(dontRender) { + delete icons[app.name]; + return; + } let size = 30; if((diff*0.5) < size) size -= (diff*0.5); else size = 0; @@ -72,8 +80,12 @@ function drawIcons(offset){ return; } // icon - const icon = app.icon ? Storage.read(app.icon) : null; + + const icon = app.icon ? + icons[app.name] ? icons[app.name] : Storage.read(app.icon) + : null; if(icon){ + icons[app.name] = icon; try { g.drawImage(icon, x-(scale*24), y-(scale*24), { scale: scale }); } catch(e){ @@ -100,7 +112,8 @@ function drawIcons(offset){ } function draw(ignoreLoop){ - g.clear(); + g.setColor(0,0,0); + g.fillRect(0,0,WIDTH,HEIGHT); drawIcons(slideOffset); g.flip(); if(slideOffset == target) return;