-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile.java
68 lines (59 loc) · 1.76 KB
/
Tile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import com.sun.javafx.sg.prism.NGImageView;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import com.sun.javafx.sg.prism.NGNode;
import com.sun.prism.Graphics;
import com.sun.prism.Texture;
import com.sun.prism.impl.BaseResourceFactory;
/**
* Created by Mushra on 2017-09-10.
*/
public class Tile extends ImageView {
private Tile liten;
private int ofs_x;
private int ofs_y;
private int width;
private int height;
public Tile(Image image, int offset_x, int offset_y, int width, int height) {
super(image);
this.width = width;
this.height = height;
this.ofs_x = offset_x;
this.ofs_y = offset_y;
Rectangle2D crop = new Rectangle2D(offset_x, offset_y, width, height);
this.setViewport(crop);
this.setFitHeight(6*3);
this.setFitWidth(6*3);
}
public Tile(Tile copyme, int scale) {
super(copyme.getImage());
Rectangle2D crop = new Rectangle2D(copyme.ofs_x, copyme.ofs_y, 6, 6);
this.ofs_x = copyme.ofs_x;
this.ofs_y = copyme.ofs_y;
this.setViewport(crop);
this.setFitHeight(6*scale);
this.setFitWidth(6*scale);
}
public Tile getSmall() {
return new Tile(this,1);
}
// stack overflow-hack, thanks Martin Sojka
// this removes smoothing.
@Override protected NGNode impl_createPeer() {
return new NGImageView() {
private com.sun.prism.Image image;
@Override public void setImage(Object img) {
super.setImage(img);
image = (com.sun.prism.Image) img;
}
@Override protected void renderContent(Graphics g) {
BaseResourceFactory factory = (BaseResourceFactory) g.getResourceFactory();
Texture tex = factory.getCachedTexture(image, Texture.WrapMode.CLAMP_TO_EDGE);
tex.setLinearFiltering(false);
tex.unlock();
super.renderContent(g);
}
};
}
}