changeset 86:8a491b67bc46

Checkpoint
author daveb
date Mon, 16 Aug 2010 18:37:56 +0930
parents 98980cee8c5b
children c825e6db57c1
files doodle/gtk/opengl_canvas.d
diffstat 1 files changed, 97 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/doodle/gtk/opengl_canvas.d	Mon Aug 16 17:59:42 2010 +0930
+++ b/doodle/gtk/opengl_canvas.d	Mon Aug 16 18:37:56 2010 +0930
@@ -35,6 +35,26 @@
     import std.stdio;
 }
 
+private {
+    import gtk.DrawingArea;
+    import glgtk.GLCapability;
+    import glgdk.GLDrawable;
+    import glgdk.GLConfig;
+    import glgdk.GLContext;
+    import gtkglc.glgdktypes;
+
+    import gtkglc.gl;
+    import gtkglc.glu;
+
+    import gdk.Event;
+
+    import gtk.Widget;
+
+    import gtk.Main;
+    import gtk.MainWindow;
+}
+
+
 final class OpenGLCanvas : Table, private IViewport {
     this(in Layer[] layers, IEventHandler eventHandler, IGrid grid, in double pixelsPerMillimetre) {
         super(3, 3, 0);
@@ -137,7 +157,7 @@
             Cursor.HAND      : CursorType.HAND1,
             Cursor.CROSSHAIR : CursorType.CROSSHAIR,
             Cursor.PENCIL    : CursorType.PENCIL
-            ];
+                ];
     }
 
     protected {         // XXX the compiler complains about unimplemented methods if this is private
@@ -215,7 +235,7 @@
             trace("onExpose %sx%s", event.area.width, event.area.height);
 
             /+
-            Drawable dr = _drawingArea.getWindow;
+                Drawable dr = _drawingArea.getWindow;
 
             int width, height;
             dr.getSize(width, height);
@@ -267,7 +287,7 @@
             return true;
             +/
 
-            return false;
+                return false;
         }
 
         bool onButtonPress(GdkEventButton * event, Widget widget) {
@@ -464,107 +484,93 @@
 
         immutable CursorType[Cursor] _cursors;
     }
-}
 
-private import gtk.DrawingArea;
-private import glgtk.GLCapability;
-private import glgdk.GLDrawable;
-private import glgdk.GLConfig;
-private import glgdk.GLContext;
-private import gtkglc.glgdktypes;
+    private {
+        class GLDrawingArea : DrawingArea {
+            GLfloat width;
+            GLfloat height;
 
-private import gtkglc.gl;
-private import gtkglc.glu;
-
-private import gdk.Event;
+            /** need to include the mixin to add GL capabilities to this widget */
+            mixin GLCapability;
 
-private import gtk.Widget;
-
-private import gtk.Main;
-private import gtk.MainWindow;
+            /**
+             * Construct a simple DrawingArea and sets the GLCapabilities
+             */
+            this() {
+                setGLCapability();	// set the GL capabilities for this widget
+            }
 
-class GLDrawingArea : DrawingArea {
-    GLfloat width;
-    GLfloat height;
+            /**
+             * put any gl initializations here
+             * returns true to consume the event
+             */
+            bool initGL() {
+                trace("initGL");
 
-    /** need to include the mixin to add GL capabilities to this widget */
-    mixin GLCapability;
+                //resizeGL(null);
+                return false;
+            }
 
-    /**
-     * Construct a simple DrawingArea and sets the GLCapabilities
-     */
-    this() {
-        setGLCapability();	// set the GL capabilities for this widget
-    }
+            /**
+             * This method is called every time the window must be paint or repaint
+             * This is where you put the OpenGL call to draw something.
+             * This method call be called directly by the application without an event object
+             * to force redrawing of the scene.
+             * returns true to consume the event
+             */
+            bool drawGL(GdkEventExpose* event = null) {
+                trace("drawGL");
 
-    /**
-     * put any gl initializations here
-     * returns true to consume the event
-     */
-    bool initGL() {
-        trace("initGL");
+                glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+                glLoadIdentity ();
 
-        resizeGL(null);
-        return true;
-    }
+                gluLookAt(0, 0, 10, 0, 0, 0, 0, 1,0); //Set the camera position
 
-    /**
-     * This method is called every time the window must be paint or repaint
-     * This is where you put the OpenGL call to draw something.
-     * This method call be called directly by the application without an event object
-     * to force redrawing of the scene.
-     * returns true to consume the event
-     */
-    bool drawGL(GdkEventExpose* event = null) {
-        trace("drawGL");
-
-        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-        glLoadIdentity ();
+                //Just Draw a tri-colored triangle
+                glBegin(GL_TRIANGLES);
+                glColor3f(1.0f,0.0f,0.0f);
+                glVertex3f( 0.0f, 1.0f, 0.0f);
+                glColor3f(0.0f,1.0f,0.0f);
+                glVertex3f(-1.0f,-1.0f, 0.0f);
+                glColor3f(0.0f,0.0f,1.0f);
+                glVertex3f( 1.0f,-1.0f, 0.0f);
+                glEnd();
 
-        gluLookAt(0, 0, 10, 0, 0, 0, 0, 1,0); //Set the camera position
+                return false;
+            }
 
-        //Just Draw a tri-colored triangle
-        glBegin(GL_TRIANGLES);
-        glColor3f(1.0f,0.0f,0.0f);
-        glVertex3f( 0.0f, 1.0f, 0.0f);
-        glColor3f(0.0f,1.0f,0.0f);
-        glVertex3f(-1.0f,-1.0f, 0.0f);
-        glColor3f(0.0f,0.0f,1.0f);
-        glVertex3f( 1.0f,-1.0f, 0.0f);
-        glEnd();
-
-        return true;
-    }
+            /**
+             * This method is called when the window is resized
+             * returns true to consume the event
+             */
+            bool resizeGL(GdkEventConfigure* event = null) {
+                trace("resizeGL");
+                assert(event);
 
-    /**
-     * This method is called when the window is resized
-     * returns true to consume the event
-     */
-    bool resizeGL(GdkEventConfigure* event = null) {
-        trace("resizeGL");
+                if (event == null) {
+                    width = getWidth();
+                    height = getHeight();
+                }
+                else {
+                    width = event.width;
+                    height = event.height;
+                }
+
+                trace("Size %sx%s", width, height);
 
-        if (event == null) {
-            width = getWidth();
-            height = getHeight();
-        }
-        else {
-            width = event.width;
-            height = event.height;
+                glViewport(0, 0, cast(int)width, cast(int)height); //Adjust the viewport according to new window dimensions 
+
+                /*
+                 * Update the projection Matrix accoding to the new dimension
+                 * and reset the OpenGL state to MODELVIEW
+                 */
+                glMatrixMode(GL_PROJECTION);
+                glLoadIdentity();
+                gluPerspective(20, width/height, 0.1, 10);
+                glMatrixMode(GL_MODELVIEW);
+
+                return false;
+            }
         }
-
-        trace("Size %sx%s", width, height);
-
-        glViewport(0, 0, cast(int)width, cast(int)height); //Adjust the viewport according to new window dimensions 
-
-        /*
-         * Update the projection Matrix accoding to the new dimension
-         * and reset the OpenGL state to MODELVIEW
-         */
-        glMatrixMode(GL_PROJECTION);
-        glLoadIdentity();
-        gluPerspective(20, width/height, 0.1, 10);
-        glMatrixMode(GL_MODELVIEW);
-
-        return false;
     }
 }