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/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/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/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/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 |
} |
} |