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); _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(); }); }