diff doodle/gtk/events.d @ 73:6f2525e170f2

Cairo/OpenGL checkpoint
author "David Bryant <bagnose@gmail.com>"
date Sun, 15 Aug 2010 01:02:15 +0930
parents
children 15ca7d5cd1ed
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doodle/gtk/events.d	Sun Aug 15 01:02:15 2010 +0930
@@ -0,0 +1,155 @@
+module doodle.gtk.events;
+
+public {
+    import doodle.tk.events;
+}
+
+private {
+    import doodle.gtk.conversions;
+
+    import core.stdc.string : strlen;
+}
+
+
+// Functions for creating the events
+
+/*
+   public struct GdkEventButton {
+   GdkEventType type;
+   GdkWindow *window;
+   byte sendEvent;
+   uint time;
+   double x;
+   double y;
+   double *axes;
+   uint state;
+   uint button;
+   GdkDevice *device;
+   double xRoot, yRoot;
+   }
+*/
+
+ButtonEvent makeButtonEvent(const GdkEventButton * event, in PixelModel pixelModel) {
+    Point pixelPoint = Point(event.x + 0.5, pixelModel.viewBounds.h - (event.y + 0.5));
+    Point modelPoint = pixelModel.pixelToModel(pixelPoint);
+    return new ButtonEvent(gtk2tkButtonAction(event.type),
+                           gtk2tkButtonName(event.button),
+                           pixelPoint, modelPoint, gtk2tkMask(event.state));
+}
+
+/*
+   public struct GdkEventMotion {
+   GdkEventType type;
+   GdkWindow *window;
+   byte sendEvent;
+   uint time;
+   double x;
+   double y;
+   double *axes;
+   uint state;
+   short isHint;
+   GdkDevice *device;
+   double xRoot, yRoot;
+   }
+ */
+
+MotionEvent makeMotionEvent(const GdkEventMotion * event, in PixelModel pixelModel) {
+    Point pixelPoint = Point(event.x + 0.5, pixelModel.viewBounds.h - (event.y + 0.5));
+    Point modelPoint = pixelModel.pixelToModel(pixelPoint);
+
+    return new MotionEvent(pixelPoint, modelPoint, gtk2tkMask(event.state));
+}
+
+/*
+   public struct GdkEventKey {
+   GdkEventType type;
+   GdkWindow *window;
+   byte sendEvent;
+   uint time;
+   uint state;
+   uint keyval;
+   int length;
+   char *string;
+   ushort hardwareKeycode;
+   ubyte group;
+   uint bitfield0;
+   uint isModifier : 1;
+   }
+ */
+
+KeyEvent makeKeyEvent(const GdkEventKey * event, in PixelModel pixelModel) {
+    return new KeyEvent(event.string[0..strlen(event.string)].idup,
+                        event.keyval,
+                        gtk2tkMask(event.state));
+}
+
+/*
+   public struct GdkEventScroll {
+   GdkEventType type;
+   GdkWindow *window;
+   byte sendEvent;
+   uint time;
+   double x;
+   double y;
+   uint state;
+   GdkScrollDirection direction;
+   GdkDevice *device;
+   double xRoot, yRoot;
+   }
+ */
+
+ScrollEvent makeScrollEvent(const GdkEventScroll * event, in PixelModel pixelModel) {
+    Point pixelPoint = Point(event.x + 0.5, pixelModel.viewBounds.h - (event.y + 0.5));
+    Point modelPoint = pixelModel.pixelToModel(pixelPoint);
+    return new ScrollEvent(gtk2tkDirection(event.direction),
+                           pixelPoint,
+                           modelPoint,
+                           gtk2tkMask(event.state));
+}
+
+/*
+   public enum GdkCrossingMode {       
+   NORMAL,
+   GRAB,
+   UNGRAB,
+   GTK_GRAB,
+   GTK_UNGRAB,
+   STATE_CHANGED
+   }
+
+   public struct GdkEventCrossing {
+   GdkEventType type;
+   GdkWindow *window;
+   byte sendEvent;
+   GdkWindow *subwindow;
+   uint time;
+   double x;
+   double y;
+   double xRoot;
+   double yRoot;
+   GdkCrossingMode mode;
+   GdkNotifyType detail;
+   int focus;
+   uint state;
+   }
+ */
+
+CrossingEvent makeCrossingEvent(const GdkEventCrossing * event, in PixelModel pixelModel) {
+    Point pixelPoint = Point(event.x + 0.5, pixelModel.viewBounds.h - (event.y + 0.5));
+    Point modelPoint = pixelModel.pixelToModel(pixelPoint);
+    return new CrossingEvent(gtk2tkCrossingMode(event.mode),
+                             pixelPoint,
+                             modelPoint,
+                             gtk2tkMask(event.state));
+}
+
+
+/*
+   public struct GdkEventFocus {
+   GdkEventType type;
+   GdkWindow *window;
+   byte sendEvent;
+   short inn;
+   }
+ */
+// In case we implement focus event...