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; |