package authoring_environment.ObjectGUI.centerPane;

import java.util.ResourceBundle;

import authoring_environment.ObjectGUI.ObjectController;
import javafx.scene.Group;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class ObjectCenterPane {

	private ResourceBundle r = ResourceBundle.getBundle("authoring_environment/ObjectGUI/centerPane/CenterPaneResources");
	private ObjectController myController;
	private	Image sprite;
	private ImageView spriteview;
	private double xPos, yPos,spriteWidth ,spriteHeight;

	public Group init(ObjectController controller) {
		myController = controller;
		Group root = new Group();
		Canvas c = new Canvas(Integer.parseInt(r.getString("canvasWidth")), Integer.parseInt(r.getString("canvasHeight")));
		GraphicsContext gc = c.getGraphicsContext2D();
		double a= Double.parseDouble(r.getString("defaultSize"));
		try {
			sprite = addSprite(myController.getCurrentSprite().getName());

		}
		catch (NullPointerException e) {
			sprite = addSprite("Mario.png");
		}
		spriteview = new ImageView(sprite);
		spriteview.setFitWidth(a);
		spriteview.setPreserveRatio(true);
		spriteWidth = spriteview.getBoundsInParent().getWidth()/spriteview.getImage().getWidth();;
		spriteHeight =  spriteview.getBoundsInParent().getHeight()/spriteview.getImage().getHeight();
		xPos = Integer.parseInt(r.getString("canvasWidth"))/2 - myController.getSize()[0]/2*spriteWidth;
		yPos = Integer.parseInt(r.getString("canvasHeight"))/2 - myController.getSize()[1]/2*spriteHeight;
		gc.drawImage(sprite, xPos, yPos, myController.getSize()[0]*spriteWidth, myController.getSize()[1]*spriteHeight);
		Button b = new Button(r.getString("buttonText"));
		b.setOnAction(e ->  {
			gc.clearRect(0, 0, Integer.parseInt(r.getString("canvasWidth")), Integer.parseInt(r.getString("canvasHeight")));
			if (myController.getVisibile()) {
				xPos = Integer.parseInt(r.getString("canvasWidth"))/2 - myController.getSize()[0]/2*spriteWidth;
				yPos = Integer.parseInt(r.getString("canvasHeight"))/2 - myController.getSize()[1]/2*spriteHeight;
				gc.drawImage(sprite, xPos, yPos, myController.getSize()[0]*spriteWidth, myController.getSize()[1]*spriteHeight);
			}
		});
		root.getChildren().addAll(c, b);
		return root;
	}


	private Image addSprite(String s) {
		return new Image(getClass().getClassLoader().getResourceAsStream(s), myController.getSize()[0], myController.getSize()[1], false, false);
	}
}

@@ -316,45 +316,8 @@
 ge;%0A
-import javafx.scene.image.ImageView;%0A
 impo
@@ -345,16 +345,16 @@
 .Color;%0A
+
 import j
@@ -603,39 +603,8 @@
 te;%0A
-%09private ImageView spriteview;%0A
 %09pri
@@ -637,17 +637,16 @@
 iteWidth
- 
 ,spriteH
@@ -931,68 +931,8 @@
 ();%0A
-%09%09double a= Double.parseDouble(r.getString(%22defaultSize%22));%0A
 %09%09tr
@@ -1001,17 +1001,16 @@
 ame());%0A
-%0A
 %09%09%7D%0A%09%09ca
@@ -1084,112 +1084,8 @@
 %09%09%7D%0A
-%09%09spriteview = new ImageView(sprite);%0A%09%09spriteview.setFitWidth(a);%0A%09%09spriteview.setPreserveRatio(true);%0A
 %09%09sp
@@ -1099,84 +1099,25 @@
 th =
- 
 sprite
-view.getBoundsInParent().getWidth()/spriteview.getImage().getWidth();
+.getWidth()
 ;%0A%09%09
@@ -1134,74 +1134,14 @@
 ht =
-  
 sprite
-view.getBoundsInParent().getHeight()/spriteview.getImage()
 .get
@@ -2118,16 +2118,16 @@
 ng s) %7B%0A
+
 %09%09return
@@ -2191,76 +2191,8 @@
 m(s)
-, myController.getSize()%5B0%5D, myController.getSize()%5B1%5D, false, false
 );%0A%09

fix the fking ratios for centerpane