- 
                Notifications
    You must be signed in to change notification settings 
- Fork 59
Feat: Custom Input Map #134
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure of a couple of things. I tried adding most of the functionality after the Style  blocks of code.
@brenocq if you could please just provide some feedback I would really appreciate it.
| // If the user is no longer pressing the translation/zoom buttons, set axes as not held | ||
| if (!ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseDown(ImGuiMouseButton_Middle)) { | ||
| if (!(ImPlot3D::ImHasFlag(IO.KeyMods, gp.InputMap.PanMod) && ImGui::IsMouseDown(gp.InputMap.Pan)) && | ||
| !(ImPlot3D::ImHasFlag(IO.KeyMods, gp.InputMap.ZoomMod) && ImGui::IsMouseDown(ImGuiMouseButton_Middle))) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should gp.InputMap.ZoomModalso be applied here and later on for theImGui::IsMouseDown(ImGuiMouseButton_Middle)andImGui::IsMouseDoubleClicked(ImGuiMouseButton_Middle)checks?
- Should we add ImGuiMouseButton_Middleas a option forZoomtogether withZoomModor should we just keep it as it since it is previous behaviour?Zoommight not make a lot of sense though since it does not use it for zoom ad is for fit(already have option forFitthough), maybe call it something else?
|  | ||
| // Handle translation/zoom fit with double click | ||
| if (plot_clicked && (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) || ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Middle))) { | ||
| if (plot_clicked && (ImGui::IsMouseDoubleClicked(gp.InputMap.Fit) || | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add support for FitMod? This is not in ImPlot and I think it might be because it is only triggered on double click which does not happen very often.
| } | ||
|  | ||
| // cancel due to DND activity | ||
| if (GImGui->DragDropActive || ImPlot3D::ImHasFlag(IO.KeyMods, gp.InputMap.OverrideMod)) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where to put this? I put it here after the FitThisFrame   has been set for the plot which means that the auto fit can be applied to the plot. ImPlot has similar behavior. Should the data be fitted to the plot if OverrideMod is valid?
| map.ResetRotate = ImGuiMouseButton_Right; | ||
| map.Rotate = ImGuiMouseButton_Right; | ||
| map.RotateMod = ImGuiMod_None; | ||
| map.Menu = ImGuiMouseButton_Right; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add MenuMod and FitMod as well?
Add small overhead for some more control.
| ImGuiMouseButton Pan; // LMB enables panning when held, | ||
| int PanMod; // none optional modifier that must be held for panning/fitting | ||
| ImGuiMouseButton Fit; // LMB initiates fit when double clicked | ||
| ImGuiMouseButton ResetRotate; // RMB initiates reset of the rotate when double clicked. When double clicked over the axis change to 2D view of the axis | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of the name ResetRotate here. Open to suggestions for a better name?
| if (ImGui::BeginTabItem("Custom")) { | ||
| DemoHeader("Custom Styles", DemoCustomStyles); | ||
| DemoHeader("Custom Rendering", DemoCustomRendering); | ||
| DemoHeader("Show Input Mapping", ShowInputMapping); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where to put this? I put it here for now and this will affect all the plots. Open to moving/changing this
| float delta = ImGui::IsMouseDown(ImGuiMouseButton_Middle) ? (-0.01f * IO.MouseDelta.y) : (-0.1f * IO.MouseWheel); | ||
| const bool middle_mouse_button_down = ImGui::IsMouseDown(ImGuiMouseButton_Middle); | ||
| if (middle_mouse_button_down || IO.MouseWheel != 0.0f) { | ||
| float delta = middle_mouse_button_down ? (-0.01f * IO.MouseDelta.y) : (-gp.InputMap.ZoomRate * IO.MouseWheel); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When middle_mouse_button_down  is true should the delta be a function of the ZoomRate? Maybe (-gp.InputMap.ZoomRate * IO.MouseDelta.y / 10.0f) instead of (-0.01f * IO.MouseDelta.y)?
Can always create a new variable specifically just for zoom rate with button press(MouseDelta.y) which is separate from the ZoomRate(MouseWheel) ?
Closes #97
Added Input Map support for #97 . @brenocq if you get a chance can you maybe take a look and let me know if I am going in the right direction.
This is not done yet and requires some more work:
ImGuiMouseButton_Middlebutton. Should still work like before where theImGuiMouseButton_Middledoes what it did previously so that it can be used to reset the plotOverrideModaffects. InImPlotit comes after theFitThisFrameandHoveredwhich is what I tried replicating