public static PhysicsCanvas FindPhysicsCanvas(SysWinF.FrameworkElement element)
        {
            if (element != null)
            {
                if (element is PhysicsCanvas)
                {
                    return (element as PhysicsCanvas);
                }
                else
                {
                    element = SysWinMedia.VisualTreeHelper.GetParent(element) as SysWinF.FrameworkElement;
                    return FindPhysicsCanvas(element);
                }
            }

            return null;
        }
Пример #2
0
		public static FontDecoration Convert(sw.TextDecorationCollection decorations)
		{
			var decoration = FontDecoration.None;
			if (decorations != null)
			{
				if (sw.TextDecorations.Underline.All(decorations.Contains))
					decoration |= FontDecoration.Underline;
				if (sw.TextDecorations.Strikethrough.All(decorations.Contains))
					decoration |= FontDecoration.Strikethrough;
			}
			return decoration;
		}
Пример #3
0
		public static MouseEventArgs ToEto(this swi.MouseWheelEventArgs e, sw.IInputElement control, swi.MouseButtonState buttonState = swi.MouseButtonState.Pressed)
		{
			var buttons = MouseButtons.None;
			if (e.LeftButton == buttonState)
				buttons |= MouseButtons.Primary;
			if (e.RightButton == buttonState)
				buttons |= MouseButtons.Alternate;
			if (e.MiddleButton == buttonState)
				buttons |= MouseButtons.Middle;
			var modifiers = Keys.None;
			var location = e.GetPosition(control).ToEto();
			var delta = new SizeF(0, (float)e.Delta / WheelDelta);

			return new MouseEventArgs(buttons, modifiers, location, delta);
		}
