kapstok / NHL-DePa2 (public) (License: Unspecified) (since 2018-11-09) (hash sha1)
Design Patterns school project; a GUI using multiple Design Patterns.
List of commits:
Subject Hash Author Date (UTC)
Setup for decorator pattern. 762914dec31b1fb1d4cf6bb0cef2e148010652a4 Jan Allersma 2018-11-01 14:12:51
Revert commit '5678eb6'. 6225242719b2cfc5ee0de9f8d05edbc7a69007a7 Jan Allersma 2018-11-01 14:10:27
Make groups movable and resizable. 1ca7c18ab103a8d1055b27f63192038fd75aef3e Jan Allersma 2018-10-17 14:51:32
Use translations instead of positions for moving shapes. 9551c7d2608f01c3950743fd97bd217aab8f5766 Jan Allersma 2018-10-16 16:11:03
Implement Visitor pattern for Groups. bd30477ce616362d3f58cef072d1ebc78077fa85 Jan Allersma 2018-10-16 13:28:37
Implement Visitor pattern for Shapes. e52412c3059c1ee5fa9abdf4a32db0f47981eee1 Jan Allersma 2018-10-16 12:43:17
Setup 'Decorator' and 'Ornament' class. 5678eb6257bcf88502078d08395a394a1c24568b Jan Allersma 2018-10-09 09:29:50
Use different strats instead of seperate Shapes. a56e1e665a0292d15139eddfd8ebdeb8c95251b4 Jan Allersma 2018-10-01 11:37:45
Make ornament interface compatible with Entities. 21383d5f200a338f8255d7d33b6989937c19fed6 Jan Allersma 2018-10-08 20:36:23
Fix bug in Rect from commit 6c91140 in other Shapes as well. 4165a5da98dd9a548a222c6160390e4e54026d48 Jan Allersma 2018-09-28 14:53:40
Build interface for ornament creation. adcf22a4e878edc45ac0775a5e15ebf0bb1a937d Jan Allersma 2018-10-08 13:53:52
Fully implement File I/O. 45cbb48489a24857cfc76144b38b12ccebfd9e61 Jan Allersma 2018-09-27 16:03:40
Fix GroupMenu bug. be41e51819be1a23e7761ea0662eb188ac641aca Jan Allersma 2018-09-27 14:55:20
Fix TODO's from previous commit. 89d8172b77336a6c18f30521147eb81287961f11 Jan Allersma 2018-09-27 14:06:30
Add groups as preparation for step 3. a91368128e7444f69b3a30ee4d17f9063c8846b8 Jan Allersma 2018-09-26 18:31:49
Fix minor bug. Small cleanup 'ellipse' code. 6c911405eb8e48ffe2d63aaff5255adbd4aec889 Jan Allersma 2018-09-21 18:10:01
Implement file I/O. 6219eca932d454a7dab5fe8679f07865ce3cf49d Jan Allersma 2018-09-21 15:52:45
Add shape 'ellipse'. 99d8b029c769bc291af73df3fd445da3cbf5bef4 Jan Allersma 2018-09-21 10:44:36
Add shape 'circle'. 092cb3c3f788b461192a6e164955c53acaf58720 Jan Allersma 2018-09-21 09:35:27
Add resize option (again). 08c95e97268cf9d74bcb963503eec512e528edfe Jan Allersma 2018-09-20 18:09:03
Commit 762914dec31b1fb1d4cf6bb0cef2e148010652a4 - Setup for decorator pattern.
Author: Jan Allersma
Author date (UTC): 2018-11-01 14:12
Committer name: Jan Allersma
Committer date (UTC): 2018-11-01 14:12
Parent(s): 6225242719b2cfc5ee0de9f8d05edbc7a69007a7
Signing key:
Tree: 1ac254a61f25a8acf4de7f3a1107297cbbbf0243
File Lines added Lines deleted
source/entities/ornament.d 56 0
source/entities/shape/decorator.d 54 0
source/entities/shape/shape.d 43 6
source/entities/shape/shapeornament.d 52 0
source/strategies/circle.d 1 1
source/strategies/ellipse.d 3 3
source/strategies/rect.d 1 1
source/vistors/moveVisitor.d 2 2
source/vistors/resizeVisitor.d 5 6
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/strategies/rect.d changed (mode: 100644) (index 8484b1a..80f2eb9)
... ... private static class RectDrawer : Strategy {
33 33 } }
34 34
35 35 public override void draw(Shape shape) { public override void draw(Shape shape) {
36 shape.c.rectangle (
36 shape.context.rectangle (
37 37 shape.bounds[0][0], shape.bounds[0][0],
38 38 shape.bounds[0][1], shape.bounds[0][1],
39 39 shape.size, shape.size,
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) {
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/kapstok/NHL-DePa2

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/kapstok/NHL-DePa2

Clone this repository using git:
git clone git://git.rocketgit.com/user/kapstok/NHL-DePa2

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main