Skip to content

Commit

Permalink
[gui] Fix ggui & vulkan swapchain sizes on HiDPI displays (#7394)
Browse files Browse the repository at this point in the history
Fixes #7393
  • Loading branch information
bobcao3 authored Feb 18, 2023
1 parent 8d18ccc commit faf5ea0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions taichi/rhi/vulkan/vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2787,6 +2787,8 @@ VulkanSurface::~VulkanSurface() {

void VulkanSurface::resize(uint32_t width, uint32_t height) {
destroy_swap_chain();
this->width_ = width;
this->height_ = height;
create_swap_chain();
}

Expand Down
3 changes: 3 additions & 0 deletions taichi/ui/backends/vulkan/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ void Window::init(Program *prog, const AppConfig &config) {
&renderer_->swap_chain(), glfw_window_);
fps_limit_ = config.fps_limit;

if (config_.show_window) {
resize();
}
prepare_for_next_frame();
}

Expand Down
7 changes: 5 additions & 2 deletions taichi/ui/common/input_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ class InputHandler {
first_mouse_ = false;
}

last_x_ = xpos;
last_y_ = ypos;
int w, h;
glfwGetWindowSize(window, &w, &h);

last_x_ = xpos / double(w);
last_y_ = ypos / double(h);

for (auto f : user_mouse_pos_callbacks_) {
f(xpos, ypos);
Expand Down
4 changes: 1 addition & 3 deletions taichi/ui/common/window_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ void WindowBase::set_is_running(bool value) {
std::pair<float, float> WindowBase::get_cursor_pos() {
CHECK_WINDOW_SHOWING;
float x = input_handler_.last_x();
float y = input_handler_.last_y();
float y = 1.0 - input_handler_.last_y();

x = x / (float)config_.width;
y = (config_.height - y) / (float)config_.height;
return std::make_pair(x, y);
}

Expand Down

0 comments on commit faf5ea0

Please sign in to comment.