ImGUI | Как работать с цветом?

Scra1chy

Известный
Автор темы
36
2
Версия MoonLoader
.026-beta
Доброго времени суток! Как в ImGUI работать с цветом?
Находил только работу например через imgui.ImVec4(0.96, 0.59, 0.11, 1.00), можно ли как-то задавать цвет через Hex?
 

ШPEK

Известный
1,476
525
Доброго времени суток! Как в ImGUI работать с цветом?
Находил только работу например через imgui.ImVec4(0.96, 0.59, 0.11, 1.00), можно ли как-то задавать цвет через Hex?
Разбивать цвет в hex формате на байты и вписывать в ImVec4
 
  • Нравится
Реакции: Scra1chy

Scra1chy

Известный
Автор темы
36
2
Разбивать цвет в hex формате на байты и вписывать в ImVec4
А других способов нет?(
А если например изначально в lua цвет в тексте указывался через Hex, кактогда правильно заменить его на imVec4?

Например было imgui.Text(u8"{0xFFFFFF}Список доступных команд и клавиш:\n ... , станет imgui.Text(u8"imgui.ImVec4(0.96, 0.59, 0.11, 1.00) Список доступных команд и клавиш:\n ... или как?
 

ШPEK

Известный
1,476
525
А других способов нет?(
А если например изначально в lua цвет в тексте указывался через Hex, кактогда правильно заменить его на imVec4?

Например было imgui.Text(u8"{0xFFFFFF}Список доступных команд и клавиш:\n ... , станет imgui.Text(u8"imgui.ImVec4(0.96, 0.59, 0.11, 1.00) Список доступных команд и клавиш:\n ... или как?
TextColoredRGB функция от @imring смотри
 

Dmitriy Makarov

25.05.2021
Проверенный
2,485
1,116
 

meowprd

Тот самый Котовский
Проверенный
1,280
712
По поводу TextColoredRGB, у кого-то есть версия под mimgui? Чёт пробовал сам подправить под mimgui, но нифига не вышло :(
Из-за обычного textcoloredrgb жалуется на :GetVec4()
Lua:
function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
        local a = bit.band(bit.rshift(argb, 24), 0xFF)
        local r = bit.band(bit.rshift(argb, 16), 0xFF)
        local g = bit.band(bit.rshift(argb, 8), 0xFF)
        local b = bit.band(argb, 0xFF)
        return a, r, g, b
    end

    local getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) == 'string' and tonumber(color, 16) or color
        if type(color) ~= 'number' then return end
        local r, g, b, a = explode_argb(color)
        return imgui.ImVec4(r/255, g/255, b/255, a/255)
    end

    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(u8(w)) end
        end
    end

    render_text(text)
end

Недавно адаптировал как раз таки.
 

Andrinall

Известный
689
535
Lua:
function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
        local a = bit.band(bit.rshift(argb, 24), 0xFF)
        local r = bit.band(bit.rshift(argb, 16), 0xFF)
        local g = bit.band(bit.rshift(argb, 8), 0xFF)
        local b = bit.band(argb, 0xFF)
        return a, r, g, b
    end

    local getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) == 'string' and tonumber(color, 16) or color
        if type(color) ~= 'number' then return end
        local r, g, b, a = explode_argb(color)
        return imgui.ImVec4(r/255, g/255, b/255, a/255)
    end

    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(u8(w)) end
        end
    end

    render_text(text)
end

Недавно адаптировал как раз таки.
Жирный лайк.. я пытался приблизительно так же сделать, но что-то делал не так постоянно)
Спасибо.
 
  • Вау
Реакции: meowprd