File source/entities/ornament.d added (mode: 100644) (index 0000000..653e37d) |
|
1 |
|
module dp.ent.ornament; |
|
2 |
|
|
|
3 |
|
import dp.ent.shape; |
|
4 |
|
import dp.ent.entity; |
|
5 |
|
|
|
6 |
|
class Ornament : Entity { |
|
7 |
|
Shape shape; |
|
8 |
|
string position; |
|
9 |
|
string value; |
|
10 |
|
|
|
11 |
|
this(Shape shape, string position, string value) { |
|
12 |
|
this.shape = shape; |
|
13 |
|
this.position = position; |
|
14 |
|
this.value = value; |
|
15 |
|
} |
|
16 |
|
|
|
17 |
|
@property |
|
18 |
|
public override string type() { |
|
19 |
|
return "ornament"; |
|
20 |
|
} |
|
21 |
|
|
|
22 |
|
@property |
|
23 |
|
public override string to_string() { |
|
24 |
|
return type ~ " " ~ position ~ " " ~ value; |
|
25 |
|
} |
|
26 |
|
|
|
27 |
|
public override void checkBounds(int x, int y) {} |
|
28 |
|
|
|
29 |
|
public override void render() { |
|
30 |
|
// render text. |
|
31 |
|
} |
|
32 |
|
|
|
33 |
|
private void calcBounds() { |
|
34 |
|
int[2] pos = shape.position; |
|
35 |
|
double[2][2] bounds = shape.calcBounds(pos[0], pos[1]); |
|
36 |
|
|
|
37 |
|
final switch(position) { |
|
38 |
|
case "Top": |
|
39 |
|
bounds[0][1] -= 30 + shape.size; |
|
40 |
|
bounds[1][1] -= 30 + shape.size; |
|
41 |
|
break; |
|
42 |
|
case "Bottom": |
|
43 |
|
bounds[0][1] += 30 + shape.size; |
|
44 |
|
bounds[1][1] += 30 + shape.size; |
|
45 |
|
break; |
|
46 |
|
case "Left": |
|
47 |
|
bounds[0][0] -= 30 + shape.size; |
|
48 |
|
bounds[0][1] -= 30 + shape.size; |
|
49 |
|
break; |
|
50 |
|
case "Right": |
|
51 |
|
bounds[0][0] += 30 + shape.size; |
|
52 |
|
bounds[0][1] += 30 + shape.size; |
|
53 |
|
break; |
|
54 |
|
} |
|
55 |
|
} |
|
56 |
|
} |
File source/entities/shape/decorator.d added (mode: 100644) (index 0000000..8c1b989) |
|
1 |
|
module dp.dec.shape; |
|
2 |
|
|
|
3 |
|
import dp.ent.shape; |
|
4 |
|
import dp.visitor.visitor; |
|
5 |
|
|
|
6 |
|
abstract class Decorator : Shape { |
|
7 |
|
protected Shape s; |
|
8 |
|
|
|
9 |
|
this(Shape shape) { |
|
10 |
|
super(0,0,null,null); // Superclass will not be used. |
|
11 |
|
s = shape; |
|
12 |
|
} |
|
13 |
|
|
|
14 |
|
@property |
|
15 |
|
public override string type() { |
|
16 |
|
return s.type; |
|
17 |
|
} |
|
18 |
|
|
|
19 |
|
@property |
|
20 |
|
public override string to_string() { |
|
21 |
|
return s.to_string; |
|
22 |
|
} |
|
23 |
|
|
|
24 |
|
@property |
|
25 |
|
public override int[2] position() { |
|
26 |
|
return s.position; |
|
27 |
|
} |
|
28 |
|
|
|
29 |
|
@property |
|
30 |
|
public override double sizeX() { |
|
31 |
|
return s.sizeX; |
|
32 |
|
} |
|
33 |
|
|
|
34 |
|
@property |
|
35 |
|
public override double sizeY() { |
|
36 |
|
return s.sizeY; |
|
37 |
|
} |
|
38 |
|
|
|
39 |
|
public override void accept(Visitor v) { |
|
40 |
|
s.accept(v); |
|
41 |
|
} |
|
42 |
|
|
|
43 |
|
public override void checkBounds(int x, int y) { |
|
44 |
|
s.checkBounds(x,y); |
|
45 |
|
} |
|
46 |
|
|
|
47 |
|
public override void render() { |
|
48 |
|
s.render(); |
|
49 |
|
} |
|
50 |
|
|
|
51 |
|
public override double[2][2] calcBounds(int x, int y) { |
|
52 |
|
return s.calcBounds(x,y); |
|
53 |
|
} |
|
54 |
|
} |
File source/entities/shape/shape.d renamed from source/entities/shape.d (similarity 66%) (mode: 100644) (index 1f3453a..40e5f21) |
... |
... |
class Shape : Entity { |
15 |
15 |
bounds[1][1] = maxY |
bounds[1][1] = maxY |
16 |
16 |
+/ |
+/ |
17 |
17 |
|
|
18 |
|
public Context c; |
|
19 |
|
public double[2][2] bounds; |
|
20 |
|
public double size; |
|
|
18 |
|
private Context c; // context |
|
19 |
|
private double[2][2] b; // bounds |
|
20 |
|
private double s; // size |
21 |
21 |
private Strategy strat; |
private Strategy strat; |
22 |
22 |
|
|
23 |
23 |
this(int x, int y, Context context, Strategy strategy, double size = 0) { |
this(int x, int y, Context context, Strategy strategy, double size = 0) { |
|
... |
... |
class Shape : Entity { |
25 |
25 |
active = true; |
active = true; |
26 |
26 |
this.strat = strategy; |
this.strat = strategy; |
27 |
27 |
this.size = size != 0 ? size : strat.initialSize; |
this.size = size != 0 ? size : strat.initialSize; |
28 |
|
this.bounds = calcBounds(x,y); |
|
|
28 |
|
bounds = [x,y]; |
29 |
29 |
} |
} |
30 |
30 |
|
|
31 |
31 |
@property |
@property |
|
... |
... |
class Shape : Entity { |
42 |
42 |
@property |
@property |
43 |
43 |
public int[2] position() { |
public int[2] position() { |
44 |
44 |
return [ |
return [ |
45 |
|
to!int(bounds[0][0] + sizeX), |
|
46 |
|
to!int(bounds[0][1] + sizeY) |
|
|
45 |
|
to!int(b[0][0] + sizeX), |
|
46 |
|
to!int(b[0][1] + sizeY) |
47 |
47 |
]; |
]; |
48 |
48 |
} |
} |
49 |
49 |
|
|
|
... |
... |
class Shape : Entity { |
84 |
84 |
c.fill(); |
c.fill(); |
85 |
85 |
} |
} |
86 |
86 |
} |
} |
|
87 |
|
// ----------------- NEW STUFF |
|
88 |
|
@property |
|
89 |
|
public Context context() { |
|
90 |
|
return c; |
|
91 |
|
} |
|
92 |
|
|
|
93 |
|
@property |
|
94 |
|
public Context context(Context c) { |
|
95 |
|
return this.c = c; |
|
96 |
|
} |
|
97 |
|
|
|
98 |
|
@property |
|
99 |
|
public double size() { |
|
100 |
|
return s; |
|
101 |
|
} |
|
102 |
|
|
|
103 |
|
@property |
|
104 |
|
public double size(double s) { |
|
105 |
|
return this.s = s; |
|
106 |
|
} |
|
107 |
|
|
|
108 |
|
@property |
|
109 |
|
public double[2][2] bounds() { |
|
110 |
|
return calcBounds(position[0], position[1]); |
|
111 |
|
} |
|
112 |
|
|
|
113 |
|
@property |
|
114 |
|
public double[2][2] bounds(double[2] pos) { |
|
115 |
|
double[2][2] result; |
|
116 |
|
|
|
117 |
|
result[0][0] = pos[0] - sizeX; // minX |
|
118 |
|
result[1][0] = pos[0] + sizeX; // maxX |
|
119 |
|
result[0][1] = pos[1] - sizeY; // minY |
|
120 |
|
result[1][1] = pos[1] + sizeY; // maxY |
|
121 |
|
|
|
122 |
|
return b = result; |
|
123 |
|
} |
87 |
124 |
|
|
88 |
125 |
public double[2][2] calcBounds(int x, int y) { |
public double[2][2] calcBounds(int x, int y) { |
89 |
126 |
double[2][2] result; |
double[2][2] result; |
File source/entities/shape/shapeornament.d added (mode: 100644) (index 0000000..08bdc94) |
|
1 |
|
module dp.dec.shapeornament; |
|
2 |
|
|
|
3 |
|
import dp.dec.shape; |
|
4 |
|
import dp.ent.shape; |
|
5 |
|
import dp.ent.ornament; |
|
6 |
|
|
|
7 |
|
class ShapeOrnament : Decorator { |
|
8 |
|
Ornament o; |
|
9 |
|
|
|
10 |
|
this(Shape shape) { |
|
11 |
|
super(shape); |
|
12 |
|
o = null; |
|
13 |
|
} |
|
14 |
|
|
|
15 |
|
@property |
|
16 |
|
public override string type() { |
|
17 |
|
string result = s.type; |
|
18 |
|
|
|
19 |
|
if(o !is null) |
|
20 |
|
result ~= "\n" ~ o.type; |
|
21 |
|
|
|
22 |
|
return result; |
|
23 |
|
} |
|
24 |
|
|
|
25 |
|
@property |
|
26 |
|
public override string to_string() { |
|
27 |
|
string result = s.to_string; |
|
28 |
|
|
|
29 |
|
if(o !is null) |
|
30 |
|
result ~= "\n" ~ o.to_string; |
|
31 |
|
|
|
32 |
|
return result; |
|
33 |
|
} |
|
34 |
|
|
|
35 |
|
public override void render() { |
|
36 |
|
s.render(); |
|
37 |
|
if(o !is null) |
|
38 |
|
o.render(); |
|
39 |
|
} |
|
40 |
|
/+ |
|
41 |
|
public override void move(int x, int y) { |
|
42 |
|
s.move(x,y); |
|
43 |
|
} |
|
44 |
|
|
|
45 |
|
public override void resize(int amount) { |
|
46 |
|
s.resize(amount); |
|
47 |
|
} |
|
48 |
|
+/ |
|
49 |
|
public void setOrnament(Ornament ornament) { |
|
50 |
|
o = ornament; |
|
51 |
|
} |
|
52 |
|
} |
File source/strategies/circle.d changed (mode: 100644) (index 69aa55f..2fd2435) |
... |
... |
private static class CircleDrawer : Strategy { |
35 |
35 |
} |
} |
36 |
36 |
|
|
37 |
37 |
public override void draw(Shape shape) { |
public override void draw(Shape shape) { |
38 |
|
shape.c.arc ( |
|
|
38 |
|
shape.context.arc ( |
39 |
39 |
shape.bounds[0][0] + shape.size, |
shape.bounds[0][0] + shape.size, |
40 |
40 |
shape.bounds[0][1] + shape.size, |
shape.bounds[0][1] + shape.size, |
41 |
41 |
shape.size, |
shape.size, |
File source/strategies/ellipse.d changed (mode: 100644) (index 1886a40..439bf38) |
... |
... |
private static class EllipseDrawer : Strategy { |
35 |
35 |
} |
} |
36 |
36 |
|
|
37 |
37 |
public override void draw(Shape shape) { |
public override void draw(Shape shape) { |
38 |
|
shape.c.scale(0.5, 1); |
|
|
38 |
|
shape.context.scale(0.5, 1); |
39 |
39 |
|
|
40 |
|
shape.c.arc ( |
|
|
40 |
|
shape.context.arc ( |
41 |
41 |
shape.bounds[0][0] * 2 + shape.size, |
shape.bounds[0][0] * 2 + shape.size, |
42 |
42 |
shape.bounds[0][1] + shape.size, |
shape.bounds[0][1] + shape.size, |
43 |
43 |
shape.size, |
shape.size, |
|
... |
... |
private static class EllipseDrawer : Strategy { |
45 |
45 |
2 * pi |
2 * pi |
46 |
46 |
); |
); |
47 |
47 |
|
|
48 |
|
shape.c.scale(2, 1); |
|
|
48 |
|
shape.context.scale(2, 1); |
49 |
49 |
} |
} |
50 |
50 |
} |
} |
File source/vistors/moveVisitor.d changed (mode: 100644) (index 79bc248..6bee3f1) |
... |
... |
public class MoveVisitor : Visitor { |
14 |
14 |
} |
} |
15 |
15 |
|
|
16 |
16 |
public override void visit(Shape s) { |
public override void visit(Shape s) { |
17 |
|
s.bounds = s.calcBounds( |
|
|
17 |
|
s.bounds = [ |
18 |
18 |
this.translation[0] + s.position[0], |
this.translation[0] + s.position[0], |
19 |
19 |
this.translation[1] + s.position[1] |
this.translation[1] + s.position[1] |
20 |
|
); |
|
|
20 |
|
]; |
21 |
21 |
} |
} |
22 |
22 |
|
|
23 |
23 |
public override void visit(Group g) { |
public override void visit(Group g) { |
File source/vistors/resizeVisitor.d changed (mode: 100644) (index 15dfe0c..27270f6) |
1 |
1 |
module dp.visitor.resize; |
module dp.visitor.resize; |
2 |
2 |
|
|
3 |
3 |
import dp.visitor.visitor; |
import dp.visitor.visitor; |
4 |
|
import std.conv; |
|
5 |
4 |
|
|
6 |
5 |
public class ResizeVisitor : Visitor { |
public class ResizeVisitor : Visitor { |
7 |
6 |
int amount; |
int amount; |
|
... |
... |
public class ResizeVisitor : Visitor { |
11 |
10 |
} |
} |
12 |
11 |
|
|
13 |
12 |
public override void visit(Shape s) { |
public override void visit(Shape s) { |
14 |
|
int[2] newPos; |
|
|
13 |
|
double[2] newPos; |
15 |
14 |
|
|
16 |
15 |
/+ |
/+ |
17 |
16 |
'size' can become negative number due to 'amount' being a |
'size' can become negative number due to 'amount' being a |
|
... |
... |
public class ResizeVisitor : Visitor { |
25 |
24 |
return; |
return; |
26 |
25 |
|
|
27 |
26 |
newPos = [ |
newPos = [ |
28 |
|
to!int(s.bounds[0][0] + s.sizeX), |
|
29 |
|
to!int(s.bounds[0][1] + s.sizeY) |
|
|
27 |
|
s.bounds[0][0] + s.sizeX, |
|
28 |
|
s.bounds[0][1] + s.sizeY |
30 |
29 |
]; |
]; |
31 |
30 |
|
|
32 |
|
s.size += amount; |
|
33 |
|
s.bounds = s.calcBounds(newPos[0], newPos[1]); |
|
|
31 |
|
s.size = s.size + amount; |
|
32 |
|
s.bounds = newPos; |
34 |
33 |
} |
} |
35 |
34 |
|
|
36 |
35 |
public override void visit(Group g) { |
public override void visit(Group g) { |