Вопрос Не работает колорпикер

B.O.M.J
Эксперт
Статус
Оффлайн
Регистрация
19 Май 2017
Сообщения
2,403
Реакции[?]
897
Поинты[?]
3K
имгуи все дела
вот код колор пикера
C#:
bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const float square_sz = GetFrameHeight();
    const float w_full = CalcItemWidth();
    const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x);
    const float w_inputs = w_full - w_button;
    const char* label_display_end = FindRenderedTextEnd(label);
    g.NextItemData.ClearFlags();

    BeginGroup();
    PushID(label);

    // If we're not showing any slider there's no point in doing any HSV conversions
    const ImGuiColorEditFlags flags_untouched = flags;
    if (flags & ImGuiColorEditFlags_NoInputs)
        flags = (flags & (~ImGuiColorEditFlags__DisplayMask)) | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoOptions;

    // Context menu: display and modify options (before defaults are applied)
    if (!(flags & ImGuiColorEditFlags_NoOptions))
        ColorEditOptionsPopup(col, flags);

    // Read stored options
    if (!(flags & ImGuiColorEditFlags__DisplayMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DisplayMask);
    if (!(flags & ImGuiColorEditFlags__DataTypeMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DataTypeMask);
    if (!(flags & ImGuiColorEditFlags__PickerMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__PickerMask);
    if (!(flags & ImGuiColorEditFlags__InputMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__InputMask);
    flags |= (g.ColorEditOptions & ~(ImGuiColorEditFlags__DisplayMask | ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask));
    IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags__DisplayMask)); // Check that only 1 is selected
    IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags__InputMask));   // Check that only 1 is selected

    const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0;
    const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0;
    const int components = alpha ? 4 : 3;

    // Convert to the formats we need
    float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f };
    if ((flags & ImGuiColorEditFlags_InputHSV) && (flags & ImGuiColorEditFlags_DisplayRGB))
        ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
    else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV))
    {
        // Hue is lost when converting from greyscale rgb (saturation=0). Restore it.
        ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);
        if (memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0)
        {
            if (f[1] == 0)
                f[0] = g.ColorEditLastHue;
            if (f[2] == 0)
                f[1] = g.ColorEditLastSat;
        }
    }
    int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) };

    bool value_changed = false;
    bool value_changed_as_float = false;

    const ImVec2 pos = window->DC.CursorPos;
    const float inputs_offset_x = (style.ColorButtonPosition == ImGuiDir_Left) ? w_button : 0.0f;
    window->DC.CursorPos.x = pos.x + inputs_offset_x;

    static std::map<ImGuiID, colorpicket_state> open_animation;
    auto it_open = open_animation.find(GetCurrentWindow()->GetID(label));
    if (it_open == open_animation.end())
    {
        open_animation.insert({ GetCurrentWindow()->GetID(label), {false, 0.f} });
        it_open = open_animation.find(GetCurrentWindow()->GetID(label));
    }
    it_open->second.mult = std::clamp(it_open->second.mult + 0.03f + (it_open->second.mult * 0.03f) * GetIO().DeltaTime * (it_open->second.play ? 1.f : -1.f), 0.01f, 1.f);
    if (!it_open->second.play)
        it_open->second.mult = 0.01f;

    ImGuiWindow* picker_active_window = NULL;
    if (!(flags & ImGuiColorEditFlags_NoSmallPreview))
    {
        const float button_offset_x = ((flags & ImGuiColorEditFlags_NoInputs) || (style.ColorButtonPosition == ImGuiDir_Left)) ? 0.0f : w_inputs + style.ItemInnerSpacing.x;
        window->DC.CursorPos = ImVec2(pos.x + button_offset_x, pos.y);

        const ImVec4 col_v4(col[0], col[1], col[2], alpha ? col[3] : 1.0f);
        SetCursorPosX(window->Size.x - 25);
        if (ColorButton("##ColorButton", col_v4, flags))
        {
            if (!(flags & ImGuiColorEditFlags_NoPicker))
            {
                it_open->second.play = true;
                // Store current color and open a picker
                g.ColorPickerRef = col_v4;
                OpenPopup("picker");
                SetNextWindowPos(window->DC.LastItemRect.GetBL() + ImVec2(-6, style.ItemSpacing.y - 2));
            }
        }
        if (!(flags & ImGuiColorEditFlags_NoOptions))
            OpenPopupOnItemClick("context");
        PushStyleVar(ImGuiStyleVar_Alpha, it_open->second.mult);
        PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_PopupBorderSize, 0);
        PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_PopupRounding, 4);
        PushStyleColor(ImGuiCol_PopupBg, ImVec4(41 / 255.f, 40 / 255.f, 46 / 255.f, it_open->second.mult * 0.8f));
        if (BeginPopup("picker", ImGuiWindowFlags_NoMove))
        {
            picker_active_window = g.CurrentWindow;
            ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
            ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags__DisplayMask | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
            SetNextItemWidth(min(it_open->second.mult * 3.2, 1.f) * square_sz * 12.0f); // Use 256 + bar sizes?
            value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x);
            EndPopup();
        }
        else
            it_open->second.play = false;
        PopStyleVar(3);
        PopStyleColor();
    }

    if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel))
    {
        window->DC.CursorPos = ImVec2(pos.x + w_button, pos.y + style.FramePadding.y);
        SetCursorPosX(10);
        TextEx(label, label_display_end);
    }

    // Convert back
    if (value_changed && picker_active_window == NULL)
    {
        if (!value_changed_as_float)
            for (int n = 0; n < 4; n++)
                f[n] = i[n] / 255.0f;
        if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB))
        {
            g.ColorEditLastHue = f[0];
            g.ColorEditLastSat = f[1];
            ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
            memcpy(g.ColorEditLastColor, f, sizeof(float) * 3);
        }
        if ((flags & ImGuiColorEditFlags_DisplayRGB) && (flags & ImGuiColorEditFlags_InputHSV))
            ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);

        col[0] = f[0];
        col[1] = f[1];
        col[2] = f[2];
        if (alpha)
            col[3] = f[3];
    }

    PopID();
    EndGroup();

    // Drag and Drop Target
    // NB: The flag test is merely an optional micro-optimization, BeginDragDropTarget() does the same test.
    if ((window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) && !(flags & ImGuiColorEditFlags_NoDragDrop) && BeginDragDropTarget())
    {
        bool accepted_drag_drop = false;
        if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
        {
            memcpy((float*)col, payload->Data, sizeof(float) * 3); // Preserve alpha if any //-V512
            value_changed = accepted_drag_drop = true;
        }
        if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
        {
            memcpy((float*)col, payload->Data, sizeof(float) * components);
            value_changed = accepted_drag_drop = true;
        }

        // Drag-drop payloads are always RGB
        if (accepted_drag_drop && (flags & ImGuiColorEditFlags_InputHSV))
            ColorConvertRGBtoHSV(col[0], col[1], col[2], col[0], col[1], col[2]);
        EndDragDropTarget();
    }

    // When picker is being actively used, use its active id so IsItemActive() will function on ColorEdit4().
    if (picker_active_window && g.ActiveId != 0 && g.ActiveIdWindow == picker_active_window)
        window->DC.LastItemId = g.ActiveId;

    if (value_changed)
        MarkItemEdited(window->DC.LastItemId);

    return value_changed;
}
Вот так происходит преобразование колора в float
Код:
bool c_menu::color_edit(const char* label, Color* color)
{
    float fcolor[4] =
    {
        color->r() / 255.0f,
        color->g() / 255.0f,
        color->b() / 255.0f,
        color->a() / 255.0f
    };


    if (ImGui::ColorEdit4(label, fcolor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_RGB)) {
        color->SetColor(fcolor[0], fcolor[1], fcolor[2], fcolor[3]);
        return true;
    }
    return false;
}
собственно говоря проблема
 
