Mercurial > projects > doodle
annotate doodle/main/prog/doodler.d @ 60:e64baac3efb2
Attempt at a templatised palette
author | David Bryant <bagnose@gmail.com> |
---|---|
date | Tue, 10 Aug 2010 22:55:54 +0930 |
parents | c63719604adb |
children | 08ffc44fc21a |
rev | line source |
---|---|
28
1754cb773d41
Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
27
diff
changeset
|
1 private { |
44 | 2 import doodle.core.backtrace; |
38
452915ecd1f4
Basic logging functionality
David Bryant <bagnose@gmail.com>
parents:
35
diff
changeset
|
3 import doodle.core.logging; |
45 | 4 import doodle.core.backtrace; |
38
452915ecd1f4
Basic logging functionality
David Bryant <bagnose@gmail.com>
parents:
35
diff
changeset
|
5 |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
6 import doodle.dia.standard_tools; |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
7 import doodle.dia.page_layer; |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
8 import doodle.dia.grid_layer; |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
9 import doodle.fig.diagram_layer; |
28
1754cb773d41
Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
27
diff
changeset
|
10 import doodle.dia.tool_layer; |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
11 |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
12 import doodle.fig.tools; |
20 | 13 |
28
1754cb773d41
Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
27
diff
changeset
|
14 import doodle.gtk.canvas; |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
15 import doodle.gtk.palette2; |
27 | 16 |
20 | 17 import gtk.Main; |
18 import gtk.MainWindow; | |
27 | 19 import gtk.VBox; |
20 | 20 |
21 import std.stdio; | |
22 } | |
23 | |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
24 final class TopLevel : private IToolStackObserver { |
56 | 25 this(string[] args) { |
26 Main.init(args); | |
27 auto window = new MainWindow("Doodle"); | |
28 auto vbox = new VBox(false, 0); | |
54 | 29 |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
30 auto palette = new Palette2!Tool; |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
31 _palette = palette; |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
32 |
56 | 33 vbox.packStart(palette, false, false, 0); |
34 | |
35 Tool[] tools; | |
36 tools ~= new PanTool; | |
37 tools ~= new ZoomTool; | |
38 tools ~= new SelectTool; | |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
39 auto toolLayer = new ToolLayer(tools, this); |
56 | 40 _toolStack = toolLayer; |
41 | |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
42 auto gridLayer = new GridLayer; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
43 |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
44 auto diagramLayer = new DiagramLayer; |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
45 _diagram = diagramLayer; |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
46 |
56 | 47 Layer[] layers; |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
48 layers ~= new PageLayer; |
56 | 49 layers ~= gridLayer; |
50 layers ~= toolLayer; | |
51 auto canvas = new Canvas(layers, toolLayer, gridLayer, 120.0); | |
51 | 52 |
56 | 53 vbox.packStart(canvas, true, true, 0); |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
54 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
55 Palette2!Tool.Item[] items = [ |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
56 { "select.svg", "Select", "Select and modify elements", new SelectTool }, |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
57 { "rectangle.svg", "Rectangle", "Create rectangle", new CreateRectangleTool(_diagram) }, |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
58 { "ellipse.svg", "Ellipse", "Create ellipse", new CreateRectangleTool(_diagram) }, |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
59 { "polyline.svg", "Polyline", "Create polyline", new CreateRectangleTool(_diagram) } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
60 ]; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
61 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
62 palette.configure(items, &paletteCallback); |
56 | 63 window.add(vbox); |
64 window.setDefaultSize(640, 580); | |
65 window.showAll(); | |
66 Main.run(); | |
67 } | |
51 | 68 |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
69 void toolChanged(Tool tool) { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
70 message("Tool changed %s", tool.name); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
71 _palette.activate(tool); |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
72 } |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
73 |
56 | 74 private { |
57 | 75 IToolStack _toolStack; |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
76 Palette2!Tool _palette; // FIXME refer to the interface? |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
77 IDiagram _diagram; |
51 | 78 |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
79 void paletteCallback(Tool tool) { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
58
diff
changeset
|
80 _toolStack.use(tool); |
56 | 81 } |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
82 |
56 | 83 } |
20 | 84 } |
56 | 85 |
86 void main(string[] args) { | |
87 new TopLevel(args); | |
88 } |