Beispiel #1
0
        internal Microsoft.Xna.Framework.Rectangle GetScissorRectangleFor(Camera camera, IRenderableIpso ipso)
        {
            if (ipso == null)
            {
                return(new Microsoft.Xna.Framework.Rectangle(
                           0, 0,
                           camera.ClientWidth,
                           camera.ClientHeight

                           ));
            }
            else
            {
                float worldX = ipso.GetAbsoluteLeft();
                float worldY = ipso.GetAbsoluteTop();

                float screenX;
                float screenY;
                camera.WorldToScreen(worldX, worldY, out screenX, out screenY);

                int left = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX);
                int top  = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY);

                worldX = ipso.GetAbsoluteRight();
                worldY = ipso.GetAbsoluteBottom();
                camera.WorldToScreen(worldX, worldY, out screenX, out screenY);

                int right  = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX);
                int bottom = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY);



                left   = System.Math.Max(0, left);
                top    = System.Math.Max(0, top);
                right  = System.Math.Max(0, right);
                bottom = System.Math.Max(0, bottom);

                left  = System.Math.Min(left, camera.ClientWidth);
                right = System.Math.Min(right, camera.ClientWidth);

                top    = System.Math.Min(top, camera.ClientHeight);
                bottom = System.Math.Min(bottom, camera.ClientHeight);


                int width  = System.Math.Max(0, right - left);
                int height = System.Math.Max(0, bottom - top);


                Microsoft.Xna.Framework.Rectangle thisRectangle = new Microsoft.Xna.Framework.Rectangle(
                    left,
                    top,
                    width,
                    height);

                return(thisRectangle);
            }
        }