Забаненный
Статус
Оффлайн
Регистрация
22 Апр 2020
Сообщения
731
Реакции[?]
752
Поинты[?]
1K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
имгуи все дела
вот код колор пикера
C#:
bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const float square_sz = GetFrameHeight();
    const float w_full = CalcItemWidth();
    const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x);
    const float w_inputs = w_full - w_button;
    const char* label_display_end = FindRenderedTextEnd(label);
    g.NextItemData.ClearFlags();

    BeginGroup();
    PushID(label);

    // If we're not showing any slider there's no point in doing any HSV conversions
    const ImGuiColorEditFlags flags_untouched = flags;
    if (flags & ImGuiColorEditFlags_NoInputs)
        flags = (flags & (~ImGuiColorEditFlags__DisplayMask)) | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoOptions;

    // Context menu: display and modify options (before defaults are applied)
    if (!(flags & ImGuiColorEditFlags_NoOptions))
        ColorEditOptionsPopup(col, flags);

    // Read stored options
    if (!(flags & ImGuiColorEditFlags__DisplayMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DisplayMask);
    if (!(flags & ImGuiColorEditFlags__DataTypeMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DataTypeMask);
    if (!(flags & ImGuiColorEditFlags__PickerMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__PickerMask);
    if (!(flags & ImGuiColorEditFlags__InputMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__InputMask);
    flags |= (g.ColorEditOptions & ~(ImGuiColorEditFlags__DisplayMask | ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask));
    IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags__DisplayMask)); // Check that only 1 is selected
    IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags__InputMask));   // Check that only 1 is selected

    const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0;
    const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0;
    const int components = alpha ? 4 : 3;

    // Convert to the formats we need
    float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f };
    if ((flags & ImGuiColorEditFlags_InputHSV) && (flags & ImGuiColorEditFlags_DisplayRGB))
        ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
    else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV))
    {
        // Hue is lost when converting from greyscale rgb (saturation=0). Restore it.
        ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);
        if (memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0)
        {
            if (f[1] == 0)
                f[0] = g.ColorEditLastHue;
            if (f[2] == 0)
                f[1] = g.ColorEditLastSat;
        }
    }
    int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) };

    bool value_changed = false;
    bool value_changed_as_float = false;

    const ImVec2 pos = window->DC.CursorPos;
    const float inputs_offset_x = (style.ColorButtonPosition == ImGuiDir_Left) ? w_button : 0.0f;
    window->DC.CursorPos.x = pos.x + inputs_offset_x;

    static std::map<ImGuiID, colorpicket_state> open_animation;
    auto it_open = open_animation.find(GetCurrentWindow()->GetID(label));
    if (it_open == open_animation.end())
    {
        open_animation.insert({ GetCurrentWindow()->GetID(label), {false, 0.f} });
        it_open = open_animation.find(GetCurrentWindow()->GetID(label));
    }
    it_open->second.mult = std::clamp(it_open->second.mult + 0.03f + (it_open->second.mult * 0.03f) * GetIO().DeltaTime * (it_open->second.play ? 1.f : -1.f), 0.01f, 1.f);
    if (!it_open->second.play)
        it_open->second.mult = 0.01f;

    ImGuiWindow* picker_active_window = NULL;
    if (!(flags & ImGuiColorEditFlags_NoSmallPreview))
    {
        const float button_offset_x = ((flags & ImGuiColorEditFlags_NoInputs) || (style.ColorButtonPosition == ImGuiDir_Left)) ? 0.0f : w_inputs + style.ItemInnerSpacing.x;
        window->DC.CursorPos = ImVec2(pos.x + button_offset_x, pos.y);

        const ImVec4 col_v4(col[0], col[1], col[2], alpha ? col[3] : 1.0f);
        SetCursorPosX(window->Size.x - 25);
        if (ColorButton("##ColorButton", col_v4, flags))
        {
            if (!(flags & ImGuiColorEditFlags_NoPicker))
            {
                it_open->second.play = true;
                // Store current color and open a picker
                g.ColorPickerRef = col_v4;
                OpenPopup("picker");
                SetNextWindowPos(window->DC.LastItemRect.GetBL() + ImVec2(-6, style.ItemSpacing.y - 2));
            }
        }
        if (!(flags & ImGuiColorEditFlags_NoOptions))
            OpenPopupOnItemClick("context");
        PushStyleVar(ImGuiStyleVar_Alpha, it_open->second.mult);
        PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_PopupBorderSize, 0);
        PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_PopupRounding, 4);
        PushStyleColor(ImGuiCol_PopupBg, ImVec4(41 / 255.f, 40 / 255.f, 46 / 255.f, it_open->second.mult * 0.8f));
        if (BeginPopup("picker", ImGuiWindowFlags_NoMove))
        {
            picker_active_window = g.CurrentWindow;
            ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
            ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags__DisplayMask | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
            SetNextItemWidth(min(it_open->second.mult * 3.2, 1.f) * square_sz * 12.0f); // Use 256 + bar sizes?
            value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x);
            EndPopup();
        }
        else
            it_open->second.play = false;
        PopStyleVar(3);
        PopStyleColor();
    }

    if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel))
    {
        window->DC.CursorPos = ImVec2(pos.x + w_button, pos.y + style.FramePadding.y);
        SetCursorPosX(10);
        TextEx(label, label_display_end);
    }

    // Convert back
    if (value_changed && picker_active_window == NULL)
    {
        if (!value_changed_as_float)
            for (int n = 0; n < 4; n++)
                f[n] = i[n] / 255.0f;
        if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB))
        {
            g.ColorEditLastHue = f[0];
            g.ColorEditLastSat = f[1];
            ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
            memcpy(g.ColorEditLastColor, f, sizeof(float) * 3);
        }
        if ((flags & ImGuiColorEditFlags_DisplayRGB) && (flags & ImGuiColorEditFlags_InputHSV))
            ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);

        col[0] = f[0];
        col[1] = f[1];
        col[2] = f[2];
        if (alpha)
            col[3] = f[3];
    }

    PopID();
    EndGroup();

    // Drag and Drop Target
    // NB: The flag test is merely an optional micro-optimization, BeginDragDropTarget() does the same test.
    if ((window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) && !(flags & ImGuiColorEditFlags_NoDragDrop) && BeginDragDropTarget())
    {
        bool accepted_drag_drop = false;
        if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
        {
            memcpy((float*)col, payload->Data, sizeof(float) * 3); // Preserve alpha if any //-V512
            value_changed = accepted_drag_drop = true;
        }
        if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
        {
            memcpy((float*)col, payload->Data, sizeof(float) * components);
            value_changed = accepted_drag_drop = true;
        }

        // Drag-drop payloads are always RGB
        if (accepted_drag_drop && (flags & ImGuiColorEditFlags_InputHSV))
            ColorConvertRGBtoHSV(col[0], col[1], col[2], col[0], col[1], col[2]);
        EndDragDropTarget();
    }

    // When picker is being actively used, use its active id so IsItemActive() will function on ColorEdit4().
    if (picker_active_window && g.ActiveId != 0 && g.ActiveIdWindow == picker_active_window)
        window->DC.LastItemId = g.ActiveId;

    if (value_changed)
        MarkItemEdited(window->DC.LastItemId);

    return value_changed;
}
Вот так происходит преобразование колора в float
Код:
bool c_menu::color_edit(const char* label, Color* color)
{
    float fcolor[4] =
    {
        color->r() / 255.0f,
        color->g() / 255.0f,
        color->b() / 255.0f,
        color->a() / 255.0f
    };


    if (ImGui::ColorEdit4(label, fcolor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_RGB)) {
        color->SetColor(fcolor[0], fcolor[1], fcolor[2], fcolor[3]);
        return true;
    }
    return false;
}
собственно говоря проблема
Трайни значение в static поставить
 
