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)
Improve Quality of Code. 9e0c9d1b640bfbee558b3d2b85b481bd311cdf46 Jan Allersma 2018-11-14 11:19:23
Fix colour of subgroups. 8e16f02cbc7ef08943a1642e8f986c6eb90f10a3 Jan Allersma 2018-11-14 10:51:01
Fix File I/O for EntityOrnaments. e38712e53a13ba2bbb0a0b792688cfff29689826 Jan Allersma 2018-11-13 17:46:45
Allow multiple Ornaments to be aligned at the same Entity. b01673996a5b4a589b8e6c6d9dee0dc9b3c1cc60 Jan Allersma 2018-11-09 21:46:01
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
Commit 9e0c9d1b640bfbee558b3d2b85b481bd311cdf46 - Improve Quality of Code.
Author: Jan Allersma
Author date (UTC): 2018-11-14 11:19
Committer name: Jan Allersma
Committer date (UTC): 2018-11-14 11:19
Parent(s): 8e16f02cbc7ef08943a1642e8f986c6eb90f10a3
Signing key:
Tree: 43d34f41792a794a503d755512407351fb0e042e
File Lines added Lines deleted
source/brush.d 1 1
source/canvas.d 11 4
source/commands/create.d 2 1
source/commands/load.d 6 10
source/entities/decorator/entornament.d 5 8
source/entities/group.d 10 15
source/entities/ornament.d 4 6
source/entities/shape.d 18 18
source/file.d 6 13
source/frontend/ornamentDialog.d 7 10
source/frontend/shapeOptions.d 1 2
source/history.d 8 19
source/selection.d 6 1
source/strategies/circle.d 1 3
source/strategies/ellipse.d 1 3
source/strategies/rect.d 1 3
source/strategies/strategy.d 1 0
source/vistors/moveVisitor.d 2 1
source/vistors/resizeVisitor.d 3 3
source/vistors/saveVisitor.d 12 17
File source/brush.d changed (mode: 100644) (index f270929..763992e)
... ... module dp.brush;
2 2
3 3 import dp.ent.entity; import dp.ent.entity;
4 4
5 static bool cloneGroup; // Move clone's group instead of clone?
5 static bool cloneGroup;
6 6 static Shape clone; static Shape clone;
7 7 static string shape; static string shape;
8 8 static double red; static double red;
File source/canvas.d changed (mode: 100644) (index 1c96b37..168fe8f)
... ... public class Canvas : DrawingArea {
46 46 // Get mouse position relative to widget.. // Get mouse position relative to widget..
47 47 getPointer(mouseX, mouseY); getPointer(mouseX, mouseY);
48 48
49 if(event.button.button == 3) { // if right click...
49 // if right click...
50 if(event.button.button == 3) {
50 51 Global.History.CheckBounds(mouseX, mouseY); Global.History.CheckBounds(mouseX, mouseY);
51 52 } }
52 53 else if(Global.Brush.clone !is null) { else if(Global.Brush.clone !is null) {
 
... ... public class Canvas : DrawingArea {
83 84 else if(Global.Brush.shape !is null) { else if(Global.Brush.shape !is null) {
84 85 final switch (Global.Brush.shape) { final switch (Global.Brush.shape) {
85 86 case "rectangle": case "rectangle":
86 Global.History.addCommand(new CreateCmd(new Shape(mouseX, mouseY, newContext, rect)));
87 Global.History.addCommand(new CreateCmd(
88 new Shape(mouseX, mouseY, newContext, rect)
89 ));
87 90 break; break;
88 91 case "circle": case "circle":
89 Global.History.addCommand(new CreateCmd(new Shape(mouseX, mouseY, newContext, circle)));
92 Global.History.addCommand(new CreateCmd(
93 new Shape(mouseX, mouseY, newContext, circle)
94 ));
90 95 break; break;
91 96 case "ellipse": case "ellipse":
92 Global.History.addCommand(new CreateCmd(new Shape(mouseX, mouseY, newContext, ellipse)));
97 Global.History.addCommand(new CreateCmd(
98 new Shape(mouseX, mouseY, newContext, ellipse)
99 ));
93 100 break; break;
94 101 } }
95 102 Global.Brush.shape = null; Global.Brush.shape = null;
File source/commands/create.d changed (mode: 100644) (index 893629f..789ffa5)
... ... public class CreateCmd : Command {
33 33 public override void save(Savefile file) { public override void save(Savefile file) {
34 34 if(e.type == "ornament") return; if(e.type == "ornament") return;
35 35
36 if(e.group is null && !e.partOfEo)
36 if(e.group is null && !e.partOfEo) {
37 37 e.accept(new SaveVisitor(file)); e.accept(new SaveVisitor(file));
38 }
38 39 } }
39 40 } }
File source/commands/load.d changed (mode: 100644) (index 395d82e..f2a6ac4)
... ... public class LoadCmd : Command {
15 15 } }
16 16
17 17 public override void execute() { public override void execute() {
18 foreach(e; entities)
19 e.active = true;
18 foreach(e; entities) e.active = true;
20 19 } }
21 20
22 21 public override void undo() { public override void undo() {
23 foreach(e; entities)
24 e.active = false;
22 foreach(e; entities) e.active = false;
25 23 } }
26 24
27 25 public override void render() { public override void render() {
28 foreach(e; entities)
29 e.render();
26 foreach(e; entities) e.render();
30 27 } }
31 28
32 29 public override void check(int x, int y) { public override void check(int x, int y) {
33 foreach(e; entities)
34 e.checkBounds(x,y);
30 foreach(e; entities) e.checkBounds(x,y);
35 31 } }
36 32
37 // Should be done by Visitor self.
38 33 public override void save(Savefile file) { public override void save(Savefile file) {
39 34 foreach(e; entities) { foreach(e; entities) {
40 if(e.group is null)
35 if(e.group is null) {
41 36 e.accept(new SaveVisitor(file)); e.accept(new SaveVisitor(file));
37 }
42 38 } }
43 39 } }
44 40 } }
File source/entities/decorator/entornament.d changed (mode: 100644) (index 36a64f5..a1e702b)
... ... class EntityOrnament : Decorator {
11 11 super(entity); super(entity);
12 12 ornaments = []; ornaments = [];
13 13
14 if(entity.group !is null)
15 entity.group.add(this);
14 if(entity.group !is null) entity.group.add(this);
16 15 } }
17 16
18 17 @property @property
 
... ... class EntityOrnament : Decorator {
24 23 public override string to_string() { public override string to_string() {
25 24 string result = e.to_string; string result = e.to_string;
26 25
27 foreach(o; ornaments)
26 foreach(o; ornaments) {
28 27 result ~= "\n" ~ o.to_string; result ~= "\n" ~ o.to_string;
28 }
29 29
30 30 return result; return result;
31 31 } }
32 32
33 33 public override void render() { public override void render() {
34 foreach(o; ornaments) o.render();
34 35 e.render(); e.render();
35 foreach(o; ornaments)
36 o.render();
37 36 } }
38 37
39 38 public override void accept(Visitor v) { public override void accept(Visitor v) {
40 foreach(o; ornaments)
41 o.accept(v);
42
39 foreach(o; ornaments) o.accept(v);
43 40 e.accept(v); e.accept(v);
44 41 } }
45 42 } }
File source/entities/group.d changed (mode: 100644) (index 0786cff..01b7bb8)
... ... class Group : Entity {
43 43
44 44 @property @property
45 45 public override double size(double s) { public override double size(double s) {
46 return this._size = s;
46 return _size = s;
47 47 } }
48 48
49 49 @property @property
 
... ... class Group : Entity {
56 56 foreach(e; entities) { foreach(e; entities) {
57 57 double[2][2] bnds = e.bounds; double[2][2] bnds = e.bounds;
58 58
59 if(bnds[0][0] < result[0][0])
60 result[0][0] = bnds[0][0];
61 if(bnds[0][1] < result[0][1])
62 result[0][1] = bnds[0][1];
63 if(bnds[1][0] > result[1][0])
64 result[1][0] = bnds[1][0];
65 if(bnds[1][1] > result[1][1])
66 result[1][1] = bnds[1][1];
59 if(bnds[0][0] < result[0][0]) result[0][0] = bnds[0][0];
60 if(bnds[0][1] < result[0][1]) result[0][1] = bnds[0][1];
61 if(bnds[1][0] > result[1][0]) result[1][0] = bnds[1][0];
62 if(bnds[1][1] > result[1][1]) result[1][1] = bnds[1][1];
67 63 } }
68 64
69 65 return result; return result;
 
... ... class Group : Entity {
89 85 } }
90 86
91 87 public override void render() { public override void render() {
92 foreach(e; entities)
93 e.render();
88 foreach(e; entities) e.render();
94 89 } }
95 90
96 91 public override void checkBounds(int x, int y) { public override void checkBounds(int x, int y) {
97 if(active)
98 foreach(e; entities)
99 e.checkBounds(x,y);
92 if(!active) return;
93 foreach(e; entities) e.checkBounds(x,y);
100 94 } }
101 95
102 96 public size_t add(Entity entity) { public size_t add(Entity entity) {
 
... ... class Group : Entity {
113 107
114 108 entities.length++; entities.length++;
115 109
116 for(size_t i = index; i < entities.length; i++)
110 for(size_t i = index; i < entities.length; i++) {
117 111 entities[i] = entities[i+1]; entities[i] = entities[i+1];
112 }
118 113
119 114 entities.length--; entities.length--;
120 115 } }
File source/entities/ornament.d changed (mode: 100644) (index 0c21c00..e415ece)
... ... class Ornament : Entity {
23 23
24 24 foreach(o; entity.ornaments) { foreach(o; entity.ornaments) {
25 25 if(o.alignment == alignment) { if(o.alignment == alignment) {
26 if(alignment == "Top")
27 offset -= 30;
28 else
29 offset += 30;
26 if(alignment == "Top") offset -= 30;
27 else offset += 30;
30 28 } }
31 29 } }
32 30
 
... ... class Ornament : Entity {
77 75 public override void checkBounds(int x, int y) {} public override void checkBounds(int x, int y) {}
78 76
79 77 public override void render() { public override void render() {
80 if(!active)
81 return;
78 if(!active) return;
82 79
83 80 double[2] pos = position; double[2] pos = position;
81
84 82 context.moveTo(pos[0], pos[1]); context.moveTo(pos[0], pos[1]);
85 83 context.showText(value); context.showText(value);
86 84 } }
File source/entities/shape.d changed (mode: 100644) (index 2e36f6b..3b3d743)
... ... class Shape : Entity {
15 15 bounds[1][1] = maxY bounds[1][1] = maxY
16 16 +/ +/
17 17
18 private Context c; // context
19 private double[2][2] b; // bounds
20 private double s; // size
18 private Context _context;
19 private double[2][2] _bounds;
20 private double _size;
21 21 private Strategy strat; private Strategy strat;
22 private Group g; // group
22 private Group _group;
23 23
24 24 this(int x, int y, Context context, Strategy strategy, double size = 0) { this(int x, int y, Context context, Strategy strategy, double size = 0) {
25 c = context;
25 _context = context;
26 26 active = true; active = true;
27 27 this.strat = strategy; this.strat = strategy;
28 28 this.size = size != 0 ? size : strat.initialSize; this.size = size != 0 ? size : strat.initialSize;
 
... ... class Shape : Entity {
31 31
32 32 @property @property
33 33 public override Group group() { public override Group group() {
34 return g;
34 return _group;
35 35 } }
36 36
37 37 @property @property
38 38 public override Group group(Group g) { public override Group group(Group g) {
39 return this.g = g;
39 return _group = g;
40 40 } }
41 41
42 42 @property @property
 
... ... class Shape : Entity {
53 53 @property @property
54 54 public int[2] position() { public int[2] position() {
55 55 return [ return [
56 to!int(b[0][0] + sizeX),
57 to!int(b[0][1] + sizeY)
56 to!int(_bounds[0][0] + sizeX),
57 to!int(_bounds[0][1] + sizeY)
58 58 ]; ];
59 59 } }
60 60
 
... ... class Shape : Entity {
88 88 public override void render() { public override void render() {
89 89 if(active) { if(active) {
90 90 if(group is null) { if(group is null) {
91 c.setSourceRgba (
91 _context.setSourceRgba (
92 92 Global.Brush.red, Global.Brush.green, Global.Brush.red, Global.Brush.green,
93 93 Global.Brush.blue, Global.Brush.alpha Global.Brush.blue, Global.Brush.alpha
94 94 ); );
95 95 } else { } else {
96 c.setSourceRgba (
96 _context.setSourceRgba (
97 97 group.colour[0], group.colour[1], group.colour[0], group.colour[1],
98 98 group.colour[2], Global.Brush.alpha group.colour[2], Global.Brush.alpha
99 99 ); );
100 100 } }
101 101
102 102 strat.draw(this); strat.draw(this);
103 c.fill();
103 _context.fill();
104 104 } }
105 105 } }
106 106
107 107 @property @property
108 108 public Context context() { public Context context() {
109 return c;
109 return _context;
110 110 } }
111 111
112 112 @property @property
113 113 public Context context(Context c) { public Context context(Context c) {
114 return this.c = c;
114 return _context = c;
115 115 } }
116 116
117 117 @property @property
118 118 public override double size() { public override double size() {
119 return s;
119 return _size;
120 120 } }
121 121
122 122 @property @property
123 123 public override double size(double s) { public override double size(double s) {
124 return this.s = s;
124 return _size = s;
125 125 } }
126 126
127 127 @property @property
128 128 public override double[2][2] bounds() { public override double[2][2] bounds() {
129 return b;
129 return _bounds;
130 130 } }
131 131
132 132 @property @property
 
... ... class Shape : Entity {
138 138 result[0][1] = pos[1] - sizeY; // minY result[0][1] = pos[1] - sizeY; // minY
139 139 result[1][1] = pos[1] + sizeY; // maxY result[1][1] = pos[1] + sizeY; // maxY
140 140
141 return b = result;
141 return _bounds = result;
142 142 } }
143 143 } }
File source/file.d changed (mode: 100644) (index 3116029..0666a4f)
... ... public class Savefile {
28 28
29 29 public void toFile(Entity entity) { public void toFile(Entity entity) {
30 30 if(entity.active) { if(entity.active) {
31 for(int i = 0; i < indent; i++)
32 content ~= "\t";
33
31 for(int i = 0; i < indent; i++) content ~= "\t";
34 32 content ~= entity.to_string(); content ~= entity.to_string();
35 33 } }
36 34 } }
 
... ... public class Savefile {
109 107 Group g = Global.Groups.newGroup; Group g = Global.Groups.newGroup;
110 108 Entity[] e; Entity[] e;
111 109 fromFile(f,e); fromFile(f,e);
112 foreach(entity; e)
113 g.add(entity);
110 foreach(entity; e) g.add(entity);
114 111
115 112 EntityOrnament eo = new EntityOrnament(g); EntityOrnament eo = new EntityOrnament(g);
116 113 entities[entities.length - 1] = eo; entities[entities.length - 1] = eo;
117 114
118 foreach(wrds; o_words)
115 foreach(wrds; o_words) {
119 116 new Ornament(eo, wrds[0], wrds[1], Global.canvas.newContext); new Ornament(eo, wrds[0], wrds[1], Global.canvas.newContext);
117 }
120 118
121 119 o_words.length = 0; o_words.length = 0;
122
123 writeln("F: group");
124 120 break; break;
125 121 case "rectangle": case "rectangle":
126 122 case "circle": case "circle":
 
... ... public class Savefile {
128 124 EntityOrnament eo = parseShape(words[0], words[1], words[2], words[3]); EntityOrnament eo = parseShape(words[0], words[1], words[2], words[3]);
129 125 entities[entities.length - 1] = eo; entities[entities.length - 1] = eo;
130 126
131 foreach(wrds; o_words)
127 foreach(wrds; o_words) {
132 128 new Ornament(eo, wrds[0], wrds[1], Global.canvas.newContext); new Ornament(eo, wrds[0], wrds[1], Global.canvas.newContext);
129 }
133 130
134 131 o_words.length = 0; o_words.length = 0;
135
136 writeln("F: shape");
137 132 break; break;
138 133 case "ornament": case "ornament":
139 134 o_words.length++; o_words.length++;
140 135 o_words[o_words.length - 1] = [words[1], words[2]]; o_words[o_words.length - 1] = [words[1], words[2]];
141 136 entities.length--; entities.length--;
142
143 writeln("F: ornament");
144 137 break; break;
145 138 default: default:
146 139 writeln("ERROR: unsupported type in 'dp.file.fromFile'!"); writeln("ERROR: unsupported type in 'dp.file.fromFile'!");
File source/frontend/ornamentDialog.d changed (mode: 100644) (index fcfd5af..82d238f)
... ... import dp.command.create;
16 16 import Global = dp.global; import Global = dp.global;
17 17
18 18 class OrnamentDialog : Dialog { class OrnamentDialog : Dialog {
19 Entity e;
19 Entity _entity;
20 20 Entry factorEntry; Entry factorEntry;
21 21 RadioButton topRd, bottomRd, leftRd, rightRd; RadioButton topRd, bottomRd, leftRd, rightRd;
22 22 string position = "Top"; // Default value since 'topRd' is mnemonic. string position = "Top"; // Default value since 'topRd' is mnemonic.
 
... ... class OrnamentDialog : Dialog {
24 24 this(Entity e) { this(Entity e) {
25 25 super(); super();
26 26 setTitle("Attach ornament"); setTitle("Attach ornament");
27 this.e = e;
27 _entity = e;
28 28
29 29 Box box = new Box(Orientation.VERTICAL, 50); Box box = new Box(Orientation.VERTICAL, 50);
30 30
 
... ... class OrnamentDialog : Dialog {
75 75 private void clickCallback(Button button) { private void clickCallback(Button button) {
76 76 string input = factorEntry.getText(); string input = factorEntry.getText();
77 77
78 if(e is null)
79 this.close();
78 if(_entity is null) this.close();
80 79
81 EntityOrnament eo = new EntityOrnament(e);
82 e.partOfEo = true;
80 EntityOrnament eo = new EntityOrnament(_entity);
81 _entity.partOfEo = true; // Should be moved to eo contructor?
83 82
84 83 if(input != "") { if(input != "") {
85 84 Ornament o = new Ornament(eo, position, input, Global.canvas.newContext); Ornament o = new Ornament(eo, position, input, Global.canvas.newContext);
86 85 Global.History.addCommand(new CreateCmd(eo)); Global.History.addCommand(new CreateCmd(eo));
87 86 Global.canvas.repaint(); Global.canvas.repaint();
88 87 this.close(); this.close();
89 }
90 else {
88 } else {
91 89 MessageDialog msgd = new MessageDialog ( MessageDialog msgd = new MessageDialog (
92 90 this, DialogFlags.MODAL, MessageType.ERROR, ButtonsType.OK, this, DialogFlags.MODAL, MessageType.ERROR, ButtonsType.OK,
93 91 "Please enter a value.", "Please enter a value.",
 
... ... class OrnamentDialog : Dialog {
103 101 } }
104 102
105 103 private void toggledRd(ToggleButton rd) { private void toggledRd(ToggleButton rd) {
106 if(rd.getActive)
107 position = rd.getLabel();
104 if(rd.getActive) position = rd.getLabel();
108 105 } }
109 106 } }
File source/frontend/shapeOptions.d changed (mode: 100644) (index a973949..36a94cd)
... ... protected class ResizeGroup : MenuItem {
104 104 } }
105 105
106 106 private bool relCallback (Event event, Widget widget) { private bool relCallback (Event event, Widget widget) {
107 if(s.group !is null)
108 rd = new ResizeDialog(s.group);
107 if(s.group !is null) rd = new ResizeDialog(s.group);
109 108 return false; // Hide ShapeOptions when button is released. return false; // Hide ShapeOptions when button is released.
110 109 } }
111 110 } }
File source/history.d changed (mode: 100644) (index 704c2fb..6d7b89d)
... ... import dp.file;
5 5
6 6 import Global = dp.global; import Global = dp.global;
7 7
8 import std.stdio; // Debug
9
10 8 // The Invoker in the command pattern. // The Invoker in the command pattern.
11 9 static class History { static class History {
12 10 private static Command[] commands; private static Command[] commands;
 
... ... static class History {
14 12 private static bool belowZero; private static bool belowZero;
15 13
16 14 public static void addCommand(Command cmd) { public static void addCommand(Command cmd) {
17 if(cmdPtr != commands.length)
18 commands.length = cmdPtr;
15 if(cmdPtr != commands.length) commands.length = cmdPtr;
19 16
20 17 commands.length++; commands.length++;
21 18 commands[cmdPtr] = cmd; commands[cmdPtr] = cmd;
22 19 cmdPtr = commands.length; cmdPtr = commands.length;
23 20 belowZero = false; belowZero = false;
24
25 writeln(commands.length);
26 writeln(cmdPtr);
27 21 } }
28 22
29 23 public static void undo() { public static void undo() {
30 if(belowZero)
31 return;
32 else if(cmdPtr == 0)
24 if(belowZero) return;
25
26 if(cmdPtr == 0) {
33 27 belowZero = true; belowZero = true;
34 else {
28 } else {
35 29 commands[--cmdPtr].undo(); commands[--cmdPtr].undo();
36 write("undo ");write(cmdPtr);writeln(commands.length);
37 30 Global.canvas.repaint(); Global.canvas.repaint();
38 31 } }
39 32 } }
 
... ... static class History {
43 36 commands[cmdPtr++].execute(); commands[cmdPtr++].execute();
44 37 Global.canvas.repaint(); Global.canvas.repaint();
45 38 belowZero = false; belowZero = false;
46 write("redo ");write(cmdPtr);writeln(commands.length);
47 39 } }
48 40 } }
49 41
50 42 public static void render() { public static void render() {
51 foreach(command; commands)
52 command.render();
43 foreach(command; commands) command.render();
53 44 } }
54 45
55 46 public static void CheckBounds(int x, int y) { public static void CheckBounds(int x, int y) {
56 foreach(command; commands)
57 command.check(x,y);
47 foreach(command; commands) command.check(x,y);
58 48 } }
59 49
60 50 public static void clear() { public static void clear() {
 
... ... static class History {
64 54 public static void save(string filename) { public static void save(string filename) {
65 55 Savefile file = new Savefile(filename); Savefile file = new Savefile(filename);
66 56
67 foreach(command; commands)
68 command.save(file);
57 foreach(command; commands) command.save(file);
69 58
70 59 file.save(); file.save();
71 60 } }
File source/selection.d changed (mode: 100644) (index 9076c2d..aa50fc5)
... ... public class Selection : Label {
10 10 } }
11 11
12 12 public void update(string groupname) { public void update(string groupname) {
13 groupname is null ? setText("No group selected") : setText("Selected group: '" ~ groupname ~ "'.");
13 if(groupname is null) {
14 setText("No group selected");
15 } else {
16 setText("Selected group: '" ~ groupname ~ "'.");
17 }
18
14 19 show(); show();
15 20 } }
16 21 } }
File source/strategies/circle.d changed (mode: 100644) (index 2fd2435..83f7597)
... ... import dp.strat.strat;
5 5 private static CircleDrawer _circle; private static CircleDrawer _circle;
6 6
7 7 public static CircleDrawer circle() { public static CircleDrawer circle() {
8 if(_circle is null)
9 _circle = new CircleDrawer;
10
8 if(_circle is null) _circle = new CircleDrawer;
11 9 return _circle; return _circle;
12 10 } }
13 11
File source/strategies/ellipse.d changed (mode: 100644) (index 439bf38..0e5281b)
... ... import dp.strat.strat;
5 5 private static EllipseDrawer _ellipse; private static EllipseDrawer _ellipse;
6 6
7 7 public static EllipseDrawer ellipse() { public static EllipseDrawer ellipse() {
8 if(_ellipse is null)
9 _ellipse = new EllipseDrawer;
10
8 if(_ellipse is null) _ellipse = new EllipseDrawer;
11 9 return _ellipse; return _ellipse;
12 10 } }
13 11
File source/strategies/rect.d changed (mode: 100644) (index 80f2eb9..654b1e6)
... ... import dp.strat.strat;
5 5 private static RectDrawer _rect; private static RectDrawer _rect;
6 6
7 7 public static RectDrawer rect() { public static RectDrawer rect() {
8 if(_rect is null)
9 _rect = new RectDrawer();
10
8 if(_rect is null) _rect = new RectDrawer();
11 9 return _rect; return _rect;
12 10 } }
13 11
File source/strategies/strategy.d changed (mode: 100644) (index 5b8db29..67418a9)
... ... abstract class Strategy {
21 21
22 22 public string to_string(Shape shape) { public string to_string(Shape shape) {
23 23 string result = type ~ " "; string result = type ~ " ";
24
24 25 result ~= to!string(shape.position[0]) ~ " "; result ~= to!string(shape.position[0]) ~ " ";
25 26 result ~= to!string(shape.position[1]) ~ " "; result ~= to!string(shape.position[1]) ~ " ";
26 27 result ~= to!string(shape.size) ~ "\n"; result ~= to!string(shape.size) ~ "\n";
File source/vistors/moveVisitor.d changed (mode: 100644) (index 39d0c35..d66c99c)
... ... public class MoveVisitor : Visitor {
25 25 } }
26 26
27 27 public override void visit(Group g) { public override void visit(Group g) {
28 for(size_t i = 0; i < g.length; i++)
28 for(size_t i = 0; i < g.length; i++) {
29 29 g.get(i).accept(new MoveVisitor(translation)); g.get(i).accept(new MoveVisitor(translation));
30 }
30 31 } }
31 32
32 33 public override void visit(Ornament o) {} public override void visit(Ornament o) {}
File source/vistors/resizeVisitor.d changed (mode: 100644) (index c76850c..35f738a)
... ... public class ResizeVisitor : Visitor {
24 24 shape. Therefore, the size will be checked in it's smallest shape. Therefore, the size will be checked in it's smallest
25 25 possible size: this.size divided by 2. possible size: this.size divided by 2.
26 26 +/ +/
27 if(s.size / 2 + amount <= 0)
28 return;
27 if(s.size / 2 + amount <= 0) return;
29 28
30 29 newPos = [ newPos = [
31 30 s.bounds[0][0] + s.sizeX, s.bounds[0][0] + s.sizeX,
 
... ... public class ResizeVisitor : Visitor {
37 36 } }
38 37
39 38 public override void visit(Group g) { public override void visit(Group g) {
40 for(size_t i = 0; i < g.length; i++)
39 for(size_t i = 0; i < g.length; i++) {
41 40 g.get(i).accept(new ResizeVisitor(amount)); g.get(i).accept(new ResizeVisitor(amount));
41 }
42 42
43 43 g.size = g.size + amount; g.size = g.size + amount;
44 44 } }
File source/vistors/saveVisitor.d changed (mode: 100644) (index 64fbcfa..2fa1866)
... ... import dp.visitor.visitor;
4 4 import dp.ent.entity; import dp.ent.entity;
5 5 import dp.file; import dp.file;
6 6
7 import std.stdio; // Debug
8
9 7 public class SaveVisitor : Visitor { public class SaveVisitor : Visitor {
10 Savefile f;
8 Savefile file;
11 9
12 10 this(Savefile file) { this(Savefile file) {
13 f = file;
11 this.file = file;
14 12 } }
15 13
16 14 public override void visit(EntityOrnament eo) { public override void visit(EntityOrnament eo) {
17 eo.accept(new SaveVisitor(f));
15 eo.accept(new SaveVisitor(file));
18 16 } }
19 17
20 18 public override void visit(Shape s) { public override void visit(Shape s) {
21 writeln("S: shape");
22
23 f.toFile(s);
19 file.toFile(s);
24 20 } }
25 21
26 22 public override void visit(Group g) { public override void visit(Group g) {
27 writeln("S: group");
23 file.toFile(g);
28 24
29 f.toFile(g);
30
31 f.indent++;
25 file.indent++;
32 26
33 27 for(size_t i = 0; i < g.length; i++) { for(size_t i = 0; i < g.length; i++) {
34 28 Entity e = g.get(i); Entity e = g.get(i);
35 if(!e.partOfEo)
36 e.accept(new SaveVisitor(f));
29
30 if(!e.partOfEo) {
31 e.accept(new SaveVisitor(file));
32 }
37 33 } }
38 34
39 f.indent--;
35 file.indent--;
40 36 } }
41 37
42 38 public override void visit(Ornament o) { public override void visit(Ornament o) {
43 writeln("S: ornament");
44 f.toFile(o);
39 file.toFile(o);
45 40 } }
46 41 } }
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