/// <summary> /// Toucheses the moved. /// </summary> /// <param name="touches">Touches.</param> /// <param name="evt">Evt.</param> public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); var touch = evt.AllTouches.AnyObject as UITouch; if (touch.View is UIImageView) { var mustReturnToOldRotation = false; var degrees = GetRotationValueOfView(touch.View); if (Math.Abs(degrees / 45) % 2 == 1) { mustReturnToOldRotation = true; degrees += 45.0f; var radians = Math.PI / 180 * degrees; touch.View.Transform = CGAffineTransform.MakeRotation((float)radians); } int rawX = (int)touch.LocationInView(View).X; int rawY = (int)touch.LocationInView(View).Y; var xDelta = rawX - _oldX; var yDelta = rawY - _oldY; var touchLocation = touch.LocationInView(View); var frame = touch.View.Frame; frame.X = View.Window.Frame.X + touchLocation.X - _oldX; frame.Y = View.Window.Frame.Y + touchLocation.Y - _oldY; touch.View.Frame = frame; _viewModel.MoveKite((int)touch.View.Tag, new Position { X = (float)touch.View.Frame.X, Y = (float)touch.View.Frame.Y }); if (mustReturnToOldRotation) { degrees -= 45.0f; var radians = Math.PI / 180 * degrees; touch.View.Transform = CGAffineTransform.MakeRotation((float)radians); } _drawView.UpdateTeam(_viewModel.Team); View.SetNeedsDisplay(); _drawView.SetNeedsDisplay(); } }
bool View.IOnTouchListener.OnTouch(View v, MotionEvent e) { RelativeLayout.LayoutParams layoutParams; int rawX = (int)e.RawX; int rawY = (int)e.RawY; switch (e.Action & MotionEventActions.Mask) { case MotionEventActions.Down: layoutParams = v.LayoutParameters as RelativeLayout.LayoutParams; _oldX = rawX - layoutParams.LeftMargin; _oldY = rawY - layoutParams.TopMargin; _oldRawX = rawX; _oldRawY = rawY; break; case MotionEventActions.Up: var rawXDelta = Math.Abs(rawX - _oldRawX); var rawYDelta = Math.Abs(rawY - _oldRawY); if (rawXDelta < 15 && rawYDelta < 15) { if (_viewModel.IsTurningClockwise) { v.Rotation += 45.0f; } else { v.Rotation -= 45.0f; } _viewModel.RotateKite((int)v.Tag); } break; case MotionEventActions.PointerDown: break; case MotionEventActions.PointerUp: break; case MotionEventActions.Move: var xDelta = rawX - _oldX; var yDelta = rawY - _oldY; layoutParams = v.LayoutParameters as RelativeLayout.LayoutParams; layoutParams.LeftMargin = xDelta; layoutParams.TopMargin = yDelta; v.LayoutParameters = layoutParams; _viewModel.MoveKite((int)v.Tag, new Position { X = v.GetX(), Y = v.GetY() }); break; } _drawView.UpdateTeam(_viewModel.Team); _root.Invalidate(); _drawView.Invalidate(); return(true); }
private void Reset() { TurningButtonPressed(true); foreach (var view in View.Subviews) { view.RemoveFromSuperview(); } _gridView = new GridView { Frame = new CGRect(0, 0, View.Frame.Width, View.Frame.Height), BackgroundColor = UIColor.White }; View.AddSubview(_gridView); _drawView = new DrawView { Frame = new CGRect(0, 0, View.Frame.Width, View.Frame.Height), BackgroundColor = UIColor.FromWhiteAlpha(0.0f, 0.0f) }; View.AddSubview(_drawView); _commentView = new UILabel(new CGRect(50, 50, 200, 150)) { TextColor = UIColor.FromRGB(139, 0, 0) }; View.AddSubview(_commentView); DrawPilots(); DrawRevKites(); _viewModel.Team.Pilots.Clear(); _viewModel.AddPilot(new Pilot { Name = "Vienna", PlaceInLine = 1, Position = new Position { X = (float)_pilotVienna.Frame.X, Y = (float)_pilotVienna.Frame.Y }, Kite = new Kite { Rotation = GetRotationValueOfView(_kiteVienna), Position = new Position { X = (float)_kiteVienna.Frame.X, Y = (float)_kiteVienna.Frame.Y } } }); _viewModel.AddPilot(new Pilot { Name = "Tim", PlaceInLine = 2, Position = new Position { X = (float)_pilotTim.Frame.X, Y = (float)_pilotTim.Frame.Y }, Kite = new Kite { Rotation = GetRotationValueOfView(_kiteTim), Position = new Position { X = (float)_kiteTim.Frame.X, Y = (float)_kiteTim.Frame.Y } } }); _viewModel.AddPilot(new Pilot { Name = "Mario", PlaceInLine = 3, Position = new Position { X = (float)_pilotMario.Frame.X, Y = (float)_pilotMario.Frame.Y }, Kite = new Kite { Rotation = GetRotationValueOfView(_kiteMario), Position = new Position { X = (float)_kiteMario.Frame.X, Y = (float)_kiteMario.Frame.Y } } }); _viewModel.AddPilot(new Pilot { Name = "Twan", PlaceInLine = 4, Position = new Position { X = (float)_pilotTwan.Frame.X, Y = (float)_pilotTwan.Frame.Y }, Kite = new Kite { Rotation = GetRotationValueOfView(_kiteTwan), Position = new Position { X = (float)_kiteTwan.Frame.X, Y = (float)_kiteTwan.Frame.Y } } }); _viewModel.AddPilot(new Pilot { Name = "Judith", PlaceInLine = 5, Position = new Position { X = (float)_pilotJudith.Frame.X, Y = (float)_pilotJudith.Frame.Y }, Kite = new Kite { Rotation = GetRotationValueOfView(_kiteJudith), Position = new Position { X = (float)_kiteJudith.Frame.X, Y = (float)_kiteJudith.Frame.Y } } }); _viewModel.AddPilot(new Pilot { Name = "Sanne", PlaceInLine = 6, Position = new Position { X = (float)_pilotSanne.Frame.X, Y = (float)_pilotSanne.Frame.Y }, Kite = new Kite { Rotation = GetRotationValueOfView(_kiteSanne), Position = new Position { X = (float)_kiteSanne.Frame.X, Y = (float)_kiteSanne.Frame.Y } } }); _drawView.UpdateTeam(_viewModel.Team); _drawView.SetNeedsDisplay(); }
private void Reset() { TurningButtonPressed(true); _root.RemoveAllViews(); _gridView = new GridView(this); _root.AddView(_gridView); _drawView = new DrawView(this); _root.AddView(_drawView); _commentView = new TextView(this); _commentView.SetTextColor(Color.DarkRed); var layoutParams = new RelativeLayout.LayoutParams(400, 250) { LeftMargin = 100, TopMargin = 100 }; _commentView.LayoutParameters = layoutParams; _root.AddView(_commentView); DrawPilots(); DrawRevKites(); _root.Post(() => { _viewModel.Team.Pilots.Clear(); _viewModel.AddPilot(new Pilot { Name = "Vienna", PlaceInLine = 1, Position = new Position { X = _pilotVienna.GetX(), Y = _pilotVienna.GetY() }, Kite = new Kite { Rotation = _kiteVienna.Rotation, Position = new Position { X = _kiteVienna.GetX(), Y = _kiteVienna.GetY() } } }); _viewModel.AddPilot(new Pilot { Name = "Tim", PlaceInLine = 2, Position = new Position { X = _pilotTim.GetX(), Y = _pilotTim.GetY() }, Kite = new Kite { Rotation = _kiteTim.Rotation, Position = new Position { X = _kiteTim.GetX(), Y = _kiteTim.GetY() } } }); _viewModel.AddPilot(new Pilot { Name = "Mario", PlaceInLine = 3, Position = new Position { X = _pilotMario.GetX(), Y = _pilotMario.GetY() }, Kite = new Kite { Rotation = _kiteMario.Rotation, Position = new Position { X = _kiteMario.GetX(), Y = _kiteMario.GetY() } } }); _viewModel.AddPilot(new Pilot { Name = "Twan", PlaceInLine = 4, Position = new Position { X = _pilotTwan.GetX(), Y = _pilotTwan.GetY() }, Kite = new Kite { Rotation = _kiteTwan.Rotation, Position = new Position { X = _kiteTwan.GetX(), Y = _kiteTwan.GetY() } } }); _viewModel.AddPilot(new Pilot { Name = "Judith", PlaceInLine = 5, Position = new Position { X = _pilotJudith.GetX(), Y = _pilotJudith.GetY() }, Kite = new Kite { Rotation = _kiteJudith.Rotation, Position = new Position { X = _kiteJudith.GetX(), Y = _kiteJudith.GetY() } } }); _viewModel.AddPilot(new Pilot { Name = "Sanne", PlaceInLine = 6, Position = new Position { X = _pilotSanne.GetX(), Y = _pilotSanne.GetY() }, Kite = new Kite { Rotation = _kiteSanne.Rotation, Position = new Position { X = _kiteSanne.GetX(), Y = _kiteSanne.GetY() } } }); _drawView.UpdateTeam(_viewModel.Team); _drawView.Invalidate(); }); }