std::X$$V::Z::_Func_impl_no_alloc
Пользователь
Статус
Оффлайн
Регистрация
30 Мар 2019
Сообщения
389
Реакции[?]
103
Поинты[?]
1K
имгуи все дела
вот код колор пикера
C#:
bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const float square_sz = GetFrameHeight();
    const float w_full = CalcItemWidth();
    const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x);
    const float w_inputs = w_full - w_button;
    const char* label_display_end = FindRenderedTextEnd(label);
    g.NextItemData.ClearFlags();

    BeginGroup();
    PushID(label);

    // If we're not showing any slider there's no point in doing any HSV conversions
    const ImGuiColorEditFlags flags_untouched = flags;
    if (flags & ImGuiColorEditFlags_NoInputs)
        flags = (flags & (~ImGuiColorEditFlags__DisplayMask)) | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoOptions;

    // Context menu: display and modify options (before defaults are applied)
    if (!(flags & ImGuiColorEditFlags_NoOptions))
        ColorEditOptionsPopup(col, flags);

    // Read stored options
    if (!(flags & ImGuiColorEditFlags__DisplayMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DisplayMask);
    if (!(flags & ImGuiColorEditFlags__DataTypeMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DataTypeMask);
    if (!(flags & ImGuiColorEditFlags__PickerMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__PickerMask);
    if (!(flags & ImGuiColorEditFlags__InputMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__InputMask);
    flags |= (g.ColorEditOptions & ~(ImGuiColorEditFlags__DisplayMask | ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask));
    IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags__DisplayMask)); // Check that only 1 is selected
    IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags__InputMask));   // Check that only 1 is selected

    const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0;
    const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0;
    const int components = alpha ? 4 : 3;

    // Convert to the formats we need
    float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f };
    if ((flags & ImGuiColorEditFlags_InputHSV) && (flags & ImGuiColorEditFlags_DisplayRGB))
        ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
    else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV))
    {
        // Hue is lost when converting from greyscale rgb (saturation=0). Restore it.
        ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);
        if (memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0)
        {
            if (f[1] == 0)
                f[0] = g.ColorEditLastHue;
            if (f[2] == 0)
                f[1] = g.ColorEditLastSat;
        }
    }
    int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) };

    bool value_changed = false;
    bool value_changed_as_float = false;

    const ImVec2 pos = window->DC.CursorPos;
    const float inputs_offset_x = (style.ColorButtonPosition == ImGuiDir_Left) ? w_button : 0.0f;
    window->DC.CursorPos.x = pos.x + inputs_offset_x;

    static std::map<ImGuiID, colorpicket_state> open_animation;
    auto it_open = open_animation.find(GetCurrentWindow()->GetID(label));
    if (it_open == open_animation.end())
    {
        open_animation.insert({ GetCurrentWindow()->GetID(label), {false, 0.f} });
        it_open = open_animation.find(GetCurrentWindow()->GetID(label));
    }
    it_open->second.mult = std::clamp(it_open->second.mult + 0.03f + (it_open->second.mult * 0.03f) * GetIO().DeltaTime * (it_open->second.play ? 1.f : -1.f), 0.01f, 1.f);
    if (!it_open->second.play)
        it_open->second.mult = 0.01f;

    ImGuiWindow* picker_active_window = NULL;
    if (!(flags & ImGuiColorEditFlags_NoSmallPreview))
    {
        const float button_offset_x = ((flags & ImGuiColorEditFlags_NoInputs) || (style.ColorButtonPosition == ImGuiDir_Left)) ? 0.0f : w_inputs + style.ItemInnerSpacing.x;
        window->DC.CursorPos = ImVec2(pos.x + button_offset_x, pos.y);

        const ImVec4 col_v4(col[0], col[1], col[2], alpha ? col[3] : 1.0f);
        SetCursorPosX(window->Size.x - 25);
        if (ColorButton("##ColorButton", col_v4, flags))
        {
            if (!(flags & ImGuiColorEditFlags_NoPicker))
            {
                it_open->second.play = true;
                // Store current color and open a picker
                g.ColorPickerRef = col_v4;
                OpenPopup("picker");
                SetNextWindowPos(window->DC.LastItemRect.GetBL() + ImVec2(-6, style.ItemSpacing.y - 2));
            }
        }
        if (!(flags & ImGuiColorEditFlags_NoOptions))
            OpenPopupOnItemClick("context");
        PushStyleVar(ImGuiStyleVar_Alpha, it_open->second.mult);
        PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_PopupBorderSize, 0);
        PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_PopupRounding, 4);
        PushStyleColor(ImGuiCol_PopupBg, ImVec4(41 / 255.f, 40 / 255.f, 46 / 255.f, it_open->second.mult * 0.8f));
        if (BeginPopup("picker", ImGuiWindowFlags_NoMove))
        {
            picker_active_window = g.CurrentWindow;
            ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
            ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags__DisplayMask | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
            SetNextItemWidth(min(it_open->second.mult * 3.2, 1.f) * square_sz * 12.0f); // Use 256 + bar sizes?
            value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x);
            EndPopup();
        }
        else
            it_open->second.play = false;
        PopStyleVar(3);
        PopStyleColor();
    }

    if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel))
    {
        window->DC.CursorPos = ImVec2(pos.x + w_button, pos.y + style.FramePadding.y);
        SetCursorPosX(10);
        TextEx(label, label_display_end);
    }

    // Convert back
    if (value_changed && picker_active_window == NULL)
    {
        if (!value_changed_as_float)
            for (int n = 0; n < 4; n++)
                f[n] = i[n] / 255.0f;
        if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB))
        {
            g.ColorEditLastHue = f[0];
            g.ColorEditLastSat = f[1];
            ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
            memcpy(g.ColorEditLastColor, f, sizeof(float) * 3);
        }
        if ((flags & ImGuiColorEditFlags_DisplayRGB) && (flags & ImGuiColorEditFlags_InputHSV))
            ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);

        col[0] = f[0];
        col[1] = f[1];
        col[2] = f[2];
        if (alpha)
            col[3] = f[3];
    }

    PopID();
    EndGroup();

    // Drag and Drop Target
    // NB: The flag test is merely an optional micro-optimization, BeginDragDropTarget() does the same test.
    if ((window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) && !(flags & ImGuiColorEditFlags_NoDragDrop) && BeginDragDropTarget())
    {
        bool accepted_drag_drop = false;
        if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
        {
            memcpy((float*)col, payload->Data, sizeof(float) * 3); // Preserve alpha if any //-V512
            value_changed = accepted_drag_drop = true;
        }
        if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
        {
            memcpy((float*)col, payload->Data, sizeof(float) * components);
            value_changed = accepted_drag_drop = true;
        }

        // Drag-drop payloads are always RGB
        if (accepted_drag_drop && (flags & ImGuiColorEditFlags_InputHSV))
            ColorConvertRGBtoHSV(col[0], col[1], col[2], col[0], col[1], col[2]);
        EndDragDropTarget();
    }

    // When picker is being actively used, use its active id so IsItemActive() will function on ColorEdit4().
    if (picker_active_window && g.ActiveId != 0 && g.ActiveIdWindow == picker_active_window)
        window->DC.LastItemId = g.ActiveId;

    if (value_changed)
        MarkItemEdited(window->DC.LastItemId);

    return value_changed;
}
Вот так происходит преобразование колора в float
Код:
bool c_menu::color_edit(const char* label, Color* color)
{
    float fcolor[4] =
    {
        color->r() / 255.0f,
        color->g() / 255.0f,
        color->b() / 255.0f,
        color->a() / 255.0f
    };


    if (ImGui::ColorEdit4(label, fcolor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_RGB)) {
        color->SetColor(fcolor[0], fcolor[1], fcolor[2], fcolor[3]);
        return true;
    }
    return false;
}
собственно говоря проблема
Что за класс Color? Покажи что там внутри лежит
 
