view tk/events.d @ 5:8a39b13cd3e6

Checkpoint
author David Bryant <daveb@acres.com.au>
date Fri, 10 Jul 2009 18:19:16 +0930
parents 7d57cae10805
children a27d2093991c
line wrap: on
line source

module tk.events;

import tk.types;
import tk.geometry;

//
// Should we pass the screen and model points into
// the events or pass a transform in separately to the handler
//

abstract class Event {
    this() {
    }

    private {
    }
}

final class ExposeEvent : Event {
    this() {
        super();
    }

    private {
    }
}

abstract class InputEvent : Event {
    this(in Mask mask) {
        mMask = new Mask(mask);
    }

    const(Mask) mask() const { return mMask; }

    private {
        Mask mMask;
    }
}

final class CrossingEvent : InputEvent {
    this(Mask mask) {
        super(mask);
    }

    private {
    }
}

final class KeyEvent : InputEvent {
    this(string str, uint value, Mask mask) {
        super(mask);
        mStr = str;
        mValue = value;
    }

    string str() const { return mStr; }

    override string toString() const {
        return std.string.format("Key event: %s, %d", mStr, mValue);
    }

    private {
        string mStr;
        uint mValue;
    }
}

abstract class PointerEvent : InputEvent {
    this(in Point screen_point, in Point model_point, in Mask mask) {
        super(mask);
        mScreenPoint = screen_point;
        mModelPoint = model_point;
    }

    Point screen_point() const { return mScreenPoint; }
    Point model_point() const { return mModelPoint; }

    private {
        Point mScreenPoint;
        Point mModelPoint;
    }
}

final class ButtonEvent : PointerEvent {
    this(ButtonPress button_press,
         ButtonNumber button_number,
         Point screen_point,
         Point model_point,
         Mask mask) {   
        super(screen_point, model_point, mask);
        mButtonPress = button_press;
        mButtonNumber = button_number;
    }

    override string toString() const {
        return std.string.format("Button event: %s, %s, %s, %s, %s", mButtonPress, mButtonNumber, mScreenPoint, mModelPoint, mMask);
    }

    ButtonPress button_press() const { return mButtonPress; }
    ButtonNumber button_number() const { return mButtonNumber; }

    private {
        ButtonPress mButtonPress;
        ButtonNumber mButtonNumber;
    }
}

final class MotionEvent : PointerEvent {
    this(in Point screen_point,
         in Point model_point,
         in Mask mask) {
        super(screen_point, model_point, mask);
    }

    override string toString() const {
        return std.string.format("Motion event: %s, %s, %s", mScreenPoint, mModelPoint, mMask);
    }
}

final class ScrollEvent : PointerEvent {
    this(in ScrollDirection scroll_direction,
         in Point screen_point,
         in Point model_point,
         in Mask mask) {
        super(screen_point, model_point, mask);
        mScrollDirection = scroll_direction;
    }

    override string toString() const {
        return std.string.format("Scroll event: %s, %s, %s, %s", mScrollDirection, mScreenPoint, mModelPoint, mMask);
    }

    ScrollDirection scroll_direction() const { return mScrollDirection; }

    private {
        ScrollDirection mScrollDirection;
    }
}