Ejemplo n.º 1
0
        private void RenderPanel_Paint(object sender, PaintEventArgs e)
        {
            if (this.ContainsFocus)
            {
                Renderer.cam.WASDMoveMent();
            }
            Control control = sender as Control;

            state    = Mouse.GetState();
            keystate = Keyboard.GetState();
            Point   pt         = control.PointToClient(Control.MousePosition);
            Vector2 Boundaries = new Vector2(RenderPanel.Width, RenderPanel.Height);

            if (ControlPanel.Visible)
            {
                Boundaries.X -= ControlPanel.Size.Width;                       //shorten boundaries if control panel is open
            }
            if (keystate[Key.C])
            {
                Cursor.Current = Cursors.Cross;
                if (state[MouseButton.Left])
                {
                    byte[] color = new byte[4];
                    GL.ReadPixels(pt.X, RenderPanel.Height - pt.Y - 1, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, color);
                    UpdateColour(color[0], color[1], color[2], color[3]);
                }
            }
            else
            {
                Cursor.Current = Cursors.Default;
            }
            if (state[MouseButton.Left] && !keystate[Key.C])
            {
                if (pt.X > 0 && pt.Y > 0 && pt.X < Boundaries.X && pt.Y < Boundaries.Y && this.ContainsFocus == true) //Left Click in GLControl & windowfocused
                {
                    float movementX = oldXYDelta.X + ((Control.MousePosition.X - lastMousePos.X) * MouseSensitivity); //last rotation + new rotation (Both are differences)
                    float movementY = oldXYDelta.Y + ((Control.MousePosition.Y - lastMousePos.Y) * MouseSensitivity);
                    if (movementY > 1.57)
                    {
                        movementY = 1.57f;                  // limit Y axis rotation
                    }
                    else if (movementY < -1.57)
                    {
                        movementY = -1.57f;
                    }
                    Renderer.cam.AddRotation(movementX, movementY);
                    XYEnd.X = movementX;
                    XYEnd.Y = movementY;
                }
                if (ControlPanel.Visible) // Colour Picker
                {
                    Point cursor = new Point();
                    GetCursorPos(ref cursor);
                    Point PaletteLocation      = VertexRGBA.PointToScreen(RGBPalette.Location);
                    Point AlphaPaletteLocation = VertexRGBA.PointToScreen(AlphaPalette.Location);
                    if (cursor.X > PaletteLocation.X && cursor.X < PaletteLocation.X + RGBPalette.Size.Width && cursor.Y > PaletteLocation.Y && cursor.Y < PaletteLocation.Y + RGBPalette.Size.Height)
                    {
                        System.Drawing.Color PxColor = GetColorAt(cursor);
                        UpdateColour(PxColor.R, PxColor.G, PxColor.B);
                        //AlphaNum.Value = PxColor.A; //All alpha here is 255 so don't copy it
                    }
                    else if (cursor.X >= AlphaPaletteLocation.X && cursor.X <= AlphaPaletteLocation.X + AlphaPalette.Size.Width && cursor.Y > AlphaPaletteLocation.Y && cursor.Y < AlphaPaletteLocation.Y + AlphaPalette.Size.Height)
                    {
                        int right = AlphaPaletteLocation.X + AlphaPalette.Size.Width;
                        int alpha = Convert.ToInt32((double)((double)(right - cursor.X) / AlphaPalette.Size.Width) * (double)255);
                        if (alpha >= 252)
                        {
                            alpha = 255;
                        }
                        else if (alpha <= 4)
                        {
                            alpha = 0;
                        }
                        AlphaNum.Value = alpha;
                    }
                }
            }
            else //When not clicking, track mouse position
            {
                lastMousePos.X = Control.MousePosition.X;
                lastMousePos.Y = Control.MousePosition.Y;
            }
            if (state[MouseButton.Right] && pt.X > 0 && pt.Y > 0 && pt.X < Boundaries.X && pt.Y < Boundaries.Y && this.ContainsFocus == true)
            {
                EditVertex
                (
                    ClientRectangle,
                    Width,
                    Height,
                    RenderPanel,
                    pt,
                    (byte)Math.Round(RedNum.Value * ((decimal)Brightness.Value / 100)),
                    (byte)Math.Round(GreenNum.Value * ((decimal)Brightness.Value / 100)),
                    (byte)Math.Round(BlueNum.Value * ((decimal)Brightness.Value / 100)),
                    (byte)AlphaNum.Value,
                    AlphaOnlyCheckbox.Checked
                );
                byte[] color2 = new byte[4];
                GL.ReadPixels(pt.X, RenderPanel.Height - pt.Y - 1, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, color2);
                UInt32 addrr = (uint)((color2[0] << 24) | (color2[1] << 16) | (color2[2] << 8) | (color2[3]));
            }
            Render(ClientRectangle, Width, Height, RenderPanel);
        }
