diff dwt/opengl/GLCanvas.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children 580596d83ac4
line wrap: on
line diff
--- a/dwt/opengl/GLCanvas.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/opengl/GLCanvas.d	Mon Dec 01 17:07:00 2008 +0100
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -26,6 +26,10 @@
 /**
  * GLCanvas is a widget capable of displaying OpenGL content.
  * 
+ * @see GLData
+ * @see <a href="http://www.eclipse.org/swt/snippets/#opengl">OpenGL snippets</a>
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
+ *
  * @since 3.2
  */
 
@@ -52,7 +56,7 @@
     if (data is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
     int attrib [] = new int [MAX_ATTRIBUTES];
     int pos = 0;
-    //TODO this is not working
+    //TODO use color options
 //  attrib [pos++] = OS.AGL_RGBA;
     if (data.doubleBuffer) attrib [pos++] = OS.NSOpenGLPFADoubleBuffer;
     if (data.stereo) attrib [pos++] = OS.NSOpenGLPFAStereo;
@@ -117,18 +121,22 @@
         dispose ();
         DWT.error (DWT.ERROR_UNSUPPORTED_DEPTH);
     }
-    glView.initWithFrame(parent.view.frame(), pixelFormat);
+    glView.initWithFrame(parent.view.bounds(), pixelFormat);
     glView.setAutoresizingMask(OS.NSViewWidthSizable | OS.NSViewHeightSizable);
+    parent.view.addSubview(glView);
 
     Listener listener = new Listener () {
         public void handleEvent (Event event) {
             switch (event.type) {
-            case DWT.Dispose:
-                if (glView !is null) glView.release();
-                glView = null;
-                if (pixelFormat !is null) pixelFormat.release();
-                pixelFormat = null;
-                break;
+                case DWT.Dispose:
+                    if (glView !is null) {
+                        glView.clearGLContext();
+                        glView.release();
+                    }
+                    glView = null;
+                    if (pixelFormat !is null) pixelFormat.release();
+                    pixelFormat = null;
+                    break;
             }
         }
     };
@@ -148,6 +156,7 @@
     checkWidget ();
     GLData data = new GLData ();
     int [] value = new int [1];
+    //TODO implement getGLData()
 //  AGL.aglDescribePixelFormat (pixelFormat, AGL.AGL_DOUBLEBUFFER, value);
 //  data.doubleBuffer = value [0] !is 0;
 //  AGL.aglDescribePixelFormat (pixelFormat, AGL.AGL_STEREO, value);