Пример #4
0
		public static MouseEventArgs ToEto(this swi.MouseButtonEventArgs e, sw.IInputElement control, swi.MouseButtonState buttonState = swi.MouseButtonState.Pressed)
		{
			var buttons = MouseButtons.None;
			if (e.ChangedButton == swi.MouseButton.Left && e.LeftButton == buttonState)
				buttons |= MouseButtons.Primary;
			if (e.ChangedButton == swi.MouseButton.Right && e.RightButton == buttonState)
				buttons |= MouseButtons.Alternate;
			if (e.ChangedButton == swi.MouseButton.Middle && e.MiddleButton == buttonState)
				buttons |= MouseButtons.Middle;
			var modifiers = Keys.None;
			var location = e.GetPosition(control).ToEto();

			return new MouseEventArgs(buttons, modifiers, location);
		}
        /// <summary>
        /// When sprites are added into the game canvas, if they have storyboards targeting them then 
        /// this method will redirect to the INSTANCE of the target instead of the NAME.
        /// </summary>
        /// <param name="uc"></param>
        public static void RedirectStoryboardTargets(SysWinF.FrameworkElement uc)
        {

            foreach (object item in uc.Resources)
            {
#if WINDOWS_PHONE || SILVERLIGHT
                if (item is System.Collections.DictionaryEntry)
                {
                    Object itemValue = ((System.Collections.DictionaryEntry)item).Value;

#else
                if (item is System.Collections.Generic.KeyValuePair<object, object>)
                {
                    Object itemValue = ((System.Collections.Generic.KeyValuePair<object, object>)item).Value;
#endif
                    if (itemValue is Storyboard)
                    {
                        Storyboard sb = itemValue as Storyboard;
                        foreach (Timeline tl in sb.Children)
                        {
                            string target = tl.GetValue(Storyboard.TargetNameProperty).ToString();
                            SysWinF.UIElement targetElement = uc.FindName(target) as SysWinF.UIElement;
                            if (targetElement != null)
                                Storyboard.SetTarget(tl, targetElement);

                        }
                    }
                }
            }

            // now do any children
            for (int i = 0; i < SysWinMedia.VisualTreeHelper.GetChildrenCount(uc); i++)
            {
                SysWinF.DependencyObject child = SysWinMedia.VisualTreeHelper.GetChild(uc, 0);
                if (child is SysWinF.FrameworkElement)
                {
                    RedirectStoryboardTargets(child as SysWinF.FrameworkElement);
                }
            }

        }
        public static void DebugVisualTree(SysWinF.DependencyObject cnv, int level)
        {
            // tab in
            string tabIn = string.Empty;
            for (int i = 0; i < level * 4; i++)
            {
                tabIn += " ";
            }
            level++;

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < SysWinMedia.VisualTreeHelper.GetChildrenCount(cnv); i++)
            {
                SysWinF.DependencyObject thisChild = SysWinMedia.VisualTreeHelper.GetChild(cnv, i);

                sb.Clear();
                sb.Append(tabIn);
                sb.Append(thisChild.GetValue(Canvas.NameProperty));
                sb.Append(" [Type = " + thisChild.GetType().ToString() + "] ");
                if (thisChild is FrameworkElement)
                {
                    sb.Append(" [Visibility = " + (thisChild as FrameworkElement).Visibility.ToString() + "] ");
                    sb.Append(" [Opacity = " + (thisChild as FrameworkElement).Opacity.ToString() + "] ");
                    sb.Append(" [Transform = " + (thisChild as FrameworkElement).RenderTransform.ToString() + "] ");
                }
                //if (thisChild is Path)
                //{
                //    PathGeometry pg = (thisChild as Path).Data as PathGeometry;
                //    int fig = 1;
                //    foreach (PathFigure pf in pg.Figures)
                //    {

                //        sb.Append(" [figure " + fig.ToString() + ", start = " pf.StartPoint.ToString() + pf.Segments[0].X + "] ");
                //    }
                //}

                System.Diagnostics.Debug.WriteLine(sb.ToString());
                DebugVisualTree(thisChild, level);
            }
        }
        public static void EnsureUniqueNames(SysWinF.DependencyObject uc, Guid ucOffset, int collisionGroup, List<PhysicsSprite> spriteList)
        {
            for (int i = 0; i < SysWinMedia.VisualTreeHelper.GetChildrenCount(uc); i++)
            {
                SysWinF.DependencyObject thisChild = SysWinMedia.VisualTreeHelper.GetChild(uc, i);


                if (thisChild is PhysicsSprite)
                {
                    PhysicsSprite spr = (thisChild as PhysicsSprite);
                    spr.OriginalName = spr.Name;
                    spr.Name = spr.Name + "_" + ucOffset.ToString();
                    spr.InternalName = spr.Name;

                    if (collisionGroup > 0 && spr.CollisionGroup > 0)
                    {
                        spr.CollisionGroup = collisionGroup;
                    }
                    spriteList.Add(spr);
                }
                else
                    if (thisChild is PhysicsJoint)
                    {
                        PhysicsJoint joint = (thisChild as PhysicsJoint);
                        joint.BodyOne = joint.BodyOne + "_" + ucOffset.ToString();
                        joint.BodyTwo = joint.BodyTwo + "_" + ucOffset.ToString();
                        if (collisionGroup > 0 && joint.CollisionGroup > 0)
                        {
                            joint.CollisionGroup = collisionGroup;
                        }
                    }
                    else
                        if (thisChild is SysWinF.FrameworkElement)
                        {
                            SysWinF.FrameworkElement child = (thisChild as SysWinF.FrameworkElement);
                            if (child.Name != null && child.Name != string.Empty)
                            {
                                string newName = child.Name + "_" + ucOffset.ToString();

                                child.Name = newName;
                            }

                        }

                if (thisChild is SysWinF.FrameworkElement)
                {
                    foreach (Object x in (thisChild as SysWinF.FrameworkElement).Resources)
                    {
#if WINDOWS_PHONE || SILVERLIGHT
                        if (x is System.Collections.DictionaryEntry)
                        {
                            Object itemValue = ((System.Collections.DictionaryEntry)x).Value;

#else
                        if (x is System.Collections.Generic.KeyValuePair<object, object>)
                        {
                            Object itemValue = ((System.Collections.Generic.KeyValuePair<object, object>)x).Value;
#endif

                            if (itemValue is Storyboard)
                            {
                                string currName = Convert.ToString((itemValue as Storyboard).GetValue(Canvas.NameProperty));
                                (itemValue as Storyboard).SetValue(Canvas.NameProperty, currName + "_" + ucOffset.ToString());
                            }
                        }

                    }
                }

                EnsureUniqueNames(thisChild, ucOffset, collisionGroup, spriteList);
            }


        }