package com.lucasdnd.ags.ui;
import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.state.StateBasedGame;
import com.lucasdnd.ags.map.OffsetUtil;
import com.lucasdnd.ags.ui.components.Clickable;
/**
* A Window.
* @author tulio
*
*/
public abstract class Panel extends UIComponent implements Clickable {
protected String title; // The Title of the window
protected Rectangle titleBar; // The Title Bar
protected Color backgroundColor;
protected Color titleBackgroundColor;
protected Rectangle window; // The Window Rectangle
protected Rectangle dropShadow; // The shadow
public static final float LINE_Y_OFFSET = 27f; // The distance from the top of the Panel (yPos) to the point where the titleBarLine is rendered
/**
* Basic Constructor
* @param title
* @param xPos
* @param yPos
* @param width
* @param height
* @throws SlickException
*/
public Panel(String title, float xPos, float yPos, float width, float height) throws SlickException {
// Basic Attributes
this.title = title;
this.xPos = xPos;
this.yPos = yPos;
this.width = width;
this.height = height;
// As default, it is not visible when it's first created
this.visible = false;
// Creates the Rectangle forms
window = new Rectangle(xPos, yPos, width, height);
dropShadow = new Rectangle(xPos + 4f, yPos + 4f, width, height);
titleBar = new Rectangle(xPos, yPos, width, LINE_Y_OFFSET + 6f);
backgroundColor = new Color(255f, 255f, 255f, 1f);
}
protected Panel(String title, float xPos, float yPos, float width, float height, float titleBarHeight) throws SlickException {
// Basic Attributes
this.title = title;
this.xPos = xPos;
this.yPos = yPos;
this.width = width;
this.height = height;
// As default, it is not visible when it's first created
this.visible = false;
// Creates the Rectangle forms
window = new Rectangle(xPos, yPos, width, height);
dropShadow = new Rectangle(xPos + 4f, yPos + 4f, width, height);
titleBar = new Rectangle(xPos, yPos, width, titleBarHeight);
backgroundColor = new Color(255f, 255f, 255f, 1f);
}
/**
* Render
* @param container
* @param game
* @param g
* @throws SlickException
*/
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {
// Only renders the Panel if it's visible
if(visible) {
Color previousColor = g.getColor();
// Renders the geometry
g.setColor(Color.gray);
g.draw(dropShadow);
g.setColor(Color.black);
g.draw(window);
g.draw(titleBar);
// Fills the Panel with a solid color
g.setColor(backgroundColor);
g.fill(window);
g.setColor(titleBackgroundColor);
g.fill(titleBar);
g.setColor(previousColor);
// Renders the Title of the Panel
shadowFont.drawString(OffsetUtil.getPreciseOffset(xPos) + 5f + 1f, OffsetUtil.getPreciseOffset(yPos) + 4f + 1f, title);
panelFont.drawString(OffsetUtil.getPreciseOffset(xPos) + 5f, OffsetUtil.getPreciseOffset(yPos) + 4f, title);
}
}
public Rectangle getWindow() {
return window;
}
public void setWindow(Rectangle window) {
this.window = window;
}
public Color getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}