package View.MainFrame;

import javax.swing.JPanel;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Dimension;

public class MyLayeredKeyboardPanel extends JPanel {

    //Had a problem with printing multiple keys on screen.
    //Because if new key is pressed, old information about other pressed key is lost.
    //Because of that I use an array which contains information about all keys if they are pressed or not.
    //Unfortunately the keyevent interface only detects maximum two pressed keys.
    //Don't know yet if it counts for all key-listening.
    
    //[0] == If 0 image is not painted, if 1 image is painted
    //[1] == x-Coordinate for image
    //[2] == y-Coordinate for image
    private int[][] aiiImages = new int[62][3];
    
    private int iTheme = 0;

    public MyLayeredKeyboardPanel() {
        this.setPreferredSize(new Dimension(1000, 500));
        initImagePositions();
    }

    @Override
    public void paint(Graphics g) {
        Graphics2D g2D = (Graphics2D) g;

        for (int i = 0; i < aiiImages.length; i++) {
            if (aiiImages[i][0] == 1) {
                g2D.drawImage(MyImages.getImage(i), aiiImages[i][1], aiiImages[i][2], null);
            }
        }        
    }

    public void setImage(int iSet, int iIndex) {
        aiiImages[iIndex][0] = iSet;
    }

    public void setTheme(int i) {
        iTheme = i;
    }

    private void initImagePositions() {
        //Background
        aiiImages[0][0] = 1;
        aiiImages[0][1] = aiiImages[0][2] = 0;

        //` / ~ Key
        aiiImages[1][1] = 83;
        aiiImages[1][2] = 0;

        //1 / ! Key
        aiiImages[2][1] = 143;
        aiiImages[2][2] = 0;

        //2 / @ Key
        aiiImages[3][1] = 197;
        aiiImages[3][2] = 0;

        //Tab Key
        aiiImages[14][1] = 68;
        aiiImages[14][2] = 43;

        //Q Key
        aiiImages[15][1] = 156;
        aiiImages[15][2] = 45;

        //Shift Key
        aiiImages[41][1] = 46;
        aiiImages[41][2] = 150;
    }
}