cursor pos from left bottom window corner

This commit is contained in:
2020-01-30 11:42:57 +07:00
parent ae54d9112d
commit 55d0c0bb77
2 changed files with 5 additions and 3 deletions

View File

@@ -82,7 +82,7 @@ namespace e2d::imgui
void imgui_event_listener::on_move_cursor(const v2f& pos) noexcept {
const v2f real_size = window_.real_size().cast_to<f32>();
if ( math::minimum(real_size) > 0.f ) {
io_.MousePos = pos * (v2f(io_.DisplaySize) / real_size);
io_.MousePos = v2f(pos.x, real_size.y - pos.y) / real_size * v2f(io_.DisplaySize);
}
}

View File

@@ -362,7 +362,9 @@ namespace e2d
double cursor_x = 0.0, cursor_y = 0.0;
E2D_ASSERT(window);
glfwGetCursorPos(window.get(), &cursor_x, &cursor_y);
listener.on_move_cursor(make_vec2(cursor_x, cursor_y).cast_to<f32>());
listener.on_move_cursor(make_vec2(
cursor_x,
math::numeric_cast<double>(real_size.y) - cursor_y).cast_to<f32>());
return listener;
}
private:
@@ -427,7 +429,7 @@ namespace e2d
if ( self ) {
self->for_all_listeners(
&event_listener::on_move_cursor,
make_vec2(pos_x, pos_y).cast_to<f32>());
make_vec2(pos_x, math::numeric_cast<double>(self->real_size.y) - pos_y).cast_to<f32>());
}
}