From: Tim R. <ti...@us...> - 2004-07-31 13:57:35
|
Update of /cvsroot/csdopenglnet/csdOpenGL/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26235 Modified Files: gtkAdvanced.cs Log Message: all but mouse Index: gtkAdvanced.cs =================================================================== RCS file: /cvsroot/csdopenglnet/csdOpenGL/samples/gtkAdvanced.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** gtkAdvanced.cs 31 Jul 2004 12:48:22 -0000 1.3 --- gtkAdvanced.cs 31 Jul 2004 13:57:25 -0000 1.4 *************** *** 16,21 **** protected Entry speedY_entry; protected Entry speedZ_entry; - public GtkAdvanced() { Debug.Indent(); --- 16,28 ---- protected Entry speedY_entry; protected Entry speedZ_entry; + protected Button reset_btn; + protected ToggleButton animate_tglbtn; + protected Button update_btn; + + protected float propRotX, propRotY, propRotZ; + protected float propSpeedX, propSpeedY, propSpeedZ; + protected bool propAnimate; + protected bool stop = true; public GtkAdvanced() { Debug.Indent(); *************** *** 33,46 **** Debug.WriteLine( "Init GtkGLArea" ); glarea = new GtkGLArea(); Debug.WriteLine( "Init rotation entry fields" ); ! rotX_entry = new Entry(); ! rotY_entry = new Entry(); ! rotZ_entry = new Entry(); Debug.WriteLine( "Init speed entry fields" ); ! speedX_entry = new Entry(); ! speedY_entry = new Entry(); ! speedZ_entry = new Entry(); Debug.WriteLine( "Init Table-Layout rotTable" ); --- 40,58 ---- Debug.WriteLine( "Init GtkGLArea" ); glarea = new GtkGLArea(); + glarea.Realized += new EventHandler (OnRealized); + glarea.ConfigureEvent += new ConfigureEventHandler (OnConfigure); + glarea.ExposeEvent += new ExposeEventHandler (OnExpose); + glarea.MapEvent += new MapEventHandler (OnMap); + glarea.UnmapEvent += new UnmapEventHandler (OnUnmap); Debug.WriteLine( "Init rotation entry fields" ); ! rotX_entry = new Entry(); rotX_entry.ActivatesDefault = true; ! rotY_entry = new Entry(); rotY_entry.ActivatesDefault = true; ! rotZ_entry = new Entry(); rotZ_entry.ActivatesDefault = true; Debug.WriteLine( "Init speed entry fields" ); ! speedX_entry = new Entry(); speedX_entry.ActivatesDefault = true; ! speedY_entry = new Entry(); speedY_entry.ActivatesDefault = true; ! speedZ_entry = new Entry(); speedZ_entry.ActivatesDefault = true; Debug.WriteLine( "Init Table-Layout rotTable" ); *************** *** 62,69 **** speedTable.Attach( speedZ_entry, 1, 2, 2, 3 ); Debug.WriteLine( "Init Table-Layout buttonTable" ); ! Table buttonTable = new Table( 2, 1, true ); ! buttonTable.Attach( new ToggleButton( "Animate" ), 0, 1, 0, 1 ); ! buttonTable.Attach( new Button( "Reset" ), 0, 1, 1, 2 ); Debug.WriteLine( "Init HBox-Layout hbox" ); --- 74,93 ---- speedTable.Attach( speedZ_entry, 1, 2, 2, 3 ); + Debug.WriteLine( "Init buttons" ); + animate_tglbtn = new ToggleButton( "Animate" ); + animate_tglbtn.Toggled += new EventHandler( OnButton ); + reset_btn = new Button( "Reset" ); + reset_btn.Clicked += new EventHandler( OnButton ); + update_btn = new Button( "Update" ); + update_btn.Clicked += new EventHandler( OnButton ); + update_btn.CanFocus = true; + update_btn.CanDefault = true; + window.Default = update_btn; + Debug.WriteLine( "Init Table-Layout buttonTable" ); ! Table buttonTable = new Table( 3, 1, true ); ! buttonTable.Attach( animate_tglbtn, 0, 1, 0, 1 ); ! buttonTable.Attach( reset_btn, 0, 1, 1, 2 ); ! buttonTable.Attach( update_btn, 0, 1, 2, 3 ); Debug.WriteLine( "Init HBox-Layout hbox" ); *************** *** 75,79 **** Debug.WriteLine( "Init VBox-Layout vbox" ); VBox vbox = new VBox( false, 2 ); ! vbox.PackStart( new Button( "GL" ), true, true, 5 ); vbox.PackEnd( hbox, false, true, 5 ); --- 99,103 ---- Debug.WriteLine( "Init VBox-Layout vbox" ); VBox vbox = new VBox( false, 2 ); ! vbox.PackStart( glarea, true, true, 5 ); vbox.PackEnd( hbox, false, true, 5 ); *************** *** 81,84 **** --- 105,111 ---- window.Add( vbox ); window.ShowAll(); + + setDefaults(); + Debug.WriteLine( "MainLoop" ); Application.Run (); *************** *** 88,92 **** --- 115,246 ---- } + + protected void updateValues() { + bool p = animate; + animate = false; + + try { + speedX = System.Convert.ToSingle( speedX_entry.Text ); + } catch { + speedX_entry.Text = speedX.ToString(); + } + try { + speedY = System.Convert.ToSingle( speedY_entry.Text ); + } catch { + speedY_entry.Text = speedY.ToString(); + } + try { + speedZ = System.Convert.ToSingle( speedZ_entry.Text ); + } catch { + speedZ_entry.Text = speedZ.ToString(); + } + + try { + rotX = System.Convert.ToSingle( rotX_entry.Text ); + } catch { + rotX_entry.Text = rotX.ToString(); + } + try { + rotY = System.Convert.ToSingle( rotY_entry.Text ); + } catch { + rotY_entry.Text = rotY.ToString(); + } + try { + rotZ = System.Convert.ToSingle( rotZ_entry.Text ); + } catch { + rotZ_entry.Text = rotZ.ToString(); + } + + animate = p; + } + + protected void setDefaults() { + animate = false; + rotX = 0.0f; + rotY = 0.0f; + rotZ = 0.0f; + speedX = 0.1f; + speedY = 0.2f; + speedZ = 0.5f; + } + protected bool Animate () { + rotX += speedX; + rotY += speedY; + rotZ += speedZ; + if ( (glarea!=null) && (!stop) ) glarea.QueueDraw (); + return animate; + } + + protected void OnMap (object obj, MapEventArgs args) { + stop = false; + } + + protected void OnUnmap (object obj, UnmapEventArgs args) { + stop = true; + } + + protected virtual void OnExpose (object obj, ExposeEventArgs args) { + if (glarea.MakeCurrent()) { + glClearColor( 0, 0, 0, 0 ); + glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glPushMatrix(); + glRotatef( rotX, 1.0f, 0.0f, 0.0f ); + glRotatef( rotY, 0.0f, 1.0f, 0.0f ); + glRotatef( rotZ, 0.0f, 0.0f, 1.0f ); + draw(); + glPopMatrix(); + glarea.SwapBuffers(); + } + } + + protected virtual void draw() { + if (glarea.MakeCurrent()) { + glTranslatef( -0.5f, -0.5f, 0.0f ); + glBegin( GL_TRIANGLES ); + glColor3f( 1.0f, 0.0f, 0.0f ); + glVertex2f( 0.0f, 0.0f); + glColor3f( 0.0f, 1.0f, 0.0f ); + glVertex2f( 0.5f, 1.0f); + glColor3f( 0.0f, 0.0f, 1.0f ); + glVertex2f( 1.0f, 0.0f); + glEnd(); + } + } + + protected virtual void OnConfigure (object obj, ConfigureEventArgs args) { + if (glarea.MakeCurrent()) { + glViewport(0, 0, glarea.Allocation.Width, glarea.Allocation.Height); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + float h = (float) glarea.Allocation.Height / (float) (glarea.Allocation.Width); + glFrustum( -1.0f, 1.0f, -h, h, 5.0f, 5.0f ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + //glTranslatef( 0.0f, 0.0f, -40.0f); + glEnd(); + } + } + + protected void OnRealized (object obj, EventArgs args) { + glShadeModel( GL_SMOOTH ); + glClearColor( 0.0f, 0.0f, 0.0f, 0.5f ); + glClearDepth( 1.0f ); + glEnable( GL_DEPTH_TEST ); + glDepthFunc( GL_LEQUAL ); + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + } + + protected void OnButton( object obj, EventArgs args ) { + if (obj==reset_btn) { + setDefaults(); + } else if (obj==animate_tglbtn) { + animate = animate_tglbtn.Active; + } else if (obj==update_btn) { + updateValues(); + } + } + protected void OnDeleteEvent (object obj, DeleteEventArgs args) { Debug.Indent(); *************** *** 99,102 **** --- 253,327 ---- } + protected float rotX { + get { return propRotX; } + set { + propRotX = value; + while (propRotX<0) propRotX += 360.0f; + while (propRotX>=360.0f) propRotX -= 360.0f; + rotX_entry.Text = propRotX.ToString(); + } + } + + protected float rotY { + get { return propRotY; } + set { + propRotY = value; + while (propRotY<0) propRotY += 360.0f; + while (propRotY>=360.0f) propRotY -= 360.0f; + rotY_entry.Text = propRotY.ToString(); + } + } + + protected float rotZ { + get { return propRotZ; } + set { + propRotZ = value; + while (propRotZ<0) propRotZ += 360.0f; + while (propRotZ>=360.0f) propRotZ -= 360.0f; + rotZ_entry.Text = propRotZ.ToString(); + } + } + + protected float speedX { + get { return propSpeedX; } + set { + propSpeedX = value; + while (propSpeedX<=-360.0f) propSpeedX += 360.0f; + while (propSpeedX>=360.0f) propSpeedX -= 360.0f; + speedX_entry.Text = propSpeedX.ToString(); + } + } + + protected float speedY { + get { return propSpeedY; } + set { + propSpeedY = value; + while (propSpeedY<=-360.0f) propSpeedY += 360.0f; + while (propSpeedY>=360.0f) propSpeedY -= 360.0f; + speedY_entry.Text = propSpeedY.ToString(); + } + } + + protected float speedZ { + get { return propSpeedZ; } + set { + propSpeedZ = value; + while (propSpeedZ<=-360.0f) propSpeedZ += 360.0f; + while (propSpeedZ>=360.0f) propSpeedZ -= 360.0f; + speedZ_entry.Text = propSpeedZ.ToString(); + } + } + + protected bool animate { + get { return propAnimate; } + set { + if ( value && !propAnimate ) GLib.Idle.Add (new IdleHandler (Animate)); + propAnimate = value; + animate_tglbtn.Active = value; + } + } + + + public static void Main( string[] args) { Debug.Listeners.Add( new TextWriterTraceListener( Console.Out ) ); |