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)
Use entities instead of shapes when constructing ornaments. 13f08847624489f60a37db55c2aedbba6b021f98 Jan Allersma 2018-11-01 17:02:47
Remove obsolete 'calcBounds' function. 475ec330736b5800d12d091415480b163dd244e2 Jan Allersma 2018-11-01 14:28:29
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
Commit 13f08847624489f60a37db55c2aedbba6b021f98 - Use entities instead of shapes when constructing ornaments.
* Add 'size' and 'bounds' as properties for Entity.
* Inherit decorator from Entity instead of Shape.
* Accept Ornaments for Visitors.
* Enable user to add Ornaments to Entities with OrnamentDialog.
Author: Jan Allersma
Author date (UTC): 2018-11-01 17:02
Committer name: Jan Allersma
Committer date (UTC): 2018-11-01 17:02
Parent(s): 475ec330736b5800d12d091415480b163dd244e2
Signing key:
Tree: d9f026954d2e28febe72192de98ba4d5e64da481
File Lines added Lines deleted
README.md 2 0
source/entities/entity.d 9 0
source/entities/group.d 35 0
source/entities/ornament.d 31 13
source/entities/shape/decorator.d 27 46
source/entities/shape/entornament.d 9 9
source/entities/shape/shape.d 3 3
source/frontend/ornamentDialog.d 5 10
source/vistors/moveVisitor.d 2 0
source/vistors/resizeVisitor.d 4 0
source/vistors/saveVisitor.d 4 0
source/vistors/visitor.d 2 0
File README.md changed (mode: 100644) (index d37e6ad..b38bb0d)
... ... variable.
48 48 maar subgroepen niet. maar subgroepen niet.
49 49
50 50 - Groups worden nog niet goed geladen: ze verliezen hun kleurtje. - Groups worden nog niet goed geladen: ze verliezen hun kleurtje.
51
52 - Decorator moet nog 'group' en 'active' correct implementeren.
File source/entities/entity.d changed (mode: 100644) (index a93d0dc..e317789)
... ... class Entity {
13 13 public bool active = true; public bool active = true;
14 14 public Group group = null; public Group group = null;
15 15
16 @property
17 public abstract double size();
18
19 @property
20 public abstract double size(double s);
21
22 @property
23 public abstract double[2][2] bounds();
24
16 25 @property @property
17 26 public abstract string type(); public abstract string type();
18 27
File source/entities/group.d changed (mode: 100644) (index bd71c97..a7746b7)
... ... import Global = dp.global;
13 13 class Group : Entity { class Group : Entity {
14 14 public double[3] colour; // R, G, B public double[3] colour; // R, G, B
15 15 private Entity[] entities; private Entity[] entities;
16 private double s;
16 17
17 18 this() { this() {
18 19 auto random = rndGen(); auto random = rndGen();
20 s = 1;
19 21 entities = []; entities = [];
20 22 active = true; active = true;
21 23 colour = [ colour = [
 
... ... class Group : Entity {
27 29 writeln(colour); writeln(colour);
28 30 } }
29 31
32 @property
33 public override double size() {
34 return s;
35 }
36
37 @property
38 public override double size(double s) {
39 return this.s = s;
40 }
41
42 @property
43 public override double[2][2] bounds() {
44 double[2][2] result = [
45 [double.infinity,double.infinity],
46 [0.0,0.0]
47 ];
48
49 foreach(e; entities) {
50 double[2][2] bnds = e.bounds;
51
52 if(bnds[0][0] < result[0][0])
53 result[0][0] = bnds[0][0];
54 if(bnds[0][1] < result[0][1])
55 result[0][1] = bnds[0][1];
56 if(bnds[1][0] > result[1][0])
57 result[1][0] = bnds[1][0];
58 if(bnds[1][1] > result[1][1])
59 result[1][1] = bnds[1][1];
60 }
61
62 return result;
63 }
64
30 65 @property @property
31 66 public size_t length() { public size_t length() {
32 67 return entities.length; return entities.length;
File source/entities/ornament.d changed (mode: 100644) (index 040c90b..00deab9)
1 1 module dp.ent.ornament; module dp.ent.ornament;
2 2
3 import dp.ent.shape;
4 3 import dp.ent.entity; import dp.ent.entity;
5 4
6 5 class Ornament : Entity { class Ornament : Entity {
7 Shape shape;
6 Entity entity;
8 7 string position; string position;
9 8 string value; string value;
10 9
11 this(Shape shape, string position, string value) {
12 this.shape = shape;
10 this(Entity entity, string position, string value) {
11 this.entity = entity;
13 12 this.position = position; this.position = position;
14 13 this.value = value; this.value = value;
15 14 } }
16 15
16 @property
17 public override double size() {
18 return entity.size;
19 }
20
21 @property
22 public override double size(double s) {
23 return entity.size = s;
24 }
25
26 @property
27 public override double[2][2] bounds() {
28 return entity.bounds;
29 }
30
17 31 @property @property
18 32 public override string type() { public override string type() {
19 33 return "ornament"; return "ornament";
 
... ... class Ornament : Entity {
24 38 return type ~ " " ~ position ~ " " ~ value; return type ~ " " ~ position ~ " " ~ value;
25 39 } }
26 40
41 public override void accept(Visitor v) {
42 v.visit(this);
43 }
44
27 45 public override void checkBounds(int x, int y) {} public override void checkBounds(int x, int y) {}
28 46
29 47 public override void render() { public override void render() {
 
... ... class Ornament : Entity {
31 49 } }
32 50
33 51 private void calcBounds() { private void calcBounds() {
34 double[2][2] bounds = shape.bounds;
52 double[2][2] bounds = entity.bounds;
35 53
36 54 final switch(position) { final switch(position) {
37 55 case "Top": case "Top":
38 bounds[0][1] -= 30 + shape.size;
39 bounds[1][1] -= 30 + shape.size;
56 bounds[0][1] -= 30 + size;
57 bounds[1][1] -= 30 + size;
40 58 break; break;
41 59 case "Bottom": case "Bottom":
42 bounds[0][1] += 30 + shape.size;
43 bounds[1][1] += 30 + shape.size;
60 bounds[0][1] += 30 + size;
61 bounds[1][1] += 30 + size;
44 62 break; break;
45 63 case "Left": case "Left":
46 bounds[0][0] -= 30 + shape.size;
47 bounds[0][1] -= 30 + shape.size;
64 bounds[0][0] -= 30 + size;
65 bounds[0][1] -= 30 + size;
48 66 break; break;
49 67 case "Right": case "Right":
50 bounds[0][0] += 30 + shape.size;
51 bounds[0][1] += 30 + shape.size;
68 bounds[0][0] += 30 + size;
69 bounds[0][1] += 30 + size;
52 70 break; break;
53 71 } }
54 72 } }
File source/entities/shape/decorator.d changed (mode: 100644) (index b813a0d..670c9ce)
1 module dp.dec.shape;
1 module dp.dec.entity;
2 2
3 import dp.ent.shape;
3 import dp.ent.entity;
4 4 import dp.visitor.visitor; import dp.visitor.visitor;
5 import cairo.Context;
6 5
7 abstract class Decorator : Shape {
8 protected Shape s;
6 abstract class Decorator : Entity {
7 protected Entity e;
9 8
10 this(Shape shape) {
11 super(0,0,null,null); // Superclass will not be used.
12 s = shape;
9 this(Entity entity) {
10 e = entity;
13 11 } }
14 12
13 // public bool active = true;
14 // public Group group = null;
15 /+
15 16 @property @property
16 public override string type() {
17 return s.type;
18 }
19
20 @property
21 public override string to_string() {
22 return s.to_string;
23 }
24
25 @property
26 public override int[2] position() {
27 return s.position;
28 }
29
30 @property
31 public override double sizeX() {
32 return s.sizeX;
17 public override Group group() {
18 return e.group;
33 19 } }
34 20
35 21 @property @property
36 public override double sizeY() {
37 return s.sizeY;
38 }
39
40 @property
41 public override Context context() {
42 return s.context;
43 }
44
45 @property
46 public override Context context(Context c) {
47 return s.context = c;
48 }
22 public override bool active() {
23 return e.active;
24 }+/
49 25
50 26 @property @property
51 27 public override double size() { public override double size() {
52 return s.size;
28 return e.size;
53 29 } }
54 30
55 31 @property @property
56 32 public override double size(double s) { public override double size(double s) {
57 return this.s.size = s;
33 return e.size = s;
58 34 } }
59 35
60 36 @property @property
61 37 public override double[2][2] bounds() { public override double[2][2] bounds() {
62 return s.bounds;
38 return e.bounds;
63 39 } }
64 40
65 41 @property @property
66 public override double[2][2] bounds(double[2] pos) {
67 return s.bounds = pos;
42 public override string type() {
43 return e.type;
44 }
45
46 @property
47 public override string to_string() {
48 return e.to_string();
68 49 } }
69 50
70 51 public override void accept(Visitor v) { public override void accept(Visitor v) {
71 s.accept(v);
52 e.accept(v);
72 53 } }
73 54
74 55 public override void checkBounds(int x, int y) { public override void checkBounds(int x, int y) {
75 s.checkBounds(x,y);
56 e.checkBounds(x,y);
76 57 } }
77 58
78 59 public override void render() { public override void render() {
79 s.render();
60 e.render();
80 61 } }
81 62 } }
File source/entities/shape/entornament.d renamed from source/entities/shape/shapeornament.d (similarity 67%) (mode: 100644) (index 93e4b8f..caeddf1)
1 module dp.dec.shapeornament;
1 module dp.dec.entornament;
2 2
3 import dp.dec.shape;
4 import dp.ent.shape;
3 import dp.dec.entity;
4 import dp.ent.entity;
5 5 import dp.ent.ornament; import dp.ent.ornament;
6 6
7 class ShapeOrnament : Decorator {
7 class EntityOrnament : Decorator {
8 8 Ornament o; Ornament o;
9 9
10 this(Shape shape) {
11 super(shape);
10 this(Entity entity) {
11 super(entity);
12 12 o = null; o = null;
13 13 } }
14 14
15 15 @property @property
16 16 public override string type() { public override string type() {
17 string result = s.type;
17 string result = e.type;
18 18
19 19 if(o !is null) if(o !is null)
20 20 result ~= "\n" ~ o.type; result ~= "\n" ~ o.type;
 
... ... class ShapeOrnament : Decorator {
24 24
25 25 @property @property
26 26 public override string to_string() { public override string to_string() {
27 string result = s.to_string;
27 string result = e.to_string;
28 28
29 29 if(o !is null) if(o !is null)
30 30 result ~= "\n" ~ o.to_string; result ~= "\n" ~ o.to_string;
 
... ... class ShapeOrnament : Decorator {
33 33 } }
34 34
35 35 public override void render() { public override void render() {
36 s.render();
36 e.render();
37 37 if(o !is null) if(o !is null)
38 38 o.render(); o.render();
39 39 } }
File source/entities/shape/shape.d changed (mode: 100644) (index fa08cb9..4073a93)
... ... class Shape : Entity {
96 96 } }
97 97
98 98 @property @property
99 public double size() {
99 public override double size() {
100 100 return s; return s;
101 101 } }
102 102
103 103 @property @property
104 public double size(double s) {
104 public override double size(double s) {
105 105 return this.s = s; return this.s = s;
106 106 } }
107 107
108 108 @property @property
109 public double[2][2] bounds() {
109 public override double[2][2] bounds() {
110 110 return b; return b;
111 111 } }
112 112
File source/frontend/ornamentDialog.d changed (mode: 100644) (index 205f18f..44a440d)
... ... import gtk.RadioButton, gtk.ToggleButton;
9 9 import gtk.Box; import gtk.Box;
10 10
11 11 import dp.ent.entity; import dp.ent.entity;
12 import dp.ent.ornament;
13 import dp.dec.entornament;
12 14
13 15 import Global = dp.global; import Global = dp.global;
14 16
 
... ... class OrnamentDialog : Dialog {
71 73
72 74 private void clickCallback(Button button) { private void clickCallback(Button button) {
73 75 string input = factorEntry.getText(); string input = factorEntry.getText();
76 EntityOrnament eo = new EntityOrnament(e);
74 77
75 78 if(e is null) if(e is null)
76 79 this.close(); this.close();
77 80
78 81 if(input != "") { if(input != "") {
79 final switch(position) {
80 case "Top":
81 break;
82 case "Bottom":
83 break;
84 case "Left":
85 break;
86 case "Right":
87 break;
88 }
82 eo.setOrnament(new Ornament(e, position, input));
83 //e = eo;
89 84 this.close(); this.close();
90 85 } }
91 86 else { else {
File source/vistors/moveVisitor.d changed (mode: 100644) (index 6bee3f1..c0ebc45)
... ... public class MoveVisitor : Visitor {
24 24 for(size_t i = 0; i < g.length; i++) for(size_t i = 0; i < g.length; i++)
25 25 g.get(i).accept(new MoveVisitor(translation)); g.get(i).accept(new MoveVisitor(translation));
26 26 } }
27
28 public override void visit(Ornament o) {}
27 29 } }
File source/vistors/resizeVisitor.d changed (mode: 100644) (index 27270f6..2f8db00)
... ... public class ResizeVisitor : Visitor {
35 35 public override void visit(Group g) { public override void visit(Group g) {
36 36 for(size_t i = 0; i < g.length; i++) for(size_t i = 0; i < g.length; i++)
37 37 g.get(i).accept(new ResizeVisitor(amount)); g.get(i).accept(new ResizeVisitor(amount));
38
39 g.size = g.size + amount;
38 40 } }
41
42 public override void visit(Ornament o) {}
39 43 } }
File source/vistors/saveVisitor.d changed (mode: 100644) (index 55cedf2..5501494)
... ... public class SaveVisitor : Visitor {
17 17 public override void visit(Group g) { public override void visit(Group g) {
18 18 f.toFile(g); f.toFile(g);
19 19 } }
20
21 public override void visit(Ornament o) {
22 f.toFile(o);
23 }
20 24 } }
File source/vistors/visitor.d changed (mode: 100644) (index 8c878d4..36f51d4)
... ... module dp.visitor.visitor;
2 2
3 3 public import dp.ent.shape; public import dp.ent.shape;
4 4 public import dp.ent.group; public import dp.ent.group;
5 public import dp.ent.ornament;
5 6
6 7 abstract class Visitor { abstract class Visitor {
7 8 public abstract void visit(Shape s); public abstract void visit(Shape s);
8 9 public abstract void visit(Group g); public abstract void visit(Group g);
10 public abstract void visit(Ornament o);
9 11 } }
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