OSDN Git Service

SL Style Controls
authorLatif Khalifa <latifer@streamgrid.net>
Thu, 14 Apr 2011 14:52:37 +0000 (14:52 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Thu, 14 Apr 2011 14:52:37 +0000 (14:52 +0000)
git-svn-id: https://radegast.googlecode.com/svn/trunk@838 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/GUI/Dialogs/PrimWorkshop.Designer.cs
Radegast/GUI/Dialogs/PrimWorkshop.cs

index d054509..ab7c3ba 100644 (file)
@@ -65,8 +65,10 @@ namespace Radegast
             this.scrollYaw = new System.Windows.Forms.HScrollBar();
             this.scrollZoom = new System.Windows.Forms.HScrollBar();
             this.gbZoom = new System.Windows.Forms.GroupBox();
+            this.btnResetView = new System.Windows.Forms.Button();
             this.chkWireFrame = new System.Windows.Forms.CheckBox();
             this.label1 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
             this.gbZoom.SuspendLayout();
             this.SuspendLayout();
             // 
@@ -77,7 +79,7 @@ namespace Radegast
             this.glControl.Dock = System.Windows.Forms.DockStyle.Fill;
             this.glControl.Location = new System.Drawing.Point(0, 0);
             this.glControl.Name = "glControl";
-            this.glControl.Size = new System.Drawing.Size(644, 549);
+            this.glControl.Size = new System.Drawing.Size(644, 524);
             this.glControl.TabIndex = 5;
             this.glControl.VSync = false;
             this.glControl.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl_Paint);
@@ -127,6 +129,8 @@ namespace Radegast
             // 
             // gbZoom
             // 
+            this.gbZoom.Controls.Add(this.label2);
+            this.gbZoom.Controls.Add(this.btnResetView);
             this.gbZoom.Controls.Add(this.chkWireFrame);
             this.gbZoom.Controls.Add(this.label1);
             this.gbZoom.Controls.Add(this.scrollZoom);
@@ -134,12 +138,22 @@ namespace Radegast
             this.gbZoom.Controls.Add(this.scrollPitch);
             this.gbZoom.Controls.Add(this.scrollRoll);
             this.gbZoom.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.gbZoom.Location = new System.Drawing.Point(0, 549);
+            this.gbZoom.Location = new System.Drawing.Point(0, 524);
             this.gbZoom.Name = "gbZoom";
-            this.gbZoom.Size = new System.Drawing.Size(644, 56);
+            this.gbZoom.Size = new System.Drawing.Size(644, 81);
             this.gbZoom.TabIndex = 8;
             this.gbZoom.TabStop = false;
             // 
+            // btnResetView
+            // 
+            this.btnResetView.Location = new System.Drawing.Point(12, 52);
+            this.btnResetView.Name = "btnResetView";
+            this.btnResetView.Size = new System.Drawing.Size(94, 23);
+            this.btnResetView.TabIndex = 22;
+            this.btnResetView.Text = "Reset View";
+            this.btnResetView.UseVisualStyleBackColor = true;
+            this.btnResetView.Click += new System.EventHandler(this.btnReset_Click);
+            // 
             // chkWireFrame
             // 
             this.chkWireFrame.AutoSize = true;
@@ -154,11 +168,21 @@ namespace Radegast
             // label1
             // 
             this.label1.AutoSize = true;
-            this.label1.Location = new System.Drawing.Point(293, 32);
+            this.label1.Location = new System.Drawing.Point(385, 29);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(132, 13);
+            this.label1.Size = new System.Drawing.Size(34, 13);
             this.label1.TabIndex = 20;
-            this.label1.Text = "Zoom (mouse scroll wheel)";
+            this.label1.Text = "Zoom";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(140, 57);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(391, 13);
+            this.label2.TabIndex = 23;
+            this.label2.Text = "Drag to rotate object, ALT-Drag for Zoom, Alt-Ctrl-Drag for rotate, Ctrl-Drag  to" +
+                " pan";
             // 
             // frmPrimWorkshop
             // 
