Exemplo n.º 1
0
        private void TryHandleFileDropOnComponent(float worldX, float worldY, string[] files, ref bool handled, ref bool shouldUpdate)
        {
            List <ElementWithState> elementStack = new List <ElementWithState>();

            elementStack.Add(new ElementWithState(SelectedState.Self.SelectedElement)
            {
                StateName = SelectedState.Self.SelectedStateSave.Name
            });

            // see if it's over the component:
            IPositionedSizedObject ipsoOver = SelectionManager.Self.GetRepresentationAt(worldX, worldY, false, elementStack);

            if (ipsoOver?.Tag is ComponentSave component && (component.BaseType == "Sprite" || component.BaseType == "NineSlice"))
            {
                string fileName = FileManager.MakeRelative(files[0], FileLocations.Self.ProjectFolder);

                MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                mbmb.StartPosition = FormStartPosition.Manual;

                mbmb.Location = new Point(MainWindow.MousePosition.X - mbmb.Width / 2,
                                          MainWindow.MousePosition.Y - mbmb.Height / 2);

                mbmb.MessageText = "What do you want to do with the file " + fileName;

                mbmb.AddButton("Set source file on " + component.Name, DialogResult.OK);
                mbmb.AddButton("Add new Sprite", DialogResult.Yes);
                mbmb.AddButton("Nothing", DialogResult.Cancel);


                var result = mbmb.ShowDialog();

                if (result == DialogResult.OK)
                {
                    var oldValue = SelectedState.Self.SelectedStateSave
                                   .GetValueOrDefault <string>("SourceFile");

                    SelectedState.Self.SelectedStateSave.SetValue("SourceFile", fileName);
                    ProjectState.Self.Selected.SelectedInstance = null;
                    SetVariableLogic.Self.PropertyValueChanged("SourceFile", oldValue);

                    shouldUpdate = true;
                    handled      = true;
                }
                else if (result == DialogResult.Cancel)
                {
                    handled = true;
                }
            }
        }
Exemplo n.º 2
0
 private static float GetRatioXOverInSelection(IPositionedSizedObject ipso, HorizontalAlignment horizontalAlignment)
 {
     if (horizontalAlignment == HorizontalAlignment.Left)
     {
         return(0);
     }
     else if (horizontalAlignment == HorizontalAlignment.Center)
     {
         return(.5f);
     }
     else// if (horizontalAlignment == HorizontalAlignment.Right)
     {
         return(1);
     }
 }
Exemplo n.º 3
0
 private static float GetRatioYDownInSelection(IPositionedSizedObject ipso, VerticalAlignment verticalAlignment)
 {
     if (verticalAlignment == VerticalAlignment.Top)
     {
         return(0);
     }
     else if (verticalAlignment == VerticalAlignment.Center)
     {
         return(.5f);
     }
     else //if (verticalAlignment == VerticalAlignment.Bottom)
     {
         return(1);
     }
 }
        public static string GetAttachmentQualifiedName(this IPositionedSizedObject ipso, List <ElementWithState> elementStack)
        {
            IPositionedSizedObject parent = ipso.Parent;
            IPositionedSizedObject child  = ipso;

            while (parent != null)
            {
                if (parent.Tag is ElementSave || parent.Tag == null)
                {
                    // we found it, so break!
                    break;
                }
                else
                {
                    InstanceSave thisInstance = child.Tag as InstanceSave;

                    if (thisInstance.IsParentASibling(elementStack))
                    {
                        child  = parent;
                        parent = parent.Parent;
                    }
                    else
                    {
                        // we found it, so break;
                        break;
                    }
                }
            }


            if (parent == null)
            {
                return(ipso.Name);
            }
            else
            {
                var parentName = parent.GetAttachmentQualifiedName(elementStack);
                if (!string.IsNullOrEmpty(parentName))
                {
                    return(parentName + "." + ipso.Name);
                }
                else
                {
                    return(ipso.Name);
                }
            }
        }
Exemplo n.º 5
0
        public void UpdateAspectRatioForGrabbedIpso()
        {
            if (SelectedState.Self.SelectedInstance != null &&
                SelectedState.Self.SelectedIpso != null
                )
            {
                IPositionedSizedObject ipso = SelectedState.Self.SelectedIpso;

                float width  = ipso.Width;
                float height = ipso.Height;

                if (height != 0)
                {
                    aspectRatioOnGrab = width / height;
                }
            }
        }
Exemplo n.º 6
0
        public void SetValuesFrom(IPositionedSizedObject ipso)
        {
            this.mX      = ipso.GetAbsoluteX();
            this.mY      = ipso.GetAbsoluteY();
            this.mWidth  = ipso.Width;
            this.mHeight = ipso.Height;

            if (ipso is GraphicalUiElement)
            {
                var asGue = ipso as GraphicalUiElement;

                SetOriginXPosition(asGue);
            }


            UpdateToProperties();
        }
Exemplo n.º 7
0
        private void SetOriginXPosition(GraphicalUiElement asGue)
        {
            IPositionedSizedObject asIpso = asGue;
            float zoom = Renderer.Self.Camera.Zoom;

            float offset = RadiusAtNoZoom * 1.5f / zoom;



            float absoluteX = asGue.AbsoluteX;
            float absoluteY = asGue.AbsoluteY;

            mXLine1.X = absoluteX - offset;
            mXLine1.Y = absoluteY - offset;

            mXLine2.X = absoluteX - offset;
            mXLine2.Y = absoluteY + offset;

            mXLine1.RelativePoint = new Microsoft.Xna.Framework.Vector2(offset * 2, offset * 2);
            mXLine2.RelativePoint = new Microsoft.Xna.Framework.Vector2(offset * 2, -offset * 2);



            bool shouldShowOffsetLine = asGue.Parent != null && asGue.Parent is GraphicalUiElement;

            mOriginLine.Visible = shouldShowOffsetLine;

            if (shouldShowOffsetLine)
            {
                var gueParent = asGue.Parent as GraphicalUiElement;

                float parentOriginOffsetX;
                float parentOriginOffsetY;
                asGue.GetParentOffsets(out parentOriginOffsetX, out parentOriginOffsetY);

                mOriginLine.X = parentOriginOffsetX + asGue.Parent.GetAbsoluteX();
                mOriginLine.Y = parentOriginOffsetY + asGue.Parent.GetAbsoluteY();

                mOriginLine.RelativePoint.X = asGue.AbsoluteX - mOriginLine.X;
                mOriginLine.RelativePoint.Y = asGue.AbsoluteY - mOriginLine.Y;
            }
        }
