mirror of
https://github.com/gwm17/implot.git
synced 2024-11-23 02:38:53 -05:00
clean up and debug input mappings
This commit is contained in:
parent
676ea011b8
commit
c6ad6e9c7f
66
implot.cpp
66
implot.cpp
|
@ -134,29 +134,20 @@ bool ImPlotLimits::Contains(double x, double y) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImPlotInputMap::ImPlotInputMap() {
|
ImPlotInputMap::ImPlotInputMap() {
|
||||||
|
|
||||||
PanButton = ImGuiMouseButton_Left;
|
PanButton = ImGuiMouseButton_Left;
|
||||||
PanMod = ImGuiKeyModFlags_None;
|
PanMod = ImGuiKeyModFlags_None;
|
||||||
|
FitButton = ImGuiMouseButton_Left;
|
||||||
|
ContextMenuButton = ImGuiMouseButton_Right;
|
||||||
BoxSelectButton = ImGuiMouseButton_Right;
|
BoxSelectButton = ImGuiMouseButton_Right;
|
||||||
BoxSelectMod = ImGuiKeyModFlags_None;
|
BoxSelectMod = ImGuiKeyModFlags_None;
|
||||||
|
BoxSelectCancelButton = ImGuiMouseButton_Left;
|
||||||
BoxCancelButton = ImGuiMouseButton_Left;
|
QueryButton = ImGuiMouseButton_Middle;
|
||||||
|
QueryMod = ImGuiKeyModFlags_None;
|
||||||
QueryClickButton = ImGuiMouseButton_Left;
|
QueryToggleMod = ImGuiKeyModFlags_Ctrl;
|
||||||
QueryClickMod = ImGuiKeyModFlags_Ctrl;
|
HorizontalMod = ImGuiKeyModFlags_Alt;
|
||||||
|
VerticalMod = ImGuiKeyModFlags_Shift;
|
||||||
QueryDragButton = ImGuiMouseButton_Middle;
|
|
||||||
QueryDragMod = ImGuiKeyModFlags_None;
|
|
||||||
|
|
||||||
QueryDragButton2 = ImGuiMouseButton_Right;
|
|
||||||
QueryDragMod2 = ImGuiKeyModFlags_Ctrl;
|
|
||||||
|
|
||||||
HorizontalSizeMod = ImGuiKeyModFlags_Alt;
|
|
||||||
VerticalSizeMod = ImGuiKeyModFlags_Shift;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace ImPlot {
|
namespace ImPlot {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -1155,7 +1146,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// start drag
|
// start drag
|
||||||
if (!drag_in_progress && gp.Hov_Frame && IO.MouseClicked[gp.InputMap.PanButton] && IO.KeyMods == gp.InputMap.PanMod && !plot.Selecting && !hov_legend && !hov_query && !plot.DraggingQuery) {
|
if (!drag_in_progress && gp.Hov_Frame && IO.MouseClicked[gp.InputMap.PanButton] && HasFlag(IO.KeyMods, gp.InputMap.PanMod) && !plot.Selecting && !hov_legend && !hov_query && !plot.DraggingQuery) {
|
||||||
if (hov_x_axis_region) {
|
if (hov_x_axis_region) {
|
||||||
plot.XAxis.Dragging = true;
|
plot.XAxis.Dragging = true;
|
||||||
}
|
}
|
||||||
|
@ -1207,16 +1198,16 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
||||||
if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && ImFabs(select_size.x) > 2 && ImFabs(select_size.y) > 2) {
|
if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && ImFabs(select_size.x) > 2 && ImFabs(select_size.y) > 2) {
|
||||||
ImPlotPoint p1 = PixelsToPlot(plot.SelectStart);
|
ImPlotPoint p1 = PixelsToPlot(plot.SelectStart);
|
||||||
ImPlotPoint p2 = PixelsToPlot(IO.MousePos);
|
ImPlotPoint p2 = PixelsToPlot(IO.MousePos);
|
||||||
if (!gp.X.LockMin && IO.KeyMods != gp.InputMap.HorizontalSizeMod)
|
if (!gp.X.LockMin && IO.KeyMods != gp.InputMap.HorizontalMod)
|
||||||
plot.XAxis.Range.Min = ImMin(p1.x, p2.x);
|
plot.XAxis.Range.Min = ImMin(p1.x, p2.x);
|
||||||
if (!gp.X.LockMax && IO.KeyMods != gp.InputMap.HorizontalSizeMod)
|
if (!gp.X.LockMax && IO.KeyMods != gp.InputMap.HorizontalMod)
|
||||||
plot.XAxis.Range.Max = ImMax(p1.x, p2.x);
|
plot.XAxis.Range.Max = ImMax(p1.x, p2.x);
|
||||||
for (int i = 0; i < MAX_Y_AXES; i++) {
|
for (int i = 0; i < MAX_Y_AXES; i++) {
|
||||||
p1 = PixelsToPlot(plot.SelectStart, i);
|
p1 = PixelsToPlot(plot.SelectStart, i);
|
||||||
p2 = PixelsToPlot(IO.MousePos, i);
|
p2 = PixelsToPlot(IO.MousePos, i);
|
||||||
if (!gp.Y[i].LockMin && IO.KeyMods != gp.InputMap.VerticalSizeMod)
|
if (!gp.Y[i].LockMin && IO.KeyMods != gp.InputMap.VerticalMod)
|
||||||
plot.YAxis[i].Range.Min = ImMin(p1.y, p2.y);
|
plot.YAxis[i].Range.Min = ImMin(p1.y, p2.y);
|
||||||
if (!gp.Y[i].LockMax && IO.KeyMods != gp.InputMap.VerticalSizeMod)
|
if (!gp.Y[i].LockMax && IO.KeyMods != gp.InputMap.VerticalMod)
|
||||||
plot.YAxis[i].Range.Max = ImMax(p1.y, p2.y);
|
plot.YAxis[i].Range.Max = ImMax(p1.y, p2.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1227,27 +1218,27 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
||||||
ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed);
|
ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed);
|
||||||
}
|
}
|
||||||
// cancel selection
|
// cancel selection
|
||||||
if (plot.Selecting && (IO.MouseClicked[gp.InputMap.BoxCancelButton] || IO.MouseDown[gp.InputMap.BoxCancelButton])) {
|
if (plot.Selecting && (IO.MouseClicked[gp.InputMap.BoxSelectCancelButton] || IO.MouseDown[gp.InputMap.BoxSelectCancelButton])) {
|
||||||
plot.Selecting = false;
|
plot.Selecting = false;
|
||||||
}
|
}
|
||||||
// begin selection or query
|
// begin selection or query
|
||||||
if (gp.Hov_Frame && gp.Hov_Plot && IO.MouseClicked[gp.InputMap.BoxSelectButton] && IO.KeyMods == gp.InputMap.BoxSelectMod) {
|
if (gp.Hov_Frame && gp.Hov_Plot && IO.MouseClicked[gp.InputMap.BoxSelectButton] && HasFlag(IO.KeyMods, gp.InputMap.BoxSelectMod)) {
|
||||||
plot.SelectStart = IO.MousePos;
|
plot.SelectStart = IO.MousePos;
|
||||||
plot.Selecting = true;
|
plot.Selecting = true;
|
||||||
}
|
}
|
||||||
// update query
|
// update query
|
||||||
if (plot.Querying) {
|
if (plot.Querying) {
|
||||||
UpdateTransformCache();
|
UpdateTransformCache();
|
||||||
plot.QueryRect.Min.x = IO.KeyMods == gp.InputMap.HorizontalSizeMod ? gp.BB_Plot.Min.x : ImMin(plot.QueryStart.x, IO.MousePos.x);
|
plot.QueryRect.Min.x = HasFlag(IO.KeyMods, gp.InputMap.HorizontalMod) ? gp.BB_Plot.Min.x : ImMin(plot.QueryStart.x, IO.MousePos.x);
|
||||||
plot.QueryRect.Max.x = IO.KeyMods == gp.InputMap.HorizontalSizeMod ? gp.BB_Plot.Max.x : ImMax(plot.QueryStart.x, IO.MousePos.x);
|
plot.QueryRect.Max.x = HasFlag(IO.KeyMods, gp.InputMap.HorizontalMod) ? gp.BB_Plot.Max.x : ImMax(plot.QueryStart.x, IO.MousePos.x);
|
||||||
plot.QueryRect.Min.y = IO.KeyMods == gp.InputMap.HorizontalSizeMod ? gp.BB_Plot.Min.y : ImMin(plot.QueryStart.y, IO.MousePos.y);
|
plot.QueryRect.Min.y = HasFlag(IO.KeyMods, gp.InputMap.VerticalMod) ? gp.BB_Plot.Min.y : ImMin(plot.QueryStart.y, IO.MousePos.y);
|
||||||
plot.QueryRect.Max.y = IO.KeyMods == gp.InputMap.HorizontalSizeMod ? gp.BB_Plot.Max.y : ImMax(plot.QueryStart.y, IO.MousePos.y);
|
plot.QueryRect.Max.y = HasFlag(IO.KeyMods, gp.InputMap.VerticalMod) ? gp.BB_Plot.Max.y : ImMax(plot.QueryStart.y, IO.MousePos.y);
|
||||||
|
|
||||||
plot.QueryRect.Min -= gp.BB_Plot.Min;
|
plot.QueryRect.Min -= gp.BB_Plot.Min;
|
||||||
plot.QueryRect.Max -= gp.BB_Plot.Min;
|
plot.QueryRect.Max -= gp.BB_Plot.Min;
|
||||||
}
|
}
|
||||||
// end query
|
// end query
|
||||||
if (plot.Querying && (IO.MouseReleased[2] || IO.MouseReleased[1])) {
|
if (plot.Querying && (IO.MouseReleased[gp.InputMap.QueryButton] || IO.MouseReleased[gp.InputMap.BoxSelectButton])) {
|
||||||
plot.Querying = false;
|
plot.Querying = false;
|
||||||
if (plot.QueryRect.GetWidth() > 2 && plot.QueryRect.GetHeight() > 2) {
|
if (plot.QueryRect.GetWidth() > 2 && plot.QueryRect.GetHeight() > 2) {
|
||||||
plot.Queried = true;
|
plot.Queried = true;
|
||||||
|
@ -1257,27 +1248,22 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool isSelectInput = IO.MouseDown[gp.InputMap.BoxSelectButton] && IO.KeyMods == gp.InputMap.BoxSelectButton;
|
|
||||||
const bool isQueryInput = (IO.MouseDown[gp.InputMap.QueryDragButton] && IO.KeyMods == gp.InputMap.QueryDragMod) || (IO.MouseDown[gp.InputMap.QueryDragButton2] && IO.KeyMods == gp.InputMap.QueryDragMod2);
|
|
||||||
const bool isQueryInputBegin = (IO.MouseClicked[gp.InputMap.QueryDragButton] && IO.KeyMods == gp.InputMap.QueryDragMod) || (IO.MouseClicked[gp.InputMap.QueryDragButton2] && IO.KeyMods == gp.InputMap.QueryDragMod2);
|
|
||||||
|
|
||||||
|
|
||||||
// begin query
|
// begin query
|
||||||
if (HasFlag(plot.Flags, ImPlotFlags_Query) && (gp.Hov_Frame && gp.Hov_Plot && isQueryInputBegin)) {
|
if (HasFlag(plot.Flags, ImPlotFlags_Query) && gp.Hov_Frame && gp.Hov_Plot && IO.MouseClicked[gp.InputMap.QueryButton] && HasFlag(IO.KeyMods, gp.InputMap.QueryMod)) {
|
||||||
plot.QueryRect = ImRect(0,0,0,0);
|
plot.QueryRect = ImRect(0,0,0,0);
|
||||||
plot.Querying = true;
|
plot.Querying = true;
|
||||||
plot.Queried = true;
|
plot.Queried = true;
|
||||||
plot.QueryStart = IO.MousePos;
|
plot.QueryStart = IO.MousePos;
|
||||||
}
|
}
|
||||||
// toggle between select/query
|
// toggle between select/query
|
||||||
if (HasFlag(plot.Flags, ImPlotFlags_Query) && plot.Selecting && isQueryInput) {
|
if (HasFlag(plot.Flags, ImPlotFlags_Query) && plot.Selecting && HasFlag(IO.KeyMods,gp.InputMap.QueryToggleMod)) {
|
||||||
plot.Selecting = false;
|
plot.Selecting = false;
|
||||||
plot.QueryRect = ImRect(0,0,0,0);
|
plot.QueryRect = ImRect(0,0,0,0);
|
||||||
plot.Querying = true;
|
plot.Querying = true;
|
||||||
plot.Queried = true;
|
plot.Queried = true;
|
||||||
plot.QueryStart = plot.SelectStart;
|
plot.QueryStart = plot.SelectStart;
|
||||||
}
|
}
|
||||||
if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && plot.Querying && isSelectInput) {
|
if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && plot.Querying && !HasFlag(IO.KeyMods, gp.InputMap.QueryToggleMod) && !IO.MouseDown[gp.InputMap.QueryButton]) {
|
||||||
plot.Selecting = true;
|
plot.Selecting = true;
|
||||||
plot.Querying = false;
|
plot.Querying = false;
|
||||||
plot.Queried = false;
|
plot.Queried = false;
|
||||||
|
@ -1286,7 +1272,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
||||||
|
|
||||||
// DOUBLE CLICK -----------------------------------------------------------
|
// DOUBLE CLICK -----------------------------------------------------------
|
||||||
|
|
||||||
if ( IO.MouseDoubleClicked[0] && gp.Hov_Frame && (hov_x_axis_region || any_hov_y_axis_region) && !hov_legend && !hov_query) {
|
if ( IO.MouseDoubleClicked[gp.InputMap.FitButton] && gp.Hov_Frame && (hov_x_axis_region || any_hov_y_axis_region) && !hov_legend && !hov_query) {
|
||||||
gp.FitThisFrame = true;
|
gp.FitThisFrame = true;
|
||||||
gp.FitX = hov_x_axis_region;
|
gp.FitX = hov_x_axis_region;
|
||||||
for (int i = 0; i < MAX_Y_AXES; i++) {
|
for (int i = 0; i < MAX_Y_AXES; i++) {
|
||||||
|
@ -1304,7 +1290,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
||||||
// FOCUS ------------------------------------------------------------------
|
// FOCUS ------------------------------------------------------------------
|
||||||
|
|
||||||
// focus window
|
// focus window
|
||||||
if ((IO.MouseClicked[0] || IO.MouseClicked[1]) && gp.Hov_Frame)
|
if ((IO.MouseClicked[0] || IO.MouseClicked[1] || IO.MouseClicked[2]) && gp.Hov_Frame)
|
||||||
ImGui::FocusWindow(ImGui::GetCurrentWindow());
|
ImGui::FocusWindow(ImGui::GetCurrentWindow());
|
||||||
|
|
||||||
UpdateTransformCache();
|
UpdateTransformCache();
|
||||||
|
@ -1797,7 +1783,7 @@ void EndPlot() {
|
||||||
|
|
||||||
// CONTEXT MENU -----------------------------------------------------------
|
// CONTEXT MENU -----------------------------------------------------------
|
||||||
|
|
||||||
if (HasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && gp.Hov_Plot && IO.MouseDoubleClicked[1] && !hov_legend)
|
if (HasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && gp.Hov_Plot && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend)
|
||||||
ImGui::OpenPopup("##Context");
|
ImGui::OpenPopup("##Context");
|
||||||
if (ImGui::BeginPopup("##Context")) {
|
if (ImGui::BeginPopup("##Context")) {
|
||||||
PlotContextMenu(plot);
|
PlotContextMenu(plot);
|
||||||
|
|
33
implot.h
33
implot.h
|
@ -174,28 +174,19 @@ struct ImPlotStyle {
|
||||||
|
|
||||||
// Input mapping structure, default values listed in the comments.
|
// Input mapping structure, default values listed in the comments.
|
||||||
struct ImPlotInputMap {
|
struct ImPlotInputMap {
|
||||||
|
ImGuiMouseButton PanButton; // LMB enables panning when held
|
||||||
|
ImGuiKeyModFlags PanMod; // none optional modifier that must be held for panning
|
||||||
|
ImGuiMouseButton FitButton; // LMB fits visible data when double clicked
|
||||||
|
ImGuiMouseButton ContextMenuButton; // RMB opens plot context menu (if enabled) when double clicked
|
||||||
|
ImGuiMouseButton BoxSelectButton; // RMB begins box selection when pressed and confirms selection when released
|
||||||
|
ImGuiKeyModFlags BoxSelectMod; // none optional modifier that must be held for box selection
|
||||||
|
ImGuiMouseButton BoxSelectCancelButton; // LMB cancels active box selection when pressed
|
||||||
|
ImGuiMouseButton QueryButton; // MMB begins query selection when pressed and end query selection when released
|
||||||
|
ImGuiKeyModFlags QueryMod; // none optional modifier that must be held for query selection
|
||||||
|
ImGuiKeyModFlags QueryToggleMod; // Ctrl when held, active box selections turn into queries
|
||||||
|
ImGuiKeyModFlags HorizontalMod; // Alt expands active box selection/query horizontally to plot edge when held
|
||||||
|
ImGuiKeyModFlags VerticalMod; // Shift expands active box selection/query vertically to plot edge when held
|
||||||
ImPlotInputMap();
|
ImPlotInputMap();
|
||||||
|
|
||||||
ImGuiMouseButton PanButton; // left mouse
|
|
||||||
ImGuiKeyModFlags PanMod; // none
|
|
||||||
|
|
||||||
ImGuiMouseButton BoxSelectButton; // right mouse
|
|
||||||
ImGuiKeyModFlags BoxSelectMod; // none
|
|
||||||
|
|
||||||
ImGuiMouseButton BoxCancelButton; // left mouse
|
|
||||||
|
|
||||||
ImGuiMouseButton QueryClickButton; // left mouse
|
|
||||||
ImGuiKeyModFlags QueryClickMod; // ctrl
|
|
||||||
|
|
||||||
ImGuiMouseButton QueryDragButton; // middle mouse
|
|
||||||
ImGuiKeyModFlags QueryDragMod; // none
|
|
||||||
|
|
||||||
ImGuiMouseButton QueryDragButton2; // right mouse, alternative way to query drag, useful when middle mouse is not available
|
|
||||||
ImGuiKeyModFlags QueryDragMod2; // ctrl
|
|
||||||
|
|
||||||
ImGuiKeyModFlags HorizontalSizeMod; // alt
|
|
||||||
ImGuiKeyModFlags VerticalSizeMod; // shift
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user