Contains() public method

public Contains ( Point point ) : bool
point Point
return bool
Ejemplo n.º 1
0
        private void _contentGrid_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            if (e.PointerDeviceType != PointerDeviceType.Touch)
            {
                return;
            }
            if (manipulationStatus == ManipulationStatus.None)
            {
                if (PivotItem != null && FrozenColumns > 0)
                {
                    var pt = e.Position;
                    pt = this.TransformToVisual(_columnHeaderPanel).TransformPoint(pt);

                    var fx = _columnHeaderPanel.Columns.GetFrozenSize();
                    // adjust for scroll position
                    var sp = _columnHeaderPanel.ScrollPosition;
                    if (pt.X < 0 || pt.X > fx) pt.X -= sp.X;
                    var column = _columnHeaderPanel.Columns.GetItemAt(pt.X);
                    if (FrozenColumns > column)
                    {
                        startingCrossSlideLeft = startingCrossSlideRight = true;
                    }
                }

                if (_header != null)
                {
                    var pt = e.Position;
                    pt = this.TransformToVisual(_header).TransformPoint(pt);
                    var rect = new Rect(0, 0, _header.ActualWidth, _header.ActualHeight);
                    if (rect.Contains(pt))
                    {
                        if (PivotItem != null)
                        {
                            startingCrossSlideLeft = startingCrossSlideRight = true;
                        }
                        manipulationOnHeaderOrFooter = true;
                    }
                }

                if (_footer != null)
                {
                    var pt = e.Position;
                    pt = this.TransformToVisual(_footer).TransformPoint(pt);
                    var rect = new Rect(0, 0, _footer.ActualWidth, _footer.ActualHeight);
                    if (rect.Contains(pt))
                    {
                        if (PivotItem != null)
                        {
                            startingCrossSlideLeft = startingCrossSlideRight = true;
                        }
                        manipulationOnHeaderOrFooter = true;
                    }
                }
            }
        }
        public static bool IsElementFullVisible(FrameworkElement element, FrameworkElement container)
        {
            if (element.Visibility == Visibility.Collapsed)
                return false;

            var elementSize = new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight);

            Rect bounds = element.TransformToVisual(container).TransformBounds(elementSize);

            var parentBounds = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);

            return parentBounds.Contains(new Point(bounds.Left, bounds.Top)) && parentBounds.Contains(new Point(bounds.Right, bounds.Bottom));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Core game method. Updates state of the game.
        /// </summary>
        public void Update()
        {
            _lastUpdated = DateTime.Now;

            Twinkle(); // Stars always twinkle
            if(!GameOver)
            {
                // Check if there is any invader ship. If not, create new wave
                if(!_invaders.Any())
                    NextWave();

                // Check if player is alive
                if(!PlayerDying)
                {
                    MoveInvaders();

                    // Move all shots
                    Rect playAreaRect = new Rect(new Point(0, 0), PlayAreaSize);

                    foreach (var shot in _playerShots)
                    {
                        shot.Move();
                        if (!playAreaRect.Contains(shot.Location))
                            _playerShots.Remove(shot);
                        OnShotMoved(shot, false);
                    }
                    foreach (var shot in _invaderShots)
                    {
                        shot.Move();
                        if (!playAreaRect.Contains(shot.Location))
                            _invaderShots.Remove(shot);
                        OnShotMoved(shot, false);
                    }

                    ReturnFire();

                    // Collisions check
                    // At first check for shots which struck into invader ship

                    //We are using ToList() to make collection copy. We're iterating through copy
                    // and we're using remove on the original collection. This prevents the occurrence
                    // of an exception.
                    foreach (Shot playerShot in _playerShots.ToList())
                    {
                        foreach (Invader invader in _invaders.ToList())
                        {
                            if (CheckForInvaderCollision(playerShot, invader))
                            {
                                _invaders.Remove(invader);
                                OnShipChanged(invader, true);
                                _playerShots.Remove(playerShot);
                                OnShotMoved(playerShot, true);
                                break;
                            }
                        }
                    }
                    // Check if any enemy shot struck player ship
                    foreach (Shot enemyShot in _invaderShots.ToList())
                    {
                        if (CheckForPlayerCollision(enemyShot))
                        {
                            _playerDied = DateTime.Now;
                            OnShipChanged(_player, true);
                            _invaderShots.Remove(enemyShot);
                            OnShotMoved(enemyShot, true);
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
		public static bool Intersects(Point p1, Point p2, Rect r)
		{
			return Intersects(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)).HasValue ||
				   Intersects(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)).HasValue ||
				   Intersects(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)).HasValue ||
				   Intersects(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)).HasValue ||
				   (r.Contains(p1) && r.Contains(p2));
		}
Ejemplo n.º 5
0
 //check if point is in shape
 public virtual Boolean CheckIsSelected(Point point)
 {
     Rect rect = new Rect(TopLeftPoint, BottomRightPoint);
     return rect.Contains(point);
 }
Ejemplo n.º 6
0
        protected override void OnPointerEntered(PointerRoutedEventArgs e)
        {
            base.OnPointerEntered(e);
            double leftLimit = (ActualWidth / 2) - (YawGazJoystick.ActualWidth / 2);
            double rightLimit = (ActualWidth / 2) + (YawGazJoystick.ActualWidth / 2);
            double topLimit = YawGazJoystick.ActualHeight / 2;
            double bottomLimit = ActualHeight - (YawGazJoystick.ActualWidth / 2);
            if (e.Pointer.PointerDeviceType != Windows.Devices.Input.PointerDeviceType.Touch)
                return;
            Point pos = e.GetCurrentPoint(JoystickGrid).Position;
            var joy = pos.X < (ActualWidth / 2) ? RollPitchJoystick : YawGazJoystick;
            var bounds = new Rect(joy.ActualWidth / 2, joy.ActualHeight / 2, JoystickGrid.ActualWidth - joy.ActualWidth / 2, JoystickGrid.ActualHeight - joy.ActualHeight / 2);
            if (!bounds.Contains(pos))
                return;
            joy.Margin = new Thickness(pos.X - joy.ActualWidth / 2, pos.Y - joy.ActualHeight / 2, 0, 0);
            joy.VerticalAlignment = VerticalAlignment.Top;
            joy.HorizontalAlignment = HorizontalAlignment.Left;

            //if (location.Y > topLimit && location.Y < bottomLimit)
            //{
            //    JoystickControl joystick = null;
            //    if (location.X < leftLimit)
            //    {
            //        joystick = RollPitchJoystick;
            //    }
            //    else if (location.X > rightLimit)
            //    {
            //        joystick = YawGazJoystick;
            //        //YawGazJoystick.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
            //        //YawGazJoystick.Margin = new Thickness(0, location.Y - joyPos.X, ActualWidth - location.X - joyPos.Y, 0);
            //    }
            //    if (joystick != null)
            //    {
            //        var joyPos = new Point(RollPitchJoystick.ActualWidth / 2, RollPitchJoystick.ActualHeight / 2);
            //        joystick.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
            //        joystick.Margin = new Thickness(location.X - joyPos.X, location.Y - joyPos.Y, 0, 0);
            //    }
            //}
        }
Ejemplo n.º 7
0
        static void PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            FrameworkElement uiElement = sender as FrameworkElement;
            if (uiElement == null) return;
            Point ptStart = GetStartPoint(uiElement);
            Point pt = e.GetCurrentPoint(null).Position;
            
            Rect itemRect = new Rect(ptStart.X, ptStart.Y, uiElement.ActualWidth, uiElement.ActualHeight);

            Debug.WriteLine(itemRect.ToString());
            if (itemRect.Contains(pt)) {
                Debug.WriteLine("down:" + pt.ToString());
                DisplayDownAnimation(uiElement);
            }
            else
            {
                Debug.WriteLine("up:"+pt.ToString());
                DisplayUpAnimation(uiElement);
            }

            // DOESN'T work
            //var elems = VisualTreeHelper.FindElementsInHostCoordinates(pt, uiElement);
            //if (elems.Contains(uiElement))
            
        }
Ejemplo n.º 8
0
        protected override void OnPointerEntered(PointerRoutedEventArgs e)
        {
            base.OnPointerEntered(e);

            if (e.Pointer.PointerDeviceType != Windows.Devices.Input.PointerDeviceType.Touch)
                return;

            Point pos = e.GetCurrentPoint(JoystickGrid).Position;
            var joy = pos.X < (ActualWidth / 2) ? RollPitchJoystick : YawGazJoystick;
            var bounds = new Rect(joy.ActualWidth / 2, joy.ActualHeight / 2, JoystickGrid.ActualWidth - joy.ActualWidth / 2, JoystickGrid.ActualHeight - 75 - joy.ActualHeight / 2);
            if (!bounds.Contains(pos))
                return;
            joy.Margin = new Thickness(pos.X - joy.ActualWidth / 2, pos.Y - joy.ActualHeight / 2, 0, 0);
            joy.VerticalAlignment = VerticalAlignment.Top;
            joy.HorizontalAlignment = HorizontalAlignment.Left;
        }