Exemplo n.º 8
0
        private float GetYMultiplierForBottom(InstanceSave instanceSave, IPositionedSizedObject ipso)
        {
            object yOriginAsObject = EditingManager.GetCurrentValueForVariable("Y Origin", instanceSave);
            bool   shouldContiue   = yOriginAsObject != null;

            if (shouldContiue)
            {
                VerticalAlignment yOrigin = (VerticalAlignment)yOriginAsObject;

                float ratioOver = GetRatioYDownInSelection(ipso, yOrigin);

                var toReturn = 0 + ratioOver;

                return(toReturn);
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 9
0
        private float GetXMultiplierForRight(InstanceSave instanceSave, IPositionedSizedObject ipso)
        {
            object xOriginAsObject = EditingManager.GetCurrentValueForVariable("X Origin", instanceSave);

            bool shouldContiue = xOriginAsObject != null;

            if (shouldContiue)
            {
                HorizontalAlignment xOrigin = (HorizontalAlignment)xOriginAsObject;
                float ratioOver             = GetRatioXOverInSelection(ipso, xOrigin);

                var toReturn = 0 + ratioOver;

                return(toReturn);
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 10
0
        public void Test()
        {
            SelectedState.Self.SelectedElement = mElements.Screen;
            WireframeObjectManager.Self.RefreshAll(true,
                                                   mElements.Screen);



            IPositionedSizedObject ipso = WireframeObjectManager.Self.GetRepresentation(mTextInScreen);

            if (ipso == null)
            {
                throw new Exception("Could not find representation for the Text in Screen.");
            }

            if (ipso.Parent != null)
            {
                throw new Exception("The IPSO being returned is improper!  It shouldn't have a parent");
            }
        }
Exemplo n.º 11
0
        public void SetOriginXPosition(GraphicalUiElement asGue)
        {
            float absoluteX = asGue.AbsoluteX;
            float absoluteY = asGue.AbsoluteY;

            IPositionedSizedObject asIpso = asGue;
            float zoom = Renderer.Self.Camera.Zoom;

            float offset = RadiusAtNoZoom * 1.5f / zoom;



            mXLine1.X = absoluteX - offset;
            mXLine1.Y = absoluteY - offset;

            mXLine2.X = absoluteX - offset;
            mXLine2.Y = absoluteY + offset;

            mXLine1.RelativePoint = new Microsoft.Xna.Framework.Vector2(offset * 2, offset * 2);
            mXLine2.RelativePoint = new Microsoft.Xna.Framework.Vector2(offset * 2, -offset * 2);
        }
Exemplo n.º 12
0
        private void SetGuideParent(GraphicalUiElement parentIpso, GraphicalUiElement ipso, string guideName, bool setParentToBoundsIfNoGuide)
        {
            // I dont't think we want to do this anymore because it should be handled by the GraphicalUiElement
            if (parentIpso != null && (parentIpso.Tag == null || parentIpso.Tag is ScreenSave == false))
            {
                ipso.Parent = parentIpso;
            }

            if (!string.IsNullOrEmpty(guideName))
            {
                IPositionedSizedObject guideIpso = GetGuide(guideName);

                if (guideIpso != null)
                {
                    ipso.Parent = guideIpso;
                }
            }
            else if (setParentToBoundsIfNoGuide)
            {
                ipso.Parent = mWireframeControl.ScreenBounds;
            }
        }
Exemplo n.º 13
0
        private static bool IsIpsoVisible(IPositionedSizedObject ipso)
        {
            bool isVisible = true;

            if (ipso is GraphicalUiElement)
            {
                if (ipso.Tag == null || ipso.Tag is ScreenSave == false)
                {
                    // If this has no object, then just treat it as true:
                    try
                    {
                        isVisible = ((IVisible)ipso).AbsoluteVisible;
                    }
                    catch
                    {
                        isVisible = true;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            else if (ipso is IVisible)
            {
                isVisible = ((IVisible)ipso).AbsoluteVisible;
            }
            else if (ipso is Sprite)
            {
                isVisible = ((Sprite)ipso).AbsoluteVisible;
            }
            else if (ipso is Text)
            {
                isVisible = ((Text)ipso).AbsoluteVisible;
            }

            return(isVisible);
        }
Exemplo n.º 14
0
        private InstanceSave FindInstanceWithSourceFile(float worldX, float worldY)
        {
            List <ElementWithState> elementStack = new List <ElementWithState>();

            elementStack.Add(new ElementWithState(SelectedState.Self.SelectedElement)
            {
                StateName = SelectedState.Self.SelectedStateSave.Name
            });

            IPositionedSizedObject ipsoOver = SelectionManager.Self.GetRepresentationAt(worldX, worldY, false, elementStack);

            if (ipsoOver != null && ipsoOver.Tag is InstanceSave)
            {
                var baseStandardElement = ObjectFinder.Self.GetRootStandardElementSave(ipsoOver.Tag as InstanceSave);

                if (baseStandardElement.DefaultState.Variables.Any(v => v.Name == "SourceFile"))
                {
                    return(ipsoOver.Tag as InstanceSave);
                }
            }

            return(null);
        }
Exemplo n.º 15
0
 public void ShowSizeHandlesFor(IPositionedSizedObject representation)
 {
     mResizeHandles.Visible = true;
     mResizeHandles.SetValuesFrom(representation);
 }
 void IPositionedSizedObject.SetParentDirect(IPositionedSizedObject newParent)
 {
     // do nothing
 }
Exemplo n.º 17
0
        /// <summary>
        /// Performs every-frame highlight activity.
        /// </summary>
        /// <param name="forceNoHighlight">If force no highlight, the highlight will not act as if it's over anything. This is used
        /// to un-highlight anything if the cursor is outside of the window</param>
        void HighlightActivity(bool forceNoHighlight)
        {
            if (forceNoHighlight && HighlightedIpso != null)
            {
                int m = 3;
            }
            if (!InputLibrary.Cursor.Self.PrimaryDownIgnoringIsInWindow)
            {
                // There is currently a known
                // bug where the user can click+drag
                // on the divider and move "in" to the
                // wireframe window and the cursor will
                // change.

                Cursor cursorToSet = Cursors.Arrow;

                float worldXAt = Cursor.GetWorldX();
                float worldYAt = Cursor.GetWorldY();

                IPositionedSizedObject representationOver = null;


                if (EditingManager.Self.ContextMenuStrip != null && EditingManager.Self.ContextMenuStrip.Visible)
                {
                    // do nothing!
                }
                else
                {
                    if (WireframeEditor != null)
                    {
                        cursorToSet = WireframeEditor.GetWindowsCursorToShow(cursorToSet, worldXAt, worldYAt);
                    }

                    #region Selecting element activity

                    if (forceNoHighlight)
                    {
                        IsOverBody = false;
                    }

                    if (forceNoHighlight == false)
                    {
                        if (WireframeEditor?.HasCursorOver == true)
                        {
                            representationOver = WireframeObjectManager.Self.GetSelectedRepresentation();
                            IsOverBody         = false;
                        }
                        else
                        {
                            if (IsOverBody && Cursor.PrimaryDown)
                            {
                                cursorToSet        = Cursors.SizeAll;
                                representationOver = WireframeObjectManager.Self.GetSelectedRepresentation();
                            }
                            else
                            {
                                List <ElementWithState> elementStack = new List <ElementWithState>();
                                elementStack.Add(new ElementWithState(SelectedState.Self.SelectedElement));


                                representationOver =
                                    GetRepresentationAt(worldXAt, worldYAt, false, elementStack);

                                if (representationOver != null)
                                {
                                    cursorToSet = Cursors.SizeAll;
                                    IsOverBody  = true;
                                }
                                else
                                {
                                    IsOverBody = false;
                                }
                            }
                        }
                    }
                    #endregion
                }


                if (representationOver != null && representationOver is NineSlice)
                {
                    // This function updates the sizes and texture coordinates of the
                    // highlighted representation if it's a NineSlice.  This is needed before
                    // we set the HighlightedIpso and before we update the highlight objects
                    (representationOver as NineSlice).RefreshTextureCoordinatesAndSpriteSizes();
                }



                // We used to not check this, but we have to now because the cursor might be
                if (Cursor.IsInWindow)
                {
                    Cursor.SetWinformsCursor(cursorToSet);

                    // We don't want to show the highlight when the user is performing some kind of editing.
                    // Therefore make sure the cursor isn't down.
                    if (representationOver != null && Cursor.PrimaryDown == false)
                    {
                        HighlightedIpso = representationOver;
                    }
                    else
                    {
                        HighlightedIpso = null;
                    }
                }
            }
            else if (InputLibrary.Cursor.Self.PrimaryDown && Cursor.IsInWindow)
            {
                // We only want to hide it if the user is holding the cursor down over the wireframe window.
                HighlightedIpso = null;
            }

            if (forceNoHighlight)
            {
                HighlightedIpso = null;
            }

            highlightManager.UpdateHighlightObjects();
        }
Exemplo n.º 18
0
 public static float GetAbsoluteBottom(this IPositionedSizedObject ipso)
 {
     return(ipso.GetAbsoluteY() + ipso.Height);
 }
Exemplo n.º 19
0
        private float GetYMultiplierForTop(InstanceSave instanceSave, IPositionedSizedObject ipso)
        {
            object yOriginAsObject = GetCurrentValueForVariable("Y Origin", instanceSave);

            VerticalAlignment yOrigin = (VerticalAlignment)yOriginAsObject;

            float ratioOver = GetRatioYDownInSelection(ipso, yOrigin);
            return 1 - ratioOver;
        }
Exemplo n.º 20
0
 void IPositionedSizedObject.SetParentDirect(IPositionedSizedObject parent)
 {
     mContainedObjectAsIpso.SetParentDirect(parent);
 }
Exemplo n.º 21
0
        public static void RenderLinePrimitive(LinePrimitive linePrimitive, SpriteBatch spriteBatch, IPositionedSizedObject ipso, SystemManagers managers, bool isDotted)
        {
            linePrimitive.Position.X = ipso.GetAbsoluteX();
            linePrimitive.Position.Y = ipso.GetAbsoluteY();

            Renderer renderer;
            if (managers != null)
            {
                renderer = managers.Renderer;
            }
            else
            {
                renderer = Renderer.Self;
            }

            Texture2D textureToUse = renderer.SinglePixelTexture;

            if (isDotted)
            {
                textureToUse = renderer.DottedLineTexture;
            }

            linePrimitive.Render(spriteBatch, managers, textureToUse, .2f * renderer.Camera.Zoom);
        }
Exemplo n.º 22
0
        private void CalculateMultipliers(InstanceSave instanceSave, List <ElementWithState> elementStack, out float changeXMultiplier, out float changeYMultiplier, out float widthMultiplier, out float heightMultiplier)
        {
            changeXMultiplier = 0;
            changeYMultiplier = 0;
            widthMultiplier   = 0;
            heightMultiplier  = 0;

            IPositionedSizedObject ipso = WireframeObjectManager.Self.GetRepresentation(instanceSave, elementStack);

            if (ipso == null)
            {
                ipso = WireframeObjectManager.Self.GetRepresentation(SelectedState.Self.SelectedElement);
            }

            switch (this.SideGrabbed)
            {
            case ResizeSide.TopLeft:
                changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso);
                widthMultiplier   = -1;
                changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso);
                heightMultiplier  = -1;
                break;

            case ResizeSide.Top:
                changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso);
                heightMultiplier  = -1;
                break;

            case ResizeSide.TopRight:
                changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso);
                widthMultiplier   = 1;
                changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso);
                heightMultiplier  = -1;
                break;

            case ResizeSide.Right:
                changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso);
                widthMultiplier   = 1;
                break;

            case ResizeSide.BottomRight:
                changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso);

                changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso);
                widthMultiplier   = 1;
                heightMultiplier  = 1;
                break;

            case ResizeSide.Bottom:
                heightMultiplier  = 1;
                changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso);

                break;

            case ResizeSide.BottomLeft:
                changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso);
                changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso);
                widthMultiplier   = -1;
                heightMultiplier  = 1;
                break;

            case ResizeSide.Left:
                changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso);
                widthMultiplier   = -1;
                break;
            }

            if (mResizeHandles.Width != 0)
            {
                widthMultiplier *= (ipso.Width / mResizeHandles.Width);
            }

            if (mResizeHandles.Height != 0)
            {
                heightMultiplier *= (ipso.Height / mResizeHandles.Height);
            }

            if (GetIsAltDown())
            {
                if (widthMultiplier != 0)
                {
                    // user grabbed a corner that can change width, so adjust the x multiplier
                    changeXMultiplier = (changeXMultiplier - .5f) * 2;
                }

                if (heightMultiplier != 0)
                {
                    changeYMultiplier = (changeYMultiplier - .5f) * 2;
                }

                heightMultiplier *= 2;
                widthMultiplier  *= 2;
            }
        }
