From e5e76d784e0016d2c6c1cddd71f6f47993a3dc17 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sun, 22 Aug 2021 03:52:28 -0400 Subject: [PATCH] [client] egl: allow postprocessing filters to be reordered by dragging --- client/renderers/EGL/postprocess.c | 38 ++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/client/renderers/EGL/postprocess.c b/client/renderers/EGL/postprocess.c index 7c7712fc..3c91807f 100644 --- a/client/renderers/EGL/postprocess.c +++ b/client/renderers/EGL/postprocess.c @@ -57,14 +57,44 @@ static void configUI(void * opaque, int * id) struct EGL_PostProcess * this = opaque; bool redraw = false; + size_t moveIdx = 0; - EGL_Filter * filter; - vector_forEach(filter, this->filters) + float lastBegin = 0.0f; + ImVec2 window; + igGetWindowPos(&window); + + EGL_Filter ** filters = vector_data(this->filters); + size_t count = vector_size(this->filters); + for (size_t i = 0; i < count; ++i) { - igPushIDInt(++*id); - if (igCollapsingHeaderBoolPtr(filter->ops.name, NULL, 0)) + EGL_Filter * filter = filters[i]; + float begin = igGetCursorPosY(); + + igPushIDPtr(filter); + bool draw = igCollapsingHeaderBoolPtr(filter->ops.name, NULL, 0); + bool active = igIsItemActive(); + if (draw) redraw |= egl_filterImguiConfig(filter); igPopID(); + + if (active && igIsMouseDragging(ImGuiMouseButton_Left, -1.0f)) + { + ImVec2 pos; + igGetMousePos(&pos); + if (i > 0 && pos.y - window.y < (lastBegin + begin) / 2.0f) + moveIdx = i; + else if (i + 1 < count && pos.y - window.y > igGetCursorPosY()) + moveIdx = i + 1; + } + + lastBegin = begin; + } + + if (moveIdx) + { + EGL_Filter * tmp = filters[moveIdx]; + filters[moveIdx] = filters[moveIdx - 1]; + filters[moveIdx - 1] = tmp; } if (redraw)