File source/commands/shapeCommands.d changed (mode: 100644) (index dcd2941..06b10d2) |
... |
... |
public class CreateCmd : Command { |
29 |
29 |
} |
} |
30 |
30 |
|
|
31 |
31 |
public class MoveCmd : Command { |
public class MoveCmd : Command { |
32 |
|
size_t shapeIndex; |
|
33 |
|
// bool executed; |
|
34 |
|
|
|
35 |
|
this () { |
|
36 |
|
//executed = false; |
|
37 |
|
shapeIndex = Global.canvas.childrenAmount; |
|
|
32 |
|
Shape original; |
|
33 |
|
Shape newShape; |
|
34 |
|
|
|
35 |
|
this (Shape original) { |
|
36 |
|
this.original = original; |
|
37 |
|
newShape = new Shape(); |
|
38 |
|
Global.Brush.Shape = original.type; |
|
39 |
|
Global.canvas.addShape(newShape); |
38 |
40 |
execute(); |
execute(); |
39 |
41 |
} |
} |
40 |
42 |
|
|
41 |
43 |
public override void execute() { |
public override void execute() { |
42 |
|
//if(!executed) { |
|
43 |
|
//double[2] tmp = Global.canvas.getShape(shapePtr).lastPosition; |
|
44 |
|
|
|
45 |
|
//executed = true; |
|
46 |
|
|
|
47 |
|
//Global.canvas.getShape(shapePtr).lastPosition = Global.canvas.getShape(shapePtr).position; |
|
48 |
|
//Global.canvas.getShape(shapePtr).position = tmp; |
|
49 |
|
// Global.canvas.getShape(shapeIndex).remove(); |
|
50 |
|
|
|
51 |
|
/+ Global.canvas.getShape(shapeIndex).revive( |
|
52 |
|
12,//Global.canvas.getShape(shapePtr).position[0], |
|
53 |
|
177//Global.canvas.getShape(shapePtr).position[1] |
|
54 |
|
); |
|
55 |
|
+/ //} |
|
|
44 |
|
original.visible = original.enabled = false; |
|
45 |
|
newShape.visible = newShape.enabled = true; |
56 |
46 |
} |
} |
57 |
47 |
|
|
58 |
48 |
public override void undo() { |
public override void undo() { |
59 |
|
//if(executed) { |
|
60 |
|
//double[2] tmp = Global.canvas.getShape(shapePtr).position; |
|
61 |
|
|
|
62 |
|
//executed = false; |
|
63 |
|
|
|
64 |
|
//Global.canvas.getShape(shapePtr).position = Global.canvas.getShape(shapePtr).lastPosition; |
|
65 |
|
//Global.canvas.getShape(shapePtr).lastPosition = tmp; |
|
66 |
|
// Global.canvas.getShape(shapeIndex).remove(); |
|
67 |
|
|
|
68 |
|
//Global.canvas.getShape(shapePtr).revive( |
|
69 |
|
//Global.canvas.getShape(shapePtr).position[0], |
|
70 |
|
//Global.canvas.getShape(shapePtr).position[1] |
|
71 |
|
//); |
|
72 |
|
//} |
|
|
49 |
|
original.visible = original.enabled = true; |
|
50 |
|
newShape.visible = newShape.enabled = false; |
73 |
51 |
} |
} |
74 |
52 |
} |
} |
File source/entities/shape.d changed (mode: 100644) (index d524870..bb2a901) |
... |
... |
import cairo.Context; |
6 |
6 |
import cairo.ImageSurface; |
import cairo.ImageSurface; |
7 |
7 |
|
|
8 |
8 |
import std.stdio; // For debug |
import std.stdio; // For debug |
9 |
|
import std.conv; |
|
|
9 |
|
import std.conv; // Redundant? |
10 |
10 |
|
|
11 |
11 |
import dp.history; |
import dp.history; |
12 |
12 |
import dp.command.shape; |
import dp.command.shape; |
13 |
13 |
|
|
14 |
14 |
class Shape : Global.Entity { |
class Shape : Global.Entity { |
15 |
15 |
private Context c; |
private Context c; |
16 |
|
/+private+/public bool visible; |
|
|
16 |
|
public bool visible; // Should be encapsulated. |
|
17 |
|
private string shapeType; |
17 |
18 |
|
|
18 |
19 |
/+ |
/+ |
19 |
20 |
bounds[0][0] = minX |
bounds[0][0] = minX |
|
... |
... |
class Shape : Global.Entity { |
22 |
23 |
bounds[1][1] = maxY |
bounds[1][1] = maxY |
23 |
24 |
+/ |
+/ |
24 |
25 |
private double[2][2] bounds; |
private double[2][2] bounds; |
25 |
|
//private double[2] lastPos; |
|
26 |
|
|
|
27 |
|
private string shapeType; |
|
28 |
|
|
|
29 |
26 |
|
|
30 |
|
// this(Context context, int x, int y) { |
|
31 |
27 |
this() { |
this() { |
32 |
28 |
enabled = visible = true; |
enabled = visible = true; |
33 |
29 |
} |
} |
|
... |
... |
class Shape : Global.Entity { |
37 |
33 |
return bounds[0]; |
return bounds[0]; |
38 |
34 |
} |
} |
39 |
35 |
|
|
40 |
|
/* @property |
|
41 |
|
public double[2] lastPosition() { |
|
42 |
|
return lastPos; |
|
43 |
|
} */ |
|
44 |
|
|
|
45 |
|
/* //TMP? |
|
46 |
|
@property |
|
47 |
|
public double[2] lastPosition(double[2] newPos) { |
|
48 |
|
return lastPos = newPos; |
|
49 |
|
} */ |
|
50 |
|
|
|
51 |
36 |
@property |
@property |
52 |
37 |
public double[2] position(double[2] newPos) { |
public double[2] position(double[2] newPos) { |
53 |
38 |
double sX = sizeX; |
double sX = sizeX; |
|
... |
... |
class Shape : Global.Entity { |
92 |
77 |
} |
} |
93 |
78 |
|
|
94 |
79 |
public void remove () { |
public void remove () { |
95 |
|
writeln("Shape removed. Please repaint canvas to see changes."); |
|
96 |
80 |
visible = enabled = false; |
visible = enabled = false; |
97 |
81 |
} |
} |
98 |
82 |
|
|
99 |
|
/* public void revive (int x, int y) { |
|
100 |
|
writeln("Im alive! Redraw me!"); |
|
101 |
|
enabled = true; |
|
102 |
|
c.newPath(); |
|
103 |
|
|
|
104 |
|
final switch (type) { |
|
105 |
|
case "rectangle": |
|
106 |
|
c.rectangle(x, y, sizeX, sizeY); |
|
107 |
|
c.fillPreserve(); |
|
108 |
|
|
|
109 |
|
/+ |
|
110 |
|
Recalculate the bounds, since they changed due to |
|
111 |
|
moving the shape. |
|
112 |
|
|
|
113 |
|
Since sizeX and sizeY change to different values |
|
114 |
|
during recalculation of bounds, due to sizeX and |
|
115 |
|
sizeY are based off the bounds, sizeX and sizeY |
|
116 |
|
have to be captured before recalculation. |
|
117 |
|
+/ |
|
118 |
|
double sX = sizeX; |
|
119 |
|
double sY = sizeY; |
|
120 |
|
bounds[0][0] = x; |
|
121 |
|
bounds[1][0] = x + sX; |
|
122 |
|
bounds[0][1] = y; |
|
123 |
|
bounds[1][1] = y + sY; |
|
124 |
|
|
|
125 |
|
break; |
|
126 |
|
case "ellipse": |
|
127 |
|
/+ |
|
128 |
|
3.141 = Pi. |
|
129 |
|
sizeY is in diameters. Parameter arc() requires radius. |
|
130 |
|
+/ |
|
131 |
|
c.arc(x * 2 + sizeX / 2, y + sizeY / 2, sizeY / 2 , 0 , 2 * 3.141); |
|
132 |
|
c.fillPreserve(); |
|
133 |
|
|
|
134 |
|
/+ |
|
135 |
|
No need to scale c again. That has been preserved |
|
136 |
|
from the first time it was drawn. |
|
137 |
|
|
|
138 |
|
Recalculate the bounds, since they changed due to |
|
139 |
|
moving the shape. |
|
140 |
|
|
|
141 |
|
Since sizeX and sizeY change to different values |
|
142 |
|
during recalculation of bounds, due to sizeX and |
|
143 |
|
sizeY are based off the bounds, sizeX and sizeY |
|
144 |
|
have to be captured before recalculation. |
|
145 |
|
+/ |
|
146 |
|
double sX = sizeX; |
|
147 |
|
double sY = sizeY; |
|
148 |
|
bounds[0][0] = x; |
|
149 |
|
bounds[1][0] = x + sX; |
|
150 |
|
bounds[0][1] = y; |
|
151 |
|
bounds[1][1] = y + sY; |
|
152 |
|
|
|
153 |
|
break; |
|
154 |
|
case "circle": |
|
155 |
|
/+ |
|
156 |
|
3.141 = Pi. |
|
157 |
|
sizeY is in diameters. Parameter arc() requires radius. |
|
158 |
|
+/ |
|
159 |
|
c.arc(x + sizeX / 2, y + sizeY / 2, sizeY / 2 , 0 , 2 * 3.141); |
|
160 |
|
c.fillPreserve(); |
|
161 |
|
|
|
162 |
|
/+ |
|
163 |
|
Recalculate the bounds, since they changed due to |
|
164 |
|
moving the shape. |
|
165 |
|
|
|
166 |
|
Since sizeX and sizeY change to different values |
|
167 |
|
during recalculation of bounds, due to sizeX and |
|
168 |
|
sizeY are based off the bounds, sizeX and sizeY |
|
169 |
|
have to be captured before recalculation. |
|
170 |
|
+/ |
|
171 |
|
double sX = sizeX; |
|
172 |
|
double sY = sizeY; |
|
173 |
|
bounds[0][0] = x; |
|
174 |
|
bounds[1][0] = x + sX; |
|
175 |
|
bounds[0][1] = y; |
|
176 |
|
bounds[1][1] = y + sY; |
|
177 |
|
|
|
178 |
|
break; |
|
179 |
|
|
|
180 |
|
} |
|
181 |
|
applyToSource(); |
|
182 |
|
Global.canvas.repaint(); |
|
183 |
|
} */ |
|
184 |
|
|
|
185 |
|
/* /+private+/public void revive(double x, double y) { revive(cast(int)x, cast(int)y); } */ |
|
186 |
|
|
|
187 |
83 |
private void draw(int x, int y) { |
private void draw(int x, int y) { |
188 |
84 |
if(visible) { |
if(visible) { |
189 |
85 |
shapeType = Global.Brush.Shape; |
shapeType = Global.Brush.Shape; |
|
... |
... |
class Shape : Global.Entity { |
243 |
139 |
return true; |
return true; |
244 |
140 |
} |
} |
245 |
141 |
} |
} |
246 |
|
else if(visible) { |
|
247 |
|
/* lastPos = [x - sizeX / 2, y - sizeY / 2]; |
|
248 |
|
History.addCommand(new MoveCmd()); */ |
|
249 |
|
} |
|
|
142 |
|
else if(visible) |
|
143 |
|
History.addCommand(new MoveCmd(this)); |
250 |
144 |
|
|
251 |
145 |
return false; |
return false; |
252 |
146 |
} |
} |
|
... |
... |
class Shape : Global.Entity { |
254 |
148 |
// This will be used when the user scrolls on the canvas. |
// This will be used when the user scrolls on the canvas. |
255 |
149 |
public bool CheckBounds (int x, int y, int growContext) { |
public bool CheckBounds (int x, int y, int growContext) { |
256 |
150 |
if(enabled) { |
if(enabled) { |
257 |
|
//write(bounds[0][0]);write(" <- ");write(x);write(" -> ");writeln(bounds[1][0]); |
|
258 |
|
//write(bounds[0][1]);write(" <- ");write(y);write(" -> ");writeln(bounds[1][1]); |
|
259 |
|
|
|
260 |
151 |
if( |
if( |
261 |
152 |
x > bounds[0][0] && // minX |
x > bounds[0][0] && // minX |
262 |
153 |
x < bounds[1][0] && // maxX |
x < bounds[1][0] && // maxX |
|
... |
... |
class Shape : Global.Entity { |
274 |
165 |
bounds[0][1] += 5; |
bounds[0][1] += 5; |
275 |
166 |
bounds[1][1] -= 5; |
bounds[1][1] -= 5; |
276 |
167 |
} |
} |
277 |
|
/+ |
|
278 |
|
revive( |
|
279 |
|
(bounds[0][0] + bounds[1][0]) / 2, |
|
280 |
|
(bounds[0][1] + bounds[1][1]) / 2 |
|
281 |
|
); |
|
282 |
|
+/ |
|
283 |
168 |
return true; |
return true; |
284 |
169 |
} |
} |
285 |
|
|
|
286 |
170 |
} |
} |
287 |
171 |
return false; |
return false; |
288 |
172 |
} |
} |