@@ -187,6 +211,8 @@ namespace Radegast
         public System.Windows.Forms.GroupBox gbZoom;
         private System.Windows.Forms.CheckBox chkWireFrame;
         private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Button btnResetView;
+        private System.Windows.Forms.Label label2;
 
     }
 }
index edf0ae8..650df5f 100644 (file)
@@ -54,7 +54,6 @@ namespace Radegast
 
         List<FacetedMesh> Prims = null;
 
-        bool DraggingTexture = false;
         bool Wireframe = false;
         bool RenderingEnabled = false;
 
@@ -121,10 +120,10 @@ namespace Radegast
 
         #region GLControl Callbacks
 
-        private void glControl_Paint(object sender, PaintEventArgs e)
-        {
-            if (!RenderingEnabled) return;
+        Vector3 Center = Vector3.Zero;
 
+        private void Render()
+        {
             GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
             GL.LoadIdentity();
 
@@ -138,16 +137,14 @@ namespace Radegast
                 GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
             }
 
-            Vector3 center = Vector3.Zero;
-
             //var mLookAt = OpenTK.Matrix4d.LookAt(
             //        center.X, (double)scrollZoom.Value * 0.1d + center.Y, center.Z,
             //        center.X, center.Y, center.Z,
             //        0d, 0d, 1d);
             //GL.MultMatrix(ref mLookAt);
             OpenTK.Graphics.Glu.LookAt(
-                    center.X, (double)scrollZoom.Value * 0.1d + center.Y, center.Z,
-                    center.X, center.Y, center.Z,
+                    Center.X, (double)scrollZoom.Value * 0.1d + Center.Y, Center.Z,
+                    Center.X, Center.Y, Center.Z,
                     0d, 0d, 1d);
             //GL.Light(LightName.Light0, LightParameter.Position, lightPos);
 
@@ -221,9 +218,11 @@ namespace Radegast
                                 break;
                         }
 
-                        GL.Color4(teFace.RGBA.R, teFace.RGBA.G, teFace.RGBA.B, teFace.RGBA.A);
-                        GL.Material(MaterialFace.Front, MaterialParameter.AmbientAndDiffuse, new float[] { teFace.RGBA.R, teFace.RGBA.G, teFace.RGBA.B, teFace.RGBA.A });
-                        GL.Material(MaterialFace.Front, MaterialParameter.Specular, new float[4] { teFace.RGBA.R, teFace.RGBA.G, teFace.RGBA.B, teFace.RGBA.A });
+                        var faceColor = new float[] { teFace.RGBA.R, teFace.RGBA.G, teFace.RGBA.B, teFace.RGBA.A };
+
+                        GL.Color4(faceColor);
+                        GL.Material(MaterialFace.Front, MaterialParameter.AmbientAndDiffuse, faceColor);
+                        GL.Material(MaterialFace.Front, MaterialParameter.Specular, faceColor);
                         #region Texturing
 
                         Face face = Prims[i].Faces[j];
@@ -261,6 +260,14 @@ namespace Radegast
             GL.DisableClientState(ArrayCap.NormalArray);
 
             GL.Flush();
+        }
+
+        private void glControl_Paint(object sender, PaintEventArgs e)
+        {
+            if (!RenderingEnabled) return;
+
+            Render();
+            
             glControl.SwapBuffers();
         }
 
@@ -534,61 +541,66 @@ namespace Radegast
                         data.TexCoords[k * 2 + 1] = face.Vertices[k].TexCoord.Y;
                     }
 
