mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
ColorButton, ColorPicker: painfully made RenderColorRectWithAlphaCheckerboard more friendly to using Rounding and Border in style, still not perfect :( (#346) + comments
This commit is contained in:
parent
6796e771fd
commit
19c6a9c0e0
34
imgui.cpp
34
imgui.cpp
@ -9017,7 +9017,7 @@ void ImGui::ColorTooltip(const char* text, const float col[4], ImGuiColorEditFla
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 sz(g.FontSize * 3, g.FontSize * 3);
|
ImVec2 sz(g.FontSize * 3, g.FontSize * 3);
|
||||||
RenderColorRectWithAlphaGrid(window->DC.CursorPos, window->DC.CursorPos + sz, IM_COL32(cr,cg,cb,ca), g.FontSize, g.Style.FrameRounding);
|
RenderColorRectWithAlphaCheckerboard(window->DC.CursorPos, window->DC.CursorPos + sz, IM_COL32(cr,cg,cb,ca), g.FontSize, g.Style.FrameRounding);
|
||||||
Dummy(sz);
|
Dummy(sz);
|
||||||
SameLine();
|
SameLine();
|
||||||
if (flags & ImGuiColorEditFlags_NoAlpha)
|
if (flags & ImGuiColorEditFlags_NoAlpha)
|
||||||
@ -9033,22 +9033,32 @@ static inline float ColorSquareSize()
|
|||||||
return g.FontSize + g.Style.FramePadding.y * 2.0f;
|
return g.FontSize + g.Style.FramePadding.y * 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::RenderColorRectWithAlphaGrid(ImVec2 p_min, ImVec2 p_max, ImU32 col, float grid_step, float rounding)
|
void ImGui::RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 col, float grid_step, float rounding, int rounding_corners_flags_parent)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
if (((col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) < 0xFF)
|
if (((col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) < 0xFF)
|
||||||
{
|
{
|
||||||
|
// We use rounding+1 here which is counterintuitive but it inhibit mosts of the edge artifacts with overlayed rounded shapes
|
||||||
ImU32 col_bg1 = GetColorU32(IM_COL32(204,204,204,255));
|
ImU32 col_bg1 = GetColorU32(IM_COL32(204,204,204,255));
|
||||||
ImU32 col_bg2 = GetColorU32(IM_COL32(128,128,128,255));
|
ImU32 col_bg2 = GetColorU32(IM_COL32(128,128,128,255));
|
||||||
window->DrawList->AddRectFilled(p_min, p_max, col_bg1, rounding);
|
window->DrawList->AddRectFilled(p_min, p_max, col_bg1, rounding+1, rounding_corners_flags_parent);
|
||||||
int yi = 0;
|
int x_count = (int)((p_max.x - p_min.x) / grid_step + 0.99f);
|
||||||
for (float y = p_min.y; y < p_max.y; y += grid_step, yi++)
|
int y_count = (int)((p_max.y - p_min.y) / grid_step + 0.99f);
|
||||||
for (float x = p_min.x + ((yi & 1) ? grid_step : 0.0f); x < p_max.x; x += grid_step * 2)
|
for (int y_i = 0; y_i < y_count; y_i++)
|
||||||
{
|
{
|
||||||
window->DrawList->AddRectFilled(ImVec2(x,y), ImMin(ImVec2(x + grid_step, y + grid_step), p_max), col_bg2, 0.0f);
|
for (int x_i = (y_i & 1) ^ 1; x_i < x_count; x_i += 2)
|
||||||
|
{
|
||||||
|
int rounding_corners_flags = 0;
|
||||||
|
if (y_i == 0) rounding_corners_flags |= (x_i == 0) ? ImGuiCorner_TopLeft : (x_i == x_count-1) ? ImGuiCorner_TopRight : 0;
|
||||||
|
if (y_i == y_count-1) rounding_corners_flags |= (x_i == 0) ? ImGuiCorner_BottomLeft : (x_i == x_count-1) ? ImGuiCorner_BottomRight : 0;
|
||||||
|
rounding_corners_flags &= rounding_corners_flags_parent;
|
||||||
|
ImVec2 p1(p_min.x + x_i * grid_step, p_min.y + y_i * grid_step);
|
||||||
|
ImVec2 p2(ImMin(p1.x + grid_step, p_max.x), ImMin(p1.y + grid_step, p_max.y));
|
||||||
|
window->DrawList->AddRectFilled(p1, p2, col_bg2, rounding_corners_flags ? rounding+1 : 0.0f, rounding_corners_flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window->DrawList->AddRectFilled(p_min, p_max, col, rounding);
|
}
|
||||||
|
window->DrawList->AddRectFilled(p_min, p_max, col, rounding, rounding_corners_flags_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A little colored square. Return true when clicked.
|
// A little colored square. Return true when clicked.
|
||||||
@ -9076,7 +9086,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl
|
|||||||
bool hovered, held;
|
bool hovered, held;
|
||||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
|
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
|
||||||
float grid_step = ImMin(g.FontSize, ImMin(size.x, size.y) * 0.5f);
|
float grid_step = ImMin(g.FontSize, ImMin(size.x, size.y) * 0.5f);
|
||||||
RenderColorRectWithAlphaGrid(bb.Min, bb.Max, GetColorU32((flags & (ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoAlphaPreview)) ? ImVec4(col.x, col.y, col.z, 1.0f) : col), grid_step, style.FrameRounding);
|
RenderColorRectWithAlphaCheckerboard(bb.Min, bb.Max, GetColorU32((flags & (ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoAlphaPreview)) ? ImVec4(col.x, col.y, col.z, 1.0f) : col), grid_step, style.FrameRounding);
|
||||||
RenderFrameBorder(bb.Min, bb.Max, style.FrameRounding);
|
RenderFrameBorder(bb.Min, bb.Max, style.FrameRounding);
|
||||||
|
|
||||||
if (hovered && !(flags & ImGuiColorEditFlags_NoTooltip))
|
if (hovered && !(flags & ImGuiColorEditFlags_NoTooltip))
|
||||||
@ -9294,11 +9304,9 @@ bool ImGui::ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags fl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ColorPicker v2.60 WIP
|
// ColorPicker
|
||||||
// see https://github.com/ocornut/imgui/issues/346
|
|
||||||
// TODO: English strings in context menu (see FIXME-LOCALIZATION)
|
|
||||||
// Note: we adjust item height based on item widget, which may cause a flickering feedback loop (if automatic height makes a vertical scrollbar appears, affecting automatic width..)
|
|
||||||
// Note: only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
|
// Note: only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
|
||||||
|
// FIXME: we adjust the big color square height based on item width, which may cause a flickering feedback loop (if automatic height makes a vertical scrollbar appears, affecting automatic width..)
|
||||||
bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags)
|
bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
@ -733,7 +733,7 @@ namespace ImGui
|
|||||||
IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0,0), const ImRect* clip_rect = NULL);
|
IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0,0), const ImRect* clip_rect = NULL);
|
||||||
IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
|
IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
|
||||||
IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f);
|
IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f);
|
||||||
IMGUI_API void RenderColorRectWithAlphaGrid(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, float rounding = 0.0f);
|
IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, float rounding = 0.0f, int rounding_corners_flags = ~0);
|
||||||
IMGUI_API void RenderCollapseTriangle(ImVec2 pos, bool is_open, float scale = 1.0f);
|
IMGUI_API void RenderCollapseTriangle(ImVec2 pos, bool is_open, float scale = 1.0f);
|
||||||
IMGUI_API void RenderBullet(ImVec2 pos);
|
IMGUI_API void RenderBullet(ImVec2 pos);
|
||||||
IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col);
|
IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col);
|
||||||
|
Loading…
Reference in New Issue
Block a user