@@ -43,7 +43,11 @@ public class GameActivity extends SDLActivity {
4343
4444 public static native void commandLine (int argc , String [] argv );
4545
46+ public static Osc osc ;
47+
4648 private boolean hideControls = false ;
49+ private boolean touchControls = false ;
50+
4751 private MouseCursor cursor ;
4852 private SharedPreferences prefs ;
4953
@@ -103,6 +107,8 @@ public void onCreate(Bundle savedInstanceState) {
103107 int minRes = Math .min (dm .widthPixels , dm .heightPixels );
104108 mouseDeadzone = minRes / 40 ; // fairly arbitrary
105109
110+ touchControls = PreferenceManager .getDefaultSharedPreferences (this ).getBoolean ("touchControl" , false );
111+
106112 try {
107113 mouseScalingFactor = Float .parseFloat (prefs .getString ("pref_touchpadSensitivity" , "1.8" ));
108114 } catch (NumberFormatException e ) {
@@ -114,7 +120,7 @@ private void showControls() {
114120 hideControls = PreferenceManager .getDefaultSharedPreferences (this ).getBoolean (Constants .HIDE_CONTROLS , false );
115121 if (!hideControls ) {
116122 RelativeLayout layout = getLayout ();
117- Osc osc = new Osc (PreferenceManager .getDefaultSharedPreferences (getContext ()).getBoolean ("multiplayer" , false ));
123+ osc = new Osc (PreferenceManager .getDefaultSharedPreferences (getContext ()).getBoolean ("multiplayer" , false ));
118124 osc .placeElements (layout );
119125 }
120126 cursor = new MouseCursor (this );
@@ -146,70 +152,73 @@ public void onWindowFocusChanged(boolean hasFocus) {
146152 // Touch events
147153 @ Override
148154 public boolean onTouchEvent (MotionEvent event ) {
149- switch (event .getActionMasked ()) {
150- case MotionEvent .ACTION_DOWN :
151- case MotionEvent .ACTION_POINTER_DOWN :
152- if (numPointersDown == 0 ) {
153- startX = event .getX ();
154- startY = event .getY ();
155- }
156- ++numPointersDown ;
157- maxPointersDown = Math .max (numPointersDown , maxPointersDown );
158- break ;
159- case MotionEvent .ACTION_UP :
160- case MotionEvent .ACTION_POINTER_UP :
161- numPointersDown = Math .max (0 , numPointersDown - 1 );
162- if (numPointersDown == 0 ) {
163- // everything's up, do the action
164- if (!isMoving && SDLActivity .isMouseShown () != 0 ) {
165- // only send clicks if we didn't move
166- int mouseX = SDLActivity .getMouseX ();
167- int mouseY = SDLActivity .getMouseY ();
168- int mouseButton = 0 ;
169-
170- if (maxPointersDown == 1 )
171- mouseButton = 1 ;
172- else if (maxPointersDown == 2 )
173- mouseButton = 2 ;
174-
175- if (mouseButton != 0 ) {
176- SDLActivity .onNativeMouse (mouseButton , MotionEvent .ACTION_DOWN , mouseX , mouseY );
177- final Handler handler = new Handler ();
178- handler .postDelayed (() -> SDLActivity .onNativeMouse (0 , MotionEvent .ACTION_UP , mouseX , mouseY ), 100 );
179- }
180- }
181-
182- maxPointersDown = 0 ;
183- isMoving = false ;
184- }
185- break ;
186- case MotionEvent .ACTION_MOVE :
187- if (maxPointersDown == 1 ) {
188- float diffX = event .getX () - startX ;
189- float diffY = event .getY () - startY ;
190- double distance = Math .sqrt (diffX * diffX + diffY * diffY );
191-
192- if (distance > mouseDeadzone ) {
193- isMoving = true ;
155+ if (SDLActivity .isMouseShown () != 0 && touchControls )
156+ return false ;
157+ else {
158+ switch (event .getActionMasked ()) {
159+ case MotionEvent .ACTION_DOWN :
160+ case MotionEvent .ACTION_POINTER_DOWN :
161+ if (numPointersDown == 0 ) {
194162 startX = event .getX ();
195163 startY = event .getY ();
196- } else if (isMoving ) {
197- int mouseX = SDLActivity .getMouseX ();
198- int mouseY = SDLActivity .getMouseY ();
199-
200- long newMouseX = Math .round (mouseX + diffX * mouseScalingFactor );
201- long newMouseY = Math .round (mouseY + diffY * mouseScalingFactor );
202-
203- if (SDLActivity .isMouseShown () != 0 )
204- SDLActivity .onNativeMouse (0 , MotionEvent .ACTION_MOVE , newMouseX , newMouseY );
164+ }
165+ ++numPointersDown ;
166+ maxPointersDown = Math .max (numPointersDown , maxPointersDown );
167+ break ;
168+ case MotionEvent .ACTION_UP :
169+ case MotionEvent .ACTION_POINTER_UP :
170+ numPointersDown = Math .max (0 , numPointersDown - 1 );
171+ if (numPointersDown == 0 ) {
172+ // everything's up, do the action
173+ if (!isMoving && SDLActivity .isMouseShown () != 0 ) {
174+ // only send clicks if we didn't move
175+ int mouseX = SDLActivity .getMouseX ();
176+ int mouseY = SDLActivity .getMouseY ();
177+ int mouseButton = 0 ;
178+
179+ if (maxPointersDown == 1 )
180+ mouseButton = 1 ;
181+ else if (maxPointersDown == 2 )
182+ mouseButton = 2 ;
183+
184+ if (mouseButton != 0 ) {
185+ SDLActivity .onNativeMouse (mouseButton , MotionEvent .ACTION_DOWN , mouseX , mouseY );
186+ final Handler handler = new Handler ();
187+ handler .postDelayed (() -> SDLActivity .onNativeMouse (0 , MotionEvent .ACTION_UP , mouseX , mouseY ), 100 );
188+ }
189+ }
205190
206- startX = event . getX () ;
207- startY = event . getY () ;
191+ maxPointersDown = 0 ;
192+ isMoving = false ;
208193 }
209- }
210- break ;
194+ break ;
195+ case MotionEvent .ACTION_MOVE :
196+ if (maxPointersDown == 1 ) {
197+ float diffX = event .getX () - startX ;
198+ float diffY = event .getY () - startY ;
199+ double distance = Math .sqrt (diffX * diffX + diffY * diffY );
200+
201+ if (distance > mouseDeadzone ) {
202+ isMoving = true ;
203+ startX = event .getX ();
204+ startY = event .getY ();
205+ } else if (isMoving ) {
206+ int mouseX = SDLActivity .getMouseX ();
207+ int mouseY = SDLActivity .getMouseY ();
208+
209+ long newMouseX = Math .round (mouseX + diffX * mouseScalingFactor );
210+ long newMouseY = Math .round (mouseY + diffY * mouseScalingFactor );
211+
212+ if (SDLActivity .isMouseShown () != 0 )
213+ SDLActivity .onNativeMouse (0 , MotionEvent .ACTION_MOVE , newMouseX , newMouseY );
214+
215+ startX = event .getX ();
216+ startY = event .getY ();
217+ }
218+ }
219+ break ;
220+ }
211221 }
212-
213222 return true ;
214223 }
215224
0 commit comments