-                    // Texture for this face
-                    if (LoadTexture(teFace.TextureID, ref data.Texture, false))
-                    {
-                        if (IsHandleCreated)
+                    ThreadPool.QueueUserWorkItem(sync =>
                         {
-                            Invoke(new MethodInvoker(() =>
+                            // Texture for this face
+                            if (LoadTexture(teFace.TextureID, ref data.Texture, false))
                             {
-                                GL.GenTextures(1, out data.TexturePointer);
-                                GL.BindTexture(TextureTarget.Texture2D, data.TexturePointer);
-
-                                Bitmap bitmap = new Bitmap(data.Texture);
-                                bool hasAlpha;
-                                if (data.Texture.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
-                                {
-                                    hasAlpha = true;
-                                }
-                                else
+                                if (IsHandleCreated)
                                 {
-                                    hasAlpha = false;
+                                    Invoke(new MethodInvoker(() =>
+                                    {
+                                        GL.GenTextures(1, out data.TexturePointer);
+                                        GL.BindTexture(TextureTarget.Texture2D, data.TexturePointer);
+
+                                        Bitmap bitmap = new Bitmap(data.Texture);
+                                        bool hasAlpha;
+                                        if (data.Texture.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
+                                        {
+                                            hasAlpha = true;
+                                        }
+                                        else
+                                        {
+                                            hasAlpha = false;
+                                        }
+
+                                        bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
+                                        Rectangle rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
+
+
+                                        BitmapData bitmapData =
+                                            bitmap.LockBits(
+                                            rectangle,
+                                            ImageLockMode.ReadOnly,
+                                            hasAlpha ? System.Drawing.Imaging.PixelFormat.Format32bppArgb : System.Drawing.Imaging.PixelFormat.Format24bppRgb);
+
+                                        GL.TexImage2D(
+                                            TextureTarget.Texture2D,
+                                            0,
+                                            hasAlpha ? PixelInternalFormat.Rgba : PixelInternalFormat.Rgb8,
+                                            bitmap.Width,
+                                            bitmap.Height,
+                                            0,
+                                            hasAlpha ? OpenTK.Graphics.OpenGL.PixelFormat.Bgra : OpenTK.Graphics.OpenGL.PixelFormat.Bgr,
+                                            PixelType.UnsignedByte,
+                                            bitmapData.Scan0);
+
+                                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
+                                        //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
+                                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
+                                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
+                                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
+                                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1);
+                                        GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
+                                        bitmap.UnlockBits(bitmapData);
+                                        bitmap.Dispose();
+
+                                        SafeInvalidate();
+                                    }
+                                    ));
                                 }
-
-                                bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
-                                Rectangle rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
-
-
-                                BitmapData bitmapData =
-                                    bitmap.LockBits(
-                                    rectangle,
-                                    ImageLockMode.ReadOnly,
-                                    hasAlpha ? System.Drawing.Imaging.PixelFormat.Format32bppArgb : System.Drawing.Imaging.PixelFormat.Format24bppRgb);
-
-                                GL.TexImage2D(
-                                    TextureTarget.Texture2D,
-                                    0,
-                                    hasAlpha ? PixelInternalFormat.Rgba : PixelInternalFormat.Rgb8,
-                                    bitmap.Width,
-                                    bitmap.Height,
-                                    0,
-                                    hasAlpha ? OpenTK.Graphics.OpenGL.PixelFormat.Bgra : OpenTK.Graphics.OpenGL.PixelFormat.Bgr,
-                                    PixelType.UnsignedByte,
-                                    bitmapData.Scan0);
-
-                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
-                                //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
-                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
-                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
-                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
-                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1);
-                                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
-                                bitmap.UnlockBits(bitmapData);
-                                bitmap.Dispose();
                             }
-                            ));
-                        }
-                    }
+                        });
 
                     // Set the UserData for this face to our FaceData struct
                     face.UserData = data;
@@ -681,45 +693,6 @@ namespace Radegast
 
         #endregion Scrollbar Callbacks
 