B.O.M.J
Эксперт
Статус
Оффлайн
Регистрация
19 Май 2017
Сообщения
2,403
Реакции[?]
897
Поинты[?]
3K
Что за класс Color? Покажи что там внутри лежит
.hpp
C++:
class Color
{
public:
    Color();
    Color(int _r, int _g, int _b);
    Color(int _r, int _g, int _b, int _a);
    Color(float _r, float _g, float _b) : Color(_r, _g, _b, 1.0f) {}
    Color(float _r, float _g, float _b, float _a)
        : Color(
            static_cast<int>(_r * 255.0f),
            static_cast<int>(_g * 255.0f),
            static_cast<int>(_b * 255.0f),
            static_cast<int>(_a * 255.0f))
    {
    }
    explicit Color(float* rgb) : Color(rgb[0], rgb[1], rgb[2], rgb[3]) {}
    explicit Color(unsigned long argb)
    {
        _CColor[2] = (unsigned char)((argb & 0x000000FF) >> (0 * 8));
        _CColor[1] = (unsigned char)((argb & 0x0000FF00) >> (1 * 8));
        _CColor[0] = (unsigned char)((argb & 0x00FF0000) >> (2 * 8));
        _CColor[3] = (unsigned char)((argb & 0xFF000000) >> (3 * 8));
    }

