Inheritance: IRenderable, IPositionedSizedObject, IVisible
        public static void SetGraphicalUiElement(this ElementSave elementSave, GraphicalUiElement toReturn, SystemManagers systemManagers)
        {
            // We need to set categories and states first since those are used below;
            toReturn.SetStatesAndCategoriesRecursively(elementSave);

            toReturn.CreateGraphicalComponent(elementSave, systemManagers);

            toReturn.AddExposedVariablesRecursively(elementSave);

            toReturn.CreateChildrenRecursively(elementSave, systemManagers);

            toReturn.Tag = elementSave;

            toReturn.SetVariablesRecursively(elementSave);
        }
Esempio n. 2
0
        public GraphicalUiElement(IRenderable containedObject, GraphicalUiElement whatContainsThis)
        {
            SetContainedObject(containedObject);

            mWhatContainsThis = whatContainsThis;
            if (mWhatContainsThis != null)
            {
                mWhatContainsThis.mWhatThisContains.Add(this);

                if (whatContainsThis.mContainedObjectAsIpso != null)
                {
                    this.Parent = whatContainsThis;
                }
            }
        }
Esempio n. 3
0
 private static float GetRatioYDownInSelection(GraphicalUiElement gue, VerticalAlignment verticalAlignment)
 {
     if (verticalAlignment == VerticalAlignment.Top)
     {
         return(0);
     }
     else if (verticalAlignment == VerticalAlignment.TextBaseline)
     {
         if (gue.RenderableComponent is Text text && text.Height > 0)
         {
             return(1 - (text.DescenderHeight * text.FontScale / text.Height));
         }
         else
         {
             return(1);
         }
     }
        public static GraphicalUiElement CreateGueForElement(ElementSave elementSave, bool fullInstantiation = false)
        {
            GraphicalUiElement toReturn = null;

            if (mElementToGueTypes.ContainsKey(elementSave.Name))
            {
                var type = mElementToGueTypes[elementSave.Name];
                var constructor = type.GetConstructor(new Type[] { typeof(bool), typeof(bool) });

                bool callAssignReferences = fullInstantiation;
                toReturn = constructor.Invoke(new object[] { fullInstantiation, callAssignReferences }) as GraphicalUiElement;
            }
            else
            {
                toReturn = new GraphicalUiElement();
            }
            toReturn.ElementSave = elementSave;
            return toReturn;
        }
Esempio n. 5
0
 public void UnhighlightIpso(GraphicalUiElement highlightedIpso)
 {
     if (highlightedIpso.Component is Sprite)
     {
         mOverlaySprite.Visible = false;
     }
     else if (highlightedIpso.Component is NineSlice)
     {
         mOverlayNineSlice.Visible = false;
     }
     else if (highlightedIpso.Component is LineRectangle)
     {
         mOverlaySolidRectangle.Visible = false;
     }
     else if (highlightedIpso.Component is LinePolygon)
     {
         mOverlayLinePolygon.Visible = false;
     }
 }
Esempio n. 6
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;
            }
        }
Esempio n. 7
0
        private float GetYMultiplierForBottom(InstanceSave instanceSave, GraphicalUiElement 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);
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        private GraphicalUiElement ReverseLoopToFindIpso(float x, float y, int indexToStartAt, int indexToEndAt, bool visibleToCheck, List <ElementWithState> elementStack)
        {
            GraphicalUiElement ipsoOver = null;

            if (indexToEndAt < -1)
            {
                throw new Exception("Index cannot be less than -1");
            }
            if (indexToStartAt >= WireframeObjectManager.Self.AllIpsos.Count)
            {
                throw new Exception("Index must be less than the AllIpsos Count");
            }

            // Let's try to get visible ones first, then if we don't find anything, look at invisible ones
            for (int i = indexToStartAt; i > indexToEndAt; i--)
            {
                GraphicalUiElement ipso = WireframeObjectManager.Self.AllIpsos[i];
                bool skip = ipso.Tag is ScreenSave;
                if (!skip)
                {
                    bool visible = IsIpsoVisible(ipso);


                    if (visible == visibleToCheck && ipso.HasCursorOver(x, y) && (WireframeObjectManager.Self.IsRepresentation(ipso)))
                    {
                        // hold on, even though this is a valid IPSO and the cursor is over it, we gotta see if
                        // it's an instance that is locked.  If so, we shouldn't select it!
                        InstanceSave instanceSave = ipso.Tag as InstanceSave;
                        if (instanceSave == null || instanceSave.Locked == false)
                        {
                            ipsoOver = ipso;
                            break;
                        }
                    }
                }
            }

            return(ipsoOver);
        }