Ejemplo n.º 2
0
        private void RenderPanel_Paint(object sender, PaintEventArgs e)
        {
            if (this.ContainsFocus)
            {
                Renderer.cam.WASDMoveMent();
            }
            Control control = sender as Control;

            state = Mouse.GetState();
            Point   pt         = control.PointToClient(Control.MousePosition);
            Vector2 Boundaries = new Vector2(RenderPanel.Width, RenderPanel.Height);

            if (ControlPanel.Visible)
            {
                Boundaries.X -= ControlPanel.Size.Width;                       //shorten boundaries if control panel is open
            }
            //StatusLabel.Text = "CAMERA: " + Renderer.cam.CamRotation + ", MOUSE: " + pt;
            if (state[MouseButton.Left])
            {
                if (pt.X > 0 && pt.Y > 0 && pt.X < Boundaries.X && pt.Y < Boundaries.Y && this.ContainsFocus == true) //Left Click in GLControl & windowfocused
                {
                    float movementX = oldXYDelta.X + ((Control.MousePosition.X - lastMousePos.X));                    //last rotation + new rotation (Both are differences)
                    float movementY = oldXYDelta.Y + ((Control.MousePosition.Y - lastMousePos.Y));
                    if (movementY > 285)
                    {
                        movementY = 285;                 // limit Y axis rotation
                    }
                    else if (movementY < -314)
                    {
                        movementY = -314;
                    }
                    Renderer.cam.AddRotation(movementX, movementY);
                    XYEnd.X = movementX;
                    XYEnd.Y = movementY;
                    //StatusLabel.Text += ", MOVEMENTX: " + movementX.ToString() + ", MOVEMENTY: " + movementY.ToString();
                }
                if (ControlPanel.Visible) // Colour Picker
                {
                    Point cursor = new Point();
                    GetCursorPos(ref cursor);
                    Point PaletteLocation      = VertexRGBA.PointToScreen(RGBPalette.Location);
                    Point AlphaPaletteLocation = VertexRGBA.PointToScreen(AlphaPalette.Location);
                    if (cursor.X > PaletteLocation.X && cursor.X < PaletteLocation.X + RGBPalette.Size.Width && cursor.Y > PaletteLocation.Y && cursor.Y < PaletteLocation.Y + RGBPalette.Size.Height)
                    {
                        System.Drawing.Color PxColor = GetColorAt(cursor);
                        this.BackColor = PxColor;
                        RedNum.Value   = PxColor.R;
                        GreenNum.Value = PxColor.G;
                        BlueNum.Value  = PxColor.B;
                        //AlphaNum.Value = PxColor.A; //All alpha here is 255 so don't copy it
                    }
                    else if (cursor.X >= AlphaPaletteLocation.X && cursor.X <= AlphaPaletteLocation.X + AlphaPalette.Size.Width && cursor.Y > AlphaPaletteLocation.Y && cursor.Y < AlphaPaletteLocation.Y + AlphaPalette.Size.Height)
                    {
                        int right = AlphaPaletteLocation.X + AlphaPalette.Size.Width;
                        //StatusLabel.Text += cursor.X+", "+right + ", " + AlphaPalette.Size.Width;
                        int alpha = Convert.ToInt32((double)((double)(right - cursor.X) / AlphaPalette.Size.Width) * (double)255);
                        if (alpha >= 252)
                        {
                            alpha = 255;
                        }
                        else if (alpha <= 4)
                        {
                            alpha = 0;
                        }
                        AlphaNum.Value = alpha;
                    }
                }
            }
            else //When not clicking, track mouse position
            {
                lastMousePos.X = Control.MousePosition.X;
                lastMousePos.Y = Control.MousePosition.Y;
            }
            if (state[MouseButton.Right] && pt.X > 0 && pt.Y > 0 && pt.X < Boundaries.X && pt.Y < Boundaries.Y && this.ContainsFocus == true)
            {
                Renderer.EditVertex
                (
                    ClientRectangle,
                    Width,
                    Height,
                    RenderPanel,
                    pt,
                    (byte)Math.Round(RedNum.Value * ((decimal)Brightness.Value / 100)),
                    (byte)Math.Round(GreenNum.Value * ((decimal)Brightness.Value / 100)),
                    (byte)Math.Round(BlueNum.Value * ((decimal)Brightness.Value / 100)),
                    (byte)AlphaNum.Value
                );
            }
            Renderer.Render(ClientRectangle, Width, Height, RenderPanel);
        }