Exemplo n.º 23
0
        private void ReactIfChangedMemberIsUnitType(ElementSave parentElement, string changedMember, object oldValue)
        {
            StateSave stateSave = SelectedState.Self.SelectedStateSave;

            IPositionedSizedObject currentIpso =
                WireframeObjectManager.Self.GetSelectedRepresentation();

            float parentWidth  = ObjectFinder.Self.GumProjectSave.DefaultCanvasWidth;
            float parentHeight = ObjectFinder.Self.GumProjectSave.DefaultCanvasHeight;

            float fileWidth  = 0;
            float fileHeight = 0;

            if (currentIpso != null)
            {
                currentIpso.GetFileWidthAndHeight(out fileWidth, out fileHeight);
                if (currentIpso.Parent != null)
                {
                    parentWidth  = currentIpso.Parent.Width;
                    parentHeight = currentIpso.Parent.Height;
                }
            }


            float  outX          = 0;
            float  outY          = 0;
            float  valueToSet    = 0;
            string variableToSet = null;

            bool isWidthOrHeight = false;

            bool wasAnythingSet = false;

            if (changedMember == "X Units" || changedMember == "Y Units" || changedMember == "Width Units" || changedMember == "Height Units")
            {
                object unitType = EditingManager.GetCurrentValueForVariable(changedMember, SelectedState.Self.SelectedInstance);
                XOrY   xOrY     = XOrY.X;
                if (changedMember == "X Units")
                {
                    variableToSet = "X";
                    xOrY          = XOrY.X;
                }
                else if (changedMember == "Y Units")
                {
                    variableToSet = "Y";
                    xOrY          = XOrY.Y;
                }
                else if (changedMember == "Width Units")
                {
                    variableToSet   = "Width";
                    isWidthOrHeight = true;
                    xOrY            = XOrY.X;
                }
                else if (changedMember == "Height Units")
                {
                    variableToSet   = "Height";
                    isWidthOrHeight = true;
                    xOrY            = XOrY.Y;
                }



                float valueOnObject = 0;
                if (stateSave.TryGetValue <float>(GetQualifiedName(variableToSet), out valueOnObject))
                {
                    if (xOrY == XOrY.X)
                    {
                        UnitConverter.Self.ConvertToPixelCoordinates(
                            valueOnObject, 0, oldValue, null, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out outY);

                        UnitConverter.Self.ConvertToUnitTypeCoordinates(
                            outX, outY, unitType, null, parentWidth, parentHeight, fileWidth, fileHeight, out valueToSet, out outY);
                    }
                    else
                    {
                        UnitConverter.Self.ConvertToPixelCoordinates(
                            0, valueOnObject, null, oldValue, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out outY);

                        UnitConverter.Self.ConvertToUnitTypeCoordinates(
                            outX, outY, null, unitType, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out valueToSet);
                    }
                    wasAnythingSet = true;
                }
            }

            if (wasAnythingSet)
            {
                InstanceSave instanceSave = SelectedState.Self.SelectedInstance;
                if (SelectedState.Self.SelectedInstance != null)
                {
                    variableToSet = SelectedState.Self.SelectedInstance.Name + "." + variableToSet;
                }

                stateSave.SetValue(variableToSet, valueToSet, instanceSave);
            }
        }
Exemplo n.º 24
0
        public void SetValuesFrom(IPositionedSizedObject ipso)
        {
            this.mX = ipso.GetAbsoluteX();
            this.mY = ipso.GetAbsoluteY();
            this.mWidth = ipso.Width;
            this.mHeight = ipso.Height;

            if (ipso is GraphicalUiElement)
            {
                var asGue = ipso as GraphicalUiElement;

                SetOriginXPosition(asGue);
            }

            UpdateToProperties();
        }
Exemplo n.º 25
0
        public static void Render(SystemManagers managers, SpriteBatch spriteBatch,
                                  IPositionedSizedObject ipso, Texture2D texture, Color color,
                                  Rectangle?sourceRectangle   = null,
                                  bool flipHorizontal         = false,
                                  bool flipVertical           = false,
                                  float rotationInDegrees     = 0,
                                  bool treat0AsFullDimensions = false
                                  )
        {
            Renderer renderer = null;

            if (managers == null)
            {
                renderer = Renderer.Self;
            }
            else
            {
                renderer = managers.Renderer;
            }

            Texture2D textureToUse = texture;

            if (textureToUse == null)
            {
                textureToUse = LoaderManager.Self.InvalidTexture;

                if (textureToUse == null)
                {
                    return;
                }
            }

            SpriteEffects effects = SpriteEffects.None;

            if (flipHorizontal)
            {
                effects |= SpriteEffects.FlipHorizontally;
            }
            if (flipVertical)
            {
                effects |= SpriteEffects.FlipVertically;
            }

            if ((ipso.Width > 0 && ipso.Height > 0) || treat0AsFullDimensions == false)
            {
                Vector2 scale = Vector2.One;

                if (textureToUse == null)
                {
                    scale = new Vector2(ipso.Width, ipso.Height);
                }
                else
                {
                    float ratioWidth  = 1;
                    float ratioHeight = 1;
                    if (sourceRectangle.HasValue)
                    {
                        ratioWidth  = sourceRectangle.Value.Width / (float)textureToUse.Width;
                        ratioHeight = sourceRectangle.Value.Height / (float)textureToUse.Height;
                    }

                    scale = new Vector2(ipso.Width / (ratioWidth * textureToUse.Width),
                                        ipso.Height / (ratioHeight * textureToUse.Height));
                }

                if (textureToUse != null && textureToUse.IsDisposed)
                {
                    throw new ObjectDisposedException("Texture is disposed.  Texture name: " + textureToUse.Name + ", sprite scale: " + scale);
                }

                spriteBatch.Draw(textureToUse,
                                 new Vector2(ipso.GetAbsoluteX(), ipso.GetAbsoluteY()),
                                 sourceRectangle,
                                 color,
                                 Microsoft.Xna.Framework.MathHelper.TwoPi * -rotationInDegrees / 360.0f,
                                 Vector2.Zero,
                                 scale,
                                 effects,
                                 0);
            }
            else
            {
                int width  = textureToUse.Width;
                int height = textureToUse.Height;

                if (sourceRectangle != null && sourceRectangle.HasValue)
                {
                    width  = sourceRectangle.Value.Width;
                    height = sourceRectangle.Value.Height;
                }

                Rectangle destinationRectangle = new Rectangle(
                    (int)(ipso.GetAbsoluteX()),
                    (int)(ipso.GetAbsoluteY()),
                    width,
                    height);


                spriteBatch.Draw(textureToUse,
                                 destinationRectangle,
                                 sourceRectangle,
                                 color,
                                 rotationInDegrees / 360.0f,
                                 Vector2.Zero,
                                 effects,
                                 0
                                 );
            }
        }
