Package com.drakulo.games.ais.ui.component.window

Source Code of com.drakulo.games.ais.ui.component.window.CenteredWindow

package com.drakulo.games.ais.ui.component.window;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import com.drakulo.games.ais.core.Settings;
import com.drakulo.games.ais.ui.I18n;
import com.drakulo.games.ais.ui.UIHelper;
import com.drakulo.games.ais.ui.component.ActionHandler;
import com.drakulo.games.ais.ui.component.UIComponent;
import com.drakulo.games.ais.ui.component.button.Button;
import com.drakulo.games.ais.ui.component.button.TextButton;

/**
* Renders a simple centered window
*
* @author Drakulo
*
*/
public abstract class CenteredWindow extends UIComponent {
  /** The window Title */
  protected String title;
  /** Close button */
  private TextButton closeButton;

  protected CenteredWindow(int width, int height) {
    setSize(width, height);
    final int buttonX = this.getOX() + this.width / 2
        - Button.DEFAULT_WIDTH / 2;
    final int buttonY = this.getOY() + this.height - Button.DEFAULT_HEIGHT
        - 5;
    this.closeButton = new TextButton(I18n.get("global.close"), buttonX, buttonY);
    this.closeButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        hide();
      }
    });
  }

  @Override
  public void render(Graphics g) throws SlickException {
    // Rendering of the background
    UIHelper.drawBox(g, this.ox, this.oy, this.width, this.height);

    // Render the close button
    this.closeButton.render(g);
  }

  @Override
  public void update(Input input) throws SlickException {
    this.closeButton.update(input);
  }

  protected void setSize(int width, int height) {
    this.width = width;
    this.height = height;
    this.ox = Settings.WIDTH / 2 - width / 2;
    this.oy = Settings.HEIGHT / 2 - height / 2;
  }

}
TOP

Related Classes of com.drakulo.games.ais.ui.component.window.CenteredWindow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.