| 159 | } |
| 160 | |
| 161 | static void preprocess_finger_up(SDL_Event *event) |
| 162 | { |
| 163 | // front (0) or back (1) panel |
| 164 | SDL_TouchID port = event->tfinger.touchId; |
| 165 | // id (for multitouch) |
| 166 | SDL_FingerID id = event->tfinger.fingerId; |
| 167 | |
| 168 | // find out how many fingers were down before this event |
| 169 | int num_fingers_down = 0; |
| 170 | for (int i = 0; i < MAX_NUM_FINGERS; i++) { |
| 171 | if (finger[port][i].id >= 0) { |
| 172 | num_fingers_down++; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | int x = mouse_x; |
| 177 | int y = mouse_y; |
| 178 | |
| 179 | for (int i = 0; i < MAX_NUM_FINGERS; i++) { |
| 180 | if (finger[port][i].id != id) { |
| 181 | continue; |
| 182 | } |
| 183 | |
| 184 | finger[port][i].id = NO_TOUCH; |
| 185 | if (!multi_finger_dragging[port]) { |
| 186 | if ((event->tfinger.timestamp - finger[port][i].time_last_down) > MAX_TAP_TIME) { |
| 187 | continue; |
| 188 | } |
| 189 | |
| 190 | // short (<MAX_TAP_TIME ms) tap is interpreted as right/left mouse click depending on # fingers already down |
| 191 | // but only if the finger hasn't moved since it was pressed down by more than MAX_TAP_MOTION_DISTANCE pixels |
| 192 | float xrel = ((event->tfinger.x * dvl::GetOutputSurface()->w) - (finger[port][i].last_down_x * dvl::GetOutputSurface()->w)); |
| 193 | float yrel = ((event->tfinger.y * dvl::GetOutputSurface()->h) - (finger[port][i].last_down_y * dvl::GetOutputSurface()->h)); |
| 194 | float max_r_squared = (float)(MAX_TAP_MOTION_DISTANCE * MAX_TAP_MOTION_DISTANCE); |
| 195 | if ((xrel * xrel + yrel * yrel) >= max_r_squared) { |
| 196 | continue; |
| 197 | } |
| 198 | |
| 199 | if (num_fingers_down != 2 && num_fingers_down != 1) { |
| 200 | continue; |
| 201 | } |
| 202 | |
| 203 | Uint8 simulated_button = 0; |
| 204 | if (num_fingers_down == 2) { |
| 205 | simulated_button = SDL_BUTTON_RIGHT; |
| 206 | // need to raise the button later |
| 207 | simulated_click_start_time[port][1] = event->tfinger.timestamp; |
| 208 | } else if (num_fingers_down == 1) { |
| 209 | simulated_button = SDL_BUTTON_LEFT; |
| 210 | // need to raise the button later |
| 211 | simulated_click_start_time[port][0] = event->tfinger.timestamp; |
| 212 | if (direct_touch) { |
| 213 | x = event->tfinger.x * visible_width + x_borderwidth; |
| 214 | y = event->tfinger.y * visible_height + y_borderwidth; |
| 215 | dvl::OutputToLogical(&x, &y); |
| 216 | } |
| 217 | } |
| 218 | set_mouse_button_event(event, SDL_MOUSEBUTTONDOWN, simulated_button, x, y); |
no test coverage detected