Exemplo n.º 26
0
        public static void Render(SystemManagers managers, SpriteBatch spriteBatch, IPositionedSizedObject ipso, Texture2D texture)
        {
            Color color = new Color(1.0f, 1.0f, 1.0f, 1.0f); // White

            Render(managers, spriteBatch, ipso, texture, color);
        }
        public static string GetQualifiedPrefixWithDot(IPositionedSizedObject ipso, ElementSave elementSaveForIpso, ElementSave containerElement)
        {
            string qualifiedVariablePrefixWithDot = ipso.Name + ".";

            IPositionedSizedObject parent = ipso.Parent;

            while (parent != null)
            {
                qualifiedVariablePrefixWithDot = parent.Name + "." + qualifiedVariablePrefixWithDot;
                parent = parent.Parent;
            }

            if (
                // Not sure why we checked to make sure it doesn't contain a dot.  It always will because
                // of the first line:
                //!qualifiedVariablePrefixWithDot.Contains(".") &&
                elementSaveForIpso == containerElement)
            {
                qualifiedVariablePrefixWithDot = "";
            }
            if (containerElement is ComponentSave || containerElement is StandardElementSave)
            {
                // If the containerElement is a ComponentSave, then we assume (currently) that the ipso is attached to it.  Since we'll be using
                // the container element to get the variable, we don't want to include the name of the element, so let's get rid of the first part.
                // Update June 13, 2012
                // If we pass a Text object
                // that is the child of a Button
                // and the Button is the container
                // element, we want to return "TextInstance."
                // as the prefix.  The code below prevents that.
                // I now have unit tests for this so I'm going to
                // remove the code below and modify it later if it
                // turns out we really do need it.
                // Update June 13, 2012
                // Now we climb up the parent/child
                // relationship until we get to the root
                // If the containerElement is a ComponentSave
                // or StandardElementSave (although maybe this
                // case will never happen) we need to remove the
                // first name before the dot because it's the element
                // itself.  If it's a Screen there is no attachment so
                // the first name won't be the name of the Screen.
                int indexOfDot = qualifiedVariablePrefixWithDot.IndexOf('.');
                if (indexOfDot != -1)
                {
                    qualifiedVariablePrefixWithDot = qualifiedVariablePrefixWithDot.Substring(indexOfDot + 1, qualifiedVariablePrefixWithDot.Length - (indexOfDot + 1));
                }
            }

            return qualifiedVariablePrefixWithDot;
        }
Exemplo n.º 28
0
        public static void Render(SystemManagers managers, SpriteBatch spriteBatch,
            IPositionedSizedObject ipso, Texture2D texture, Color color,
            Rectangle? sourceRectangle = null,
            bool flipHorizontal = false,
            bool flipVertical = false,
            float rotationInDegrees = 0,
            bool treat0AsFullDimensions = false
            )
        {
            Renderer renderer = null;
            if (managers == null)
            {
                renderer = Renderer.Self;
            }
            else
            {
                renderer = managers.Renderer;
            }

            Texture2D textureToUse = texture;

            if (textureToUse == null)
            {
                textureToUse = LoaderManager.Self.InvalidTexture;

                if (textureToUse == null)
                {
                    return;
                }
            }

            SpriteEffects effects = SpriteEffects.None;
            if (flipHorizontal)
            {
                effects |= SpriteEffects.FlipHorizontally;
            }
            if (flipVertical)
            {
                effects |= SpriteEffects.FlipVertically;
            }

            if ((ipso.Width > 0 && ipso.Height > 0) || treat0AsFullDimensions == false)
            {
                Vector2 scale = Vector2.One;

                if (textureToUse == null)
                {
                    scale = new Vector2(ipso.Width, ipso.Height);
                }
                else
                {
                    float ratioWidth = 1;
                    float ratioHeight = 1;
                    if (sourceRectangle.HasValue)
                    {
                        ratioWidth = sourceRectangle.Value.Width / (float)textureToUse.Width;
                        ratioHeight = sourceRectangle.Value.Height / (float)textureToUse.Height;
                    }

                    scale = new Vector2(ipso.Width / (ratioWidth * textureToUse.Width),
                        ipso.Height / (ratioHeight * textureToUse.Height));
                }

                if (textureToUse != null && textureToUse.IsDisposed)
                {
                    throw new ObjectDisposedException("Texture is disposed.  Texture name: " + textureToUse.Name + ", sprite scale: " + scale);
                }

                spriteBatch.Draw(textureToUse,
                    new Vector2(ipso.GetAbsoluteX(), ipso.GetAbsoluteY()),
                    sourceRectangle,
                    color,
                    Microsoft.Xna.Framework.MathHelper.TwoPi * -rotationInDegrees/360.0f,
                    Vector2.Zero,
                    scale,
                    effects,
                    0);
            }
            else
            {
                int width = textureToUse.Width;
                int height = textureToUse.Height;

                if (sourceRectangle != null && sourceRectangle.HasValue)
                {
                    width = sourceRectangle.Value.Width;
                    height = sourceRectangle.Value.Height;
                }

                Rectangle destinationRectangle = new Rectangle(
                    (int)(ipso.GetAbsoluteX()),
                    (int)(ipso.GetAbsoluteY()),
                    width,
                    height);

                spriteBatch.Draw(textureToUse,
                    destinationRectangle,
                    sourceRectangle,
                    color,
                    rotationInDegrees/360.0f,
                    Vector2.Zero,
                    effects,
                    0
                    );
            }
        }
Exemplo n.º 29
0
 void IPositionedSizedObject.SetParentDirect(IPositionedSizedObject parent)
 {
     mParent = parent;
 }
Exemplo n.º 30
0
        public static void RenderLinePrimitive(LinePrimitive linePrimitive, SpriteBatch spriteBatch, IPositionedSizedObject ipso, SystemManagers managers, bool isDotted)
        {
            linePrimitive.Position.X = ipso.GetAbsoluteX();
            linePrimitive.Position.Y = ipso.GetAbsoluteY();

            Renderer renderer;

            if (managers != null)
            {
                renderer = managers.Renderer;
            }
            else
            {
                renderer = Renderer.Self;
            }

            Texture2D textureToUse = renderer.SinglePixelTexture;

            if (isDotted)
            {
                textureToUse = renderer.DottedLineTexture;
            }

            linePrimitive.Render(spriteBatch, managers, textureToUse, .2f * renderer.Camera.Zoom);
        }
