view doodle/dia/icanvas.d @ 57:9960c4fbd0dd

I is for Interface
author "David Bryant <bagnose@gmail.com>"
date Sun, 08 Aug 2010 22:01:54 +0930
parents 576b9fba4677
children c63719604adb
line wrap: on
line source

module doodle.dia.icanvas;

public {
    import doodle.tk.geometry;
    import doodle.tk.events;
    import cairo.Context;
}

private {
    import std.typecons;
}

mixin(defineEnum!("Cursor",
                  "DEFAULT", "HAND", "CROSSHAIR"));

interface IViewport {
    void zoomRelative(in Point pixelDatum, in double factor);
    void panRelative(in Vector pixelDisplacement);
    void setCursor(in Cursor cursor);

    // FIXME get rid of these and accumulate damage during event handling
    void damageModel(in Rectangle area);      // FIXME could be an inout parameter of the event handling, or a special scope Damage object that supports growth only
    void damagePixel(in Rectangle area);      // FIXME as above

    /*
    // FIXME hoping we won't need anything like this
    double zoom() const;
    Point modelToPixel(in Point model) const;
    Point pixelToModel(in Point pixel) const;
    Vector modelToPixel(in Vector model) const;
    Vector pixelToModel(in Vector pixel) const;
    Rectangle modelToPixel(in Rectangle model) const;
    Rectangle pixelToModel(in Rectangle model) const;
    double modelToPixel(in double model) const;
    double pixelToModel(in double pixel) const;
    */
}

interface IEventHandler {
    bool handleButtonPress(scope IViewport viewport, in ButtonEvent event);
    bool handleButtonRelease(scope IViewport viewport, in ButtonEvent event);
    bool handleMotion(scope IViewport viewport, in MotionEvent event);
    bool handleScroll(scope IViewport viewport, in ScrollEvent event);
    //bool handleEnter(scope IViewport viewport, CrossingEvent event);
    //bool handleLeave(scope IViewport viewport, CrossingEvent event);
    //bool handleFocusIn(scope IViewport viewport, FocusEvent event);
    //bool handleFocusOut(scope IViewport viewport, FocusEvent event);
    bool handleKeyPress(scope IViewport viewport, in KeyEvent event);
    bool handleKeyRelease(scope IViewport viewport, in KeyEvent event);
}

interface IGrid {
    void zoomChanged(double zoom);

    // TODO  inout?
    bool snap(in Point a, out Point b) const;
}

interface IPage {
    // TODO
}

abstract class Layer {
    this(in string name) {
        mName = name;
    }

    string name() const { return mName; }

    Rectangle bounds() const;

    void draw(in IViewport viewport,
              in Rectangle pixelDamage, scope Context pixelCr,
              in Rectangle modelDamage, scope Context modelCr) const;

    private {
        invariant string mName;
    }
}