Mercurial > projects > doodle
diff tk/events.d @ 0:e907d2c54ec3
Initial import
author | David Bryant <daveb@acres.com.au> |
---|---|
date | Wed, 13 May 2009 15:42:39 +0930 |
parents | |
children | d6f44347373d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tk/events.d Wed May 13 15:42:39 2009 +0930 @@ -0,0 +1,138 @@ +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(Mask mask) { + mMask = mask; + } + + Mask mask() { 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() { return mStr; } + + override string toString() { + return std.string.format("Key event: %s, %d", mStr, mValue); + } + + private { + string mStr; + uint mValue; + } +} + +abstract class PointerEvent : InputEvent { + this(Point screen_point, Point model_point, Mask mask) { + super(mask); + mScreenPoint = screen_point; + mModelPoint = model_point; + } + + Point screen_point() { return mScreenPoint; } + Point model_point() { 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() { + return std.string.format("Button event: %s, %s, %s, %s, %s", mButtonPress, mButtonNumber, mScreenPoint, mModelPoint, mMask); + } + + ButtonPress button_press() { return mButtonPress; } + ButtonNumber button_number() { return mButtonNumber; } + + private { + ButtonPress mButtonPress; + ButtonNumber mButtonNumber; + } +} + +final class MotionEvent : PointerEvent { + this(Point screen_point, + Point model_point, + Mask mask) { + super(screen_point, model_point, mask); + } + + override string toString() { + return std.string.format("Motion event: %s, %s, %s", mScreenPoint, mModelPoint, mMask); + } +} + +final class ScrollEvent : PointerEvent { + this(ScrollDirection scroll_direction, + Point screen_point, + Point model_point, + Mask mask) { + super(screen_point, model_point, mask); + mScrollDirection = scroll_direction; + } + + override string toString() { + return std.string.format("Scroll event: %s, %s, %s, %s", mScrollDirection, mScreenPoint, mModelPoint, mMask); + } + + ScrollDirection scroll_direction() { return mScrollDirection; } + + private { + ScrollDirection mScrollDirection; + } +}