Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the black screen issue on macOS, fixed HiDPI rendering, add keyboard interaction #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NaivelyWritten
Copy link

This PR fixes #15, added keyboard interactions, and also fixed the wrong mouse interaction under HiDPI environments such as on macOS retina screen.

@rajkundu
Copy link
Collaborator

This looks great! Unfortunately haven't had a chance to test this PR since I switched jobs a few years ago.
One question: how come the math for xpos and ypos are so dissimilar? I.e., why is there no viewportSize.x term for xpos, and why is io.MousePos positive for xpos and negative for ypos, and screenPos positive for ypos and negative for xpos?

ImVec2 screenPos = ImGui::GetWindowPos();
ImVec2 viewportSize = ImGui::GetWindowSize();

auto dpiScale = ImGui::GetWindowDpiScale();
double xpos = (io.MousePos[0] - screenPos.x) * dpiScale;
double ypos = (screenPos.y + viewportSize.y - io.MousePos[1]) * dpiScale;

fa38496#diff-86bc0a1a2a83bc219e04944ce2a5cd6f9fccecb6b1f993ac58e00453427d30f7R54-R55

@ProfFan
Copy link

ProfFan commented Mar 14, 2024

Hi @rajkundu it's because the mouse position is in the ImGui coordinate system and the x and y poses are in the VTK coordinate system, they are defined on different corners

@rajkundu
Copy link
Collaborator

Ah, okay. The different corners makes sense for the inversion, but why is viewportSize.x not used in the xpos calculation?

@ProfFan
Copy link

ProfFan commented Mar 14, 2024

@rajkundu because they both share the x axis, viewport size is used to convert the y:

+ (top left screen corner) - - - - - -
|
|
+ ( top left window corner)
|
|
+ (bottom left window corner)
|
+

@rajkundu
Copy link
Collaborator

Got it! Makes perfect sense, and thanks for drawing it out. I will test this when I can, likely in the next few months, but in the meantime, I'm glad that this PR is here for others to see and check out. Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minimising and then maximising window blanks screen
3 participants