public void update(double dt) { // Select when clicked if (isHovered()) { if (Input.isMousePressed()) { select(); } } if (Input.isPressed(KeyEvent.VK_PASTE) && isSelected()) { paste(); } // Determine color based on selected or not int regular = 180; if (isSelected()) setColor(Color.white); else setColor(new Color(regular, regular, regular)); }
/** * Set this field to be the selected field. Will intercept all user keystrokes until deselected. */ public void select() { selectedField = this; Input.interceptTextInput( new Observer() { public void notify(Object arg) { Character c = (Character) arg; addChar(c); } }); }
/** Unselect this field. Keystrokes will be normal again */ public void deselect() { selectedField = null; Input.releaseInterceptTextInput(); }