Open NaivelyWritten opened 1 year ago
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;
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
Ah, okay. The different corners makes sense for the inversion, but why is viewportSize.x
not used in the xpos
calculation?
@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)
|
+
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!
This PR fixes #15, added keyboard interactions, and also fixed the wrong mouse interaction under HiDPI environments such as on macOS retina screen.