    void    SetRawColor(int color32);
    int     GetRawColor() const;
    void    SetColor(int _r, int _g, int _b, int _a = 0);
    void    SetColor(float _r, float _g, float _b, float _a = 0);
    void    GetColor(int& _r, int& _g, int& _b, int& _a) const;

    __forceinline uint32_t hex(bool rgba = false) const {
        return rgba
            ? ((r() & 0xFF) << 24) + ((g() & 0xFF) << 16) + ((b() & 0xFF) << 8) + (a() & 0xFF)
            : ((a() & 0xFF) << 24) + ((b() & 0xFF) << 16) + ((g() & 0xFF) << 8) + (r() & 0xFF);
    }

    int r() const { return _CColor[0]; }
    int g() const { return _CColor[1]; }
    int b() const { return _CColor[2]; }
    int a() const { return _CColor[3]; }

    unsigned char& operator[](int index)
    {
        return _CColor[index];
    }
    const unsigned char& operator[](int index) const
    {
        return _CColor[index];
    }

    bool operator==(const Color& rhs) const;
    bool operator!=(const Color& rhs) const;
    Color& operator=(const Color& rhs);

    static Color FromHSB(float hue, float saturation, float brightness)
    {
        float h = hue == 1.0f ? 0 : hue * 6.0f;
        float f = h - (int)h;
        float p = brightness * (1.0f - saturation);
        float q = brightness * (1.0f - saturation * f);
        float t = brightness * (1.0f - (saturation * (1.0f - f)));

        if (h < 1)
        {
            return Color(
                (unsigned char)(brightness * 255),
                (unsigned char)(t * 255),
                (unsigned char)(p * 255)
            );
        }
        else if (h < 2)
        {
            return Color(
                (unsigned char)(q * 255),
                (unsigned char)(brightness * 255),
                (unsigned char)(p * 255)
            );
        }
        else if (h < 3)
        {
            return Color(
                (unsigned char)(p * 255),
                (unsigned char)(brightness * 255),
                (unsigned char)(t * 255)
            );
        }
        else if (h < 4)
        {
            return Color(
                (unsigned char)(p * 255),
                (unsigned char)(q * 255),
                (unsigned char)(brightness * 255)
            );
        }
        else if (h < 5)
        {
            return Color(
                (unsigned char)(t * 255),
                (unsigned char)(p * 255),
                (unsigned char)(brightness * 255)
            );
        }
        else
        {
            return Color(
                (unsigned char)(brightness * 255),
                (unsigned char)(p * 255),
                (unsigned char)(q * 255)
            );
        }
    }

    static Color Black;
    static Color White;
    static Color Red;
    static Color Green;
    static Color Blue;

private:
    unsigned char _CColor[4];
};
cpp
C++:
#include "color.hpp"

Color Color::Black(0, 0, 0, 255);
Color Color::White(255, 255, 255, 255);
Color Color::Red(255, 0, 0, 255);
Color Color::Green(0, 128, 0, 255);
Color Color::Blue(0, 0, 255, 255);

