17void DrawIcon(ImDrawList* drawList,
const ImVec2& a,
const ImVec2& b,
PinIcon::Type type,
bool filled, ImU32 color, ImU32 innerColor)
19 auto rect = ImRect(a, b);
20 auto rect_y = rect.Min.y;
21 auto rect_w = rect.Max.x - rect.Min.x;
22 auto rect_h = rect.Max.y - rect.Min.y;
23 auto rect_center_x = (rect.Min.x + rect.Max.x) * 0.5F;
24 auto rect_center_y = (rect.Min.y + rect.Max.y) * 0.5F;
25 auto rect_center = ImVec2(rect_center_x, rect_center_y);
26 const auto outline_scale = rect_w / 24.0F;
27 const auto extra_segments =
static_cast<int>(2 * outline_scale);
31 const auto origin_scale = rect_w / 24.0F;
33 const auto offset_x = 1.0F * origin_scale;
34 const auto offset_y = 0.0F * origin_scale;
35 const auto margin = 2.0F * origin_scale;
36 const auto rounding = 0.1F * origin_scale;
37 const auto tip_round = 0.7F;
39 const auto canvas = ImRect(
40 rect.Min.x + margin + offset_x,
41 rect.Min.y + margin + offset_y,
42 rect.Max.x - margin + offset_x,
43 rect.Max.y - margin + offset_y);
44 const auto canvas_x = canvas.Min.x;
45 const auto canvas_y = canvas.Min.y;
46 const auto canvas_w = canvas.Max.x - canvas.Min.x;
47 const auto canvas_h = canvas.Max.y - canvas.Min.y;
49 const auto left = canvas_x + canvas_w * 0.5F * 0.3F;
50 const auto right = canvas_x + canvas_w - canvas_w * 0.5F * 0.3F;
51 const auto top = canvas_y + canvas_h * 0.5F * 0.2F;
52 const auto bottom = canvas_y + canvas_h - canvas_h * 0.5F * 0.2F;
53 const auto center_y = (top + bottom) * 0.5F;
56 const auto tip_top = ImVec2(canvas_x + canvas_w * 0.5F, top);
57 const auto tip_right = ImVec2(right, center_y);
58 const auto tip_bottom = ImVec2(canvas_x + canvas_w * 0.5F, bottom);
60 drawList->PathLineTo(ImVec2(left, top) + ImVec2(0, rounding));
61 drawList->PathBezierCurveTo(
64 ImVec2(left, top) + ImVec2(rounding, 0));
65 drawList->PathLineTo(tip_top);
66 drawList->PathLineTo(tip_top + (tip_right - tip_top) * tip_round);
67 drawList->PathBezierCurveTo(
70 tip_bottom + (tip_right - tip_bottom) * tip_round);
71 drawList->PathLineTo(tip_bottom);
72 drawList->PathLineTo(ImVec2(left, bottom) + ImVec2(rounding, 0));
73 drawList->PathBezierCurveTo(
76 ImVec2(left, bottom) - ImVec2(0, rounding));
80 if (innerColor & 0xFF000000)
82 drawList->AddConvexPolyFilled(drawList->_Path.Data, drawList->_Path.Size, innerColor);
85 drawList->PathStroke(color,
true, 2.0F * outline_scale);
89 drawList->PathFillConvex(color);
94 auto triangleStart = rect_center_x + 0.32F * rect_w;
96 auto rect_offset = -
static_cast<int>(rect_w * 0.25F * 0.25F);
98 rect.Min.x +=
static_cast<float>(rect_offset);
99 rect.Max.x +=
static_cast<float>(rect_offset);
100 rect_center_x +=
static_cast<float>(rect_offset) * 0.5F;
101 rect_center.x +=
static_cast<float>(rect_offset) * 0.5F;
105 const auto c = rect_center;
109 const auto r = 0.5F * rect_w / 2.0F - 0.5F;
111 if (innerColor & 0xFF000000)
113 drawList->AddCircleFilled(c, r, innerColor, 12 + extra_segments);
115 drawList->AddCircle(c, r, color, 12 + extra_segments, 2.0F * outline_scale);
119 drawList->AddCircleFilled(c, 0.5F * rect_w / 2.0F, color, 12 + extra_segments);
127 const auto r = 0.5F * rect_w / 2.0F;
128 const auto p0 = rect_center - ImVec2(r, r);
129 const auto p1 = rect_center + ImVec2(r, r);
131 drawList->AddRectFilled(p0, p1, color, 0, ImDrawFlags_RoundCornersAll);
135 const auto r = 0.5F * rect_w / 2.0F - 0.5F;
136 const auto p0 = rect_center - ImVec2(r, r);
137 const auto p1 = rect_center + ImVec2(r, r);
139 if (innerColor & 0xFF000000)
141 drawList->AddRectFilled(p0, p1, innerColor, 0, ImDrawFlags_RoundCornersAll);
144 drawList->AddRect(p0, p1, color, 0, ImDrawFlags_RoundCornersAll, 2.0F * outline_scale);
150 const auto r = 0.5F * rect_w / 2.0F;
151 const auto w = ceilf(r / 3.0F);
153 const auto baseTl = ImVec2(floorf(rect_center_x - w * 2.5F), floorf(rect_center_y - w * 2.5F));
154 const auto baseBr = ImVec2(floorf(baseTl.x + w), floorf(baseTl.y + w));
158 for (
int i = 0; i < 3; ++i)
162 drawList->AddRectFilled(tl, br, color);
165 if (i != 1 || filled)
167 drawList->AddRectFilled(tl, br, color);
171 drawList->AddRectFilled(tl, br, color);
177 triangleStart = br.x + w + 1.0F / 24.0F * rect_w;
184 const auto r = 0.5F * rect_w / 2.0F;
185 const auto cr = r * 0.5F;
186 const auto p0 = rect_center - ImVec2(r, r);
187 const auto p1 = rect_center + ImVec2(r, r);
189 drawList->AddRectFilled(p0, p1, color, cr, ImDrawFlags_RoundCornersAll);
193 const auto r = 0.5F * rect_w / 2.0F - 0.5F;
194 const auto cr = r * 0.5F;
195 const auto p0 = rect_center - ImVec2(r, r);
196 const auto p1 = rect_center + ImVec2(r, r);
198 if (innerColor & 0xFF000000)
200 drawList->AddRectFilled(p0, p1, innerColor, cr, ImDrawFlags_RoundCornersAll);
203 drawList->AddRect(p0, p1, color, cr, ImDrawFlags_RoundCornersAll, 2.0F * outline_scale);
210 const auto r = 0.607F * rect_w / 2.0F;
211 const auto c = rect_center;
213 drawList->PathLineTo(c + ImVec2(0, -r));
214 drawList->PathLineTo(c + ImVec2(r, 0));
215 drawList->PathLineTo(c + ImVec2(0, r));
216 drawList->PathLineTo(c + ImVec2(-r, 0));
217 drawList->PathFillConvex(color);
221 const auto r = 0.607F * rect_w / 2.0F - 0.5F;
222 const auto c = rect_center;
224 drawList->PathLineTo(c + ImVec2(0, -r));
225 drawList->PathLineTo(c + ImVec2(r, 0));
226 drawList->PathLineTo(c + ImVec2(0, r));
227 drawList->PathLineTo(c + ImVec2(-r, 0));
229 if (innerColor & 0xFF000000)
231 drawList->AddConvexPolyFilled(drawList->_Path.Data, drawList->_Path.Size, innerColor);
234 drawList->PathStroke(color,
true, 2.0F * outline_scale);
239 const auto triangleTip = triangleStart + rect_w * (0.45F - 0.32F);
241 drawList->AddTriangleFilled(
242 ImVec2(ceilf(triangleTip), rect_y + rect_h * 0.5F),
243 ImVec2(triangleStart, rect_center_y + 0.15F * rect_h),
244 ImVec2(triangleStart, rect_center_y - 0.15F * rect_h),