-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShapeGraphics.java
133 lines (114 loc) · 3.42 KB
/
ShapeGraphics.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package ch.epfl.cs107.play.game.actor;
import ch.epfl.cs107.play.math.Attachable;
import ch.epfl.cs107.play.math.Node;
import ch.epfl.cs107.play.math.Shape;
import ch.epfl.cs107.play.window.Canvas;
import java.awt.Color;
/**
* Contains information to render a single shape, which can be attached to any positionable.
*/
public class ShapeGraphics extends Node implements Graphics {
private Shape shape;
private Color fillColor;
private Color outlineColor;
private float thickness;
private float alpha;
private float depth;
/**
* Creates a new shape graphics.
* @param shape shape, may be null
* @param fillColor fill color, may be null
* @param outlineColor outline color, may be null
* @param thickness outline thickness
* @param alpha transparency, between 0 (invisible) and 1 (opaque)
* @param depth render priority, lower-values drawn first
*/
public ShapeGraphics(Shape shape, Color fillColor, Color outlineColor, float thickness, float alpha, float depth) {
this.shape = shape;
this.fillColor = fillColor;
this.outlineColor = outlineColor;
this.thickness = thickness;
this.alpha = alpha;
this.depth = depth;
}
/**
* Creates a new shape graphics.
* @param shape shape, may be null
* @param fillColor fill color, may be null
* @param outlineColor outline color, may be null
* @param thickness outline thickness
*/
public ShapeGraphics(Shape shape, Color fillColor, Color outlineColor, float thickness) {
this(shape, fillColor, outlineColor, thickness, 1.0f, 0.0f);
}
/**
* Sets shape.
* @param shape new shape, may be null
*/
public void setShape(Shape shape) {
this.shape = shape;
}
/** @return current shape, may be null */
public Shape getShape() {
return shape;
}
/**
* Sets fill color.
* @param fillColor color, may be null
*/
public void setFillColor(Color fillColor) {
this.fillColor = fillColor;
}
/** @return fill color, may be null */
public Color getFillColor() {
return fillColor;
}
/**
* Sets outline color.
* @param outlineColor color, may be null
*/
public void setOutlineColor(Color outlineColor) {
this.outlineColor = outlineColor;
}
/** @return outline color, may be null */
public Color getOutlineColor() {
return outlineColor;
}
/**
* Sets outline thickness.
* @param thickness outline thickness
*/
public void setThickness(float thickness) {
this.thickness = thickness;
}
/** @return outline thickness */
public float getThickness() {
return thickness;
}
/**
* Sets transparency.
* @param alpha transparency, between 0 (invisible) and 1 (opaque)
*/
public void setAlpha(float alpha) {
this.alpha = alpha;
}
/** @return transparency, between 0 (invisible) and 1 (opaque) */
public float getAlpha() {
return alpha;
}
/**
* Sets rendering depth.
* @param depth render priority, lower-values drawn first
*/
public void setDepth(float depth) {
this.depth = depth;
}
/** @return render priority, lower-values drawn first */
public float getDepth() {
return depth;
}
@Override
public void draw(Canvas canvas) {
canvas.drawShape(shape, getTransform(), fillColor, outlineColor, thickness, alpha, depth);
}
}