-        #region PictureBox Callbacks
-
-        private void picTexture_MouseDown(object sender, MouseEventArgs e)
-        {
-            DraggingTexture = true;
-        }
-
-        private void picTexture_MouseUp(object sender, MouseEventArgs e)
-        {
-            DraggingTexture = false;
-        }
-
-        private void picTexture_MouseLeave(object sender, EventArgs e)
-        {
-            DraggingTexture = false;
-        }
-
-        private void picTexture_MouseMove(object sender, MouseEventArgs e)
-        {
-            if (DraggingTexture)
-            {
-                // What is the current action?
-                // None, DraggingEdge, DraggingCorner, DraggingWhole
-            }
-            else
-            {
-                // Check if the mouse is close to the edge or corner of a selection
-                // rectangle
-
-                // If so, change the cursor accordingly
-            }
-        }
-
-        private void picTexture_Paint(object sender, PaintEventArgs e)
-        {
-            // Draw the current selection rectangles
-        }
-
-        #endregion PictureBox Callbacks
 
         private void chkWireFrame_CheckedChanged(object sender, EventArgs e)
         {
@@ -748,21 +721,44 @@ namespace Radegast
                 int deltaX = e.X - dragX;
                 int deltaY = e.Y - dragY;
 
-                int newRoll = scrollRoll.Value + deltaY;
-                if (newRoll < 0) newRoll += 360;
-                if (newRoll > 360) newRoll -= 360;
+                if (ModifierKeys == Keys.Control || ModifierKeys == (Keys.Alt | Keys.Control | Keys.Shift))
+                {
+                    Center.X -= deltaX / 100f;
+                    Center.Z += deltaY / 100f;
+                }
 
-                scrollRoll.Value = newRoll;
+                if (ModifierKeys == Keys.Alt)
+                {
+                    Center.Y -= deltaY / 25f;
 
+                    int newYaw = scrollYaw.Value + deltaX;
+                    if (newYaw < 0) newYaw += 360;
+                    if (newYaw > 360) newYaw -= 360;
 
-                int newYaw = scrollYaw.Value + deltaX;
-                if (newYaw < 0) newYaw += 360;
-                if (newYaw > 360) newYaw -= 360;
+                    scrollYaw.Value = newYaw;
 
-                scrollYaw.Value = newYaw;
+                }
+
+                if (ModifierKeys == Keys.None || ModifierKeys == (Keys.Alt | Keys.Control))
+                {
+                    int newRoll = scrollRoll.Value + deltaY;
+                    if (newRoll < 0) newRoll += 360;
+                    if (newRoll > 360) newRoll -= 360;
+
+                    scrollRoll.Value = newRoll;
+
+
+                    int newYaw = scrollYaw.Value + deltaX;
+                    if (newYaw < 0) newYaw += 360;
+                    if (newYaw > 360) newYaw -= 360;
+
+                    scrollYaw.Value = newYaw;
+
+                }
 
                 dragX = e.X;
                 dragY = e.Y;
+
                 SafeInvalidate();
             }
         }
@@ -801,7 +797,7 @@ namespace Radegast
                 GL.Enable(EnableCap.CullFace);
                 GL.ColorMaterial(MaterialFace.Front, ColorMaterialParameter.AmbientAndDiffuse);
                 GL.ColorMaterial(MaterialFace.Front, ColorMaterialParameter.Specular);
-                
+
                 GL.DepthMask(true);
                 GL.DepthFunc(DepthFunction.Lequal);
                 GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
@@ -821,9 +817,21 @@ namespace Radegast
             // and will also invalidate the GL control
             glControl_Resize(null, null);
         }
+
+        private void btnReset_Click(object sender, EventArgs e)
+        {
+            scrollYaw.Value = 0;
+            scrollPitch.Value = 0;
+            scrollRoll.Value = 0;
+            scrollZoom.Value = -50;
+            Center = Vector3.Zero;
+
+            SafeInvalidate();
+        }
+
     }
 
-    public struct FaceData
+    public class FaceData
     {
         public float[] Vertices;
         public ushort[] Indices;