File source/commands/shapeCommands.d changed (mode: 100644) (index f0bb7e2..dcd2941) |
... |
... |
import dp.shape; |
9 |
9 |
import std.stdio; // For debug. |
import std.stdio; // For debug. |
10 |
10 |
|
|
11 |
11 |
public class CreateCmd : Command { |
public class CreateCmd : Command { |
12 |
|
//size_t shapePtr; |
|
|
12 |
|
public Shape s; |
13 |
13 |
|
|
14 |
14 |
this() { |
this() { |
15 |
|
shapePtr = Global.canvas.childrenAmount; |
|
16 |
|
Global.canvas.addShape(); |
|
17 |
|
File.Append(Global.canvas.getChild(shapePtr).toString()); |
|
|
15 |
|
s = new Shape(); |
|
16 |
|
Global.canvas.addShape(s); |
|
17 |
|
File.Append(s.toString()); |
18 |
18 |
} |
} |
19 |
19 |
|
|
20 |
20 |
public override void execute() { |
public override void execute() { |
21 |
|
//Global.canvas.getChild(shapePtr).isRemoved = false; |
|
|
21 |
|
s.enabled = s.visible = true; |
22 |
22 |
Global.canvas.repaint(); |
Global.canvas.repaint(); |
23 |
23 |
} |
} |
24 |
24 |
|
|
25 |
25 |
public override void undo() { |
public override void undo() { |
26 |
|
//Global.canvas.removeChild(shapePtr); |
|
|
26 |
|
s.enabled = s.visible = false; |
27 |
27 |
Global.canvas.repaint(); |
Global.canvas.repaint(); |
28 |
28 |
} |
} |
29 |
29 |
} |
} |
30 |
30 |
|
|
31 |
31 |
public class MoveCmd : Command { |
public class MoveCmd : Command { |
32 |
|
// size_t shapePtr; |
|
|
32 |
|
size_t shapeIndex; |
33 |
33 |
// bool executed; |
// bool executed; |
34 |
34 |
|
|
35 |
35 |
this () { |
this () { |
36 |
36 |
//executed = false; |
//executed = false; |
|
37 |
|
shapeIndex = Global.canvas.childrenAmount; |
37 |
38 |
execute(); |
execute(); |
38 |
39 |
} |
} |
39 |
40 |
|
|
|
... |
... |
public class MoveCmd : Command { |
45 |
46 |
|
|
46 |
47 |
//Global.canvas.getShape(shapePtr).lastPosition = Global.canvas.getShape(shapePtr).position; |
//Global.canvas.getShape(shapePtr).lastPosition = Global.canvas.getShape(shapePtr).position; |
47 |
48 |
//Global.canvas.getShape(shapePtr).position = tmp; |
//Global.canvas.getShape(shapePtr).position = tmp; |
48 |
|
Global.canvas.getShape(shapePtr).remove(); |
|
|
49 |
|
// Global.canvas.getShape(shapeIndex).remove(); |
49 |
50 |
|
|
50 |
|
Global.canvas.getShape(shapePtr).revive( |
|
|
51 |
|
/+ Global.canvas.getShape(shapeIndex).revive( |
51 |
52 |
12,//Global.canvas.getShape(shapePtr).position[0], |
12,//Global.canvas.getShape(shapePtr).position[0], |
52 |
53 |
177//Global.canvas.getShape(shapePtr).position[1] |
177//Global.canvas.getShape(shapePtr).position[1] |
53 |
54 |
); |
); |
54 |
|
//} |
|
|
55 |
|
+/ //} |
55 |
56 |
} |
} |
56 |
57 |
|
|
57 |
58 |
public override void undo() { |
public override void undo() { |
|
... |
... |
public class MoveCmd : Command { |
62 |
63 |
|
|
63 |
64 |
//Global.canvas.getShape(shapePtr).position = Global.canvas.getShape(shapePtr).lastPosition; |
//Global.canvas.getShape(shapePtr).position = Global.canvas.getShape(shapePtr).lastPosition; |
64 |
65 |
//Global.canvas.getShape(shapePtr).lastPosition = tmp; |
//Global.canvas.getShape(shapePtr).lastPosition = tmp; |
65 |
|
Global.canvas.getShape(shapePtr).remove(); |
|
|
66 |
|
// Global.canvas.getShape(shapeIndex).remove(); |
66 |
67 |
|
|
67 |
68 |
//Global.canvas.getShape(shapePtr).revive( |
//Global.canvas.getShape(shapePtr).revive( |
68 |
69 |
//Global.canvas.getShape(shapePtr).position[0], |
//Global.canvas.getShape(shapePtr).position[0], |
File source/entities/canvas.d changed (mode: 100644) (index fd0ffc5..d23b99b) |
... |
... |
public class Canvas : Entity { |
50 |
50 |
return cast(Entity[]) shapes; |
return cast(Entity[]) shapes; |
51 |
51 |
} |
} |
52 |
52 |
|
|
53 |
|
public Shape getShape(ulong n) { |
|
|
53 |
|
public ref Shape getShape(ulong n) { |
54 |
54 |
return shapes[n]; |
return shapes[n]; |
55 |
55 |
} |
} |
56 |
56 |
|
|
57 |
57 |
public void addChild(ulong n) { |
public void addChild(ulong n) { |
58 |
|
getChild(n).isRemoved = false; |
|
|
58 |
|
getChild(n).enabled = true; |
59 |
59 |
} |
} |
60 |
60 |
|
|
61 |
61 |
public void removeChild(ulong n) { |
public void removeChild(ulong n) { |
62 |
|
getChild(n).isRemoved = true; |
|
|
62 |
|
getChild(n).enabled = false; |
63 |
63 |
} |
} |
64 |
64 |
|
|
65 |
65 |
private bool clickCallback(Event event, Widget widget) { |
private bool clickCallback(Event event, Widget widget) { |
|
... |
... |
public class Canvas : Entity { |
130 |
130 |
area.queueDraw(); |
area.queueDraw(); |
131 |
131 |
} |
} |
132 |
132 |
|
|
133 |
|
public Shape addShape() { |
|
|
133 |
|
public void addShape(ref Shape shape) { |
134 |
134 |
size_t i = shapes.length; |
size_t i = shapes.length; |
135 |
135 |
|
|
|
136 |
|
shape.move(mouseX, mouseY, Context.create(surface)); |
|
137 |
|
|
136 |
138 |
shapes.length++; |
shapes.length++; |
137 |
|
shapes[i] = new Shape(Context.create(surface), mouseX, mouseY); |
|
|
139 |
|
shapes[i] = shape;//new Shape(Context.create(surface), mouseX, mouseY); |
138 |
140 |
|
|
139 |
141 |
area.queueDraw(); |
area.queueDraw(); |
140 |
|
|
|
141 |
|
return shapes[i]; |
|
142 |
142 |
} |
} |
143 |
143 |
} |
} |
File source/entities/shape.d changed (mode: 100644) (index 49c986d..d524870) |
... |
... |
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 bool revivable; |
|
|
16 |
|
/+private+/public bool visible; |
17 |
17 |
|
|
18 |
18 |
/+ |
/+ |
19 |
19 |
bounds[0][0] = minX |
bounds[0][0] = minX |
|
... |
... |
class Shape : Global.Entity { |
22 |
22 |
bounds[1][1] = maxY |
bounds[1][1] = maxY |
23 |
23 |
+/ |
+/ |
24 |
24 |
private double[2][2] bounds; |
private double[2][2] bounds; |
25 |
|
private double[2] lastPos; |
|
|
25 |
|
//private double[2] lastPos; |
26 |
26 |
|
|
27 |
27 |
private string shapeType; |
private string shapeType; |
28 |
28 |
|
|
29 |
29 |
|
|
30 |
|
this(Context context, int x, int y) { |
|
31 |
|
isRemoved = revivable = false; |
|
32 |
|
c = context; |
|
33 |
|
draw(x,y); |
|
|
30 |
|
// this(Context context, int x, int y) { |
|
31 |
|
this() { |
|
32 |
|
enabled = visible = true; |
34 |
33 |
} |
} |
35 |
34 |
|
|
36 |
35 |
@property |
@property |
|
... |
... |
class Shape : Global.Entity { |
38 |
37 |
return bounds[0]; |
return bounds[0]; |
39 |
38 |
} |
} |
40 |
39 |
|
|
41 |
|
@property |
|
|
40 |
|
/* @property |
42 |
41 |
public double[2] lastPosition() { |
public double[2] lastPosition() { |
43 |
42 |
return lastPos; |
return lastPos; |
44 |
|
} |
|
|
43 |
|
} */ |
45 |
44 |
|
|
46 |
|
//TMP? |
|
|
45 |
|
/* //TMP? |
47 |
46 |
@property |
@property |
48 |
47 |
public double[2] lastPosition(double[2] newPos) { |
public double[2] lastPosition(double[2] newPos) { |
49 |
48 |
return lastPos = newPos; |
return lastPos = newPos; |
50 |
|
} |
|
|
49 |
|
} */ |
51 |
50 |
|
|
52 |
51 |
@property |
@property |
53 |
52 |
public double[2] position(double[2] newPos) { |
public double[2] position(double[2] newPos) { |
|
... |
... |
class Shape : Global.Entity { |
75 |
74 |
return shapeType; |
return shapeType; |
76 |
75 |
} |
} |
77 |
76 |
|
|
78 |
|
/+ |
|
79 |
|
Wait for revival of shape until first left-click. |
|
80 |
|
Just to prevent instant movement from |
|
81 |
|
dp.shapeOptions.MoveShape. |
|
82 |
|
+/ |
|
83 |
|
@property |
|
84 |
|
public bool queueRevival (bool revive) { |
|
85 |
|
return revivable = revive; |
|
86 |
|
} |
|
87 |
|
|
|
88 |
77 |
public override string toString() { |
public override string toString() { |
89 |
78 |
return text(type, " ", bounds[0][0], " ", bounds[0][1], " ", sizeX, " ", sizeY); |
return text(type, " ", bounds[0][0], " ", bounds[0][1], " ", sizeX, " ", sizeY); |
90 |
79 |
} |
} |
91 |
80 |
|
|
|
81 |
|
public void move(int x, int y, Context context=null) { |
|
82 |
|
if(context !is null) |
|
83 |
|
c = context; |
|
84 |
|
|
|
85 |
|
draw(x,y); |
|
86 |
|
} |
|
87 |
|
|
92 |
88 |
public void select () { |
public void select () { |
93 |
89 |
c.setSourceRgba(1-Global.Brush.Red, 1-Global.Brush.Green, 1-Global.Brush.Blue, 1); |
c.setSourceRgba(1-Global.Brush.Red, 1-Global.Brush.Green, 1-Global.Brush.Blue, 1); |
94 |
90 |
c.stroke(); |
c.stroke(); |
|
... |
... |
class Shape : Global.Entity { |
97 |
93 |
|
|
98 |
94 |
public void remove () { |
public void remove () { |
99 |
95 |
writeln("Shape removed. Please repaint canvas to see changes."); |
writeln("Shape removed. Please repaint canvas to see changes."); |
100 |
|
isRemoved = true; |
|
101 |
|
revivable = false; |
|
|
96 |
|
visible = enabled = false; |
102 |
97 |
} |
} |
103 |
98 |
|
|
104 |
|
public void revive (int x, int y) { |
|
|
99 |
|
/* public void revive (int x, int y) { |
105 |
100 |
writeln("Im alive! Redraw me!"); |
writeln("Im alive! Redraw me!"); |
106 |
|
isRemoved = false; |
|
|
101 |
|
enabled = true; |
107 |
102 |
c.newPath(); |
c.newPath(); |
108 |
103 |
|
|
109 |
104 |
final switch (type) { |
final switch (type) { |
|
... |
... |
class Shape : Global.Entity { |
185 |
180 |
} |
} |
186 |
181 |
applyToSource(); |
applyToSource(); |
187 |
182 |
Global.canvas.repaint(); |
Global.canvas.repaint(); |
188 |
|
} |
|
|
183 |
|
} */ |
189 |
184 |
|
|
190 |
|
/+private+/public void revive(double x, double y) { revive(cast(int)x, cast(int)y); } |
|
|
185 |
|
/* /+private+/public void revive(double x, double y) { revive(cast(int)x, cast(int)y); } */ |
191 |
186 |
|
|
192 |
187 |
private void draw(int x, int y) { |
private void draw(int x, int y) { |
193 |
|
if(!isRemoved) { |
|
|
188 |
|
if(visible) { |
194 |
189 |
shapeType = Global.Brush.Shape; |
shapeType = Global.Brush.Shape; |
195 |
190 |
final switch (Global.Brush.Shape) { |
final switch (Global.Brush.Shape) { |
196 |
191 |
case "rectangle": |
case "rectangle": |
|
... |
... |
class Shape : Global.Entity { |
233 |
228 |
} |
} |
234 |
229 |
|
|
235 |
230 |
public bool CheckBounds (int x, int y) { |
public bool CheckBounds (int x, int y) { |
236 |
|
if(!isRemoved) { |
|
|
231 |
|
if(enabled) { |
|
232 |
|
writeln(shapeType ~ ":"); |
237 |
233 |
write(bounds[0][0]);write(" <- ");write(x);write(" -> ");writeln(bounds[1][0]); |
write(bounds[0][0]);write(" <- ");write(x);write(" -> ");writeln(bounds[1][0]); |
238 |
234 |
write(bounds[0][1]);write(" <- ");write(y);write(" -> ");writeln(bounds[1][1]); |
write(bounds[0][1]);write(" <- ");write(y);write(" -> ");writeln(bounds[1][1]); |
239 |
235 |
|
|
|
... |
... |
class Shape : Global.Entity { |
247 |
243 |
return true; |
return true; |
248 |
244 |
} |
} |
249 |
245 |
} |
} |
250 |
|
else if(revivable) { |
|
251 |
|
lastPos = [x - sizeX / 2, y - sizeY / 2]; |
|
252 |
|
History.addCommand(new MoveCmd()); |
|
|
246 |
|
else if(visible) { |
|
247 |
|
/* lastPos = [x - sizeX / 2, y - sizeY / 2]; |
|
248 |
|
History.addCommand(new MoveCmd()); */ |
253 |
249 |
} |
} |
254 |
250 |
|
|
255 |
251 |
return false; |
return false; |
|
... |
... |
class Shape : Global.Entity { |
257 |
253 |
|
|
258 |
254 |
// This will be used when the user scrolls on the canvas. |
// This will be used when the user scrolls on the canvas. |
259 |
255 |
public bool CheckBounds (int x, int y, int growContext) { |
public bool CheckBounds (int x, int y, int growContext) { |
260 |
|
if(!isRemoved) { |
|
|
256 |
|
if(enabled) { |
261 |
257 |
//write(bounds[0][0]);write(" <- ");write(x);write(" -> ");writeln(bounds[1][0]); |
//write(bounds[0][0]);write(" <- ");write(x);write(" -> ");writeln(bounds[1][0]); |
262 |
258 |
//write(bounds[0][1]);write(" <- ");write(y);write(" -> ");writeln(bounds[1][1]); |
//write(bounds[0][1]);write(" <- ");write(y);write(" -> ");writeln(bounds[1][1]); |
263 |
259 |
|
|
|
... |
... |
class Shape : Global.Entity { |
278 |
274 |
bounds[0][1] += 5; |
bounds[0][1] += 5; |
279 |
275 |
bounds[1][1] -= 5; |
bounds[1][1] -= 5; |
280 |
276 |
} |
} |
281 |
|
|
|
|
277 |
|
/+ |
282 |
278 |
revive( |
revive( |
283 |
279 |
(bounds[0][0] + bounds[1][0]) / 2, |
(bounds[0][0] + bounds[1][0]) / 2, |
284 |
280 |
(bounds[0][1] + bounds[1][1]) / 2 |
(bounds[0][1] + bounds[1][1]) / 2 |
285 |
281 |
); |
); |
286 |
|
|
|
|
282 |
|
+/ |
287 |
283 |
return true; |
return true; |
288 |
284 |
} |
} |
289 |
285 |
|
|
|
... |
... |
class Shape : Global.Entity { |
292 |
288 |
} |
} |
293 |
289 |
|
|
294 |
290 |
public void applyToSource() { |
public void applyToSource() { |
295 |
|
if(!isRemoved) |
|
|
291 |
|
if(visible) |
296 |
292 |
c.fillPreserve(); |
c.fillPreserve(); |
297 |
293 |
} |
} |
298 |
294 |
} |
} |