Color::Color()
{
    *((int*)this) = 0;
}
Color::Color(int _r, int _g, int _b)
{
    SetColor(_r, _g, _b, 255);
}
Color::Color(int _r, int _g, int _b, int _a)
{
    SetColor(_r, _g, _b, _a);
}
void Color::SetRawColor(int color32)
{
    *((int*)this) = color32;
}
int Color::GetRawColor() const
{
    return *((int*)this);
}
void Color::SetColor(int _r, int _g, int _b, int _a)
{
    _CColor[0] = (unsigned char)_r;
    _CColor[1] = (unsigned char)_g;
    _CColor[2] = (unsigned char)_b;
    _CColor[3] = (unsigned char)_a;
}
void Color::SetColor(float _r, float _g, float _b, float _a)
{
    _CColor[0] = static_cast<unsigned char>(_r * 255.0f);
    _CColor[1] = static_cast<unsigned char>(_g * 255.0f);
    _CColor[2] = static_cast<unsigned char>(_b * 255.0f);
    _CColor[3] = static_cast<unsigned char>(_a * 255.0f);
}
void Color::GetColor(int& _r, int& _g, int& _b, int& _a) const
{
    _r = _CColor[0];
    _g = _CColor[1];
    _b = _CColor[2];
    _a = _CColor[3];
}
bool Color::operator== (const Color& rhs) const
{
    return (*((int*)this) == *((int*)&rhs));
}
bool Color::operator!= (const Color& rhs) const
{
    return !(operator==(rhs));
}
Color& Color::operator=(const Color& rhs)
{
    SetRawColor(rhs.GetRawColor());
    return *this;
}
 
Участник
Статус
Оффлайн
Регистрация
15 Янв 2021
Сообщения
492
Реакции[?]
289
Поинты[?]
79K
Замени
Color* color
на
Color&color

Я мб и забыл по поводу ссылок и указателей, но ведь * != &
 
std::X$$V::Z::_Func_impl_no_alloc
Пользователь
Статус
Оффлайн
Регистрация
30 Мар 2019
Сообщения
389
Реакции[?]
103
Поинты[?]
1K
.hpp
C++:
class Color
{
public:
    Color();
    Color(int _r, int _g, int _b);
    Color(int _r, int _g, int _b, int _a);
    Color(float _r, float _g, float _b) : Color(_r, _g, _b, 1.0f) {}
    Color(float _r, float _g, float _b, float _a)
        : Color(
            static_cast<int>(_r * 255.0f),
            static_cast<int>(_g * 255.0f),
            static_cast<int>(_b * 255.0f),
            static_cast<int>(_a * 255.0f))
    {
    }
    explicit Color(float* rgb) : Color(rgb[0], rgb[1], rgb[2], rgb[3]) {}
    explicit Color(unsigned long argb)
    {
        _CColor[2] = (unsigned char)((argb & 0x000000FF) >> (0 * 8));
        _CColor[1] = (unsigned char)((argb & 0x0000FF00) >> (1 * 8));
        _CColor[0] = (unsigned char)((argb & 0x00FF0000) >> (2 * 8));
        _CColor[3] = (unsigned char)((argb & 0xFF000000) >> (3 * 8));
    }

    void    SetRawColor(int color32);
    int     GetRawColor() const;
    void    SetColor(int _r, int _g, int _b, int _a = 0);
    void    SetColor(float _r, float _g, float _b, float _a = 0);
    void    GetColor(int& _r, int& _g, int& _b, int& _a) const;

    __forceinline uint32_t hex(bool rgba = false) const {
        return rgba
            ? ((r() & 0xFF) << 24) + ((g() & 0xFF) << 16) + ((b() & 0xFF) << 8) + (a() & 0xFF)
            : ((a() & 0xFF) << 24) + ((b() & 0xFF) << 16) + ((g() & 0xFF) << 8) + (r() & 0xFF);
    }

    int r() const { return _CColor[0]; }
    int g() const { return _CColor[1]; }
    int b() const { return _CColor[2]; }
    int a() const { return _CColor[3]; }

    unsigned char& operator[](int index)
    {
        return _CColor[index];
    }
    const unsigned char& operator[](int index) const
    {
        return _CColor[index];
    }

    bool operator==(const Color& rhs) const;
    bool operator!=(const Color& rhs) const;
    Color& operator=(const Color& rhs);

    static Color FromHSB(float hue, float saturation, float brightness)
    {
        float h = hue == 1.0f ? 0 : hue * 6.0f;
        float f = h - (int)h;
        float p = brightness * (1.0f - saturation);
        float q = brightness * (1.0f - saturation * f);
        float t = brightness * (1.0f - (saturation * (1.0f - f)));

        if (h < 1)
        {
            return Color(
                (unsigned char)(brightness * 255),
                (unsigned char)(t * 255),
                (unsigned char)(p * 255)
            );
        }
        else if (h < 2)
        {
            return Color(
                (unsigned char)(q * 255),
                (unsigned char)(brightness * 255),
                (unsigned char)(p * 255)
            );
        }
        else if (h < 3)
        {
            return Color(
                (unsigned char)(p * 255),
                (unsigned char)(brightness * 255),
                (unsigned char)(t * 255)
            );
        }
        else if (h < 4)
        {
            return Color(
                (unsigned char)(p * 255),
                (unsigned char)(q * 255),
                (unsigned char)(brightness * 255)
            );
        }
        else if (h < 5)
        {
            return Color(
                (unsigned char)(t * 255),
                (unsigned char)(p * 255),
                (unsigned char)(brightness * 255)
            );
        }
        else
        {
            return Color(
                (unsigned char)(brightness * 255),
                (unsigned char)(p * 255),
                (unsigned char)(q * 255)
            );
        }
    }

    static Color Black;
    static Color White;
    static Color Red;
    static Color Green;
    static Color Blue;

private:
    unsigned char _CColor[4];
};
cpp
C++:
#include "color.hpp"