Esempio n. 10
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;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Returns the difference between the current X, Y, Width, and Height values and the nearest to-the-pixel value.
        /// </summary>
        /// <param name="gue">The GraphicalUiElement to use for current values.</param>
        /// <param name="differenceToUnitPositionX">The amount to add to the X value to snap it to-the-pixel.</param>
        /// <param name="differenceToUnitPositionY">The amount to add to the Y value to snap it to-the-pixel.</param>
        /// <param name="differenceToUnitWidth">The amount to add to the Width value to snap it to-the-pixel.</param>
        /// <param name="differenceToUnitHeight">The amount to add to the Height value to snap it to-the-pixel.</param>
        /// <remarks>
        /// The values returned here depend on the GraphicalUiElement's values for X,Y,Width, and Height. They also depend on the
        /// units for the corresponding values.
        /// As an example, if the GraphicalUiElement is using an XUnits of PixelsFromLeft and has an X value of 4.9, then the
        /// differenceToUnitPisitionX would be .1.
        /// </remarks>
        private static void GetDifferenceToUnit(GraphicalUiElement gue,
                                                out float differenceToUnitPositionX, out float differenceToUnitPositionY,
                                                out float differenceToUnitWidth, out float differenceToUnitHeight

                                                )
        {
            differenceToUnitPositionX = 0;
            differenceToUnitPositionY = 0;
            differenceToUnitWidth     = 0;
            differenceToUnitHeight    = 0;


            if (gue.XUnits.GetIsPixelBased())
            {
                float x        = gue.X;
                float desiredX = MathFunctions.RoundToInt(x);
                differenceToUnitPositionX = desiredX - x;
            }
            if (gue.YUnits.GetIsPixelBased())
            {
                float y        = gue.Y;
                float desiredY = MathFunctions.RoundToInt(y);
                differenceToUnitPositionY = desiredY - y;
            }

            if (gue.WidthUnits.GetIsPixelBased())
            {
                float width        = gue.Width;
                float desiredWidth = MathFunctions.RoundToInt(width);
                differenceToUnitWidth = desiredWidth - width;
            }

            if (gue.HeightUnits.GetIsPixelBased())
            {
                float height        = gue.Height;
                float desiredHeight = MathFunctions.RoundToInt(height);
                differenceToUnitHeight = desiredHeight - height;
            }
        }
        private IPositionedSizedObject CreateRectangleFor(InstanceSave instance, List <ElementWithState> elementStack, GraphicalUiElement graphicalUiElement)
        {
            ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);

            graphicalUiElement.CreateGraphicalComponent(instanceBase, null);
            graphicalUiElement.Tag            = instance;
            graphicalUiElement.Component.Name = instance.Name;
            graphicalUiElement.Component.Tag  = instance;

            return(graphicalUiElement);
        }
        private GraphicalUiElement CreateRepresentationsForInstanceFromComponent(InstanceSave instance,
                                                                                 List <ElementWithState> elementStack, InstanceSave parentInstance, GraphicalUiElement parentIpso,
                                                                                 ComponentSave baseComponentSave)
        {
            StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(instance);

            GraphicalUiElement rootIpso = null;

            if (ses != null)
            {
                rootIpso = new GraphicalUiElement(null, parentIpso);

                string type = ses.Name;

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

                if (renderable != null)
                {
                    rootIpso.SetContainedObject(renderable);
                    rootIpso.Tag            = instance;
                    rootIpso.Component.Name = instance.Name;
                    rootIpso.Component.Tag  = instance;
                }

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

                    if (type == "Text")
                    {
                        (rootIpso.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines;
                    }
                }
                else
                {
                    // give the plugin manager a shot at it:

                    CreateRectangleFor(instance, elementStack, rootIpso);
                }

                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");
                SetGuideParent(parentIpso, rootIpso, guide);

                ElementWithState elementWithState = new ElementWithState(baseComponentSave);
                var tempRvf = new DataTypes.RecursiveVariableFinder(instance, elementStack);
                var state   = tempRvf.GetValue("State") as string;
                elementWithState.StateName = state;

                foreach (var category in baseComponentSave.Categories)
                {
                    elementWithState.CategorizedStates.Add(category.Name, tempRvf.GetValue <string>(category.Name + "State"));
                }

                elementWithState.InstanceName = instance.Name;

                // Does this element already exist?
                bool alreadyExists = elementStack.Any(item => item.Element == elementWithState.Element);
                if (!alreadyExists)
                {
                    elementStack.Add(elementWithState);

                    foreach (InstanceSave internalInstance in baseComponentSave.Instances)
                    {
                        // let's make sure we don't recursively create the same instance causing a stack overflow:

                        GraphicalUiElement createdIpso = CreateRepresentationForInstance(internalInstance, instance, elementStack, rootIpso);
                    }
                }

                SetUpParentRelationship(rootIpso.ContainedElements, elementStack, baseComponentSave.Instances);

                elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == baseComponentSave));
            }

            return(rootIpso);
        }
        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);
        }
Esempio n. 15
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;
            }
        }
        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;
            }
        }
        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;

            if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle")
            {
                graphicalElement = new GraphicalUiElement(null, container);
                ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);
                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;
                }

            }
            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, container == null || parent == AvailableInstancesConverter.ScreenBoundsName);
            }

            if (baseElement != null)
            {
                graphicalElement.SetStatesAndCategoriesRecursively(baseElement);
                graphicalElement.SetVariablesRecursively(baseElement, baseElement.DefaultState);
            }

            return graphicalElement;
        }
Esempio n. 18
0
        //public void UpdateSelectedObjectsPositionAndDimensions()
        //{
        //    var elementStack = SelectedState.Self.GetTopLevelElementStack();
        //    if (SelectedState.Self.SelectedInstances.GetCount() != 0)
        //    {
        //        //// Can we just update layout it?
        //        //foreach (var instance in SelectedState.Self.SelectedInstances)
        //        //{
        //        //    RefreshPositionsAndScalesForInstance(instance, elementStack);
        //        //}

        //        foreach (var ipso in SelectedState.Self.SelectedIpsos)
        //        {
        //            GraphicalUiElement asGue = ipso as GraphicalUiElement;
        //            if (asGue != null)
        //            {
        //                asGue.UpdateLayout();
        //                //RecursiveVariableFinder rvf = new RecursiveVariableFinder(asGue.Tag as InstanceSave, SelectedState.Self.SelectedElement);
        //                //asGue.SetGueValues(rvf);
        //            }
        //        }
        //    }
        //    else
        //    {
        //        GraphicalUiElement ipso = WireframeObjectManager.Self.GetSelectedRepresentation();

        //        if (ipso != null)
        //        {
        //            ElementSave elementSave = SelectedState.Self.SelectedElement;

        //            var state = elementSave.DefaultState;
        //            if(SelectedState.Self.SelectedStateSave != null)
        //            {
        //                state = SelectedState.Self.SelectedStateSave;
        //            }
        //            RecursiveVariableFinder rvf = new RecursiveVariableFinder(state);
        //            (ipso as GraphicalUiElement).SetGueValues(rvf);
        //        }
        //        else if(SelectedState.Self.SelectedElement != null)
        //        {
        //            foreach (var instance in SelectedState.Self.SelectedElement.Instances)
        //            {
        //                RefreshPositionsAndScalesForInstance(instance, elementStack);
        //            }
        //        }
        //    }

        //    GuiCommands.Self.RefreshWireframe();
        //}

        public void RefreshPositionsAndScalesForInstance(InstanceSave instance, List <ElementWithState> elementStack)
        {
            GraphicalUiElement ipso = WireframeObjectManager.Self.GetRepresentation(instance, elementStack);

            ipso.UpdateLayout();
        }
