Canvas Layer Created
- Canvas is created via layering. - Resizable canvas is now a seperate abstract class #story[782]
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 4/05/17.
|
||||
*/
|
||||
public abstract class ResizableCanvas extends Canvas {
|
||||
protected GraphicsContext gc;
|
||||
|
||||
public ResizableCanvas(){
|
||||
this.gc = this.getGraphicsContext2D();
|
||||
// Redraw canvas when size changes.
|
||||
widthProperty().addListener(evt -> draw());
|
||||
heightProperty().addListener(evt -> draw());
|
||||
|
||||
}
|
||||
|
||||
abstract void draw();
|
||||
|
||||
|
||||
/**
|
||||
* Set the Canvas to resizable.
|
||||
*
|
||||
* @return That the Canvas is resizable.
|
||||
*/
|
||||
@Override
|
||||
public boolean isResizable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preferred width of the Canvas
|
||||
*
|
||||
* @param width of canvas
|
||||
* @return Returns the width of the Canvas
|
||||
*/
|
||||
@Override
|
||||
public double prefWidth(double width) {
|
||||
return getWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preferred height of the Canvas
|
||||
*
|
||||
* @param height of canvas
|
||||
* @return Returns the height of the Canvas
|
||||
*/
|
||||
@Override
|
||||
public double prefHeight(double height) {
|
||||
return getHeight();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user