package pl.shockah.ts;

import pl.shockah.glib.geom.Rectangle;
import pl.shockah.glib.gl.Graphics;
import pl.shockah.glib.gl.tex.Atlas;
import pl.shockah.glib.gl.tex.Image;

public final class AtlasHelper {
	public static void renderFrame(Graphics g, Rectangle rect, Atlas a) {
		renderFrame(g,rect,a.getImage("topleft"),a.getImage("topright"),a.getImage("bottomleft"),a.getImage("bottomright"),a.getImage("top"),a.getImage("bottom"),a.getImage("left"),a.getImage("right"),a.getImage("center"));
	}
	public static void renderFrame(Graphics g, Rectangle rect, Image tl, Image tr, Image bl, Image br, Image t, Image b, Image l, Image r, Image c) {
		tl.scale.set(1,1); g.draw(tl,rect.pos.x,rect.pos.y);
		tr.scale.set(1,1); g.draw(tr,rect.pos.x+rect.size.x-tr.getWidth(),rect.pos.y);
		bl.scale.set(1,1); g.draw(bl,rect.pos.x,rect.pos.y+rect.size.y-bl.getHeight());
		br.scale.set(1,1); g.draw(br,rect.pos.x+rect.size.x-br.getWidth(),rect.pos.y+rect.size.y-br.getHeight());
		
		t.scale.set(1d/t.getWidth()*(rect.size.x-tr.getWidth()-tl.getWidth()),1); g.draw(t,rect.pos.x+tl.getWidth(),rect.pos.y);
		b.scale.set(1d/b.getWidth()*(rect.size.x-br.getWidth()-bl.getWidth()),1); g.draw(b,rect.pos.x+bl.getWidth(),rect.pos.y+rect.size.y-b.getHeight());
		l.scale.set(1,1d/l.getHeight()*(rect.size.y-tl.getHeight()-bl.getHeight())); g.draw(l,rect.pos.x,rect.pos.y+tl.getHeight());
		r.scale.set(1,1d/r.getHeight()*(rect.size.y-tr.getHeight()-br.getHeight())); g.draw(r,rect.pos.x+rect.size.x-r.getWidth(),rect.pos.y+tr.getHeight());
		c.scale.set(1d/c.getWidth()*(rect.size.x-tr.getWidth()-tl.getWidth()),1d/c.getHeight()*(rect.size.y-tl.getHeight()-bl.getHeight())); g.draw(c,rect.pos.x+tl.getWidth(),rect.pos.y+tl.getHeight());
	}
}