Color Color::Black(0, 0, 0, 255);
Color Color::White(255, 255, 255, 255);
Color Color::Red(255, 0, 0, 255);
Color Color::Green(0, 128, 0, 255);
Color Color::Blue(0, 0, 255, 255);

Color::Color()
{
    *((int*)this) = 0;
}
Color::Color(int _r, int _g, int _b)
{
    SetColor(_r, _g, _b, 255);
}
Color::Color(int _r, int _g, int _b, int _a)
{
    SetColor(_r, _g, _b, _a);
}
void Color::SetRawColor(int color32)
{
    *((int*)this) = color32;
}
int Color::GetRawColor() const
{
    return *((int*)this);
}
void Color::SetColor(int _r, int _g, int _b, int _a)
{
    _CColor[0] = (unsigned char)_r;
    _CColor[1] = (unsigned char)_g;
    _CColor[2] = (unsigned char)_b;
    _CColor[3] = (unsigned char)_a;
}
void Color::SetColor(float _r, float _g, float _b, float _a)
{
    _CColor[0] = static_cast<unsigned char>(_r * 255.0f);
    _CColor[1] = static_cast<unsigned char>(_g * 255.0f);
    _CColor[2] = static_cast<unsigned char>(_b * 255.0f);
    _CColor[3] = static_cast<unsigned char>(_a * 255.0f);
}
void Color::GetColor(int& _r, int& _g, int& _b, int& _a) const
{
    _r = _CColor[0];
    _g = _CColor[1];
    _b = _CColor[2];
    _a = _CColor[3];
}
bool Color::operator== (const Color& rhs) const
{
    return (*((int*)this) == *((int*)&rhs));
}
bool Color::operator!= (const Color& rhs) const
{
    return !(operator==(rhs));
}
Color& Color::operator=(const Color& rhs)
{
    SetRawColor(rhs.GetRawColor());
    return *this;
}
Пожалуйста, авторизуйтесь для просмотра ссылки.
Если я правильно помню флаги в имгуи, то должно работать



Замени
Color* color
на
Color&color

Я мб и забыл по поводу ссылок и указателей, но ведь * != &
Ссылка это просто синтаксический сахар. Конечно в современных плюсах лучше использовать ссылки, но у него уже не современные плюсы, т.к он вместо стрингвью использует массив из символов
 
B.O.M.J
Эксперт
Статус
Оффлайн
Регистрация
19 Май 2017
Сообщения
2,403
Реакции[?]
897
Поинты[?]
3K
ладно пришлось как быдло вписывать колор как флоат а потом уже в функции его конвертировать
 
