#include "dl_input.h" #include #ifndef DL_DISABLE_RENDER #include "system/dl_system.h" #include "system/dl_time.h" namespace dl { Input* g_input; dl::Point Input::GetCursorPosition() { return Each::Limit(dl::as_const(_cursorPos), {}, toPoint(g_system->GetWindowSize())); } void Input::_set_cursor(int xpos, int ypos, bool b_clear_cursor_dt) { Point xy{ (int)xpos, (int)ypos }; g_system->_convert_glfw_to_system(xy); _cursorPos = xy; if (b_clear_cursor_dt) _clear_cursor_dt(); } void Input::_update_late() { if (!KeyDown(MouseCode::LEFT)) { _bClickDouble = false; return; } time_t t = g_time->GetFrameTkc(); // 上一帧双击,此帧只能是单击 if (_bClickDouble) { _bClickDouble = false; _tClickPre = t; _cursorPosClickPre = _cursorPos; return; } // 时间过长 if (t > _tClickPre + _tMaxClickDouble) { _bClickDouble = false; _tClickPre = t; _cursorPosClickPre = _cursorPos; return; } // 距离过长 if (Math::DistancePow2(_cursorPos, _cursorPosClickPre) > _disMaxClickDouble * _disMaxClickDouble) { _bClickDouble = false; _tClickPre = t; _cursorPosClickPre = _cursorPos; return; } _bClickDouble = true; } } #endif