Exemplo n.º 31
0
 public bool IsRepresentation(IPositionedSizedObject ipso)
 {
     return(mGraphicalElements.Contains(ipso));
 }
Exemplo n.º 32
0
        public static void Render(SystemManagers managers, SpriteBatch spriteBatch, IPositionedSizedObject ipso, Texture2D texture)
        {
            Color color = new Color(1.0f, 1.0f, 1.0f, 1.0f); // White

            Render(managers, spriteBatch, ipso, texture, color);
        }
Exemplo n.º 33
0
        private float GetXMultiplierForRight(InstanceSave instanceSave, IPositionedSizedObject ipso)
        {
            object xOriginAsObject = GetCurrentValueForVariable("X Origin", instanceSave);
            if (!(xOriginAsObject is HorizontalAlignment))
            {
                int m = 3;
            }
            HorizontalAlignment xOrigin = (HorizontalAlignment)xOriginAsObject;
            float ratioOver = GetRatioXOverInSelection(ipso, xOrigin);

            return 0 + ratioOver;
        }
Exemplo n.º 34
0
        public void SetContainedObject(IRenderable containedObject)
        {
            if (containedObject == this)
            {
                throw new ArgumentException("The argument containedObject cannot be 'this'");
            }

            mContainedObjectAsRenderable = containedObject;
            mContainedObjectAsIpso = mContainedObjectAsRenderable as IPositionedSizedObject;
            mContainedObjectAsIVisible = mContainedObjectAsRenderable as IVisible;

            if (containedObject is global::RenderingLibrary.Math.Geometry.LineRectangle)
            {
                if (this.ElementSave != null && ElementSave.Name == "Container")
                {
                    (containedObject as global::RenderingLibrary.Math.Geometry.LineRectangle).LocalVisible = ShowLineRectangles;
                }
            }

            UpdateLayout();
        }
Exemplo n.º 35
0
        private void SetLineRectangleAroundIpso(LineRectangle rectangle, IPositionedSizedObject pso)
        {
            float adjustedSelectionBorder = SelectionBorder / Renderer.Self.Camera.Zoom;

            rectangle.Visible = true;
            rectangle.X = pso.GetAbsoluteX() - adjustedSelectionBorder;
            rectangle.Y = pso.GetAbsoluteY() - adjustedSelectionBorder;

            rectangle.Width = pso.Width + adjustedSelectionBorder * 2;
            rectangle.Height = pso.Height + adjustedSelectionBorder * 2;
        }
        private GraphicalUiElement CreateRepresentationForInstance(InstanceSave instance, InstanceSave parentInstance, List <ElementWithState> elementStack, GraphicalUiElement container)
        {
            IPositionedSizedObject newIpso = null;

            GraphicalUiElement graphicalElement = newIpso as GraphicalUiElement;
            var baseElement = ObjectFinder.Self.GetElementSave(instance.BaseType);

            string type = instance.BaseType;

            var renderable = PluginManager.Self.CreateRenderableForType(type);

            if (renderable != null)
            {
                graphicalElement = new GraphicalUiElement(null, container);
                ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);
                graphicalElement.SetContainedObject(renderable);
                graphicalElement.Tag            = instance;
                graphicalElement.Component.Name = instance.Name;
                graphicalElement.Component.Tag  = instance;
            }


            else if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle")
            {
                graphicalElement = new GraphicalUiElement(null, container);
                ElementSave instanceBase = ObjectFinder.Self.GetElementSave(type);
                graphicalElement.CreateGraphicalComponent(instanceBase, null);
                graphicalElement.Tag            = instance;
                graphicalElement.Component.Name = instance.Name;
                graphicalElement.Component.Tag  = instance;

                if (type == "Text")
                {
                    (graphicalElement.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines;
                    if (SelectedState.Self.SelectedStateSave != null)
                    {
                        FontManager.Self.ReactToFontValueSet(instance);
                    }
                }
            }
            else if (instance.IsComponent())
            {
                newIpso = CreateRepresentationsForInstanceFromComponent(instance, elementStack, parentInstance, container, ObjectFinder.Self.GetComponent(instance.BaseType));
            }
            else
            {
                // Make sure the base type is valid.
                // This could be null if a base type changed
                // its name but the derived wasn't updated, or
                // if someone screwed with the XML files.  Who knows...

                if (baseElement != null)
                {
                    graphicalElement = new GraphicalUiElement(null, container);

                    CreateRectangleFor(instance, elementStack, graphicalElement);
                }
            }



            if (newIpso != null && (newIpso is GraphicalUiElement) == false)
            {
                graphicalElement = new GraphicalUiElement(newIpso as IRenderable, container);
            }
            else if (newIpso is GraphicalUiElement)
            {
                graphicalElement = newIpso as GraphicalUiElement;
            }

            if (graphicalElement != null)
            {
                if (baseElement != null)
                {
                    graphicalElement.ElementSave = baseElement;
                    foreach (var exposedVariable in baseElement.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName)))
                    {
                        graphicalElement.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name);
                    }
                }



                var selectedState = SelectedState.Self.SelectedStateSave;
                if (selectedState == null)
                {
                    selectedState = SelectedState.Self.SelectedElement.DefaultState;
                }

                RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(selectedState);

                string guide  = rvf.GetValue <string>("Guide");
                string parent = rvf.GetValue <string>(instance.Name + ".Parent");

                SetGuideParent(container, graphicalElement, guide);

                if (baseElement != null)
                {
                    graphicalElement.SetStatesAndCategoriesRecursively(baseElement);

                    // for performance reasons, we'll suspend the layout here:
                    graphicalElement.SuspendLayout();
                    {
                        graphicalElement.SetVariablesRecursively(baseElement, baseElement.DefaultState);
                    }
                    graphicalElement.ResumeLayout();
                }
            }

            return(graphicalElement);
        }
Exemplo n.º 37
0
        public static void UpdateLinePrimitive(LinePrimitive linePrimitive, IPositionedSizedObject ipso)
        {
            Matrix matrix = Matrix.CreateRotationZ(-MathHelper.ToRadians(ipso.Rotation));

            

            linePrimitive.Replace(0, Vector2.Zero);
            linePrimitive.Replace(1, Vector2.Transform(new Vector2(ipso.Width, 0), matrix) );
            linePrimitive.Replace(2, Vector2.Transform(new Vector2(ipso.Width, ipso.Height), matrix) );
            linePrimitive.Replace(3, Vector2.Transform(new Vector2(0, ipso.Height), matrix) );
            linePrimitive.Replace(4, Vector2.Zero); // close back on itself

        }