Esempio n. 19
0
        private static void GetDifferenceToUnit(GraphicalUiElement gue, 
            out float differenceToUnitPositionX, out float differenceToUnitPositionY,
            out float differenceToUnitWidth, out float differenceToUnitHeight
            
            )
        {
            differenceToUnitPositionX = 0;
            differenceToUnitPositionY = 0;
            differenceToUnitWidth = 0;
            differenceToUnitHeight = 0;

            if (gue.XUnits.GetIsPixelBased())
            {
                float x = gue.X;
                float desiredX = MathFunctions.RoundToInt(x);
                differenceToUnitPositionX = desiredX - x;
            }
            if(gue.YUnits.GetIsPixelBased())
            {
                float y = gue.Y;
                float desiredY = MathFunctions.RoundToInt(y);
                differenceToUnitPositionY = desiredY - y;
            }

            if(gue.WidthUnits.GetIsPixelBased())
            {
                float width = gue.Width;
                float desiredWidth = MathFunctions.RoundToInt(width);
                differenceToUnitWidth = desiredWidth - width;
            }

            if (gue.HeightUnits.GetIsPixelBased())
            {
                float height = gue.Height;
                float desiredHeight = MathFunctions.RoundToInt(height);
                differenceToUnitHeight = desiredHeight - height;
            }
        }
Esempio n. 20
0
        public void LoadFromFile(string fileName)
        {
            var section = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("LoadFromFile " + fileName);
            {

                var sectionA = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("GetElement");

                if (mProjectFileName == null || ObjectFinder.Self.GumProjectSave == null)
                {
                    throw new Exception("The GumIDB must be initialized with a project file before loading any components/screens.  Make sure you have a .gumx project file in your global content, or call StaticInitialize in code first.");
                }

                string oldDir = ToolsUtilities.FileManager.RelativeDirectory;
                string oldFrbDir = FlatRedBall.IO.FileManager.RelativeDirectory;

                ToolsUtilities.FileManager.RelativeDirectory = ToolsUtilities.FileManager.GetDirectory(mProjectFileName);

                ElementSave elementSave = null;
                string extension = ToolsUtilities.FileManager.GetExtension(fileName);

                string strippedName = FlatRedBall.IO.FileManager.RemoveExtension(FlatRedBall.IO.FileManager.RemovePath(fileName));

                if (extension == GumProjectSave.ComponentExtension)
                {
                    elementSave = ObjectFinder.Self.GumProjectSave.Components.FirstOrDefault(item => item.Name.Equals(strippedName, StringComparison.InvariantCultureIgnoreCase));
                }
                else if (extension == GumProjectSave.ScreenExtension)
                {

                    elementSave = ObjectFinder.Self.GumProjectSave.Screens.FirstOrDefault(item => item.Name.Equals(strippedName, StringComparison.InvariantCultureIgnoreCase));
                }
                else if (extension == GumProjectSave.StandardExtension)
                {
                    elementSave = ObjectFinder.Self.GumProjectSave.StandardElements.FirstOrDefault(item => item.Name.Equals(strippedName, StringComparison.InvariantCultureIgnoreCase));
                }

                // Set this *after* the deserialization happens.  The fileName is relative to FRB's relative directory but
                // contained file references won't be.
                FlatRedBall.IO.FileManager.RelativeDirectory = ToolsUtilities.FileManager.GetDirectory(mProjectFileName);

                sectionA.EndTimeAndContext();

                var sectionB = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("Set ParentContainer");

                // We used to only init the uncategorized states
                // but every state should be initialized
                //foreach (var state in elementSave.States)
                foreach (var state in elementSave.AllStates)
                {
                    state.Initialize();
                    state.ParentContainer = elementSave;
                }

                foreach (var instance in elementSave.Instances)
                {
                    instance.ParentContainer = elementSave;
                }

                sectionB.EndTimeAndContext();

                var sectionC = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("ToGraphicalUiElement");


                element = elementSave.ToGraphicalUiElement(mManagers, false);

                sectionC.EndTimeAndContext();

                var sectionD = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("Wrap up");



                element.ExplicitIVisibleParent = this;

                //Set the relative directory back once we are done
                ToolsUtilities.FileManager.RelativeDirectory = oldDir;
                FlatRedBall.IO.FileManager.RelativeDirectory = oldFrbDir;
                sectionD.EndTimeAndContext();
            }

            section.EndTimeAndContext();


        }
