package window;
import mishin870.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

public class window {
Sprite min,max,clo;
public windowTheme theme;
public int x,y;
public int wid,hei;
public String name;
public boolean maximized=false;
int sx,sy,sw,sh;
public int id;
public boolean visible=true;

public window(int id){
this.id = id;
setPosition(0,0);
}

public void setPosition(int x,int y){
this.x = x;
this.y = y;
}

public void init(windowTheme theme,String name,int wid,int hei){
this.theme = theme;
this.wid = wid;
this.hei = hei;
this.name = name;
theme.resize(wid,hei);
min = new Sprite(theme.min,theme.miw,theme.mih);
max = new Sprite(theme.max,theme.maw,theme.mah);
clo = new Sprite(theme.clo,theme.cw,theme.ch);
min.setFrame(0);
max.setFrame(0);
clo.setFrame(0);
theme.updateControlPos(x,y,wid,hei,min,max,clo);
afterInit(wid,hei);
}

public void setTheme(windowTheme theme){
Image img = this.theme.ico;
this.theme = theme;
theme.resize(wid,hei);
min = new Sprite(theme.min,theme.miw,theme.mih);
max = new Sprite(theme.max,theme.maw,theme.mah);
clo = new Sprite(theme.clo,theme.cw,theme.ch);
min.setFrame(0);
max.setFrame(0);
clo.setFrame(0);
theme.updateControlPos(x,y,wid,hei,min,max,clo);
onResize(wid,hei);
theme.ico = img;
updateControlsTheme();
}

public void updateControlsTheme(){
}

public void resize(int wid,int hei){
theme.resize(wid,hei);
this.wid = wid;
this.hei = hei;
onResize(wid,hei);
}

public void resize2(int wid,int hei){
if(maximized){
	maximize(1,1);
}
theme.resize(wid,hei);
this.wid = wid;
this.hei = hei;
onResize(wid,hei);
}

public void onResize(int wid,int hei){
}

public void afterInit(int wid,int hei){
}

public void afterPaint(Graphics g){
}

public void formMouse(int x,int y,boolean md){
}

public int getClick(int x,int y){
return theme.getClick(x,y,wid,hei);
}

public void minSet(boolean down){
theme.minSet(min,down);
}

public void maxSet(boolean down){
theme.maxSet(max,down);
}

public void maximize(int wid,int hei){
maximized=!maximized;
if(maximized){
	sx = x;
	sy = y;
	sw = this.wid;
	sh = this.hei;
	abcd temp = theme.getXYWHMax(wid,hei);
	x = temp.a;
	y = temp.b;
	resize(temp.c,temp.d);
} else {
	x = sx;
	y = sy;
	resize(sw,sh);
}
theme.maximize(max,maximized);
}

public void cloSet(boolean down){
theme.cloSet(clo,down);
}

public void paint(Graphics g){
if(visible){
	theme.updateControlPos(x,y,wid,hei,min,max,clo);
	theme.drawBorder(g,x,y,wid,hei);
	theme.drawName(g,name,x,y,wid);
	theme.drawIcon(g,x,y,wid);
	min.paint(g);
	max.paint(g);
	clo.paint(g);
	afterPaint(g);
}
}

}