Advertisement
dominus

Untitled

Jul 24th, 2021
1,799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.91 KB | None | 0 0
  1. diff --git a/exult.cc b/exult.cc
  2. index 104411b5..40c6e68c 100644
  3. --- a/exult.cc
  4. +++ b/exult.cc
  5. @@ -700,6 +700,7 @@ static void Init(
  6.     init_flags |= SDL_INIT_JOYSTICK;
  7.  #endif
  8.  #ifdef __IPHONEOS__
  9. +   Mouse::use_touch_input = true;
  10.     SDL_SetHint(SDL_HINT_IOS_HIDE_HOME_INDICATOR, "2");
  11.  #endif
  12.     if (SDL_Init(init_flags) < 0) {
  13. @@ -1260,7 +1261,8 @@ static void Handle_event(
  14.     // We want this
  15.     Gump_manager *gump_man = gwin->get_gump_man();
  16.     Gump *gump = nullptr;
  17. -
  18. +  
  19. +   static uint64 finger_id = 0;
  20.     // For detecting double-clicks.
  21.     static uint32 last_b1_click = 0;
  22.     static uint32 last_b3_click = 0;
  23. @@ -1371,6 +1373,19 @@ static void Handle_event(
  24.         }
  25.         break;
  26.     }
  27. +   case SDL_FINGERDOWN: {
  28. +       if ((Mouse::use_touch_input == false) && (event.tfinger.fingerId != finger_id) && (event.tfinger.fingerId != 0)) {
  29. +           cout << "in if Finger_ID: " << finger_id << endl;
  30. +           cout << "in if FingerID: " << event.tfinger.fingerId << endl;
  31. +           Mouse::use_touch_input = true;
  32. +           gwin->set_painted();
  33. +       }
  34. +       if (event.tfinger.fingerId != 0) {
  35. +           finger_id = event.tfinger.fingerId;
  36. +           cout << "Saved FingerID: " << finger_id << endl;
  37. +       }
  38. +       break;
  39. +   }
  40.     case SDL_MOUSEBUTTONDOWN: {
  41.         SDL_SetWindowGrab(gwin->get_win()->get_screen_window(), SDL_TRUE);
  42.         if (dont_move_mode)
  43. @@ -1585,6 +1600,8 @@ static void Handle_event(
  44.     case SDL_MOUSEMOTION: {
  45.         int mx ;
  46.         int my;
  47. +       if (event.motion.which != SDL_TOUCH_MOUSEID)
  48. +           Mouse::use_touch_input = false;
  49.         gwin->get_win()->screen_to_game(event.motion.x, event.motion.y, gwin->get_fastmouse(), mx, my);
  50.  
  51.         Mouse::mouse->move(mx, my);
  52. diff --git a/menulist.cc b/menulist.cc
  53. index 70a13368..37a68392 100644
  54. --- a/menulist.cc
  55. +++ b/menulist.cc
  56. @@ -288,6 +288,7 @@ int MenuList::handle_events(Game_window *gwin, Mouse *mouse) {
  57.     gwin->show(true);
  58.     mouse->show();
  59.  
  60. +   static uint64 finger_id1 = 0;
  61.     bool exit_loop = false;
  62.     do {
  63.         Delay();
  64. @@ -309,6 +310,8 @@ int MenuList::handle_events(Game_window *gwin, Mouse *mouse) {
  65.             int gx;
  66.             int gy;
  67.             if (event.type == SDL_MOUSEMOTION) {
  68. +               if (event.motion.which != SDL_TOUCH_MOUSEID)
  69. +                   Mouse::use_touch_input = false;
  70.                 gwin->get_win()->screen_to_game(event.motion.x, event.motion.y, gwin->get_fastmouse(), gx, gy);
  71.                 if (!mouse_updated) mouse->hide();
  72.                 mouse_updated = true;
  73. @@ -382,6 +385,15 @@ int MenuList::handle_events(Game_window *gwin, Mouse *mouse) {
  74.             } else if (event.type == SDL_QUIT) {
  75.                 return -1;
  76.             }
  77. +           else if (event.type == SDL_FINGERDOWN) {
  78. +               if ((Mouse::use_touch_input == false) && (event.tfinger.fingerId != finger_id1) && (event.tfinger.fingerId != 0)) {
  79. +                   Mouse::use_touch_input = true;
  80. +                   gwin->set_painted();
  81. +               }
  82. +               if (event.tfinger.fingerId != 0) {
  83. +                   finger_id1 = event.tfinger.fingerId;
  84. +               }
  85. +           }
  86.         }
  87.         if (mouse_updated) {
  88.             mouse->show();
  89. diff --git a/mouse.cc b/mouse.cc
  90. index ad8d848c..8278a6f3 100644
  91. --- a/mouse.cc
  92. +++ b/mouse.cc
  93. @@ -22,6 +22,7 @@
  94.  #  include <config.h>
  95.  #endif
  96.  
  97. +#include <SDL.h>
  98.  #include "SDL_mouse.h"
  99.  #include "SDL_timer.h"
  100.  #include "mouse.h"
  101. @@ -41,13 +42,16 @@
  102.  using std::max;
  103.  #endif
  104.  
  105. +bool Mouse::use_touch_input = false;
  106. +
  107.  static inline bool should_hide_frame(int frame) {
  108. -#ifdef __IPHONEOS__
  109. -   return frame == 0 || (frame >=8 && frame <= 47);
  110. -#else
  111. -   ignore_unused_variable_warning(frame);
  112. -   return false;
  113. -#endif
  114. +   if (Mouse::use_touch_input == true) {
  115. +       SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "1");
  116. +       return frame == 0 || (frame >=8 && frame <= 47);
  117. +   } else {
  118. +       SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
  119. +       return false;
  120. +   }
  121.  }
  122.  
  123.  short Mouse::short_arrows[8] = {8, 9, 10, 11, 12, 13, 14, 15};
  124. diff --git a/mouse.h b/mouse.h
  125. index 0eaf7a38..ca8931ba 100644
  126. --- a/mouse.h
  127. +++ b/mouse.h
  128. @@ -92,6 +92,7 @@ class Mouse {
  129.     };
  130.     int avatar_speed;
  131.  
  132. +   static bool use_touch_input;
  133.     static bool mouse_update;
  134.     static Mouse *mouse;
  135.  
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement