Skip to content

Commit

Permalink
Merge pull request #1773 from ivan-mogilko/android--touch2mouse
Browse files Browse the repository at this point in the history
Android: reimplement touch-to-mouse controls in the engine
  • Loading branch information
ivan-mogilko authored Sep 17, 2022
2 parents 3fab687 + 6ac3177 commit 318045d
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,4 @@ public boolean dispatchKeyEvent(KeyEvent ev)
return super.dispatchKeyEvent(ev);
}

@Keep
protected void AgsEnableLongclick() {

}

}
12 changes: 12 additions & 0 deletions Android/library/runtime/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
<item>2</item>
</string-array>

<string-array name="mouse_emulation">
<item>Off</item>
<item>One Finger (touch means button down)</item>
<item>Two Finger (tap to click)</item>
</string-array>

<string-array name="mouse_emulation_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>


<string-array name="game_language">
<item>Default</item>
Expand Down
4 changes: 2 additions & 2 deletions Android/library/runtime/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<string name="CONFIG_GFX_SMOOTH_SPRITES">16</string>
<string name="CONFIG_TRANSLATION">17</string>
<string name="CONFIG_DEBUG_LOGCAT">18</string>
<string name="CONFIG_MOUSE_METHOD">19</string>
<string name="CONFIG_MOUSE_LONGCLICK">20</string>
<string name="CONFIG_MOUSE_EMULATION">19</string>
<string name="CONFIG_MOUSE_METHOD">20</string>
<string name="toggle_keyboard">Toggle keyboard</string>
<string name="exit_game">Exit game</string>

Expand Down
18 changes: 10 additions & 8 deletions Android/library/runtime/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@
<androidx.preference.PreferenceCategory
android:key="preference_key_controls"
android:title="Controls">
<androidx.preference.CheckBoxPreference
<androidx.preference.ListPreference
android:dependency="@string/CONFIG_ENABLED"
android:key="@string/CONFIG_MOUSE_METHOD"
android:dialogTitle="Touch-to-mouse emulation scheme"
android:entries="@array/mouse_emulation"
android:entryValues="@array/mouse_emulation_values"
android:key="@string/CONFIG_MOUSE_EMULATION"
android:persistent="false"
android:shouldDisableView="true"
android:summary="The mouse gets moved relative to the finger motion"
android:title="Relative mouse control" />

android:summary="A control scheme for emulating mouse actions with touch screen"
android:title="Touch-to-mouse emulation" />
<androidx.preference.CheckBoxPreference
android:dependency="@string/CONFIG_ENABLED"
android:key="@string/CONFIG_MOUSE_LONGCLICK"
android:key="@string/CONFIG_MOUSE_METHOD"
android:persistent="false"
android:shouldDisableView="true"
android:summary="A longclick keeps the left mouse button pressed"
android:title="Dragging with longclick" />
android:summary="The mouse gets moved relative to the finger motion"
android:title="Relative mouse control" />
</androidx.preference.PreferenceCategory>

<androidx.preference.PreferenceCategory
Expand Down
7 changes: 7 additions & 0 deletions Common/util/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef __AGS_CN_UTIL__GEOMETRY_H
#define __AGS_CN_UTIL__GEOMETRY_H

#include <cmath>
#include "util/math.h"

namespace AGSMath = AGS::Common::Math;
Expand Down Expand Up @@ -387,6 +388,12 @@ struct Circle
};


// Calculates a distance between two points
inline float DistanceBetween(const Point &p1, const Point &p2)
{
return static_cast<float>(std::sqrt(((p2.X - p1.X) ^ 2) + ((p2.Y - p1.Y) ^ 2)));
}

// Tells if two rectangles intersect (overlap) at least partially
bool AreRectsIntersecting(const Rect &r1, const Rect &r2);
// Tells if the item is completely inside place
Expand Down
1 change: 1 addition & 0 deletions Engine/ac/gamesetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GameSetup::GameSetup()
mouse_ctrl_when = kMouseCtrl_Fullscreen;
mouse_ctrl_enabled = false;
mouse_speed_def = kMouseSpeed_CurrentDisplay;
touch_emulate_mouse = kTouchMouse_OneFingerDrag;
RenderAtScreenRes = false;
Supersampling = 1;
clear_cache_on_room_change = false;
Expand Down
15 changes: 15 additions & 0 deletions Engine/ac/gamesetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ enum ScreenRotation
kNumScreenRotationOptions
};

enum TouchMouseEmulation
{
// don't emulate mouse
kTouchMouse_None = 0,
// copy default SDL2 behavior:
// touch down means hold LMB down, no RMB emulation
kTouchMouse_OneFingerDrag,
// tap 1,2 fingers means LMB/RMB click;
// double tap + drag 1 finger would drag the cursor with LMB down
kTouchMouse_TwoFingersTap
};

using AGS::Common::String;

// TODO: reconsider the purpose of this struct in the future.
Expand Down Expand Up @@ -79,6 +91,9 @@ struct GameSetup
MouseControlWhen mouse_ctrl_when;
bool mouse_ctrl_enabled;
MouseSpeedDef mouse_speed_def;
// touch-to-mouse emulation mode
int touch_emulate_mouse;
//
bool RenderAtScreenRes; // render sprites at screen resolution, as opposed to native one
int Supersampling;
size_t SpriteCacheSize = 0u;
Expand Down
Loading

0 comments on commit 318045d

Please sign in to comment.