
package com.annimon.jecp.demo.screens;

import com.annimon.jecp.InputListener;
import com.annimon.jecp.Jecp;
import com.annimon.jecp.JecpGraphics;
import com.annimon.jecp.Keys;

/**
 *
 * @author aNNiMON
 */
public abstract class Screen implements InputListener {
    
    public interface OnNextScreenListener {
        void onNextScreen();
    }
    
    protected final int width, height;
    private final int nextScreenButtonSize;
    private OnNextScreenListener nextScreenListener;

    public Screen(int width, int height) {
        this.width = width;
        this.height = height;
        nextScreenButtonSize = Math.min(width, height) / 20;
        Jecp.inputListener = Screen.this;
    }
    
    public void setOnNextScreenListener(OnNextScreenListener listener) {
        this.nextScreenListener = listener;
    }
    
    public void onPaint(JecpGraphics g) {
        // Clear screen
        g.setColor(0xFF000000);
        g.fillRect(0, 0, width, height);
        // Next screen button
        g.setColor(0xFFFF0000);
        g.fillRect(width - nextScreenButtonSize, height - nextScreenButtonSize,
                nextScreenButtonSize, nextScreenButtonSize);
        g.setColor(0xFFFFFFFF);
        g.drawLine(width - nextScreenButtonSize, height - nextScreenButtonSize / 2,
                width, height - nextScreenButtonSize / 2);
        g.drawLine(width - nextScreenButtonSize / 4, height - nextScreenButtonSize,
                width, height - nextScreenButtonSize / 2);
        g.drawLine(width - nextScreenButtonSize / 4, height,
                width, height - nextScreenButtonSize / 2);
    }
    
    public abstract void onUpdate();

    public void onKeyPressed(int key) {
        if (nextScreenListener != null) {
            if (key == Keys.KEY_POUND || key == Keys.VK_ENTER) {
                nextScreenListener.onNextScreen();
            }
        }
    }
    
    public void onPointerPressed(int x, int y) {
        if (nextScreenListener != null) {
            final int btnX = width - nextScreenButtonSize;
            final int btnY = height - nextScreenButtonSize;
            if ( (x > btnX) && (y > btnY) ) {
                nextScreenListener.onNextScreen();
            }
        }
    }

    public void onKeyReleased(int key) { }

    public void onPointerReleased(int x, int y) { }

    public void onPointerDragged(int x, int y) { }
    
    protected void sleep(long time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}

@@ -269,32 +269,103 @@
 stener %7B%0D%0A    %0D%0A
+    private static final String NEXT_SCREEN_BUTTON_TEXT = %22-%3E%22;%0D%0A    %0D%0A
     public inter
@@ -1293,60 +1293,30 @@
     
-g.setColor(0xFFFFFFFF);%0D%0A        g.drawLine(
+final int x = 
 width - 
 next
@@ -1303,32 +1303,33 @@
 int x = width - 
+(
 nextScreenButton
@@ -1336,44 +1336,56 @@
 Size
-, height - nextScreenButtonSize
+ + g.getTextWidth(NEXT_SCREEN_BUTTON_TEXT))
  / 2
-,
+;
 %0D%0A  
@@ -1386,38 +1386,37 @@
 2;%0D%0A        
-        width,
+final int y =
  height - ne
@@ -1405,32 +1405,33 @@
 nt y = height - 
+(
 nextScreenButton
@@ -1439,278 +1439,118 @@
 ize 
-/ 2);%0D%0A        g.drawLine(width - nextScreenButtonSize / 4, height - nextScreenButtonSize,%0D%0A                width, height - nextScreenButtonSize / 2);%0D%0A        g.drawLine(width - nextScreenButtonSize / 4, height,%0D%0A                width, height - nextScreenButtonSize / 2
++ g.getTextHeight()) / 2;%0D%0A        g.setColor(0xFFFFFFFF);%0D%0A        g.drawString(NEXT_SCREEN_BUTTON_TEXT, x, y
 );%0D%0A

Add drawString to demo