std::X$$V::Z::_Func_impl_no_alloc
Пользователь
Статус
Оффлайн
Регистрация
30 Мар 2019
Сообщения
389
Реакции[?]
103
Поинты[?]
1K
(\ /) _ ($ __ $ ) _ (\ /)
Пользователь
Статус
Оффлайн
Регистрация
22 Окт 2021
Сообщения
361
Реакции[?]
92
Поинты[?]
24K
имгуи все дела
вот код колор пикера
C#:
bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const float square_sz = GetFrameHeight();
    const float w_full = CalcItemWidth();
    const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x);
    const float w_inputs = w_full - w_button;
    const char* label_display_end = FindRenderedTextEnd(label);
    g.NextItemData.ClearFlags();

    BeginGroup();
    PushID(label);

    // If we're not showing any slider there's no point in doing any HSV conversions
    const ImGuiColorEditFlags flags_untouched = flags;
    if (flags & ImGuiColorEditFlags_NoInputs)
        flags = (flags & (~ImGuiColorEditFlags__DisplayMask)) | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoOptions;

    // Context menu: display and modify options (before defaults are applied)
    if (!(flags & ImGuiColorEditFlags_NoOptions))
        ColorEditOptionsPopup(col, flags);

    // Read stored options
    if (!(flags & ImGuiColorEditFlags__DisplayMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DisplayMask);
    if (!(flags & ImGuiColorEditFlags__DataTypeMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__DataTypeMask);
    if (!(flags & ImGuiColorEditFlags__PickerMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__PickerMask);
    if (!(flags & ImGuiColorEditFlags__InputMask))
        flags |= (g.ColorEditOptions & ImGuiColorEditFlags__InputMask);
    flags |= (g.ColorEditOptions & ~(ImGuiColorEditFlags__DisplayMask | ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask));
    IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags__DisplayMask)); // Check that only 1 is selected
    IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags__InputMask));   // Check that only 1 is selected

    const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0;
    const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0;
    const int components = alpha ? 4 : 3;

    // Convert to the formats we need
    float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f };
    if ((flags & ImGuiColorEditFlags_InputHSV) && (flags & ImGuiColorEditFlags_DisplayRGB))
        ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
    else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV))
    {
        // Hue is lost when converting from greyscale rgb (saturation=0). Restore it.
        ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);
        if (memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0)
        {
            if (f[1] == 0)
                f[0] = g.ColorEditLastHue;
            if (f[2] == 0)
                f[1] = g.ColorEditLastSat;
        }
    }
    int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) };

    bool value_changed = false;
    bool value_changed_as_float = false;

    const ImVec2 pos = window->DC.CursorPos;
    const float inputs_offset_x = (style.ColorButtonPosition == ImGuiDir_Left) ? w_button : 0.0f;
    window->DC.CursorPos.x = pos.x + inputs_offset_x;

    static std::map<ImGuiID, colorpicket_state> open_animation;
    auto it_open = open_animation.find(GetCurrentWindow()->GetID(label));
    if (it_open == open_animation.end())
    {
        open_animation.insert({ GetCurrentWindow()->GetID(label), {false, 0.f} });
        it_open = open_animation.find(GetCurrentWindow()->GetID(label));
    }
    it_open->second.mult = std::clamp(it_open->second.mult + 0.03f + (it_open->second.mult * 0.03f) * GetIO().DeltaTime * (it_open->second.play ? 1.f : -1.f), 0.01f, 1.f);
    if (!it_open->second.play)
        it_open->second.mult = 0.01f;

    ImGuiWindow* picker_active_window = NULL;
    if (!(flags & ImGuiColorEditFlags_NoSmallPreview))
    {
        const float button_offset_x = ((flags & ImGuiColorEditFlags_NoInputs) || (style.ColorButtonPosition == ImGuiDir_Left)) ? 0.0f : w_inputs + style.ItemInnerSpacing.x;
        window->DC.CursorPos = ImVec2(pos.x + button_offset_x, pos.y);

        const ImVec4 col_v4(col[0], col[1], col[2], alpha ? col[3] : 1.0f);
        SetCursorPosX(window->Size.x - 25);
        if (ColorButton("##ColorButton", col_v4, flags))
        {
            if (!(flags & ImGuiColorEditFlags_NoPicker))
            {
                it_open->second.play = true;
                // Store current color and open a picker
                g.ColorPickerRef = col_v4;
                OpenPopup("picker");
                SetNextWindowPos(window->DC.LastItemRect.GetBL() + ImVec2(-6, style.ItemSpacing.y - 2));
            }
        }
        if (!(flags & ImGuiColorEditFlags_NoOptions))
            OpenPopupOnItemClick("context");
        PushStyleVar(ImGuiStyleVar_Alpha, it_open->second.mult);
        PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_PopupBorderSize, 0);
        PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_PopupRounding, 4);
        PushStyleColor(ImGuiCol_PopupBg, ImVec4(41 / 255.f, 40 / 255.f, 46 / 255.f, it_open->second.mult * 0.8f));
        if (BeginPopup("picker", ImGuiWindowFlags_NoMove))
        {
            picker_active_window = g.CurrentWindow;
            ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
            ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags__DisplayMask | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
            SetNextItemWidth(min(it_open->second.mult * 3.2, 1.f) * square_sz * 12.0f); // Use 256 + bar sizes?
            value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x);
            EndPopup();
        }
        else
            it_open->second.play = false;
        PopStyleVar(3);
        PopStyleColor();
    }

    if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel))
    {
        window->DC.CursorPos = ImVec2(pos.x + w_button, pos.y + style.FramePadding.y);
        SetCursorPosX(10);
        TextEx(label, label_display_end);
    }

    // Convert back
    if (value_changed && picker_active_window == NULL)
    {
        if (!value_changed_as_float)
            for (int n = 0; n < 4; n++)
                f[n] = i[n] / 255.0f;
        if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB))
        {
            g.ColorEditLastHue = f[0];
            g.ColorEditLastSat = f[1];
            ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
            memcpy(g.ColorEditLastColor, f, sizeof(float) * 3);
        }
        if ((flags & ImGuiColorEditFlags_DisplayRGB) && (flags & ImGuiColorEditFlags_InputHSV))
            ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);

        col[0] = f[0];
        col[1] = f[1];
        col[2] = f[2];
        if (alpha)
            col[3] = f[3];
    }

    PopID();
    EndGroup();

    // Drag and Drop Target
    // NB: The flag test is merely an optional micro-optimization, BeginDragDropTarget() does the same test.
    if ((window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) && !(flags & ImGuiColorEditFlags_NoDragDrop) && BeginDragDropTarget())
    {
        bool accepted_drag_drop = false;
        if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
        {
            memcpy((float*)col, payload->Data, sizeof(float) * 3); // Preserve alpha if any //-V512
            value_changed = accepted_drag_drop = true;
        }
        if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
        {
            memcpy((float*)col, payload->Data, sizeof(float) * components);
            value_changed = accepted_drag_drop = true;
        }

        // Drag-drop payloads are always RGB
        if (accepted_drag_drop && (flags & ImGuiColorEditFlags_InputHSV))
            ColorConvertRGBtoHSV(col[0], col[1], col[2], col[0], col[1], col[2]);
        EndDragDropTarget();
    }

    // When picker is being actively used, use its active id so IsItemActive() will function on ColorEdit4().
    if (picker_active_window && g.ActiveId != 0 && g.ActiveIdWindow == picker_active_window)
        window->DC.LastItemId = g.ActiveId;

    if (value_changed)
        MarkItemEdited(window->DC.LastItemId);

    return value_changed;
}
Вот так происходит преобразование колора в float
Код:
bool c_menu::color_edit(const char* label, Color* color)
{
    float fcolor[4] =
    {
        color->r() / 255.0f,
        color->g() / 255.0f,
        color->b() / 255.0f,
        color->a() / 255.0f
    };


    if (ImGui::ColorEdit4(label, fcolor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_RGB)) {
        color->SetColor(fcolor[0], fcolor[1], fcolor[2], fcolor[3]);
        return true;
    }
    return false;
}
собственно говоря проблема
Мб я тупой, но по идеи оно должно у тебя рендериться в меню, т.е. там тоже должен быть код
 
B.O.M.J
Эксперт
Статус
Оффлайн
Регистрация
19 Май 2017
Сообщения
2,403
Реакции[?]
897
Поинты[?]
3K
Забаненный
Статус
Оффлайн
Регистрация
5 Сен 2020
Сообщения
986
Реакции[?]
275
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Забаненный
Статус
Оффлайн
Регистрация
24 Фев 2022
Сообщения
276
Реакции[?]
20
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Сверху Снизу