[client] egl: implement nicer drag & drop re-ordering of filters

This commit is contained in:
Geoffrey McRae 2021-08-24 22:05:46 +10:00
parent e5e76d784e
commit b118c3b681

View File

@ -52,49 +52,91 @@ void egl_postProcessEarlyInit(void)
EGL_Filters[i]->earlyInit(); EGL_Filters[i]->earlyInit();
} }
static void drawDropTarget(void)
{
igPushStyleColorVec4(ImGuiCol_Separator, (ImVec4) { 1.0f, 1.0f, 0.0f, 1.0f });
igSeparator();
igPopStyleColor(1);
}
static void configUI(void * opaque, int * id) static void configUI(void * opaque, int * id)
{ {
struct EGL_PostProcess * this = opaque; struct EGL_PostProcess * this = opaque;
bool redraw = false; bool redraw = false;
size_t moveIdx = 0;
float lastBegin = 0.0f; static size_t mouseIdx = -1;
ImVec2 window; static bool moving = false;
static size_t moveIdx = 0;
bool doMove = false;
ImVec2 window, pos;
igGetWindowPos(&window); igGetWindowPos(&window);
igGetMousePos(&pos);
EGL_Filter ** filters = vector_data(this->filters); EGL_Filter ** filters = vector_data(this->filters);
size_t count = vector_size(this->filters); size_t count = vector_size(this->filters);
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
EGL_Filter * filter = filters[i]; EGL_Filter * filter = filters[i];
float begin = igGetCursorPosY();
if (moving && mouseIdx < moveIdx && i == mouseIdx)
drawDropTarget();
igPushIDPtr(filter); igPushIDPtr(filter);
bool draw = igCollapsingHeaderBoolPtr(filter->ops.name, NULL, 0); bool draw = igCollapsingHeaderBoolPtr(filter->ops.name, NULL, 0);
if (igIsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
mouseIdx = i;
bool active = igIsItemActive(); bool active = igIsItemActive();
if (draw) if (draw)
redraw |= egl_filterImguiConfig(filter); redraw |= egl_filterImguiConfig(filter);
igPopID(); igPopID();
if (active && igIsMouseDragging(ImGuiMouseButton_Left, -1.0f)) if (moving)
{ {
ImVec2 pos; if (!igIsMouseDragging(ImGuiMouseButton_Left, -1.0f))
igGetMousePos(&pos); {
if (i > 0 && pos.y - window.y < (lastBegin + begin) / 2.0f) moving = false;
moveIdx = i; doMove = true;
else if (i + 1 < count && pos.y - window.y > igGetCursorPosY()) }
moveIdx = i + 1;
} }
else
if (active && igIsMouseDragging(ImGuiMouseButton_Left, -1.0f))
{
moveIdx = mouseIdx;
moving = true;
}
lastBegin = begin; if (moving && mouseIdx > moveIdx && i == mouseIdx)
drawDropTarget();
} }
if (moveIdx) if (moving)
{ {
EGL_Filter * tmp = filters[moveIdx]; igSetMouseCursor(ImGuiMouseCursor_Hand);
filters[moveIdx] = filters[moveIdx - 1]; igSetTooltip(filters[moveIdx]->ops.name);
filters[moveIdx - 1] = tmp; }
if (doMove)
{
EGL_Filter * tmp[count];
memcpy(tmp, filters, sizeof(*tmp) * count);
size_t s = 0, d = 0;
for(size_t i = 0; i < count; ++i)
{
if (i == mouseIdx)
{
filters[d++] = tmp[moveIdx];
continue;
}
if (s == moveIdx)
++s;
filters[d++] = tmp[s++];
}
} }
if (redraw) if (redraw)