File README.md changed (mode: 100644) (index c4d15d1..3d9bf4e) |
... |
... |
This repo is a school project for Design Patterns. |
4 |
4 |
|
|
5 |
5 |
use 'dub' to compile and run the code. |
use 'dub' to compile and run the code. |
6 |
6 |
|
|
7 |
|
# Useful draw functions for `Context` type |
|
8 |
|
|
|
9 |
|
- `fill()`: fill path, then forget path. |
|
10 |
|
|
|
11 |
|
- `fillPreserve()`: fill path, retain path. |
|
12 |
|
|
|
13 |
|
- `fillExtends()`, `strokeExtends()` & `pathExtends()`: return corners |
|
14 |
|
(whatever that may be). |
|
15 |
|
|
|
16 |
|
- `stroke()`: draw line on path, then forget path. |
|
17 |
|
|
|
18 |
|
- `strokePreserve()`: should be obvious. |
|
19 |
|
|
|
20 |
|
- `moveTo()`: Move/Pan path. |
|
21 |
|
|
|
22 |
|
- `scale()`: Scale path. |
|
23 |
|
|
|
24 |
|
- `newPath()`: Clear path from context. |
|
25 |
|
|
|
26 |
|
- `showText()`: Write text with Cairo. |
|
27 |
|
|
|
28 |
7 |
# Entities |
# Entities |
29 |
8 |
|
|
30 |
9 |
`Shapes` are stored in a `Command`. Each `Command` is saved in `History`. |
`Shapes` are stored in a `Command`. Each `Command` is saved in `History`. |
File source/entities/decorator/entornament.d changed (mode: 100644) (index e4f5e81..bcd204c) |
... |
... |
import dp.ent.ornament; |
7 |
7 |
import std.stdio; // Debug |
import std.stdio; // Debug |
8 |
8 |
|
|
9 |
9 |
class EntityOrnament : Decorator { |
class EntityOrnament : Decorator { |
10 |
|
Ornament o; |
|
11 |
|
|
|
12 |
10 |
this(Entity entity) { |
this(Entity entity) { |
13 |
11 |
super(entity); |
super(entity); |
14 |
|
o = null; |
|
|
12 |
|
ornaments = []; |
15 |
13 |
} |
} |
16 |
14 |
|
|
17 |
15 |
@property |
@property |
18 |
16 |
public override string type() { |
public override string type() { |
19 |
17 |
string result = e.type; |
string result = e.type; |
20 |
18 |
|
|
21 |
|
if(o !is null) |
|
|
19 |
|
foreach(o; ornaments) |
22 |
20 |
result ~= "\n" ~ o.type; |
result ~= "\n" ~ o.type; |
23 |
21 |
|
|
24 |
22 |
return result; |
return result; |
|
... |
... |
class EntityOrnament : Decorator { |
29 |
27 |
string result = e.to_string; |
string result = e.to_string; |
30 |
28 |
writeln("PRE-RES: " ~ result); |
writeln("PRE-RES: " ~ result); |
31 |
29 |
|
|
32 |
|
if(o !is null) |
|
|
30 |
|
foreach(o; ornaments) |
33 |
31 |
result ~= "\n" ~ o.to_string; |
result ~= "\n" ~ o.to_string; |
34 |
32 |
|
|
35 |
33 |
writeln("POST_RES: " ~ result); |
writeln("POST_RES: " ~ result); |
|
... |
... |
class EntityOrnament : Decorator { |
39 |
37 |
|
|
40 |
38 |
public override void render() { |
public override void render() { |
41 |
39 |
e.render(); |
e.render(); |
42 |
|
if(o !is null) |
|
|
40 |
|
foreach(o; ornaments) |
43 |
41 |
o.render(); |
o.render(); |
44 |
42 |
} |
} |
45 |
43 |
|
|
46 |
44 |
public void setOrnament(Ornament ornament) { |
public void setOrnament(Ornament ornament) { |
47 |
|
o = ornament; |
|
|
45 |
|
ornaments.length++; |
|
46 |
|
ornaments[ornaments.length - 1] = ornament; |
48 |
47 |
} |
} |
49 |
48 |
} |
} |
File source/entities/ornament.d changed (mode: 100644) (index e11b12c..29ee340) |
... |
... |
class Ornament : Entity { |
14 |
14 |
this.alignment = alignment; |
this.alignment = alignment; |
15 |
15 |
this.value = value; |
this.value = value; |
16 |
16 |
this.context = context; |
this.context = context; |
17 |
|
entity.ornament = this; |
|
|
17 |
|
|
|
18 |
|
entity.ornaments.length++; |
|
19 |
|
entity.ornaments[entity.ornaments.length - 1] = this; |
18 |
20 |
|
|
19 |
21 |
context.setSourceRgba(0.5,0.5,0.5,1); |
context.setSourceRgba(0.5,0.5,0.5,1); |
20 |
22 |
context.selectFontFace("Purisa", CairoFontSlant.NORMAL, CairoFontWeight.BOLD); |
context.selectFontFace("Purisa", CairoFontSlant.NORMAL, CairoFontWeight.BOLD); |
File source/file.d changed (mode: 100644) (index 30f5d68..30fdda9) |
... |
... |
public class Savefile { |
95 |
95 |
private void fromFile(ref File f, ref Entity[] entities) { |
private void fromFile(ref File f, ref Entity[] entities) { |
96 |
96 |
string type; |
string type; |
97 |
97 |
string line; |
string line; |
98 |
|
string[2] o_words = [null, null]; |
|
|
98 |
|
string[2][] o_words = []; |
99 |
99 |
|
|
100 |
100 |
while(!f.eof) { |
while(!f.eof) { |
101 |
101 |
line = strip(f.readln()); |
line = strip(f.readln()); |
|
... |
... |
public class Savefile { |
115 |
115 |
EntityOrnament eo = new EntityOrnament(g); |
EntityOrnament eo = new EntityOrnament(g); |
116 |
116 |
entities[entities.length - 1] = eo; |
entities[entities.length - 1] = eo; |
117 |
117 |
|
|
118 |
|
if(o_words[0] !is null) { |
|
119 |
|
eo.setOrnament(new Ornament(eo, o_words[0], o_words[1], Global.canvas.newContext)); |
|
120 |
|
o_words = [null, null]; |
|
121 |
|
} |
|
|
118 |
|
foreach(wrds; o_words) |
|
119 |
|
eo.setOrnament(new Ornament(eo, wrds[0], wrds[1], Global.canvas.newContext)); |
|
120 |
|
|
|
121 |
|
o_words.length = 0; |
122 |
122 |
|
|
123 |
123 |
writeln("F: group"); |
writeln("F: group"); |
124 |
124 |
break; |
break; |
|
... |
... |
public class Savefile { |
128 |
128 |
EntityOrnament eo = parseShape(words[0], words[1], words[2], words[3]); |
EntityOrnament eo = parseShape(words[0], words[1], words[2], words[3]); |
129 |
129 |
entities[entities.length - 1] = eo; |
entities[entities.length - 1] = eo; |
130 |
130 |
|
|
131 |
|
if(o_words[0] !is null) { |
|
132 |
|
eo.setOrnament(new Ornament(eo, o_words[0], o_words[1], Global.canvas.newContext)); |
|
133 |
|
o_words = [null, null]; |
|
134 |
|
} |
|
|
131 |
|
foreach(wrds; o_words) |
|
132 |
|
eo.setOrnament(new Ornament(eo, wrds[0], wrds[1], Global.canvas.newContext)); |
|
133 |
|
|
|
134 |
|
o_words.length = 0; |
135 |
135 |
|
|
136 |
136 |
writeln("F: shape"); |
writeln("F: shape"); |
137 |
137 |
break; |
break; |
138 |
138 |
case "ornament": |
case "ornament": |
139 |
|
o_words = [words[1], words[2]]; |
|
|
139 |
|
o_words.length++; |
|
140 |
|
o_words[o_words.length - 1] = [words[1], words[2]]; |
140 |
141 |
entities.length--; |
entities.length--; |
141 |
142 |
|
|
142 |
143 |
writeln("F: ornament"); |
writeln("F: ornament"); |
File source/frontend/ornamentDialog.d changed (mode: 100644) (index ded2560..fcebbd3) |
... |
... |
import dp.ent.ornament; |
13 |
13 |
import dp.dec.entornament; |
import dp.dec.entornament; |
14 |
14 |
import dp.command.create; |
import dp.command.create; |
15 |
15 |
|
|
|
16 |
|
import std.stdio; // Debug |
|
17 |
|
|
16 |
18 |
import Global = dp.global; |
import Global = dp.global; |
17 |
19 |
|
|
18 |
20 |
class OrnamentDialog : Dialog { |
class OrnamentDialog : Dialog { |
|
... |
... |
class OrnamentDialog : Dialog { |
74 |
76 |
|
|
75 |
77 |
private void clickCallback(Button button) { |
private void clickCallback(Button button) { |
76 |
78 |
string input = factorEntry.getText(); |
string input = factorEntry.getText(); |
77 |
|
EntityOrnament eo = new EntityOrnament(e); |
|
78 |
79 |
|
|
79 |
80 |
if(e is null) |
if(e is null) |
80 |
81 |
this.close(); |
this.close(); |
81 |
82 |
|
|
|
83 |
|
EntityOrnament eo = new EntityOrnament(e); |
|
84 |
|
write("O: ");write(&e);write(", ");writeln(e.ornaments.length); |
|
85 |
|
|
82 |
86 |
if(input != "") { |
if(input != "") { |
83 |
87 |
Ornament o = new Ornament(e, position, input, Global.canvas.newContext); |
Ornament o = new Ornament(e, position, input, Global.canvas.newContext); |
84 |
88 |
Global.History.addCommand(new CreateCmd(o)); |
Global.History.addCommand(new CreateCmd(o)); |
File source/vistors/saveVisitor.d changed (mode: 100644) (index 54e12f5..1df58e0) |
... |
... |
public class SaveVisitor : Visitor { |
11 |
11 |
} |
} |
12 |
12 |
|
|
13 |
13 |
public override void visit(Shape s) { |
public override void visit(Shape s) { |
14 |
|
if(s.ornament !is null) |
|
15 |
|
s.ornament.accept(new SaveVisitor(f)); |
|
|
14 |
|
foreach(ornament; s.ornaments) |
|
15 |
|
ornament.accept(new SaveVisitor(f)); |
16 |
16 |
|
|
17 |
17 |
f.toFile(s); |
f.toFile(s); |
18 |
18 |
} |
} |
19 |
19 |
|
|
20 |
20 |
public override void visit(Group g) { |
public override void visit(Group g) { |
21 |
|
if(g.ornament !is null) |
|
22 |
|
g.ornament.accept(new SaveVisitor(f)); |
|
|
21 |
|
foreach(ornament; g.ornaments) |
|
22 |
|
ornament.accept(new SaveVisitor(f)); |
23 |
23 |
|
|
24 |
24 |
f.toFile(g); |
f.toFile(g); |
25 |
25 |
|
|