|
5 | 5 | #include "WindowManager.h" |
6 | 6 | #include "CollisionDetection.h" |
7 | 7 | #include "Loader.h" |
| 8 | +#include "Point.h" |
8 | 9 | #include "RttrConfig.h" |
9 | 10 | #include "Settings.h" |
10 | 11 | #include "Window.h" |
11 | 12 | #include "commonDefines.h" |
12 | 13 | #include "desktops/Desktop.h" |
| 14 | +#include "driver/MouseCoords.h" |
13 | 15 | #include "drivers/ScreenResizeEvent.h" |
14 | 16 | #include "drivers/VideoDriverWrapper.h" |
15 | 17 | #include "files.h" |
|
26 | 28 | #include "s25util/MyTime.h" |
27 | 29 | #include <algorithm> |
28 | 30 |
|
29 | | -// Calc square |
30 | | -#define SQR(x) ((x) * (x)) |
| 31 | +namespace { |
| 32 | +template<typename T> |
| 33 | +constexpr T square(T x) |
| 34 | +{ |
| 35 | + return x * x; |
| 36 | +} |
| 37 | +} // namespace |
31 | 38 |
|
32 | 39 | WindowManager::WindowManager() |
33 | 40 | : cursor_(Cursor::Hand), disable_mouse(false), lastMousePos(Position::Invalid()), curRenderSize(0, 0), |
@@ -360,18 +367,18 @@ void WindowManager::Msg_LeftUp(MouseCoords mc) |
360 | 367 | // Ggf. Doppelklick untersuche |
361 | 368 | unsigned time_now = VIDEODRIVER.GetTickCount(); |
362 | 369 |
|
363 | | - if(!VIDEODRIVER.IsTouch()) |
| 370 | + if(VIDEODRIVER.IsTouch()) |
364 | 371 | { |
365 | | - if(time_now - lastLeftClickTime < DOUBLE_CLICK_INTERVAL && mc.pos == lastLeftClickPos) |
366 | | - mc.dbl_click = true; |
| 372 | + if(time_now - lastLeftClickTime < TOUCH_DOUBLE_CLICK_INTERVAL) |
| 373 | + { |
| 374 | + // Calculate distance between two points |
| 375 | + const PointF diff = static_cast<PointF>(mc.pos - lastLeftClickPos); |
| 376 | + if(square(diff.x) + square(diff.y) <= square(TOUCH_MAX_DOUBLE_CLICK_DISTANCE)) |
| 377 | + mc.dbl_click = true; |
| 378 | + } |
367 | 379 |
|
368 | | - } else if(time_now - lastLeftClickTime < TOUCH_DOUBLE_CLICK_INTERVAL) |
369 | | - { |
370 | | - // Calculate distance between two points |
371 | | - unsigned cDistance = SQR(mc.pos.x - lastLeftClickPos.x) + SQR(mc.pos.y - lastLeftClickPos.y); |
372 | | - if(cDistance <= SQR(TOUCH_MAX_DOUBLE_CLICK_DISTANCE)) |
373 | | - mc.dbl_click = true; |
374 | | - } |
| 380 | + } else if(time_now - lastLeftClickTime < DOUBLE_CLICK_INTERVAL && mc.pos == lastLeftClickPos) |
| 381 | + mc.dbl_click = true; |
375 | 382 |
|
376 | 383 | if(!mc.dbl_click) |
377 | 384 | { |
|
0 commit comments