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)
Allow multiple Ornaments to be added to an Entity. db1ce677fbcbba757c18ea645b76bb1688594d04 Jan Allersma 2018-11-09 17:23:02
Change Entity.group as variable into a property. bbda7fe1dd4528b9396bff03fcb669e4c6ff2ad5 Jan Allersma 2018-11-08 16:37:41
Load nested Entities with Ornaments properly. 8da015e6fd4f43cc873a5ae330caefab73b8f5fc Jan Allersma 2018-11-08 13:56:36
Save nested Entities with Ornaments properly. 645cf4ae287fd2511b4c1404d0d9559372e5e10b Jan Allersma 2018-11-08 12:04:40
Fix bug: activate group after movement with cloning. 482c53ecab43cdee03590949669c22227d104475 Jan Allersma 2018-11-08 10:35:27
Include Groups in Commands, removing dp.groups.groups. 699f767ac316edd481630a943f7a1884c5bc16f2 Jan Allersma 2018-11-07 11:27:15
Fix ability to nest in Groups. fd546a42ef54bdf5d2966eb7facbbf21a6b72e1b Jan Allersma 2018-11-06 17:49:11
Fix file I/O for single entities. 093b7d31a215067212927b1d92bdbbee306ea345 Jan Allersma 2018-11-06 16:49:55
Fix file I/O issue. 25c0b40db223c806eb3ea8bd28238dedc38ca8b5 Jan Allersma 2018-11-02 16:22:59
Cleanup commenting. 445aea4a5115c9110a097bfc7ac9f7d5ad48a9e7 Jan Allersma 2018-11-02 14:33:08
Show Ornaments on Canvas. d8456f15d69550c4cb0aa615cccb96b45a77f6a6 Jan Allersma 2018-11-02 14:08:47
Support Entities for Create & Destruct commands. cc900579eedf9c6288ce1c1883122856794e05a0 Jan Allersma 2018-11-02 13:25:43
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
Commit db1ce677fbcbba757c18ea645b76bb1688594d04 - Allow multiple Ornaments to be added to an Entity.
Author: Jan Allersma
Author date (UTC): 2018-11-09 17:23
Committer name: Jan Allersma
Committer date (UTC): 2018-11-09 17:23
Parent(s): bbda7fe1dd4528b9396bff03fcb669e4c6ff2ad5
Signing key:
Tree: de55d0fd4be2b06c2b19e8b7d69b0b0f8e07f39f
File Lines added Lines deleted
README.md 0 21
source/entities/decorator/entornament.d 6 7
source/entities/entity.d 1 1
source/entities/ornament.d 3 1
source/file.d 11 10
source/frontend/ornamentDialog.d 5 1
source/vistors/saveVisitor.d 4 4
File README.md changed (mode: 100644) (index c4d15d1..3d9bf4e)
... ... This repo is a school project for Design Patterns.
4 4
5 5 use 'dub' to compile and run the code. use 'dub' to compile and run the code.
6 6
7 # Useful draw functions for `Context` type
8
9 - `fill()`: fill path, then forget path.
10
11 - `fillPreserve()`: fill path, retain path.
12
13 - `fillExtends()`, `strokeExtends()` & `pathExtends()`: return corners
14 (whatever that may be).
15
16 - `stroke()`: draw line on path, then forget path.
17
18 - `strokePreserve()`: should be obvious.
19
20 - `moveTo()`: Move/Pan path.
21
22 - `scale()`: Scale path.
23
24 - `newPath()`: Clear path from context.
25
26 - `showText()`: Write text with Cairo.
27
28 7 # Entities # Entities
29 8
30 9 `Shapes` are stored in a `Command`. Each `Command` is saved in `History`. `Shapes` are stored in a `Command`. Each `Command` is saved in `History`.
File source/entities/decorator/entornament.d changed (mode: 100644) (index e4f5e81..bcd204c)
... ... import dp.ent.ornament;
7 7 import std.stdio; // Debug import std.stdio; // Debug
8 8
9 9 class EntityOrnament : Decorator { class EntityOrnament : Decorator {
10 Ornament o;
11
12 10 this(Entity entity) { this(Entity entity) {
13 11 super(entity); super(entity);
14 o = null;
12 ornaments = [];
15 13 } }
16 14
17 15 @property @property
18 16 public override string type() { public override string type() {
19 17 string result = e.type; string result = e.type;
20 18
21 if(o !is null)
19 foreach(o; ornaments)
22 20 result ~= "\n" ~ o.type; result ~= "\n" ~ o.type;
23 21
24 22 return result; return result;
 
... ... class EntityOrnament : Decorator {
29 27 string result = e.to_string; string result = e.to_string;
30 28 writeln("PRE-RES: " ~ result); writeln("PRE-RES: " ~ result);
31 29
32 if(o !is null)
30 foreach(o; ornaments)
33 31 result ~= "\n" ~ o.to_string; result ~= "\n" ~ o.to_string;
34 32
35 33 writeln("POST_RES: " ~ result); writeln("POST_RES: " ~ result);
 
... ... class EntityOrnament : Decorator {
39 37
40 38 public override void render() { public override void render() {
41 39 e.render(); e.render();
42 if(o !is null)
40 foreach(o; ornaments)
43 41 o.render(); o.render();
44 42 } }
45 43
46 44 public void setOrnament(Ornament ornament) { public void setOrnament(Ornament ornament) {
47 o = ornament;
45 ornaments.length++;
46 ornaments[ornaments.length - 1] = ornament;
48 47 } }
49 48 } }
File source/entities/entity.d changed (mode: 100644) (index f1d10e7..7200966)
... ... import dp.ent.shape;
8 8
9 9 class Entity { class Entity {
10 10 public bool active = true; public bool active = true;
11 public Ornament ornament = null;
11 public Ornament[] ornaments = [];
12 12
13 13 @property @property
14 14 public abstract Group group(); public abstract Group group();
File source/entities/ornament.d changed (mode: 100644) (index e11b12c..29ee340)
... ... class Ornament : Entity {
14 14 this.alignment = alignment; this.alignment = alignment;
15 15 this.value = value; this.value = value;
16 16 this.context = context; this.context = context;
17 entity.ornament = this;
17
18 entity.ornaments.length++;
19 entity.ornaments[entity.ornaments.length - 1] = this;
18 20
19 21 context.setSourceRgba(0.5,0.5,0.5,1); context.setSourceRgba(0.5,0.5,0.5,1);
20 22 context.selectFontFace("Purisa", CairoFontSlant.NORMAL, CairoFontWeight.BOLD); context.selectFontFace("Purisa", CairoFontSlant.NORMAL, CairoFontWeight.BOLD);
File source/file.d changed (mode: 100644) (index 30f5d68..30fdda9)
... ... public class Savefile {
95 95 private void fromFile(ref File f, ref Entity[] entities) { private void fromFile(ref File f, ref Entity[] entities) {
96 96 string type; string type;
97 97 string line; string line;
98 string[2] o_words = [null, null];
98 string[2][] o_words = [];
99 99
100 100 while(!f.eof) { while(!f.eof) {
101 101 line = strip(f.readln()); line = strip(f.readln());
 
... ... public class Savefile {
115 115 EntityOrnament eo = new EntityOrnament(g); EntityOrnament eo = new EntityOrnament(g);
116 116 entities[entities.length - 1] = eo; entities[entities.length - 1] = eo;
117 117
118 if(o_words[0] !is null) {
119 eo.setOrnament(new Ornament(eo, o_words[0], o_words[1], Global.canvas.newContext));
120 o_words = [null, null];
121 }
118 foreach(wrds; o_words)
119 eo.setOrnament(new Ornament(eo, wrds[0], wrds[1], Global.canvas.newContext));
120
121 o_words.length = 0;
122 122
123 123 writeln("F: group"); writeln("F: group");
124 124 break; break;
 
... ... public class Savefile {
128 128 EntityOrnament eo = parseShape(words[0], words[1], words[2], words[3]); EntityOrnament eo = parseShape(words[0], words[1], words[2], words[3]);
129 129 entities[entities.length - 1] = eo; entities[entities.length - 1] = eo;
130 130
131 if(o_words[0] !is null) {
132 eo.setOrnament(new Ornament(eo, o_words[0], o_words[1], Global.canvas.newContext));
133 o_words = [null, null];
134 }
131 foreach(wrds; o_words)
132 eo.setOrnament(new Ornament(eo, wrds[0], wrds[1], Global.canvas.newContext));
133
134 o_words.length = 0;
135 135
136 136 writeln("F: shape"); writeln("F: shape");
137 137 break; break;
138 138 case "ornament": case "ornament":
139 o_words = [words[1], words[2]];
139 o_words.length++;
140 o_words[o_words.length - 1] = [words[1], words[2]];
140 141 entities.length--; entities.length--;
141 142
142 143 writeln("F: ornament"); writeln("F: ornament");
File source/frontend/ornamentDialog.d changed (mode: 100644) (index ded2560..fcebbd3)
... ... import dp.ent.ornament;
13 13 import dp.dec.entornament; import dp.dec.entornament;
14 14 import dp.command.create; import dp.command.create;
15 15
16 import std.stdio; // Debug
17
16 18 import Global = dp.global; import Global = dp.global;
17 19
18 20 class OrnamentDialog : Dialog { class OrnamentDialog : Dialog {
 
... ... class OrnamentDialog : Dialog {
74 76
75 77 private void clickCallback(Button button) { private void clickCallback(Button button) {
76 78 string input = factorEntry.getText(); string input = factorEntry.getText();
77 EntityOrnament eo = new EntityOrnament(e);
78 79
79 80 if(e is null) if(e is null)
80 81 this.close(); this.close();
81 82
83 EntityOrnament eo = new EntityOrnament(e);
84 write("O: ");write(&e);write(", ");writeln(e.ornaments.length);
85
82 86 if(input != "") { if(input != "") {
83 87 Ornament o = new Ornament(e, position, input, Global.canvas.newContext); Ornament o = new Ornament(e, position, input, Global.canvas.newContext);
84 88 Global.History.addCommand(new CreateCmd(o)); Global.History.addCommand(new CreateCmd(o));
File source/vistors/saveVisitor.d changed (mode: 100644) (index 54e12f5..1df58e0)
... ... public class SaveVisitor : Visitor {
11 11 } }
12 12
13 13 public override void visit(Shape s) { public override void visit(Shape s) {
14 if(s.ornament !is null)
15 s.ornament.accept(new SaveVisitor(f));
14 foreach(ornament; s.ornaments)
15 ornament.accept(new SaveVisitor(f));
16 16
17 17 f.toFile(s); f.toFile(s);
18 18 } }
19 19
20 20 public override void visit(Group g) { public override void visit(Group g) {
21 if(g.ornament !is null)
22 g.ornament.accept(new SaveVisitor(f));
21 foreach(ornament; g.ornaments)
22 ornament.accept(new SaveVisitor(f));
23 23
24 24 f.toFile(g); f.toFile(g);
25 25
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