Esempio n. 21
0
        public GraphicalUiElement GetRepresentationAt(float x, float y, bool skipSelected, List <ElementWithState> elementStack)
        {
            GraphicalUiElement ipsoOver = null;


            // First check if we're over the current
            GraphicalUiElement selectedRepresentation = WireframeObjectManager.Self.GetSelectedRepresentation();

            if (InputLibrary.Keyboard.Self.KeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
            {
                int m = 3;
            }
            int indexToStartAt = -1;

            if (skipSelected)
            {
                if (selectedRepresentation != null)
                {
                    indexToStartAt = WireframeObjectManager.Self.AllIpsos.IndexOf(selectedRepresentation);
                }
            }
            else
            {
                if (selectedRepresentation != null && selectedRepresentation.Tag is ScreenSave == false)
                {
                    if (selectedRepresentation.HasCursorOver(x, y))
                    {
                        ipsoOver = selectedRepresentation;
                    }
                }
            }

            if (ipsoOver == null)
            {
                // We used to loop through the IPSOs that are part of the WireframeObjectManager,
                // but we want to do it in the order that they appear in the
                // Renderer.  So we'll just loop through the IPositionedSizedObjects
                // in the Renderer's Layer[0], test if they're part of one of the WireframeObjectManager's
                // lists, and if so, check collision.


                if (indexToStartAt == -1)
                {
                    indexToStartAt = WireframeObjectManager.Self.AllIpsos.Count;
                }

                #region First check only visible objects
                ipsoOver = ReverseLoopToFindIpso(x, y, indexToStartAt - 1, -1, true, elementStack);

                if (ipsoOver == null && indexToStartAt != WireframeObjectManager.Self.AllIpsos.Count - 1)
                {
                    ipsoOver = ReverseLoopToFindIpso(x, y, WireframeObjectManager.Self.AllIpsos.Count - 1, indexToStartAt, true, elementStack);
                }
                #endregion

                #region If none were found, check invisible objects

                if (ipsoOver == null)
                {
                    ipsoOver = ReverseLoopToFindIpso(x, y, indexToStartAt - 1, -1, false, elementStack);

                    if (ipsoOver == null && indexToStartAt != WireframeObjectManager.Self.AllIpsos.Count - 1)
                    {
                        ipsoOver = ReverseLoopToFindIpso(x, y, WireframeObjectManager.Self.AllIpsos.Count - 1, indexToStartAt, false, elementStack);
                    }
                }

                #endregion
            }

            // Right now we're going to assume that we only want to select IPSOs that represent the current
            // element or its InstanceSaves - not any children.  So we're going to get the InstanceSave - if that's
            // null, get the ElementSave
            if (ipsoOver != null)
            {
                InstanceSave instance;
                ElementSave  element;

                GetElementOrInstanceForIpso(ipsoOver, elementStack, out instance, out element);

                if (instance != null)
                {
                    ipsoOver = WireframeObjectManager.Self.GetRepresentation(instance, elementStack);
                }
                else if (element != null) // both may be null if the user drag+dropped onto the wireframe window
                {
                    try
                    {
                        ipsoOver = WireframeObjectManager.Self.GetRepresentation(element);
                    }
                    catch (Exception e)
                    {
                        int m = 3;
                        throw e;
                    }
                }
            }

            return(ipsoOver);
        }
Esempio n. 22
0
        private GraphicalUiElement CreateIpsoForElement(ElementSave elementSave)
        {
            GraphicalUiElement rootIpso = null;

            bool isScreen = elementSave is ScreenSave;

            rootIpso     = new GraphicalUiElement();
            rootIpso.Tag = elementSave;
            mGraphicalElements.Add(rootIpso);

            rootIpso.ElementSave = elementSave;
            if (isScreen == false)
            {
                // We used to not add the IPSO for the root element to the list of graphical elements
                // and this prevented selection.  I'm not sure if this was intentionally left out or not
                // but I think it should be here
                mGraphicalElements.Add(rootIpso);

                rootIpso.CreateGraphicalComponent(elementSave, null);
                rootIpso.Component.Name = elementSave.Name;
                rootIpso.Component.Tag  = elementSave;

                RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(SelectedState.Self.SelectedStateSaveOrDefault);

                string guide = rvf.GetValue <string>("Guide");
                SetGuideParent(null, rootIpso, guide, true);
            }


            foreach (var exposedVariable in elementSave.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName)))
            {
                rootIpso.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name);
            }

            List <GraphicalUiElement> newlyAdded = new List <GraphicalUiElement>();


            List <ElementWithState> elementStack = new List <ElementWithState>();

            ElementWithState elementWithState = new ElementWithState(elementSave);

            if (elementSave == SelectedState.Self.SelectedElement)
            {
                if (SelectedState.Self.SelectedStateSave != null)
                {
                    elementWithState.StateName = SelectedState.Self.SelectedStateSave.Name;
                }
                else
                {
                    elementWithState.StateName = "Default";
                }
            }

            elementStack.Add(elementWithState);

            // parallel screws up the ordering of objects, so we'll do it on the primary thread for now
            // and parallelize it later:
            //Parallel.ForEach(elementSave.Instances, instance =>
            foreach (var instance in elementSave.Instances)
            {
                GraphicalUiElement child = CreateRepresentationForInstance(instance, null, elementStack, rootIpso);

                if (child == null)
                {
                    // This can occur
                    // if an instance references
                    // a component that doesn't exist.
                    // I don't think we need to do anything
                    // here.
                }
                else
                {
                    newlyAdded.Add(child);
                    mGraphicalElements.Add(child);
                }
            }


            SetUpParentRelationship(newlyAdded, elementStack, elementSave.Instances);



            //);
            elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == elementSave));



            rootIpso.SetStatesAndCategoriesRecursively(elementSave);

            // First we need to the default state (and do so recursively)
            rootIpso.SetVariablesRecursively(elementSave, elementSave.DefaultState);
            // then we override it with the current state if one is set:
            if (SelectedState.Self.SelectedStateSave != elementSave.DefaultState && SelectedState.Self.SelectedStateSave != null)
            {
                var state = SelectedState.Self.SelectedStateSave;
                rootIpso.SetVariablesTopLevel(elementSave, state);
            }

            // I think this has to be *after* we set varaibles because that's where clipping gets set
            if (rootIpso != null)
            {
                rootIpso.AddToManagers();

                if (rootIpso.ElementSave is ScreenSave)
                {
                    // If it's a screen and it hasn't been added yet, we need to add it.
                    foreach (var item in rootIpso.ContainedElements.Where(candidate => candidate.Managers == null))
                    {
                        item.AddToManagers();
                    }
                }
            }

            return(rootIpso);
        }
        private GraphicalUiElement CreateIpsoForElement(ElementSave elementSave)
        {
            GraphicalUiElement rootIpso = null;
            bool isScreen = elementSave is ScreenSave;

            rootIpso = new GraphicalUiElement();


            // If we don't turn off layouts, layouts can be called tens of thousands of times for
            // complex elements. We'll turn off layouts, then turn them back on at the end and manually
            // layout:
            GraphicalUiElement.IsAllLayoutSuspended = true;
            {
                rootIpso.Tag = elementSave;
                mGraphicalElements.Add(rootIpso);

                rootIpso.ElementSave = elementSave;
                if (isScreen == false)
                {
                    // We used to not add the IPSO for the root element to the list of graphical elements
                    // and this prevented selection.  I'm not sure if this was intentionally left out or not
                    // but I think it should be here
                    mGraphicalElements.Add(rootIpso);

                    rootIpso.CreateGraphicalComponent(elementSave, null);

                    // can be null if the element save references a bad file
                    if (rootIpso.Component != null)
                    {
                        rootIpso.Component.Name = elementSave.Name;
                        rootIpso.Component.Tag  = elementSave;
                    }

                    RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(SelectedState.Self.SelectedStateSaveOrDefault);

                    string guide = rvf.GetValue <string>("Guide");
                    SetGuideParent(null, rootIpso, guide);
                }

                var exposedVariables = elementSave
                                       .DefaultState
                                       .Variables
                                       .Where(item =>
                                              !string.IsNullOrEmpty(item.ExposedAsName) &&
                                              string.IsNullOrEmpty(item.SourceObject))
                                       .ToArray();

                foreach (var exposedVariable in exposedVariables)
                {
                    rootIpso.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name);
                }

                List <GraphicalUiElement> newlyAdded   = new List <GraphicalUiElement>();
                List <ElementWithState>   elementStack = new List <ElementWithState>();

                ElementWithState elementWithState = new ElementWithState(elementSave);
                if (elementSave == SelectedState.Self.SelectedElement)
                {
                    if (SelectedState.Self.SelectedStateSave != null)
                    {
                        elementWithState.StateName = SelectedState.Self.SelectedStateSave.Name;
                    }
                    else
                    {
                        elementWithState.StateName = "Default";
                    }
                }

                elementStack.Add(elementWithState);

                // parallel screws up the ordering of objects, so we'll do it on the primary thread for now
                // and parallelize it later:
                //Parallel.ForEach(elementSave.Instances, instance =>
                foreach (var instance in elementSave.Instances)
                {
                    GraphicalUiElement child = CreateRepresentationForInstance(instance, null, elementStack, rootIpso);

                    if (child == null)
                    {
                        // This can occur
                        // if an instance references
                        // a component that doesn't exist.
                        // I don't think we need to do anything
                        // here.
                    }
                    else
                    {
                        newlyAdded.Add(child);
                        mGraphicalElements.Add(child);
                    }
                }

                SetUpParentRelationship(newlyAdded, elementStack, elementSave.Instances);

                elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == elementSave));

                rootIpso.SetStatesAndCategoriesRecursively(elementSave);

                // First we need to the default state (and do so recursively)
                try
                {
                    rootIpso.SetVariablesRecursively(elementSave, elementSave.DefaultState);
                }
                catch (Exception e)
                {
                    // this barfed, but we don't want to crash the tool
                    GumCommands.Self.GuiCommands.PrintOutput($"Error loading {elementSave}:\n{e.ToString()}");
                }
                // then we override it with the current state if one is set:
                if (SelectedState.Self.SelectedStateSave != elementSave.DefaultState && SelectedState.Self.SelectedStateSave != null)
                {
                    var state = SelectedState.Self.SelectedStateSave;
                    rootIpso.ApplyState(state);
                }

                if (elementSave is StandardElementSave && elementSave.Name == "Text")
                {
                    // We created a new Text object, so let's try generating fonts for it:
                    FontManager.Self.ReactToFontValueSet(null);
                }

                // I think this has to be *after* we set varaibles because that's where clipping gets set
                if (rootIpso != null)
                {
                    gueManager.Add(rootIpso);

                    rootIpso.AddToManagers();
                }
            }
            GraphicalUiElement.IsAllLayoutSuspended = false;

            // There is a bug that currently requires layout to be performed twice.
            // Update Nov 19, 2019 - I don't know when this was written, but layout has
            // been continually improving, even as recently as today. I'm going to remove
            // the 2nd call to make things faster and to see if I can spot other issues that
            // remain after a single UpdateLayout call:
            //rootIpso.UpdateLayout();
            rootIpso.UpdateLayout();

            return(rootIpso);
        }
