MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / DragPoint

Function DragPoint

Source/3rdParty/implot/implot.cpp:3966–4013  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3964constexpr float DRAG_GRAB_HALF_SIZE = 4.0f;
3965
3966bool DragPoint(int n_id, double* x, double* y, const ImVec4& col, float radius, ImPlotDragToolFlags flags, bool* out_clicked, bool* out_hovered, bool* out_held) {
3967 ImGui::PushID("#IMPLOT_DRAG_POINT");
3968 IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != nullptr, "DragPoint() needs to be called between BeginPlot() and EndPlot()!");
3969 SetupLock();
3970
3971 if (!ImHasFlag(flags,ImPlotDragToolFlags_NoFit) && FitThisFrame()) {
3972 FitPoint(ImPlotPoint(*x,*y));
3973 }
3974
3975 const bool input = !ImHasFlag(flags, ImPlotDragToolFlags_NoInputs);
3976 const bool show_curs = !ImHasFlag(flags, ImPlotDragToolFlags_NoCursors);
3977 const bool no_delay = !ImHasFlag(flags, ImPlotDragToolFlags_Delayed);
3978 const float grab_half_size = ImMax(DRAG_GRAB_HALF_SIZE, radius);
3979 const ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col;
3980 const ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color);
3981
3982 ImVec2 pos = PlotToPixels(*x,*y,IMPLOT_AUTO,IMPLOT_AUTO);
3983 const ImGuiID id = ImGui::GetCurrentWindow()->GetID(n_id);
3984 ImRect rect(pos.x-grab_half_size,pos.y-grab_half_size,pos.x+grab_half_size,pos.y+grab_half_size);
3985 bool hovered = false, held = false;
3986
3987 ImGui::KeepAliveID(id);
3988 if (input) {
3989 bool clicked = ImGui::ButtonBehavior(rect,id,&hovered,&held);
3990 if (out_clicked) *out_clicked = clicked;
3991 if (out_hovered) *out_hovered = hovered;
3992 if (out_held) *out_held = held;
3993 }
3994
3995 bool modified = false;
3996 if (held && ImGui::IsMouseDragging(0)) {
3997 *x = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).x;
3998 *y = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).y;
3999 modified = true;
4000 }
4001
4002 PushPlotClipRect();
4003 ImDrawList& DrawList = *GetPlotDrawList();
4004 if ((hovered || held) && show_curs)
4005 ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
4006 if (modified && no_delay)
4007 pos = PlotToPixels(*x,*y,IMPLOT_AUTO,IMPLOT_AUTO);
4008 DrawList.AddCircleFilled(pos, radius, col32);
4009 PopPlotClipRect();
4010
4011 ImGui::PopID();
4012 return modified;
4013}
4014
4015bool DragLineX(int n_id, double* value, const ImVec4& col, float thickness, ImPlotDragToolFlags flags, bool* out_clicked, bool* out_hovered, bool* out_held) {
4016 // ImGui::PushID("#IMPLOT_DRAG_LINE_X");

Callers 1

Demo_DragPointsFunction · 0.85

Calls 15

PushIDFunction · 0.85
SetupLockFunction · 0.85
ImHasFlagFunction · 0.85
FitThisFrameFunction · 0.85
FitPointFunction · 0.85
ImMaxFunction · 0.85
IsColorAutoFunction · 0.85
GetStyleColorVec4Function · 0.85
PlotToPixelsFunction · 0.85
GetCurrentWindowFunction · 0.85
GetPlotMousePosFunction · 0.85
PushPlotClipRectFunction · 0.85

Tested by

no test coverage detected