mirror of
https://github.com/gwm17/implot.git
synced 2025-01-31 03:18:51 -05:00
Merge branch 'work-input-remap' of https://github.com/JaapSuter/implot into JaapSuter-work-input-remap
This commit is contained in:
commit
676ea011b8
73
implot.cpp
73
implot.cpp
|
@ -133,6 +133,30 @@ bool ImPlotLimits::Contains(double x, double y) const {
|
|||
return X.Contains(x) && Y.Contains(y);
|
||||
}
|
||||
|
||||
ImPlotInputMap::ImPlotInputMap() {
|
||||
|
||||
PanButton = ImGuiMouseButton_Left;
|
||||
PanMod = ImGuiKeyModFlags_None;
|
||||
|
||||
BoxSelectButton = ImGuiMouseButton_Right;
|
||||
BoxSelectMod = ImGuiKeyModFlags_None;
|
||||
|
||||
BoxCancelButton = ImGuiMouseButton_Left;
|
||||
|
||||
QueryClickButton = ImGuiMouseButton_Left;
|
||||
QueryClickMod = ImGuiKeyModFlags_Ctrl;
|
||||
|
||||
QueryDragButton = ImGuiMouseButton_Middle;
|
||||
QueryDragMod = ImGuiKeyModFlags_None;
|
||||
|
||||
QueryDragButton2 = ImGuiMouseButton_Right;
|
||||
QueryDragMod2 = ImGuiKeyModFlags_Ctrl;
|
||||
|
||||
HorizontalSizeMod = ImGuiKeyModFlags_Alt;
|
||||
VerticalSizeMod = ImGuiKeyModFlags_Shift;
|
||||
}
|
||||
|
||||
|
||||
namespace ImPlot {
|
||||
|
||||
namespace {
|
||||
|
@ -495,6 +519,7 @@ struct ImPlotContext {
|
|||
ImVec4* Colormap;
|
||||
int ColormapSize;
|
||||
ImPlotStyle Style;
|
||||
ImPlotInputMap InputMap;
|
||||
ImVector<ImGuiColorMod> ColorModifiers; // Stack for PushStyleColor()/PopStyleColor()
|
||||
ImVector<ImGuiStyleMod> StyleModifiers; // Stack for PushStyleVar()/PopStyleVar()
|
||||
ImPlotNextPlotData NextPlotData;
|
||||
|
@ -510,6 +535,10 @@ static ImPlotContext gp;
|
|||
// Context Utils
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ImPlotInputMap& GetInputMap() {
|
||||
return gp.InputMap;
|
||||
}
|
||||
|
||||
// Returns the next unused default plot color
|
||||
ImVec4 NextColor() {
|
||||
ImVec4 col = gp.Colormap[gp.CurrentPlot->ColorIdx % gp.ColormapSize];
|
||||
|
@ -1045,7 +1074,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
}
|
||||
|
||||
// QUERY DRAG -------------------------------------------------------------
|
||||
if (plot.DraggingQuery && (IO.MouseReleased[0] || !IO.MouseDown[0])) {
|
||||
if (plot.DraggingQuery && (IO.MouseReleased[gp.InputMap.PanButton] || !IO.MouseDown[gp.InputMap.PanButton])) {
|
||||
plot.DraggingQuery = false;
|
||||
}
|
||||
if (plot.DraggingQuery) {
|
||||
|
@ -1056,7 +1085,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
if (gp.Hov_Frame && gp.Hov_Plot && hov_query && !plot.DraggingQuery && !plot.Selecting && !hov_legend) {
|
||||
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll);
|
||||
const bool any_y_dragging = plot.YAxis[0].Dragging || plot.YAxis[1].Dragging || plot.YAxis[2].Dragging;
|
||||
if (IO.MouseDown[0] && !plot.XAxis.Dragging && !any_y_dragging) {
|
||||
if (IO.MouseDown[gp.InputMap.PanButton] && !plot.XAxis.Dragging && !any_y_dragging) {
|
||||
plot.DraggingQuery = true;
|
||||
}
|
||||
}
|
||||
|
@ -1064,12 +1093,12 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
// DRAG INPUT -------------------------------------------------------------
|
||||
|
||||
// end drags
|
||||
if (plot.XAxis.Dragging && (IO.MouseReleased[0] || !IO.MouseDown[0])) {
|
||||
if (plot.XAxis.Dragging && (IO.MouseReleased[gp.InputMap.PanButton] || !IO.MouseDown[gp.InputMap.PanButton])) {
|
||||
plot.XAxis.Dragging = false;
|
||||
G.IO.MouseDragMaxDistanceSqr[0] = 0;
|
||||
}
|
||||
for (int i = 0; i < MAX_Y_AXES; i++) {
|
||||
if (plot.YAxis[i].Dragging && (IO.MouseReleased[0] || !IO.MouseDown[0])) {
|
||||
if (plot.YAxis[i].Dragging && (IO.MouseReleased[gp.InputMap.PanButton] || !IO.MouseDown[gp.InputMap.PanButton])) {
|
||||
plot.YAxis[i].Dragging = false;
|
||||
G.IO.MouseDragMaxDistanceSqr[0] = 0;
|
||||
}
|
||||
|
@ -1126,7 +1155,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
}
|
||||
}
|
||||
// start drag
|
||||
if (!drag_in_progress && gp.Hov_Frame && IO.MouseClicked[0] && !plot.Selecting && !hov_legend && !hov_query && !plot.DraggingQuery) {
|
||||
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 (hov_x_axis_region) {
|
||||
plot.XAxis.Dragging = true;
|
||||
}
|
||||
|
@ -1172,22 +1201,22 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
// BOX-SELECTION AND QUERY ------------------------------------------------
|
||||
|
||||
// confirm selection
|
||||
if (plot.Selecting && (IO.MouseReleased[1] || !IO.MouseDown[1])) {
|
||||
if (plot.Selecting && (IO.MouseReleased[gp.InputMap.BoxSelectButton] || !IO.MouseDown[gp.InputMap.BoxSelectButton])) {
|
||||
UpdateTransformCache();
|
||||
ImVec2 select_size = plot.SelectStart - IO.MousePos;
|
||||
if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && ImFabs(select_size.x) > 2 && ImFabs(select_size.y) > 2) {
|
||||
ImPlotPoint p1 = PixelsToPlot(plot.SelectStart);
|
||||
ImPlotPoint p2 = PixelsToPlot(IO.MousePos);
|
||||
if (!gp.X.LockMin && !IO.KeyAlt)
|
||||
if (!gp.X.LockMin && IO.KeyMods != gp.InputMap.HorizontalSizeMod)
|
||||
plot.XAxis.Range.Min = ImMin(p1.x, p2.x);
|
||||
if (!gp.X.LockMax && !IO.KeyAlt)
|
||||
if (!gp.X.LockMax && IO.KeyMods != gp.InputMap.HorizontalSizeMod)
|
||||
plot.XAxis.Range.Max = ImMax(p1.x, p2.x);
|
||||
for (int i = 0; i < MAX_Y_AXES; i++) {
|
||||
p1 = PixelsToPlot(plot.SelectStart, i);
|
||||
p2 = PixelsToPlot(IO.MousePos, i);
|
||||
if (!gp.Y[i].LockMin && !IO.KeyShift)
|
||||
if (!gp.Y[i].LockMin && IO.KeyMods != gp.InputMap.VerticalSizeMod)
|
||||
plot.YAxis[i].Range.Min = ImMin(p1.y, p2.y);
|
||||
if (!gp.Y[i].LockMax && !IO.KeyShift)
|
||||
if (!gp.Y[i].LockMax && IO.KeyMods != gp.InputMap.VerticalSizeMod)
|
||||
plot.YAxis[i].Range.Max = ImMax(p1.y, p2.y);
|
||||
}
|
||||
}
|
||||
|
@ -1198,21 +1227,21 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed);
|
||||
}
|
||||
// cancel selection
|
||||
if (plot.Selecting && (IO.MouseClicked[0] || IO.MouseDown[0])) {
|
||||
if (plot.Selecting && (IO.MouseClicked[gp.InputMap.BoxCancelButton] || IO.MouseDown[gp.InputMap.BoxCancelButton])) {
|
||||
plot.Selecting = false;
|
||||
}
|
||||
// begin selection or query
|
||||
if (gp.Hov_Frame && gp.Hov_Plot && IO.MouseClicked[1]) {
|
||||
if (gp.Hov_Frame && gp.Hov_Plot && IO.MouseClicked[gp.InputMap.BoxSelectButton] && IO.KeyMods == gp.InputMap.BoxSelectMod) {
|
||||
plot.SelectStart = IO.MousePos;
|
||||
plot.Selecting = true;
|
||||
}
|
||||
// update query
|
||||
if (plot.Querying) {
|
||||
UpdateTransformCache();
|
||||
plot.QueryRect.Min.x = IO.KeyAlt ? gp.BB_Plot.Min.x : ImMin(plot.QueryStart.x, IO.MousePos.x);
|
||||
plot.QueryRect.Max.x = IO.KeyAlt ? gp.BB_Plot.Max.x : ImMax(plot.QueryStart.x, IO.MousePos.x);
|
||||
plot.QueryRect.Min.y = IO.KeyShift ? gp.BB_Plot.Min.y : ImMin(plot.QueryStart.y, IO.MousePos.y);
|
||||
plot.QueryRect.Max.y = IO.KeyShift ? gp.BB_Plot.Max.y : ImMax(plot.QueryStart.y, IO.MousePos.y);
|
||||
plot.QueryRect.Min.x = IO.KeyMods == gp.InputMap.HorizontalSizeMod ? 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.Min.y = IO.KeyMods == gp.InputMap.HorizontalSizeMod ? 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.Min -= gp.BB_Plot.Min;
|
||||
plot.QueryRect.Max -= gp.BB_Plot.Min;
|
||||
|
@ -1227,22 +1256,28 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
plot.Queried = false;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
if (HasFlag(plot.Flags, ImPlotFlags_Query) && (gp.Hov_Frame && gp.Hov_Plot && IO.MouseClicked[2])) {
|
||||
if (HasFlag(plot.Flags, ImPlotFlags_Query) && (gp.Hov_Frame && gp.Hov_Plot && isQueryInputBegin)) {
|
||||
plot.QueryRect = ImRect(0,0,0,0);
|
||||
plot.Querying = true;
|
||||
plot.Queried = true;
|
||||
plot.QueryStart = IO.MousePos;
|
||||
}
|
||||
// toggle between select/query
|
||||
if (HasFlag(plot.Flags, ImPlotFlags_Query) && plot.Selecting && IO.KeyCtrl) {
|
||||
if (HasFlag(plot.Flags, ImPlotFlags_Query) && plot.Selecting && isQueryInput) {
|
||||
plot.Selecting = false;
|
||||
plot.QueryRect = ImRect(0,0,0,0);
|
||||
plot.Querying = true;
|
||||
plot.Queried = true;
|
||||
plot.QueryStart = plot.SelectStart;
|
||||
}
|
||||
if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && plot.Querying && !IO.KeyCtrl && !IO.MouseDown[2]) {
|
||||
if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && plot.Querying && isSelectInput) {
|
||||
plot.Selecting = true;
|
||||
plot.Querying = false;
|
||||
plot.Queried = false;
|
||||
|
|
35
implot.h
35
implot.h
|
@ -172,6 +172,32 @@ struct ImPlotStyle {
|
|||
ImPlotStyle();
|
||||
};
|
||||
|
||||
// Input mapping structure, default values listed in the comments.
|
||||
struct 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
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Begin/End Plot
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -283,7 +309,14 @@ bool IsPlotQueried();
|
|||
ImPlotLimits GetPlotQuery(int y_axis = -1);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Plot Styling
|
||||
// Plot Input Mapping
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Allows changing how keyboard/mouse interaction works.
|
||||
ImPlotInputMap& GetInputMap();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Plot Styling and Behaviour
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Provides access to plot style structure for permanant modifications to colors, sizes, etc.
|
||||
|
|
Loading…
Reference in New Issue
Block a user