3 #if SILICONSTUDIO_PLATFORM_ANDROID
7 using OpenTK.Platform.Android;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Mathematics;
11 namespace SiliconStudio.
Paradox.Input
13 public partial class InputManager
15 private AndroidGameView gameView;
24 public override void Initialize()
26 var viewListener =
new ViewListener(
this);
27 gameView = Game.Context.Control;
28 gameView.SetOnTouchListener(viewListener);
29 gameView.SetOnKeyListener(viewListener);
30 gameView.Resize += GameViewOnResize;
35 private void GameViewOnResize(
object sender,
EventArgs eventArgs)
37 ControlWidth = gameView.Size.Width;
38 ControlHeight = gameView.Size.Height;
41 private bool OnTouch(MotionEvent e)
44 switch (e.ActionMasked)
46 case MotionEventActions.Cancel:
47 state = PointerState.Cancel;
49 case MotionEventActions.Move:
50 state = PointerState.Move;
52 case MotionEventActions.Outside:
53 state = PointerState.Out;
55 case MotionEventActions.Down:
56 case MotionEventActions.PointerDown:
57 state = PointerState.Down;
59 case MotionEventActions.Up:
60 case MotionEventActions.PointerUp:
61 state = PointerState.Up;
69 var endIndex = e.PointerCount;
73 startIndex = e.ActionIndex;
74 endIndex = startIndex + 1;
77 for (var i = startIndex; i < endIndex; ++i)
79 var pointerId = e.GetPointerId(i);
80 var pixelPosition =
new Vector2(e.GetX(i), e.GetY(i));
82 if(MultiTouchEnabled || pointerId == 0)
83 HandlePointerEvents(pointerId, NormalizeScreenPosition(pixelPosition), state);
89 private bool OnKey(Keycode keyCode,
Android.Views.KeyEvent e)
91 lock (KeyboardInputEvents)
93 KeyboardInputEvents.Add(
new KeyboardInputEvent
95 Key = ConvertKeyFromAndroid(keyCode),
96 Type = e.Action == KeyEventActions.Down ? InputEventType.Down : InputEventType.Up,
102 private Keys ConvertKeyFromAndroid(Keycode key)
106 case Keycode.Num0:
return Keys.D0;
107 case Keycode.Num1:
return Keys.D1;
108 case Keycode.Num2:
return Keys.D2;
109 case Keycode.Num3:
return Keys.D3;
110 case Keycode.Num4:
return Keys.D4;
111 case Keycode.Num5:
return Keys.D5;
112 case Keycode.Num6:
return Keys.D6;
113 case Keycode.Num7:
return Keys.D7;
114 case Keycode.Num8:
return Keys.D8;
115 case Keycode.Num9:
return Keys.D9;
116 case Keycode.A:
return Keys.A;
117 case Keycode.B:
return Keys.B;
118 case Keycode.C:
return Keys.C;
119 case Keycode.D:
return Keys.D;
120 case Keycode.E:
return Keys.E;
121 case Keycode.F:
return Keys.F;
122 case Keycode.G:
return Keys.G;
123 case Keycode.H:
return Keys.H;
124 case Keycode.I:
return Keys.I;
125 case Keycode.J:
return Keys.J;
126 case Keycode.K:
return Keys.K;
127 case Keycode.L:
return Keys.L;
128 case Keycode.M:
return Keys.M;
129 case Keycode.N:
return Keys.N;
130 case Keycode.O:
return Keys.O;
131 case Keycode.P:
return Keys.P;
132 case Keycode.Q:
return Keys.Q;
133 case Keycode.R:
return Keys.R;
134 case Keycode.S:
return Keys.S;
135 case Keycode.T:
return Keys.T;
136 case Keycode.U:
return Keys.U;
137 case Keycode.V:
return Keys.V;
138 case Keycode.W:
return Keys.W;
139 case Keycode.X:
return Keys.X;
140 case Keycode.Y:
return Keys.Y;
141 case Keycode.Z:
return Keys.Z;
142 case Keycode.AltLeft:
return Keys.LeftAlt;
143 case Keycode.AltRight:
return Keys.RightAlt;
144 case Keycode.ShiftLeft:
return Keys.LeftShift;
145 case Keycode.ShiftRight:
return Keys.RightShift;
146 case Keycode.Enter:
return Keys.Enter;
147 case Keycode.Back:
return Keys.Back;
148 case Keycode.Tab:
return Keys.Tab;
149 case Keycode.Del:
return Keys.Delete;
150 case Keycode.PageUp:
return Keys.PageUp;
151 case Keycode.PageDown:
return Keys.PageDown;
152 case Keycode.DpadUp:
return Keys.Up;
153 case Keycode.DpadDown:
return Keys.Down;
154 case Keycode.DpadLeft:
return Keys.Right;
155 case Keycode.DpadRight:
return Keys.Right;
161 class ViewListener : Java.Lang.
Object, View.IOnTouchListener, View.IOnKeyListener
163 private readonly InputManager inputManager;
165 public ViewListener(InputManager inputManager)
167 this.inputManager = inputManager;
170 public bool OnTouch(View v, MotionEvent e)
172 return inputManager.OnTouch(e);
175 public bool OnKey(View v, Keycode keyCode,
Android.Views.KeyEvent e)
177 return inputManager.OnKey(keyCode, e);
182 public override bool MultiTouchEnabled {
get; set; }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
SiliconStudio.Core.IServiceRegistry IServiceRegistry
SiliconStudio.Paradox.Input.Keys Keys
The type of the serialized type will be passed as a generic arguments of the serializer. Example: serializer of A becomes instantiated as Serializer{A}.