# HG changeset patch # User David Bryant # Date 1251641191 -34200 # Node ID 188397ef9a120211e6740cbb255ea36c20e6f308 # Parent 3f6bb0bb22dcc3ed3a3a17a15cae857910bbba3a Late night tinkering diff -r 3f6bb0bb22dc -r 188397ef9a12 doodle/common/undo.d --- a/doodle/common/undo.d Sun Aug 30 22:14:01 2009 +0930 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -module doodle.common.undo; - -abstract class Action { - void undo(); - void redo(); -} - -interface IUndoObserver { - void canUndo(in bool value, in string description); - void canRedo(in bool value, in string description); -} - -interface IUndoManager { - void addAction(Action action); -} diff -r 3f6bb0bb22dc -r 188397ef9a12 doodle/dia/grid_layer.d --- a/doodle/dia/grid_layer.d Sun Aug 30 22:14:01 2009 +0930 +++ b/doodle/dia/grid_layer.d Sun Aug 30 23:36:31 2009 +0930 @@ -22,6 +22,7 @@ this(in string name) { super(name); + mZoomValid = false; } // Layer overrides: @@ -36,8 +37,12 @@ in Rectangle model_damage, scope Context model_cr) const { assert(mZoomValid); + double xx = 1.0, yy = 1.0; + model_cr.userToDeviceDistance(xx, yy); + model_cr.save(); { - model_cr.setLineWidth(1.0); + model_cr.setSourceRgba(0.0, 0.0, 0.0, 0.3); + model_cr.setLineWidth(0.5); { // vertical grid lines @@ -47,7 +52,13 @@ for (;;) { line(model_cr, x, y0, x, y1); - model_cr.stroke(); + + // Ensure 1 pixel wide FIXME is this naughty? We are sneaking + // through cairo to mix model and pixel coordinates... + model_cr.save(); { + model_cr.scale(1.0 / xx, 1.0 / yy); + model_cr.stroke(); + } model_cr.restore(); if (x > model_damage.max_corner.x) { break; @@ -65,7 +76,11 @@ for (;;) { line(model_cr, x0, y, x1, y); - model_cr.stroke(); + + model_cr.save(); { + model_cr.scale(1.0 / xx, 1.0 / yy); + model_cr.stroke(); + } model_cr.restore(); if (y > model_damage.max_corner.y) { break; @@ -75,20 +90,20 @@ } } } model_cr.restore(); - - - //double start_x = modf(damage.min_corner.x, zoom); } // Grid overrides: - void zoom_changed(double zoom) { + override void zoom_changed(double zoom) { mZoom = zoom; mZoomValid = true; - mSpacing = 20.0; // mm + + // FIXME compute spacing properly + mSpacing = 10.0 / mZoom; // mm } - bool snap(in Point a, out Point b) const { + // FIXME use inout parameter? + override bool snap(in Point a, out Point b) const { b = a; return false; } diff -r 3f6bb0bb22dc -r 188397ef9a12 doodle/dia/icanvas.d --- a/doodle/dia/icanvas.d Sun Aug 30 22:14:01 2009 +0930 +++ b/doodle/dia/icanvas.d Sun Aug 30 23:36:31 2009 +0930 @@ -52,10 +52,14 @@ interface Grid { void zoom_changed(double zoom); - // TODO + // TODO inout? bool snap(in Point a, out Point b) const; } +interface Page { + // TODO +} + abstract class Layer { this(in string name) { mName = name; diff -r 3f6bb0bb22dc -r 188397ef9a12 doodle/dia/page_layer.d --- a/doodle/dia/page_layer.d Sun Aug 30 22:14:01 2009 +0930 +++ b/doodle/dia/page_layer.d Sun Aug 30 23:36:31 2009 +0930 @@ -1,14 +1,11 @@ module doodle.dia.page_layer; -private { - import doodle.cairo.routines; -} - public { import doodle.dia.icanvas; } -interface Page { +private { + import doodle.cairo.routines; } class PageLayer : Layer, Page { @@ -18,6 +15,8 @@ //mPageGeometry = Rectangle(Point.DEFAULT, Vector(100.0, 100.0)); } + // Layer overrides: + override Rectangle bounds() const { return mPageGeometry; } @@ -40,6 +39,8 @@ } model_cr.restore; } + // Page overrides: + private { Rectangle mPageGeometry; } diff -r 3f6bb0bb22dc -r 188397ef9a12 doodle/dia/standard_tools.d --- a/doodle/dia/standard_tools.d Sun Aug 30 22:14:01 2009 +0930 +++ b/doodle/dia/standard_tools.d Sun Aug 30 23:36:31 2009 +0930 @@ -89,7 +89,7 @@ } } -final class LassoTool : Tool { +final class LassoTool : Tool { // TODO convert to SelectTool override bool handle_button_press(scope Viewport viewport, in ButtonEvent event) { if (event.button_name == ButtonName.LEFT) { mActive = true; diff -r 3f6bb0bb22dc -r 188397ef9a12 doodle/dia/tool_layer.d --- a/doodle/dia/tool_layer.d Sun Aug 30 22:14:01 2009 +0930 +++ b/doodle/dia/tool_layer.d Sun Aug 30 23:36:31 2009 +0930 @@ -1,20 +1,37 @@ module doodle.dia.tool_layer; +public { + import doodle.dia.tool; +} + private { import std.stdio; import doodle.cairo.routines; } -public { - import doodle.dia.tool; -} - class ToolLayer : Layer, EventHandler { this(in Tool[] tools, in string name) { super(name); mTools = tools.dup; } + // Layer overrides: + + override Rectangle bounds() const { + return Rectangle(); + } + + override void draw(const Viewport viewport, + in Rectangle pixel_damage, scope Context pixel_cr, + in Rectangle model_damage, scope Context model_cr) const { + // FIXME this isn't how we will really draw the tools... + foreach (const Tool tool; mTools) { + tool.draw(viewport, pixel_damage, pixel_cr, model_damage, model_cr); + } + } + + // EventHandler overrides: + override bool handle_button_press(scope Viewport viewport, in ButtonEvent event) { // writefln("%s", event); @@ -94,19 +111,6 @@ return true; } - override Rectangle bounds() const { - return Rectangle(); - } - - override void draw(const Viewport viewport, - in Rectangle pixel_damage, scope Context pixel_cr, - in Rectangle model_damage, scope Context model_cr) const { - // FIXME this isn't how we will really draw the tools... - foreach (const Tool tool; mTools) { - tool.draw(viewport, pixel_damage, pixel_cr, model_damage, model_cr); - } - } - /* override void push(Tool tool) { }