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)
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
Fix undo bug. 6ab126be633075923cdcce53044e2468f967db41 Jan Allersma 2018-09-20 10:46:50
Implement 'delete shape' feature. 16d42472d44a9dae988c4745c90c791a8770541b Jan Allersma 2018-09-19 09:04:40
Fix undo/redo for 'MoveCmd'. be51bea021bfe5ff79e16a92d350677aed736ddd Jan Allersma 2018-09-19 08:49:55
Implement shapeOptions without undo/redo. bbe699f41e5dacbfdadfaa879452ac2f4501f5a1 Jan Allersma 2018-09-18 19:44:44
WIP: Restore 'shapeOptions.d'. 888b8ea647c0f25cfbeefcd97ee7ebb59e7f0751 Jan Allersma 2018-09-18 15:46:05
Rebuild project from scratch. df0f2f82a86581ba9fa3a169d63a950229341a9f Jan Allersma 2018-09-18 15:04:32
Add resize option. 961e464090918d83690ff66838f2fc96c6ad213a Jan Allersma 2018-09-13 18:29:44
Make `MoveCmd` Command-oriented. 2970a8d862285752551be2464422375ca958357f Jan Allersma 2018-09-12 15:33:17
Change of strategy: Make project command-oriented. ce40dffb1675661922411eeb07f148f61a176c22 Jan Allersma 2018-09-12 11:35:45
Initial commit. 38c8818349679937ae25dde38949202ec45ea7b2 Jan Allersma 2018-09-11 20:21:57
Commit 6c911405eb8e48ffe2d63aaff5255adbd4aec889 - Fix minor bug. Small cleanup 'ellipse' code.
- Prevent shapes from having negative size.
- Made the 'CheckBounds' function from the 'Ellipse' class less error prone, which also made the code cleaner and simpler.
Author: Jan Allersma
Author date (UTC): 2018-09-21 18:10
Committer name: Jan Allersma
Committer date (UTC): 2018-10-05 15:56
Parent(s): 6219eca932d454a7dab5fe8679f07865ce3cf49d
Signing key:
Tree: 5a2059bede9e3ea16c79188133de4b4e6011590f
File Lines added Lines deleted
source/shapes/ellipse.d 3 22
source/shapes/rect.d 10 3
File source/shapes/ellipse.d changed (mode: 100644) (index 214fa95..6e1a032)
... ... immutable float pi = 3.141;
11 11 class Ellipse : Shape { class Ellipse : Shape {
12 12
13 13 this(int x, int y, Context context, double size = 0) { this(int x, int y, Context context, double size = 0) {
14 // See 'calcBounds' function to understand what this statement is for.
15 context.scale(0.5, 1);
16
17 14 super(x, y, context, size); super(x, y, context, size);
18 15 } }
19 16
 
... ... class Ellipse : Shape {
47 44 protected override double[2][2] calcBounds(int x, int y) { protected override double[2][2] calcBounds(int x, int y) {
48 45 double[2][2] result; double[2][2] result;
49 46
50 /+
51 In order to create an ellipse, the size of c should
52 be halved on the X-axis, so a circle could be created,
53 which then looks like an ellipse due to halving c.
54
55 If c gets halved twice, the ellipse would look even
56 smaller and the bounds couldn't be calculated properly
57 anymore. Therefore, the size of c on the X-axis will be
58 doubled before the bounds are being calculated in order
59 to prevent halving c's size twice.
60
61 THIS MEANS THAT THIS IS A VERY ERROR-PRONE FUNCTION! BE
62 CAREFUL WITH APPLYING CHANGES TO OR CALLING THIS FUNCTION!
63 +/
64
65 c.scale(2, 1); // Double the size of X-axis to turn c to original size.
66
67 47 result[0][0] = x - size / 2; // minX result[0][0] = x - size / 2; // minX
68 48 result[1][0] = x + size / 2; // maxX result[1][0] = x + size / 2; // maxX
69 49 result[0][1] = y - size; // minY result[0][1] = y - size; // minY
70 50 result[1][1] = y + size; // maxY result[1][1] = y + size; // maxY
71 51
72 c.scale(0.5, 1); // Half the size of X-axis to turn circle to ellipse.
73
74 52 return result; return result;
75 53 } }
76 54
77 55 protected override void draw() { protected override void draw() {
78 56 c.setSourceRgba(Global.Brush.red, Global.Brush.green, Global.Brush.blue, Global.Brush.alpha); c.setSourceRgba(Global.Brush.red, Global.Brush.green, Global.Brush.blue, Global.Brush.alpha);
57
58 c.scale(0.5, 1);
79 59 c.arc(bounds[0][0] * 2 + size, bounds[0][1] + size, size, 0, 2 * pi); c.arc(bounds[0][0] * 2 + size, bounds[0][1] + size, size, 0, 2 * pi);
60 c.scale(2, 1);
80 61 } }
81 62 } }
File source/shapes/rect.d changed (mode: 100644) (index 27e7fe4..24f1b74)
... ... class Rectangle : Shape {
26 26 } }
27 27
28 28 public override void resize(int amount) { public override void resize(int amount) {
29 int[2] newPos = [
30 to!int(bounds[0][0] + size / 2),
31 to!int(bounds[0][1] + size / 2)
29 int[2] newPos;
30
31 // 'size' can become negative number due to 'amount' being a
32 // bigger negative number than 'size' being a positive number.
33 if(size + amount <= 0)
34 return;
35
36 newPos = [
37 to!int(bounds[0][0] + size / 2),
38 to!int(bounds[0][1] + size / 2)
32 39 ]; ];
33 40
34 41 size += amount; size += amount;
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