Skip to content

Commit

Permalink
std::chrono::high_resolution_clock didn't work (do I have different v…
Browse files Browse the repository at this point in the history
…ersions of clang?), changed to clock().
  • Loading branch information
singalen authored and jyrkive committed Oct 28, 2018
1 parent aedc081 commit c9097f4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/mouse_handler_base.cpp
Expand Up @@ -52,9 +52,9 @@ mouse_handler_base::mouse_handler_base()
: simple_warp_(false)
, minimap_scrolling_(false)
, dragging_left_(false)
, dragging_touch_(false)
, dragging_started_(false)
, dragging_right_(false)
, dragging_touch_(false)
, drag_from_x_(0)
, drag_from_y_(0)
, drag_from_hex_()
Expand All @@ -78,6 +78,8 @@ void mouse_handler_base::mouse_motion_event(const SDL_MouseMotionEvent& event, c

void mouse_handler_base::touch_motion_event(const SDL_TouchFingerEvent& event, const bool browse)
{
// This is wrong (needs to be scaled from -1..1 to screen size), but it's discarded in touch_motion anyway.
// Let's not waste CPU cycles.
touch_motion(event.x, event.y, browse);
}

Expand Down Expand Up @@ -159,24 +161,19 @@ void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bo
map_location loc = gui().hex_clicked_on(event.x, event.y);
mouse_update(browse, loc);

static time_t touch_timestamp = 0;
static clock_t touch_timestamp = 0;

if(is_touch_click(event)) {
if (event.state == SDL_PRESSED) {
cancel_dragging();
touch_timestamp = time(NULL);
touch_timestamp = clock();
init_dragging(dragging_touch_);
left_click(event.x, event.y, browse);
} else if (event.state == SDL_RELEASED) {
minimap_scrolling_ = false;

if (!dragging_started_ && touch_timestamp > 0) {
time_t dt = clock() - touch_timestamp;
// I couldn't make this work. Sorry for some C.
// auto dt_cpp = high_resolution_clock::now() - touch_timestamp_cpp;
// auto dt2 = duration_cast<milliseconds>(dt_cpp);
// auto menu_hold = milliseconds(300);
// if (dt2 > menu_hold) {
if (dt > CLOCKS_PER_SEC * 3 / 10) {
right_click(event.x, event.y, browse); // show_menu_ = true;
}
Expand Down Expand Up @@ -296,6 +293,15 @@ bool mouse_handler_base::left_click(int x, int y, const bool /*browse*/)
return false;
}

void mouse_handler_base::move_action(const bool /*browse*/)
{
// Overridden with unit move code elsewhere
}

void mouse_handler_base::touch_action(const map_location /*hex*/, bool /*browse*/)
{
}

void mouse_handler_base::left_drag_end(int /*x*/, int /*y*/, const bool browse)
{
move_action(browse);
Expand Down

0 comments on commit c9097f4

Please sign in to comment.