dominus icon

Untitled

dominus | PRO | 07/24/21 12:32:57 PM UTC | 0 ⭐ | 14774 👁️ | Never ⏰ | []
Diff |

3.91 KB

|

None

|

0 👍

/

0 👎

diff --git a/exult.cc b/exult.cc
index 104411b5..40c6e68c 100644
--- a/exult.cc
+++ b/exult.cc
@@ -700,6 +700,7 @@ static void Init(
    init_flags |= SDL_INIT_JOYSTICK;
 #endif
 #ifdef __IPHONEOS__
+   Mouse::use_touch_input = true;
    SDL_SetHint(SDL_HINT_IOS_HIDE_HOME_INDICATOR, "2");
 #endif
    if (SDL_Init(init_flags) < 0) {
@@ -1260,7 +1261,8 @@ static void Handle_event(
    // We want this
    Gump_manager *gump_man = gwin->get_gump_man();
    Gump *gump = nullptr;
-
+   
+   static uint64 finger_id = 0;
    // For detecting double-clicks.
    static uint32 last_b1_click = 0;
    static uint32 last_b3_click = 0;
@@ -1371,6 +1373,19 @@ static void Handle_event(
        }
        break;
    }
+   case SDL_FINGERDOWN: {
+       if ((Mouse::use_touch_input == false) && (event.tfinger.fingerId != finger_id) && (event.tfinger.fingerId != 0)) {
+           cout << "in if Finger_ID: " << finger_id << endl;
+           cout << "in if FingerID: " << event.tfinger.fingerId << endl;
+           Mouse::use_touch_input = true;
+           gwin->set_painted();
+       }
+       if (event.tfinger.fingerId != 0) {
+           finger_id = event.tfinger.fingerId;
+           cout << "Saved FingerID: " << finger_id << endl;
+       }
+       break;
+   }
    case SDL_MOUSEBUTTONDOWN: {
        SDL_SetWindowGrab(gwin->get_win()->get_screen_window(), SDL_TRUE);
        if (dont_move_mode)
@@ -1585,6 +1600,8 @@ static void Handle_event(
    case SDL_MOUSEMOTION: {
        int mx ;
        int my;
+       if (event.motion.which != SDL_TOUCH_MOUSEID)
+           Mouse::use_touch_input = false;
        gwin->get_win()->screen_to_game(event.motion.x, event.motion.y, gwin->get_fastmouse(), mx, my);
 
        Mouse::mouse->move(mx, my);
diff --git a/menulist.cc b/menulist.cc
index 70a13368..37a68392 100644
--- a/menulist.cc
+++ b/menulist.cc
@@ -288,6 +288,7 @@ int MenuList::handle_events(Game_window *gwin, Mouse *mouse) {
    gwin->show(true);
    mouse->show();
 
+   static uint64 finger_id1 = 0;
    bool exit_loop = false;
    do {
        Delay();
@@ -309,6 +310,8 @@ int MenuList::handle_events(Game_window *gwin, Mouse *mouse) {
            int gx;
            int gy;
            if (event.type == SDL_MOUSEMOTION) {
+               if (event.motion.which != SDL_TOUCH_MOUSEID)
+                   Mouse::use_touch_input = false;
                gwin->get_win()->screen_to_game(event.motion.x, event.motion.y, gwin->get_fastmouse(), gx, gy);
                if (!mouse_updated) mouse->hide();
                mouse_updated = true;
@@ -382,6 +385,15 @@ int MenuList::handle_events(Game_window *gwin, Mouse *mouse) {
            } else if (event.type == SDL_QUIT) {
                return -1;
            }
+           else if (event.type == SDL_FINGERDOWN) {
+               if ((Mouse::use_touch_input == false) && (event.tfinger.fingerId != finger_id1) && (event.tfinger.fingerId != 0)) {
+                   Mouse::use_touch_input = true;
+                   gwin->set_painted();
+               }
+               if (event.tfinger.fingerId != 0) {
+                   finger_id1 = event.tfinger.fingerId;
+               }
+           }
        }
        if (mouse_updated) {
            mouse->show();
diff --git a/mouse.cc b/mouse.cc
index ad8d848c..8278a6f3 100644
--- a/mouse.cc
+++ b/mouse.cc
@@ -22,6 +22,7 @@
 #  include <config.h>
 #endif
 
+#include <SDL.h>
 #include "SDL_mouse.h"
 #include "SDL_timer.h"
 #include "mouse.h"
@@ -41,13 +42,16 @@
 using std::max;
 #endif
 
+bool Mouse::use_touch_input = false;
+
 static inline bool should_hide_frame(int frame) {
-#ifdef __IPHONEOS__
-   return frame == 0 || (frame >=8 && frame <= 47);
-#else
-   ignore_unused_variable_warning(frame);
-   return false;
-#endif
+   if (Mouse::use_touch_input == true) {
+       SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "1");
+       return frame == 0 || (frame >=8 && frame <= 47);
+   } else {
+       SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
+       return false;
+   }
 }
 
 short Mouse::short_arrows[8] = {8, 9, 10, 11, 12, 13, 14, 15};
diff --git a/mouse.h b/mouse.h
index 0eaf7a38..ca8931ba 100644
--- a/mouse.h
+++ b/mouse.h
@@ -92,6 +92,7 @@ class Mouse {
    };
    int avatar_speed;
 
+   static bool use_touch_input;
    static bool mouse_update;
    static Mouse *mouse;
 
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