#include "my_imgui_internal_widgets.h" #include "imgui.h" #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif #include "imgui_internal.h" // A modded version of ScalarSlider allowing for the minimum and maximum parts // of the slider to be draggable by two other buttons. p_data is from range -1 // to 1, and s_min and max are from 0-1. #if 0 // bool ImGui::SliderLevels(const char* label, ImGuiDataType data_type, void* v, int components, const void* v_min, const void* v_max, const char* format, ImGuiSliderFlags flags) bool ImGui::SliderLevels(const char* label, void* p_data, const void* s_min, const void* s_max) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; const float MidMin = -1; const float MidMax = 1; const void* mid_min = &SliderMin; const void* mid_max = &SliderMax; ImGuiDataType data_type = ImGuiDataType_Float; const char *format = "%f"; ImVec2 picker_pos = window->DC.CursorPos; ImGuiContext& g = *GImGui; bool value_changed = false; BeginGroup(); PushID(label); value_changed |= SliderScalar("", data_type, p_data, mid_min, mid_max, format, ImGuiSliderFlags_Logarithmic); SetCursorScreenPos(ImVec2(picker_pos.x + 20.0f, picker_pos.y)); // PushItemWidth(); value_changed |= SliderScalar("", data_type, p_data, p_min, p_max, format, ImGuiSliderFlags_Logarithmic); // PushMultiItemsWidths(components, CalcItemWidth()); // size_t type_size = GDataTypeInfo[data_type].Size; // for (int i = 0; i < components; i++) // { // PushID(i); // if (i > 0) // SameLine(0, g.Style.ItemInnerSpacing.x); // value_changed |= SliderScalar("", data_type, v, v_min, v_max, format, flags); // PopID(); // PopItemWidth(); // v = (void*)((char*)v + type_size); // } PopID(); EndGroup(); return value_changed; } bool ImGui::SliderLevels(const char* label, void* p_data, void* s_left, void* s_right) { ImGuiSliderFlags flags = ImGuiSliderFlags_NoInput; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; const float SliderMin = -1; const float SliderMax = 1; const float OtherMin = 0; const float OtherMax = 1; const void* p_min = &SliderMin; const void* p_max = &SliderMax; const void* o_min = &OtherMin; const void* o_max = &OtherMax; ImGuiDataType data_type = ImGuiDataType_Float; const char *format = "%f"; ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); const ImGuiID id_mid = window->GetID("asdasbdsgd"); const ImGuiID id_L = window->GetID("ppasd"); const ImGuiID id_R = window->GetID("adsafb"); const float w = CalcItemWidth(); const ImVec2 label_size = CalcTextSize(label, NULL, true); const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f)); const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); // const bool temp_input_allowed = (flags & ImGuiSliderFlags_NoInput) == 0; // ItemSize(total_bb, style.FramePadding.y); // if (!ItemAdd(total_bb, id, &frame_bb, temp_input_allowed ? ImGuiItemFlags_Inputable : 0)) // return false; const bool hovered = ItemHoverable(frame_bb, id_L); // NOTE(fox): Making bogus calls here to get these positions so we can only activate the one we want - replace with the lower-level call. // const ImGuiID id_bogus = window->GetID("ppp"); // ImRect test_left; // SliderBehavior(frame_bb, id_bogus, data_type, s_left, o_min, o_max, format, ImGuiSliderFlags_NoInput, &test_left); // ImRect test_right; // SliderBehavior(frame_bb, id_bogus, data_type, s_right, o_min, o_max, format, ImGuiSliderFlags_NoInput, &test_right); const bool input_requested_by_tabbing = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; const bool clicked = (hovered && g.IO.MouseClicked[0]); const bool make_active = (input_requested_by_tabbing || clicked || g.NavActivateId == id_L || g.NavActivateInputId == id_L); if (make_active) { SetActiveID(id_L, window); SetFocusID(id_L, window); FocusWindow(window); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); } /* else if (make_active && g.IO.MousePos.x > test_right.Min.x) { SetActiveID(id_R, window); SetFocusID(id_R, window); FocusWindow(window); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); } else if (make_active) { SetActiveID(id_mid, window); SetFocusID(id_mid, window); FocusWindow(window); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); } */ // Draw frame const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); RenderNavHighlight(frame_bb, id); RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, g.Style.FrameRounding); // Slider behavior ImRect L_grab_bb; const bool value_changed = SliderBehavior(frame_bb, id_L, data_type, s_left, o_min, o_max, format, ImGuiSliderFlags_NoInput, &L_grab_bb); if (value_changed) MarkItemEdited(id_L); // Render grab if (L_grab_bb.Max.x > L_grab_bb.Min.x) window->DrawList->AddRectFilled(L_grab_bb.Min, L_grab_bb.Max, GetColorU32(g.ActiveId == id_L ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); #if 0 // Slider behavior ImRect R_grab_bb; const bool value_changed2 = SliderBehavior(frame_bb, id_R, data_type, s_right, o_min, o_max, format, ImGuiSliderFlags_NoInput, &R_grab_bb); if (value_changed2) MarkItemEdited(id_R); // Render grab if (R_grab_bb.Max.x > R_grab_bb.Min.x) window->DrawList->AddRectFilled(R_grab_bb.Min, R_grab_bb.Max, GetColorU32(g.ActiveId == id_R ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); const ImRect range_bb(ImVec2(L_grab_bb.Min.x, frame_bb.Min.y), ImVec2(R_grab_bb.Min.x, frame_bb.Max.y)); // Slider behavior ImRect grab_bb_mid; const bool value_changed_mid = SliderBehavior(range_bb, id_mid, data_type, p_data, p_min, p_max, format, flags | ImGuiSliderFlags_Logarithmic, &grab_bb_mid); // if (value_changed2) // MarkItemEdited(id_bogus); ImVec2 asda = ImVec2(0, 5); // // Render grab if (grab_bb_mid.Max.x > grab_bb_mid.Min.x) window->DrawList->AddRectFilled(grab_bb_mid.Min + asda, grab_bb_mid.Max + asda, GetColorU32(g.ActiveId == id_bogus ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); #endif // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. char value_buf[64]; const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, p_data, format); if (g.LogEnabled) LogSetNextTextDecoration("{", "}"); RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f)); if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); return value_changed; } #else bool ImGui::SliderLevels(const char* label, void* p_mid, void* p_left, void* p_right) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; const float SliderMin = -1; const float SliderMax = 1; const float OtherMin = 0; const float OtherMax = 1; const void* p_min = &SliderMin; const void* p_max = &SliderMax; const void* o_min = &OtherMin; const void* o_max = &OtherMax; ImGuiDataType data_type = ImGuiDataType_Float; const char *format = "%f"; ImGuiSliderFlags flags = ImGuiSliderFlags_NoInput; ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); const ImGuiID idnull = window->GetID("asdas"); const ImGuiID id_mid = window->GetID("asdasbdsgd"); const ImGuiID id_L = window->GetID("ppasd"); const ImGuiID id_R = window->GetID("adsafb"); const float w = CalcItemWidth(); const ImVec2 label_size = CalcTextSize(label, NULL, true); const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f)); const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); ImRect test_L_bb; SliderBehavior(frame_bb, idnull, data_type, p_left, o_min, o_max, format, flags, &test_L_bb); ImRect test_R_bb; SliderBehavior(frame_bb, idnull, data_type, p_right, o_min, o_max, format, flags, &test_R_bb); ItemSize(total_bb, style.FramePadding.y); if (!ItemAdd(total_bb, id_L, &frame_bb, 0)) return false; if (!ItemAdd(total_bb, id_R, &frame_bb, 0)) return false; if (!ItemAdd(total_bb, id_mid, &frame_bb, 0)) return false; const bool hovered = ItemHoverable(frame_bb, id); const bool input_requested_by_tabbing = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; const bool clicked = (hovered && g.IO.MouseClicked[0]); const bool make_active = (input_requested_by_tabbing || clicked || g.NavActivateId == id || g.NavActivateInputId == id); if (make_active) { if (g.IO.MousePos.x < test_L_bb.Max.x) { SetActiveID(id_L, window); SetFocusID(id_L, window); } else if (g.IO.MousePos.x > test_R_bb.Min.x) { SetActiveID(id_R, window); SetFocusID(id_R, window); } else { SetActiveID(id_mid, window); SetFocusID(id_mid, window); } FocusWindow(window); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); } // Draw frame const ImU32 frame_col = GetColorU32(g.ActiveId == id_L ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); RenderNavHighlight(frame_bb, id_L); RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, g.Style.FrameRounding); // Slider behavior ImRect grab_bb; const bool value_changed = SliderBehavior(frame_bb, id_L, data_type, p_left, o_min, o_max, format, flags, &grab_bb); if (value_changed) MarkItemEdited(id_L); // Render grab if (grab_bb.Max.x > grab_bb.Min.x) window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, GetColorU32(g.ActiveId == id_L ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); // Slider behavior ImRect grab_bb2; const bool value_changed2 = SliderBehavior(frame_bb, id_R, data_type, p_right, o_min, o_max, format, flags, &grab_bb2); if (value_changed2) MarkItemEdited(id_R); // Render grab if (grab_bb2.Max.x > grab_bb2.Min.x) window->DrawList->AddRectFilled(grab_bb2.Min, grab_bb2.Max, GetColorU32(g.ActiveId == id_R ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); const ImRect mid_bb(ImVec2(grab_bb.Max.x, frame_bb.Min.y), ImVec2(grab_bb2.Min.x, frame_bb.Max.y)); // Slider behavior ImRect grab_bb3; const bool value_changed3 = SliderBehavior(mid_bb, id_mid, data_type, p_mid, p_min, p_max, format, flags, &grab_bb3); if (value_changed3) MarkItemEdited(id_mid); // Render grab if (grab_bb3.Max.x > grab_bb3.Min.x) window->DrawList->AddRectFilled(grab_bb3.Min, grab_bb3.Max, GetColorU32(g.ActiveId == id_mid ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. char value_buf[64]; const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, p_left, format); if (g.LogEnabled) LogSetNextTextDecoration("{", "}"); RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f)); if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); return value_changed; } #endif