mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-02 06:40:40 +08:00
ImGuiPureWrap: Improvements for draw_hexagon()
Corners can be rounded now
This commit is contained in:
parent
da2a06c06d
commit
2241c4d9d5
@ -360,11 +360,12 @@ void ImGuiControl::draw_thumb(const ImVec2& center, bool mark/* = false*/)
|
||||
const float line_width = 1.5f * m_draw_opts.scale;
|
||||
const float radius = m_draw_opts.thumb_radius();
|
||||
const float line_offset = 0.5f * radius;
|
||||
const float rounding = 1.5f * m_draw_opts.rounding();
|
||||
|
||||
const float hexagon_angle = is_horizontal() ? 0.f : IM_PI * 0.5f;
|
||||
|
||||
ImGuiPureWrap::draw_hexagon(center, radius, border_clr, hexagon_angle);
|
||||
ImGuiPureWrap::draw_hexagon(center, radius - line_width, thumb_bg_clr, hexagon_angle);
|
||||
ImGuiPureWrap::draw_hexagon(center, radius, border_clr, hexagon_angle, rounding);
|
||||
ImGuiPureWrap::draw_hexagon(center, radius - line_width, thumb_bg_clr, hexagon_angle, rounding);
|
||||
|
||||
if (mark) {
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
|
@ -296,7 +296,7 @@ bool combo(const std::string& label, const std::vector<std::string>& options, in
|
||||
return res;
|
||||
}
|
||||
|
||||
void draw_hexagon(const ImVec2& center, float radius, ImU32 col, float start_angle)
|
||||
void draw_hexagon(const ImVec2& center, float radius, ImU32 col, float start_angle, float rounding)
|
||||
{
|
||||
if ((col & IM_COL32_A_MASK) == 0)
|
||||
return;
|
||||
@ -306,7 +306,21 @@ void draw_hexagon(const ImVec2& center, float radius, ImU32 col, float start_ang
|
||||
float a_min = start_angle;
|
||||
float a_max = start_angle + 2.f * IM_PI;
|
||||
|
||||
if (rounding <= 0) {
|
||||
window->DrawList->PathArcTo(center, radius, a_min, a_max, 6);
|
||||
}
|
||||
else {
|
||||
const float a_delta = IM_PI / 4.f;
|
||||
radius -= rounding;
|
||||
|
||||
for (int i = 0; i <= 6; i++) {
|
||||
float a = a_min + ((float)i / (float)6) * (a_max - a_min);
|
||||
if (a >= 2.f * IM_PI)
|
||||
a -= 2.f * IM_PI;
|
||||
ImVec2 pos = ImVec2(center.x + ImCos(a) * radius, center.y + ImSin(a) * radius);
|
||||
window->DrawList->PathArcTo(pos, rounding, a - a_delta, a + a_delta, 5);
|
||||
}
|
||||
}
|
||||
window->DrawList->PathFillConvex(col);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace ImGuiPureWrap
|
||||
// Use selection = -1 to not mark any option as selected
|
||||
bool combo(const std::string& label, const std::vector<std::string>& options, int& selection, ImGuiComboFlags flags = 0, float label_width = 0.0f, float item_width = 0.0f);
|
||||
|
||||
void draw_hexagon(const ImVec2& center, float radius, ImU32 col, float start_angle = 0.f);
|
||||
void draw_hexagon(const ImVec2& center, float radius, ImU32 col, float start_angle = 0.f, float rounding = 0.f);
|
||||
|
||||
void text(const char* label);
|
||||
void text(const std::string& label);
|
||||
|
Loading…
x
Reference in New Issue
Block a user