3 #if SILICONSTUDIO_PLATFORM_IOS
8 using MonoTouch.Foundation;
9 using OpenTK.Platform.iPhoneOS;
10 using SiliconStudio.Core;
11 using SiliconStudio.Core.Mathematics;
13 namespace SiliconStudio.
Paradox.Input
15 public partial class InputManager
17 private UIWindow window;
18 private iPhoneOSGameView view;
27 public override void Initialize()
29 view = Game.Context.GameView;
30 window = Game.Context.MainWindow;
32 var gameController = Game.Context.GameViewController;
34 window.UserInteractionEnabled =
true;
35 window.MultipleTouchEnabled =
true;
36 gameController.TouchesBeganDelegate += (touchesSet, _) => HandleTouches(touchesSet);
37 gameController.TouchesMovedDelegate += (touchesSet, _) => HandleTouches(touchesSet);
38 gameController.TouchesEndedDelegate += (touchesSet, _) => HandleTouches(touchesSet);
39 gameController.TouchesCancelledDelegate += (touchesSet, _) => HandleTouches(touchesSet);
40 view.Resize += OnResize;
45 private void OnResize(
object sender,
EventArgs eventArgs)
47 ControlHeight = view.Frame.Height;
48 ControlWidth = view.Frame.Width;
51 private void HandleTouches(NSSet touchesSet)
53 var touches = touchesSet.ToArray<UITouch>();
57 foreach (var uitouch
in touches)
59 var
id = uitouch.Handle.ToInt32();
60 var position = NormalizeScreenPosition(PointFToVector2(uitouch.LocationInView(view)));
62 HandlePointerEvents(
id, position, GetState(uitouch));
71 case UITouchPhase.Began:
72 return PointerState.Down;
73 case UITouchPhase.Moved:
74 case UITouchPhase.Stationary:
75 return PointerState.Move;
76 case UITouchPhase.Ended:
77 return PointerState.Up;
78 case UITouchPhase.Cancelled:
79 return PointerState.Cancel;
82 throw new ArgumentException(
"Got an invalid Touch event in GetState");
85 private Vector2 PointFToVector2(PointF point)
87 return new Vector2(point.X, point.Y);
90 public override bool MultiTouchEnabled
92 get {
return Game.Context.GameView.MultipleTouchEnabled; }
93 set { Game.Context.GameView.MultipleTouchEnabled = value; }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
SiliconStudio.Core.IServiceRegistry IServiceRegistry