
package com.annimon.jecp.demo.screens;

import com.annimon.jecp.Fps;
import com.annimon.jecp.JecpGraphics;
import com.annimon.jecp.JecpRandom;
import com.annimon.jecp.Keys;
import com.annimon.jecp.demo.DynamicLine;

/**
 * Lines animation and FPS-class methods demo.
 * @author aNNiMON
 */
public class LinesScreen extends Screen {
    
    private static final int LINES_COUNT = 5;
    
    private boolean fpsLimiter;
    private long fpsLimiterDelay;
    
    private final DynamicLine[] lines;

    public LinesScreen(int width, int height) {
        super(width, height);
        fpsLimiter = false;
        fpsLimiterDelay = 5;
        lines = new DynamicLine[LINES_COUNT];
        for (int i = 0; i < LINES_COUNT; i++) {
            lines[i] = new DynamicLine(
                    JecpRandom.rand(width), JecpRandom.rand(height),
                    JecpRandom.rand(width), JecpRandom.rand(height));
        }
    }
    
    public void onPaint(JecpGraphics g) {
        Fps.startMeasuringDelay();
        super.onPaint(g);
        for (int i = 0; i < LINES_COUNT; i++) {
            lines[i].onPaint(g);
        }
        g.setColor(0xFFFFFFFF);
        g.drawString("Fps limiter is " + (fpsLimiter ? "on" : "off") + ". Press any key to change state.", 0, 0);
        g.drawString("Fps: " + Fps.getFps(), 0, g.getTextHeight());
        
        if (fpsLimiter) fpsLimiterDelay = Fps.getDelay();
        else fpsLimiterDelay = 2;
    }

    public void onUpdate() {
        for (int i = 0; i < lines.length; i++) {
            lines[i].onUpdate(width, height);
        }
        sleep(fpsLimiterDelay);
    }

    public void onKeyPressed(int key) {
        fpsLimiter = !fpsLimiter;
        super.onKeyPressed(key);
    }
}

@@ -147,39 +147,8 @@
 m;%0D%0A
-import com.annimon.jecp.Keys;%0D%0A
 impo
@@ -215,12 +215,9 @@
 tion
- and
+,
  FPS
@@ -231,16 +231,30 @@
 methods 
+and key codes 
 demo.%0D%0A 
@@ -447,16 +447,42 @@
 Delay;%0D%0A
+    private int keyCode;%0D%0A
     %0D%0A  
@@ -656,24 +656,46 @@
 Delay = 5;%0D%0A
+        keyCode = 0;%0D%0A
         line
@@ -1397,24 +1397,92 @@
 Height());%0D%0A
+        g.drawString(%22Key: %22 + keyCode, 0, 2 * g.getTextHeight());%0D%0A
         %0D%0A  
@@ -1799,24 +1799,48 @@
 int key) %7B%0D%0A
+        keyCode = key;%0D%0A
         fpsL

Add key codes demo to Lines screen