package xunome.graphics;
/**
*
* @author Sem iNick
*/
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import xunome.game.Card;
import xunome.game.Table;
public class GraphicTable {
private Table table;
private Image iTable;
private int screenWidth;
private int screenHeight;
private final int WIDTH; //Width for table image
private final int HEIGHT; //Height for table image
private final int HX; //Cord x for horizontal card
private final int HY; //Cord y for horizontal card
private final int VX; //Cord x for vertical card
private final int VY; //Cord y for vertical card
private final int CX; //Cord x for atual color
private final int CY; //Cord y for atual color
private final static Image BACK_CARD = GraphicCard.createGraphicCard(
new Card(Card.BACK)).getRender();
public GraphicTable(Table t, int width, int height) {
table = t;
screenWidth = width;
screenHeight = height;
if ((screenWidth < 220) && (screenHeight < 300)) {
WIDTH = 105;
HEIGHT = 50;
HX = 60;
HY = 10;
VX = 70;
VY = 0;
CX = 35;
CY = 0;
} else {
WIDTH = 80;
HEIGHT = 106;
HX = 35;
HY = 70;
VX = 45;
VY = 60;
CY = 0;
CX = 60;
}
}
public void repaint() {
//Create base image for table
iTable = Image.createImage(WIDTH, HEIGHT);
Graphics gTable = iTable.getGraphics();
//Fill background with black
gTable.fillRect(0, 0, WIDTH, HEIGHT);
if ((screenWidth >= 220) && (screenHeight >= 300)) {
//Draw deck
gTable.drawRegion(BACK_CARD, 0, 0, BACK_CARD.getWidth(),
BACK_CARD.getHeight(), Sprite.TRANS_ROT270, 0, 0,
Graphics.TOP|Graphics.LEFT);
}
//Draw discarded
Vector discarded = table.getDiscarded();
if(discarded.size() > 1) {
int len = discarded.size();
if(len % 2 == 0) {
Image toDraw = ((Card) discarded.elementAt(len-2)).getGraphic().getRender();
gTable.drawRegion(toDraw, 0, 0, toDraw.getWidth(), toDraw.getHeight(),
Sprite.TRANS_ROT270, HX, HY, Graphics.TOP|Graphics.LEFT);
gTable.drawImage(((Card) discarded.elementAt(len-1))
.getGraphic().getRender(), VX, VY,
Graphics.TOP|Graphics.LEFT);
} else {
gTable.drawImage(
((Card) discarded.elementAt(len-2))
.getGraphic().getRender(), VX, VY,
Graphics.TOP|Graphics.LEFT);
Image toDraw = ((Card)discarded.elementAt(len-1)).getGraphic().getRender();
gTable.drawRegion(toDraw, 0, 0, toDraw.getWidth(), toDraw.getHeight(),
Sprite.TRANS_ROT270, HX, HY, Graphics.TOP|Graphics.LEFT);
}
} else {
gTable.drawImage(
((Card)discarded.elementAt(0))
.getGraphic().getRender(), VX, VY,
Graphics.TOP|Graphics.LEFT);
}
}
public Image getRendered() {
return iTable;
}
public void drawAtualColor(int rgb) {
Graphics g = iTable.getGraphics();
g.setColor(rgb);
g.fillRoundRect(CX, CY, 20, 20, 5, 5);
g.setColor(0);
}
}