Beispiel #2
0
        private void AdjustCursorChangeValuesForShiftDrag(ref float cursorXChange, ref float cursorYChange, InstanceSave instanceSave, List <ElementWithState> elementStack)
        {
            if (InputLibrary.Keyboard.Self.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) ||
                InputLibrary.Keyboard.Self.KeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift))
            {
                bool supportsShift =
                    SideGrabbed == ResizeSide.TopLeft || SideGrabbed == ResizeSide.TopRight ||
                    SideGrabbed == ResizeSide.BottomLeft || SideGrabbed == ResizeSide.BottomRight;

                if (supportsShift && instanceSave != null)
                {
                    IRenderableIpso ipso = WireframeObjectManager.Self.GetRepresentation(instanceSave, elementStack);

                    var   cursor  = InputLibrary.Cursor.Self;
                    float cursorX = cursor.GetWorldX();
                    float cursorY = cursor.GetWorldY();

                    float top    = ipso.GetAbsoluteTop();
                    float bottom = ipso.GetAbsoluteBottom();
                    float left   = ipso.GetAbsoluteLeft();
                    float right  = ipso.GetAbsoluteRight();

                    float absoluteXDifference = 1;
                    float absoluteYDifference = 1;

                    switch (SideGrabbed)
                    {
                    case ResizeSide.BottomRight:
                        absoluteXDifference = System.Math.Abs(left - cursorX);
                        absoluteYDifference = System.Math.Abs(top - cursorY);
                        break;

                    case ResizeSide.BottomLeft:
                        absoluteXDifference = System.Math.Abs(right - cursorX);
                        absoluteYDifference = System.Math.Abs(top - cursorY);
                        break;

                    case ResizeSide.TopLeft:
                        absoluteXDifference = System.Math.Abs(right - cursorX);
                        absoluteYDifference = System.Math.Abs(bottom - cursorY);
                        break;

                    case ResizeSide.TopRight:
                        absoluteXDifference = System.Math.Abs(left - cursorX);
                        absoluteYDifference = System.Math.Abs(bottom - cursorY);
                        break;
                    }

                    float aspectRatio = absoluteXDifference / absoluteYDifference;


                    if (aspectRatio > aspectRatioOnGrab)
                    {
                        float yToUse = 0;
                        // We use the X, but adjust the Y
                        switch (SideGrabbed)
                        {
                        case ResizeSide.BottomRight:
                            cursorXChange = cursorX - right;
                            yToUse        = top + absoluteXDifference / aspectRatioOnGrab;
                            cursorYChange = yToUse - bottom;
                            break;

                        case ResizeSide.BottomLeft:
                            cursorXChange = cursorX - left;
                            yToUse        = top + absoluteXDifference / aspectRatioOnGrab;
                            cursorYChange = yToUse - bottom;
                            break;

                        case ResizeSide.TopRight:
                            cursorXChange = cursorX - right;
                            yToUse        = bottom - absoluteXDifference / aspectRatioOnGrab;
                            cursorYChange = yToUse - top;
                            break;

                        case ResizeSide.TopLeft:
                            cursorXChange = cursorX - left;
                            yToUse        = bottom - absoluteXDifference / aspectRatioOnGrab;
                            cursorYChange = yToUse - top;
                            break;
                        }
                    }
                    else
                    {
                        float xToUse;
                        // We use the Y, but adjust the X
                        switch (SideGrabbed)
                        {
                        case ResizeSide.BottomRight:
                            cursorYChange = cursorY - bottom;
                            xToUse        = left + absoluteYDifference * aspectRatioOnGrab;
                            cursorXChange = xToUse - right;
                            break;

                        case ResizeSide.BottomLeft:
                            cursorYChange = cursorY - bottom;
                            xToUse        = right - absoluteYDifference * aspectRatioOnGrab;
                            cursorXChange = xToUse - left;
                            break;

                        case ResizeSide.TopRight:
                            cursorYChange = cursorY - top;
                            xToUse        = left + absoluteYDifference * aspectRatioOnGrab;
                            cursorXChange = xToUse - right;
                            break;

                        case ResizeSide.TopLeft:
                            cursorYChange = cursorY - top;
                            xToUse        = right - absoluteYDifference * aspectRatioOnGrab;
                            cursorXChange = xToUse - left;
                            break;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        internal Microsoft.Xna.Framework.Rectangle GetScissorRectangleFor(Camera camera, IRenderableIpso ipso)
        {
            if (ipso == null)
            {
                return(new Microsoft.Xna.Framework.Rectangle(
                           0, 0,
                           camera.ClientWidth,
                           camera.ClientHeight

                           ));
            }
            else
            {
                float worldX = ipso.GetAbsoluteLeft();
                float worldY = ipso.GetAbsoluteTop();

                float screenX;
                float screenY;
                camera.WorldToScreen(worldX, worldY, out screenX, out screenY);

                int left = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX);
                int top  = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY);

                worldX = ipso.GetAbsoluteRight();
                worldY = ipso.GetAbsoluteBottom();
                camera.WorldToScreen(worldX, worldY, out screenX, out screenY);

                int right  = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX);
                int bottom = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY);



                left   = System.Math.Max(0, left);
                top    = System.Math.Max(0, top);
                right  = System.Math.Max(0, right);
                bottom = System.Math.Max(0, bottom);

                left  = System.Math.Min(left, camera.ClientWidth);
                right = System.Math.Min(right, camera.ClientWidth);

                top    = System.Math.Min(top, camera.ClientHeight);
                bottom = System.Math.Min(bottom, camera.ClientHeight);


                int width  = System.Math.Max(0, right - left);
                int height = System.Math.Max(0, bottom - top);

                // ScissorRectangles are relative to the viewport in Gum, so we need to adjust for that:
                left  += this.GraphicsDevice.Viewport.X;
                right += this.GraphicsDevice.Viewport.X;

                if (SubtractViewportYForMonoGameGlBug)
                {
                    top    -= this.GraphicsDevice.Viewport.Y;
                    bottom -= this.GraphicsDevice.Viewport.Y;
                }
                else
                {
                    top    += this.GraphicsDevice.Viewport.Y;
                    bottom += this.GraphicsDevice.Viewport.Y;
                }

                Microsoft.Xna.Framework.Rectangle thisRectangle = new Microsoft.Xna.Framework.Rectangle(
                    left,
                    top,
                    width,
                    height);

                return(thisRectangle);
            }
        }
Beispiel #4
0
        internal Microsoft.Xna.Framework.Rectangle GetScissorRectangleFor(Camera camera, IRenderableIpso ipso)
        {
            if (ipso == null)
            {
                return new Microsoft.Xna.Framework.Rectangle(
                    0, 0,
                    camera.ClientWidth,
                    camera.ClientHeight

                    );
            }
            else
            {

                float worldX = ipso.GetAbsoluteLeft();
                float worldY = ipso.GetAbsoluteTop();

                float screenX;
                float screenY;
                camera.WorldToScreen(worldX, worldY, out screenX, out screenY);

                int left = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX);
                int top = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY);

                worldX = ipso.GetAbsoluteRight();
                worldY = ipso.GetAbsoluteBottom();
                camera.WorldToScreen(worldX, worldY, out screenX, out screenY);

                int right = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX);
                int bottom = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY);



                left = System.Math.Max(0, left);
                top = System.Math.Max(0, top);
                right = System.Math.Max(0, right);
                bottom = System.Math.Max(0, bottom);

                left = System.Math.Min(left, camera.ClientWidth);
                right = System.Math.Min(right, camera.ClientWidth);

                top = System.Math.Min(top, camera.ClientHeight);
                bottom = System.Math.Min(bottom, camera.ClientHeight);


                int width = System.Math.Max(0, right - left);
                int height = System.Math.Max(0, bottom - top);


                Microsoft.Xna.Framework.Rectangle thisRectangle = new Microsoft.Xna.Framework.Rectangle(
                    left,
                    top,
                    width,
                    height);

                return thisRectangle;
            }

        }