Exemplo n.º 38
0
        private static float GetRatioXOverInSelection(IPositionedSizedObject ipso, HorizontalAlignment horizontalAlignment)
        {
            //float handleLeft = SelectionManager.Self.ResizeHandles.X;
            //float handleWidth = SelectionManager.Self.ResizeHandles.Width;

            //float ipsoXToUse = ipso.GetAbsoluteX();

            //if (horizontalAlignment == HorizontalAlignment.Center)
            //{
            //    ipsoXToUse += ipso.Width / 2.0f;
            //}
            //else if (horizontalAlignment == HorizontalAlignment.Right)
            //{
            //    ipsoXToUse += ipso.Width;
            //}

            //return (ipsoXToUse - handleLeft) / handleWidth;
            // Isn't this easier?
            if (horizontalAlignment == HorizontalAlignment.Left)
            {
                return 0;
            }
            else if (horizontalAlignment == HorizontalAlignment.Center)
            {
                return .5f;
            }
            else// if (horizontalAlignment == HorizontalAlignment.Right)
            {
                return 1;
            }
        }
Exemplo n.º 39
0
 public static float GetAbsoluteRight(this IPositionedSizedObject ipso)
 {
     return(ipso.GetAbsoluteX() + ipso.Width);
 }
Exemplo n.º 40
0
        private void PushAndDoubleClickSelectionActivity()
        {
            try
            {
                // If the SideOver is a non-None
                // value, that means that the object
                // is already selected
                if (SideOver == ResizeSide.None)
                {
                    float x = Cursor.GetWorldX();
                    float y = Cursor.GetWorldY();

                    List <ElementWithState> elementStack = new List <ElementWithState>();
                    elementStack.Add(new ElementWithState(SelectedState.Self.SelectedElement));


                    IPositionedSizedObject representation =
                        GetRepresentationAt(x, y, Cursor.PrimaryDoubleClick, elementStack);
                    ProjectVerifier.Self.AssertIsPartOfRenderer(representation);
                    bool hasChanged = true;

                    if (representation != null)
                    {
                        InstanceSave selectedInstance;
                        ElementSave  selectedElement;
                        GetElementOrInstanceForIpso(representation, elementStack, out selectedInstance, out selectedElement);

                        if (selectedInstance == null && selectedElement == null)
                        {
                            throw new Exception("Either the selected element or instance should not be null");
                        }
                        // The representation
                        // will become invalid
                        // in the following if/else
                        // because the Wireframe view
                        // is refreshed.  So we need to
                        // re-get the representationl
                        if (selectedInstance != null)
                        {
                            bool isAlreadySelected = SelectedState.Self.SelectedInstances.Contains(selectedInstance);

                            if (isAlreadySelected)
                            {
                                hasChanged = false;
                            }
                            else
                            {
                                // If the user shift+clicks, then we want to select multiple
                                bool selectMultiple = IsShiftDown;

                                if (selectMultiple)
                                {
                                    List <InstanceSave> instances = new List <InstanceSave>();
                                    instances.AddRange(SelectedState.Self.SelectedInstances);
                                    instances.Add(selectedInstance);
                                    SelectedState.Self.SelectedInstances = instances;
                                }
                                else
                                {
                                    SelectedState.Self.SelectedInstance = selectedInstance;
                                }
                                // See comment above on why we do this
                                representation = WireframeObjectManager.Self.GetRepresentation(selectedInstance, elementStack);
                            }
                        }
                        else
                        {
                            SelectedState.Self.SelectedInstance = null;
                            SelectedState.Self.SelectedElement  = selectedElement;

                            representation = WireframeObjectManager.Self.GetRepresentation(selectedElement);
                        }
                        UndoManager.Self.RecordUndo();
                    }
                    else
                    {
                        SelectedState.Self.SelectedInstance = null;
                    }



                    if (hasChanged)
                    {
                        if (SelectedState.Self.SelectedInstances.GetCount() > 1)
                        {
                            List <GraphicalUiElement> selectedIpsos = new List <GraphicalUiElement>();
                            foreach (var instance in SelectedState.Self.SelectedInstances)
                            {
                                selectedIpsos.Add(WireframeObjectManager.Self.GetRepresentation(instance, elementStack));
                            }
                            SelectedIpsos = selectedIpsos;
                        }
                        else
                        {
                            SelectedIpso = representation as GraphicalUiElement;
                        }
                    }
                    ProjectVerifier.Self.AssertSelectedIpsosArePartOfRenderer();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error in PushAndDoubleClickSelectionActivity: " + e.ToString());
                throw e;
            }
        }
Exemplo n.º 41
0
        private void RenderUsingBitmapFont(SpriteBatch spriteBatch, SystemManagers managers)
        {
            if (mTempForRendering == null)
            {
                mTempForRendering = new LineRectangle(managers);
            }

            mTempForRendering.X = this.X;
            mTempForRendering.Y = this.Y;
            mTempForRendering.Width = this.mTextureToRender.Width * mFontScale;
            mTempForRendering.Height = this.mTextureToRender.Height * mFontScale;
            mTempForRendering.Parent = this.Parent;

            float widthDifference = this.EffectiveWidth - mTempForRendering.Width;

            if (this.HorizontalAlignment == Graphics.HorizontalAlignment.Center)
            {
                mTempForRendering.X += widthDifference / 2.0f;
            }
            else if (this.HorizontalAlignment == Graphics.HorizontalAlignment.Right)
            {
                mTempForRendering.X += widthDifference;
            }

            if (this.VerticalAlignment == Graphics.VerticalAlignment.Center)
            {
                mTempForRendering.Y += (this.EffectiveHeight - mTextureToRender.Height) / 2.0f;
            }
            else if (this.VerticalAlignment == Graphics.VerticalAlignment.Bottom)
            {
                mTempForRendering.Y += this.EffectiveHeight - mTempForRendering.Height;
            }

            Sprite.Render(managers, spriteBatch, mTempForRendering, mTextureToRender,
                new Color(mRed, mGreen, mBlue, mAlpha), null, false, false, Rotation, treat0AsFullDimensions: false);
        }
Exemplo n.º 42
0
        /// <summary>
        /// This method gets the actual width/height value of an object if the stored value is 0.  This is used for Sprites
        /// which have width/height of 0 if they let the Texture determine their size.
        /// </summary>
        /// <param name="currentValue">The value as stored in the StateSave - may be 0</param>
        /// <param name="baseVariableName">The base name - like Height</param>
        /// <param name="unitsValue">The units value - </param>
        /// <returns></returns>
        private float AdjustCurrentValueIfScale(float currentValue, string baseVariableName, object unitsValue)
        {
            if (currentValue == 0 && (baseVariableName == "Width" || baseVariableName == "Height"))
            {
                IPositionedSizedObject selectedIpso = SelectionManager.Self.SelectedIpso;

                if ((DimensionUnitType)unitsValue == DimensionUnitType.Absolute)
                {
                    if (baseVariableName == "Width")
                    {
                        currentValue = selectedIpso.Width;
                    }
                    else
                    {
                        currentValue = selectedIpso.Height;
                    }
                }
                else if ((DimensionUnitType)unitsValue == DimensionUnitType.RelativeToContainer)
                {
                    // We don't do anything special with "0" when RelativeToContainer, so don't modify the currentValue
                }
                else if ((DimensionUnitType)unitsValue == DimensionUnitType.PercentageOfSourceFile)
                {
                    if (selectedIpso is Sprite)
                    {
                        Microsoft.Xna.Framework.Graphics.Texture2D texture = (selectedIpso as Sprite).Texture;

                        if (texture != null)
                        {
                            if (baseVariableName == "Width")
                            {
                                currentValue = 100 * selectedIpso.Width / texture.Width;
                            }
                            else
                            {
                                currentValue = 100 * selectedIpso.Height / texture.Height;
                            }
                        }
                    }
                }
                else
                {
                    float parentValue;

                    // need to support percentage based width
                    if (baseVariableName == "Width")
                    {
                        if (selectedIpso.Parent == null)
                        {
                            parentValue = ObjectFinder.Self.GumProjectSave.DefaultCanvasWidth;
                        }
                        else
                        {
                            parentValue = selectedIpso.Parent.Width;
                        }
                        currentValue = 100 * selectedIpso.Width / parentValue;
                    }
                    else
                    {
                        if (selectedIpso.Parent == null)
                        {
                            parentValue = ObjectFinder.Self.GumProjectSave.DefaultCanvasHeight;
                        }
                        else
                        {
                            parentValue = selectedIpso.Parent.Height;
                        }

                        currentValue = 100 * selectedIpso.Height / parentValue;
                    }
                }
            }

            return(currentValue);
        }
Exemplo n.º 43
0
 private static float GetRatioYDownInSelection(IPositionedSizedObject ipso, VerticalAlignment verticalAlignment)
 {
     if (verticalAlignment == VerticalAlignment.Top)
     {
         return 0;
     }
     else if (verticalAlignment == VerticalAlignment.Center)
     {
         return .5f;
     }
     else //if (verticalAlignment == VerticalAlignment.Bottom)
     {
         return 1;
     }
 }
Exemplo n.º 44
0
 public static void UpdateLinePrimitive(LinePrimitive linePrimitive, IPositionedSizedObject ipso)
 {
     linePrimitive.Replace(0, Vector2.Zero);
     linePrimitive.Replace(1, new Vector2(ipso.Width, 0));
     linePrimitive.Replace(2, new Vector2(ipso.Width, ipso.Height));
     linePrimitive.Replace(3, new Vector2(0, ipso.Height));
     linePrimitive.Replace(4, Vector2.Zero); // close back on itself
 }
Exemplo n.º 45
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 =
                    mSideGrabbed == ResizeSide.TopLeft || mSideGrabbed == ResizeSide.TopRight ||
                    mSideGrabbed == ResizeSide.BottomLeft || mSideGrabbed == ResizeSide.BottomRight;

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

                    Cursor cursor  = 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 (mSideGrabbed)
                    {
                    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 > mAspectRatioOnGrab)
                    {
                        float yToUse = 0;
                        // We use the X, but adjust the Y
                        switch (mSideGrabbed)
                        {
                        case ResizeSide.BottomRight:
                            cursorXChange = cursorX - right;
                            yToUse        = top + absoluteXDifference / mAspectRatioOnGrab;
                            cursorYChange = yToUse - bottom;
                            break;

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

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

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

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

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

                        case ResizeSide.TopLeft:
                            cursorYChange = cursorY - top;
                            xToUse        = right - absoluteYDifference * mAspectRatioOnGrab;
                            cursorXChange = xToUse - left;
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 46
0
 void IPositionedSizedObject.SetParentDirect(IPositionedSizedObject parent)
 {
     mParent = parent;
 }
Exemplo n.º 47
0
        private void CalculateMultipliers(InstanceSave instanceSave, List <ElementWithState> elementStack, out float changeXMultiplier, out float changeYMultiplier, out float widthMultiplier, out float heightMultiplier)
        {
            changeXMultiplier = 0;
            changeYMultiplier = 0;
            widthMultiplier   = 0;
            heightMultiplier  = 0;

            IPositionedSizedObject ipso = WireframeObjectManager.Self.GetRepresentation(instanceSave, elementStack);

            if (ipso == null)
            {
                ipso = WireframeObjectManager.Self.GetRepresentation(SelectedState.Self.SelectedElement);
            }

            switch (this.mSideGrabbed)
            {
            case ResizeSide.TopLeft:
                changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso);
                widthMultiplier   = -1;
                changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso);
                heightMultiplier  = -1;
                break;

            case ResizeSide.Top:
                changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso);
                heightMultiplier  = -1;
                break;

            case ResizeSide.TopRight:
                changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso);
                widthMultiplier   = 1;
                changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso);
                heightMultiplier  = -1;
                break;

            case ResizeSide.Right:
                changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso);
                widthMultiplier   = 1;
                break;

            case ResizeSide.BottomRight:
                changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso);

                changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso);
                widthMultiplier   = 1;
                heightMultiplier  = 1;
                break;

            case ResizeSide.Bottom:
                heightMultiplier  = 1;
                changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso);

                break;

            case ResizeSide.BottomLeft:
                changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso);
                changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso);
                widthMultiplier   = -1;
                heightMultiplier  = 1;
                break;

            case ResizeSide.Left:
                changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso);
                widthMultiplier   = -1;
                break;
            }

            if (SelectionManager.Self.ResizeHandles.Width != 0)
            {
                widthMultiplier *= (ipso.Width / SelectionManager.Self.ResizeHandles.Width);
            }

            if (SelectionManager.Self.ResizeHandles.Height != 0)
            {
                heightMultiplier *= (ipso.Height / SelectionManager.Self.ResizeHandles.Height);
            }
        }