Esempio n. 24
0
        public GraphicalUiElement GetRepresentationAt(float x, float y, bool skipSelected, List <ElementWithState> elementStack)
        {
            GraphicalUiElement ipsoOver = null;


            // First check if we're over the current
            var selectedRepresentations = WireframeObjectManager.Self.GetSelectedRepresentations();

            int indexToStartAt = -1;

            if (skipSelected)
            {
                if (selectedRepresentations?.Length > 0)
                {
                    indexToStartAt = WireframeObjectManager.Self.AllIpsos.IndexOf(selectedRepresentations.First());
                }
            }
            else
            {
                if ((selectedRepresentations?.FirstOrDefault()?.Tag is ScreenSave) == false)
                {
                    if (selectedRepresentations != null)
                    {
                        foreach (var selectedRepresentation in selectedRepresentations)
                        {
                            // If this is a container, and dotted lines are not drawn, then this has no renderable component:
                            if (selectedRepresentation?.RenderableComponent != null)
                            {
                                var hasCursorOver = false;

                                if (selectedRepresentation.RenderableComponent is LinePolygon)
                                {
                                    hasCursorOver = (selectedRepresentation.RenderableComponent as LinePolygon).IsPointInside(x, y);
                                }
                                else
                                {
                                    hasCursorOver = selectedRepresentation.HasCursorOver(x, y);
                                }

                                if (hasCursorOver)
                                {
                                    ipsoOver = selectedRepresentation;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (ipsoOver == null)
            {
                // We used to loop through the IPSOs that are part of the WireframeObjectManager,
                // but we want to do it in the order that they appear in the
                // Renderer.  So we'll just loop through the IPositionedSizedObjects
                // in the Renderer's Layer[0], test if they're part of one of the WireframeObjectManager's
                // lists, and if so, check collision.


                if (indexToStartAt == -1)
                {
                    indexToStartAt = WireframeObjectManager.Self.AllIpsos.Count;
                }

                #region First check only visible objects
                ipsoOver = ReverseLoopToFindIpso(x, y, indexToStartAt - 1, -1, true, elementStack);

                if (ipsoOver == null && indexToStartAt != WireframeObjectManager.Self.AllIpsos.Count - 1)
                {
                    ipsoOver = ReverseLoopToFindIpso(x, y, WireframeObjectManager.Self.AllIpsos.Count - 1, indexToStartAt, true, elementStack);
                }
                #endregion

                #region If none were found, check invisible objects

                if (ipsoOver == null)
                {
                    ipsoOver = ReverseLoopToFindIpso(x, y, indexToStartAt - 1, -1, false, elementStack);

                    if (ipsoOver == null && indexToStartAt != WireframeObjectManager.Self.AllIpsos.Count - 1)
                    {
                        ipsoOver = ReverseLoopToFindIpso(x, y, WireframeObjectManager.Self.AllIpsos.Count - 1, indexToStartAt, false, elementStack);
                    }
                }

                #endregion
            }

            // Right now we're going to assume that we only want to select IPSOs that represent the current
            // element or its InstanceSaves - not any children.  So we're going to get the InstanceSave - if that's
            // null, get the ElementSave
            if (ipsoOver != null)
            {
                InstanceSave instance;
                ElementSave  element;

                GetElementOrInstanceForIpso(ipsoOver, elementStack, out instance, out element);

                if (instance != null)
                {
                    ipsoOver = WireframeObjectManager.Self.GetRepresentation(instance, elementStack);
                }
                else if (element != null) // both may be null if the user drag+dropped onto the wireframe window
                {
                    try
                    {
                        ipsoOver = WireframeObjectManager.Self.GetRepresentation(element);
                    }
                    catch (Exception e)
                    {
                        int m = 3;
                        throw e;
                    }
                }
            }

            return(ipsoOver);
        }
Esempio n. 25
0
        public void UpdateTo(GraphicalUiElement asGue)
        {
            var parent = asGue.EffectiveParentGue;


            mOriginLine.Visible = true;

            // The child's position is relative
            // to the parent, but not always the
            // top left - depending on the XUnits
            // and YUnits. ParentOriginOffset contains
            // the point that the child is relative to,
            // relative to the top-left of the parent.
            // In other words, if the child's XUnits is
            // PixelsFromRight, then the parentOriginOffsetX
            // will be the width of the parent.
            float parentOriginOffsetX;
            float parentOriginOffsetY;

            asGue.GetParentOffsets(out parentOriginOffsetX, out parentOriginOffsetY);

            // This currently has some confusing behavior:
            // If an object is part of a stacked parent, then
            // the offset line is correct if the parent is either
            // not wrapping, or if the object is not the first item
            // in a row/column.
            // If the object is the first item in a row or column that
            // isn't the first, then the origin returned is the previous
            // item's point, but the row/column index is added.

            float parentAbsoluteX = 0;
            float parentAbsoluteY = 0;

            if (parent != null)
            {
                parentAbsoluteX = parent.GetAbsoluteX();
                parentAbsoluteY = parent.GetAbsoluteY();

                if (parent.ChildrenLayout != Managers.ChildrenLayout.Regular &&
                    parent.WrapsChildren)
                {
                    // The origin may actually be a new row/column, so let's get that:
                    if (parent.ChildrenLayout == Managers.ChildrenLayout.LeftToRightStack)
                    {
                        for (int i = 0; i < asGue.StackedRowOrColumnIndex; i++)
                        {
                            parentAbsoluteY += parent.StackedRowOrColumnDimensions[i];
                        }
                    }
                    if (parent.ChildrenLayout == Managers.ChildrenLayout.TopToBottomStack)
                    {
                        for (int i = 0; i < asGue.StackedRowOrColumnIndex; i++)
                        {
                            parentAbsoluteX += parent.StackedRowOrColumnDimensions[i];
                        }
                    }
                }
            }

            var parentAbsoluteRotation = 0.0f;

            if (parent != null)
            {
                parentAbsoluteRotation = parent.GetAbsoluteRotation();
            }

            if (parentAbsoluteRotation == 0)
            {
                mOriginLine.X = parentOriginOffsetX + parentAbsoluteX;
                mOriginLine.Y = parentOriginOffsetY + parentAbsoluteY;
            }
            else
            {
                var matrix = Matrix.CreateRotationZ(-MathHelper.ToRadians(parentAbsoluteRotation));

                var rotatedVector = parentOriginOffsetX * matrix.Right + parentOriginOffsetY * matrix.Up;


                mOriginLine.X = rotatedVector.X + parentAbsoluteX;
                mOriginLine.Y = rotatedVector.Y + parentAbsoluteY;
            }
            mOriginLine.RelativePoint.X = asGue.AbsoluteX - mOriginLine.X;
            mOriginLine.RelativePoint.Y = asGue.AbsoluteY - mOriginLine.Y;
        }
        private IPositionedSizedObject CreateRectangleFor(InstanceSave instance, List<ElementWithState> elementStack, GraphicalUiElement graphicalUiElement)
        {
            ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);
            graphicalUiElement.CreateGraphicalComponent(instanceBase, null);
            graphicalUiElement.Tag = instance;
            graphicalUiElement.Component.Name = instance.Name;
            graphicalUiElement.Component.Tag = instance;

            (graphicalUiElement.RenderableComponent as LineRectangle).LocalVisible =
                GraphicalUiElement.ShowLineRectangles;
            return graphicalUiElement;
        }
Esempio n. 27
0
        private bool SideGrabbingActivityForInstanceSave(float cursorXChange, float cursorYChange, InstanceSave instanceSave, List <ElementWithState> elementStack)
        {
            float changeXMultiplier;
            float changeYMultiplier;
            float widthMultiplier;
            float heightMultiplier;

            CalculateMultipliers(instanceSave, elementStack, out changeXMultiplier, out changeYMultiplier, out widthMultiplier, out heightMultiplier);

            AdjustCursorChangeValuesForShiftDrag(ref cursorXChange, ref cursorYChange, instanceSave, elementStack);

            bool hasChangeOccurred = false;

            Vector2 reposition = new Vector2(cursorXChange * changeXMultiplier, cursorYChange * changeYMultiplier);

            // invert Y so up is positive
            reposition.Y *= -1;

            GraphicalUiElement representation = null;

            if (instanceSave != null)
            {
                representation = WireframeObjectManager.Self.GetRepresentation(instanceSave);
            }
            else
            {
                representation = WireframeObjectManager.Self.GetRepresentation(elementStack.Last().Element);
            }

            float rotation = MathHelper.ToRadians(representation?.GetAbsoluteRotation() ?? 0);

            MathFunctions.RotateVector(ref reposition, rotation);

            // flip Y back
            reposition.Y *= -1;

            if (reposition.X != 0)
            {
                hasChangeOccurred = true;
                if (instanceSave != null)
                {
                    EditingManager.Self.ModifyVariable("X", reposition.X, instanceSave);
                }
                else
                {
                    EditingManager.Self.ModifyVariable("X", reposition.X, elementStack.Last().Element);
                }
            }
            if (reposition.Y != 0)
            {
                hasChangeOccurred = true;
                if (instanceSave != null)
                {
                    EditingManager.Self.ModifyVariable("Y", reposition.Y, instanceSave);
                }
                else
                {
                    EditingManager.Self.ModifyVariable("Y", reposition.Y, elementStack.Last().Element);
                }
            }



            if (heightMultiplier != 0 && cursorYChange != 0)
            {
                hasChangeOccurred = true;
                if (instanceSave != null)
                {
                    EditingManager.Self.ModifyVariable("Height", cursorYChange * heightMultiplier, instanceSave);
                }
                else
                {
                    EditingManager.Self.ModifyVariable("Height", cursorYChange * heightMultiplier, elementStack.Last().Element);
                }
            }
            if (widthMultiplier != 0 && cursorXChange != 0)
            {
                hasChangeOccurred = true;
                if (instanceSave != null)
                {
                    EditingManager.Self.ModifyVariable("Width", cursorXChange * widthMultiplier, instanceSave);
                }
                else
                {
                    EditingManager.Self.ModifyVariable("Width", cursorXChange * widthMultiplier, elementStack.Last().Element);
                }
            }
            return(hasChangeOccurred);
        }
        private GraphicalUiElement CreateRepresentationsForInstanceFromComponent(InstanceSave instance, 
            List<ElementWithState> elementStack, InstanceSave parentInstance, GraphicalUiElement parentIpso, 
            ComponentSave baseComponentSave)
        {
            StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(instance);

            GraphicalUiElement rootIpso = null;
            if (ses != null)
            {
                rootIpso = new GraphicalUiElement(null, parentIpso);

                string type = ses.Name;

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

                    if(type == "Text")
                    {
                        (rootIpso.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines;
                    }

                }
                else
                {
                    CreateRectangleFor(instance, elementStack, rootIpso);
                }

                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");
                SetGuideParent(parentIpso, rootIpso, guide, false);

                ElementWithState elementWithState = new ElementWithState(baseComponentSave);
                var tempRvf = new DataTypes.RecursiveVariableFinder(instance, elementStack);
                var state = tempRvf.GetValue("State") as string;
                elementWithState.StateName = state;

                foreach (var category in baseComponentSave.Categories)
                {
                    elementWithState.CategorizedStates.Add(category.Name, tempRvf.GetValue<string>(category.Name + "State"));
                }

                elementWithState.InstanceName = instance.Name;
                elementStack.Add(elementWithState);

                foreach (InstanceSave internalInstance in baseComponentSave.Instances)
                {
                    GraphicalUiElement createdIpso = CreateRepresentationForInstance(internalInstance, instance, elementStack, rootIpso);

                }

                SetUpParentRelationship(rootIpso.ContainedElements, elementStack, baseComponentSave.Instances);

                elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == baseComponentSave));
            }

            return rootIpso;
        }
Esempio n. 29
0
        private void SnapSelectedToUnitValues()
        {
            bool wasAnythingModified = false;

            if (SelectedState.Self.SelectedInstances.Count() == 0 &&
                (SelectedState.Self.SelectedComponent != null || SelectedState.Self.SelectedStandardElement != null))
            {
                GraphicalUiElement gue = SelectionManager.Self.SelectedGue;


                float differenceToUnitX;
                float differenceToUnitY;
                float differenceToUnitWidth;
                float differenceToUnitHeight;
                GetDifferenceToUnit(gue, out differenceToUnitX, out differenceToUnitY, out differenceToUnitWidth, out differenceToUnitHeight);

                if (differenceToUnitX != 0)
                {
                    gue.X = EditingManager.Self.ModifyVariable("X", differenceToUnitX, SelectedState.Self.SelectedElement);
                    wasAnythingModified = true;
                }
                if (differenceToUnitY != 0)
                {
                    gue.Y = EditingManager.Self.ModifyVariable("Y", differenceToUnitY, SelectedState.Self.SelectedElement);
                    wasAnythingModified = true;
                }
                if (differenceToUnitWidth != 0)
                {
                    gue.Width           = EditingManager.Self.ModifyVariable("Width", differenceToUnitWidth, SelectedState.Self.SelectedElement);
                    wasAnythingModified = true;
                }
                if (differenceToUnitHeight != 0)
                {
                    gue.Height          = EditingManager.Self.ModifyVariable("Height", differenceToUnitHeight, SelectedState.Self.SelectedElement);
                    wasAnythingModified = true;
                }
            }
            else if (SelectedState.Self.SelectedInstances.Count() != 0)
            {
                foreach (var gue in SelectionManager.Self.SelectedGues)
                {
                    var instanceSave = gue.Tag as InstanceSave;

                    if (instanceSave != null && !EditingManager.Self.ShouldSkipDraggingMovementOn(instanceSave))
                    {
                        float differenceToUnitX;
                        float differenceToUnitY;

                        float differenceToUnitWidth;
                        float differenceToUnitHeight;

                        GetDifferenceToUnit(gue, out differenceToUnitX, out differenceToUnitY, out differenceToUnitWidth, out differenceToUnitHeight);

                        if (differenceToUnitX != 0)
                        {
                            gue.X = EditingManager.Self.ModifyVariable("X", differenceToUnitX, instanceSave);
                            wasAnythingModified = true;
                        }
                        if (differenceToUnitY != 0)
                        {
                            gue.Y = EditingManager.Self.ModifyVariable("Y", differenceToUnitY, instanceSave);
                            wasAnythingModified = true;
                        }
                        if (differenceToUnitWidth != 0)
                        {
                            gue.Width           = EditingManager.Self.ModifyVariable("Width", differenceToUnitWidth, instanceSave);
                            wasAnythingModified = true;
                        }
                        if (differenceToUnitHeight != 0)
                        {
                            gue.Height          = EditingManager.Self.ModifyVariable("Height", differenceToUnitHeight, instanceSave);
                            wasAnythingModified = true;
                        }
                    }
                }
            }

            if (wasAnythingModified)
            {
                GumCommands.Self.GuiCommands.RefreshPropertyGrid(true);
            }
        }
        private GraphicalUiElement CreateIpsoForElement(ElementSave elementSave)
        {
            GraphicalUiElement rootIpso = null;

            bool isScreen = elementSave is ScreenSave;

            rootIpso = new GraphicalUiElement();
            rootIpso.Tag = elementSave;
            mGraphicalElements.Add(rootIpso);

            rootIpso.ElementSave = elementSave;
            if (isScreen == false)
            {
                // We used to not add the IPSO for the root element to the list of graphical elements
                // and this prevented selection.  I'm not sure if this was intentionally left out or not
                // but I think it should be here
                mGraphicalElements.Add(rootIpso);

                rootIpso.CreateGraphicalComponent(elementSave, null);
                rootIpso.Component.Name = elementSave.Name;
                rootIpso.Component.Tag = elementSave;

                RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(SelectedState.Self.SelectedStateSaveOrDefault);

                string guide = rvf.GetValue<string>("Guide");
                SetGuideParent(null, rootIpso, guide, true);

            }

            foreach(var exposedVariable in elementSave.DefaultState.Variables.Where(item=> !string.IsNullOrEmpty(item.ExposedAsName) ))
            {
                rootIpso.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name);
            }

            List<GraphicalUiElement> newlyAdded = new List<GraphicalUiElement>();

            List<ElementWithState> elementStack = new List<ElementWithState>();

            ElementWithState elementWithState = new ElementWithState(elementSave);
            if (elementSave == SelectedState.Self.SelectedElement)
            {
                if (SelectedState.Self.SelectedStateSave != null)
                {
                    elementWithState.StateName = SelectedState.Self.SelectedStateSave.Name;
                }
                else
                {
                    elementWithState.StateName = "Default";
                }
            }

            elementStack.Add(elementWithState);

            // parallel screws up the ordering of objects, so we'll do it on the primary thread for now
            // and parallelize it later:
            //Parallel.ForEach(elementSave.Instances, instance =>
            foreach (var instance in elementSave.Instances)
            {
                GraphicalUiElement child = CreateRepresentationForInstance(instance, null, elementStack, rootIpso);

                if (child == null)
                {
                    // This can occur
                    // if an instance references
                    // a component that doesn't exist.
                    // I don't think we need to do anything
                    // here.
                }
                else
                {
                    newlyAdded.Add(child);
                    mGraphicalElements.Add(child);

                }
            }

            SetUpParentRelationship(newlyAdded, elementStack, elementSave.Instances);

            //);
            elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == elementSave));

            rootIpso.SetStatesAndCategoriesRecursively(elementSave);

            // First we need to the default state (and do so recursively)
            rootIpso.SetVariablesRecursively(elementSave, elementSave.DefaultState);
            // then we override it with the current state if one is set:
            if (SelectedState.Self.SelectedStateSave != elementSave.DefaultState && SelectedState.Self.SelectedStateSave != null)
            {
                var state = SelectedState.Self.SelectedStateSave;
                rootIpso.SetVariablesTopLevel(elementSave, state);
            }

            // I think this has to be *after* we set varaibles because that's where clipping gets set
            if (rootIpso != null)
            {
                rootIpso.AddToManagers();

                if (rootIpso.ElementSave is ScreenSave)
                {
                    // If it's a screen and it hasn't been added yet, we need to add it.
                    foreach (var item in rootIpso.ContainedElements.Where(candidate=>candidate.Managers == null))
                    {
                        item.AddToManagers();
                    }
                }
            }

            return rootIpso;
        }
Esempio n. 31
0
        public void LoadFromFile(string fileName)
        {
            if (mProjectFileName == null || ObjectFinder.Self.GumProjectSave == null)
            {
                throw new Exception("The GumIDB must be initialized with a project file before loading any components/screens.  Make sure you have a .gumx project file in your global content, or call StaticInitialize in code first.");
            }

            string oldDir = ToolsUtilities.FileManager.RelativeDirectory;
            ToolsUtilities.FileManager.RelativeDirectory = ToolsUtilities.FileManager.GetDirectory(mProjectFileName);

            ComponentSave elementSave = FlatRedBall.IO.FileManager.XmlDeserialize<ComponentSave>(fileName);
            foreach (var state in elementSave.States)
            {
                state.Initialize();
                state.ParentContainer = elementSave;
            }

            foreach (var instance in elementSave.Instances)
            {
                instance.ParentContainer = elementSave;
            }


            element = elementSave.ToGraphicalUiElement(mManagers, false);

            //Set the relative directory back once we are done
            ToolsUtilities.FileManager.RelativeDirectory = oldDir;

        }