Ejemplo n.º 1
0
        /// <summary>
        /// Returns a guaranteed unique name for an element in the canvas
        /// </summary>
        public static void EnsureUniqueNames(Canvas cnv, bool setTag)
        {
            foreach (UIElement element in cnv.Children)
            {
                string thisName = element.GetValue(Canvas.NameProperty).ToString();
                string newName  = thisName;

                if (thisName == string.Empty)
                {
                    continue;
                }

                newName = EnsureUniqueNameSingle(_parentCanvas, newName);

                element.SetValue(Canvas.NameProperty, newName);
                if (setTag)
                {
                    element.SetValue(Canvas.TagProperty, thisName);
                }

                // we also need to update contoller body names for joins, static bodies
                foreach (UIElement elementSub in cnv.Children)
                {
                    if (elementSub is PhysicsJoint)
                    {
                        PhysicsJoint thisJoint = elementSub as PhysicsJoint;
                        if (thisJoint.BodyOne == thisName)
                        {
                            thisJoint.BodyOne = newName;
                        }
                        if (thisJoint.BodyTwo == thisName)
                        {
                            thisJoint.BodyTwo = newName;
                        }
                    }
                    if (elementSub is PhysicsStaticHolder)
                    {
                        PhysicsStaticHolder thisHolder = elementSub as PhysicsStaticHolder;
                        if (thisHolder.Body == thisName)
                        {
                            thisHolder.Body = newName;
                        }
                    }
                    PhysicsJointMain physJoint = elementSub.GetValue(PhysicsJointMain.PhysicsJointProperty) as PhysicsJointMain;
                    if (physJoint != null)
                    {
                        if (physJoint.BodyOne == thisName)
                        {
                            physJoint.BodyOne = newName;
                        }
                        if (physJoint.BodyTwo == thisName)
                        {
                            physJoint.BodyTwo = newName;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a single Static holder object from a canvas into the simulation.
        /// </summary>
        /// <param name="cnvContainer">The static holder to add</param>
        public void AddStaticHolder(PhysicsStaticHolder staticHolder)
        {
            if (!PhysicsObjects.ContainsKey(staticHolder.Body))
            {
                throw new Exception("A PhysicsStaticHolder exists with an invalid Body value of '" + staticHolder.Body + "'.");
            }

            Body body1 = PhysicsObjects[staticHolder.Body].BodyObject;

            body1.IsStatic = true;

            staticHolder.Visibility = Visibility.Collapsed;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a single Static holder object from a canvas into the simulation.
 /// </summary>
 /// <param name="cnvContainer">The static holder to add</param>
 public void AddStaticHolder(PhysicsStaticHolder staticHolder)
 {
     _physicsControllerMain.AddStaticHolder(staticHolder);
 }