MCPcopy Create free account
hub / github.com/dfranx/SHADERed / FavoriteButton

Function FavoriteButton

libs/misc/ImFileDialog.cpp:222–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220 return ret;
221 }
222 bool FavoriteButton(const char* label, bool isFavorite)
223 {
224 ImGuiContext& g = *GImGui;
225 ImGuiWindow* window = g.CurrentWindow;
226
227 ImVec2 pos = window->DC.CursorPos;
228 bool ret = ImGui::InvisibleButton(label, ImVec2(GUI_ELEMENT_SIZE, GUI_ELEMENT_SIZE));
229
230 bool hovered = ImGui::IsItemHovered();
231 bool active = ImGui::IsItemActive();
232
233 float size = window->DC.LastItemRect.Max.x - window->DC.LastItemRect.Min.x;
234
235 int numPoints = 5;
236 float innerRadius = size / 4;
237 float outerRadius = size / 2;
238 float angle = PI / numPoints;
239 ImVec2 center = ImVec2(pos.x + size / 2, pos.y + size / 2);
240
241 // fill
242 if (isFavorite || hovered || active) {
243 ImU32 fillColor = 0xff00ffff;// ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_Text]);
244 if (hovered || active)
245 fillColor = ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[active ? ImGuiCol_HeaderActive : ImGuiCol_HeaderHovered]);
246
247 // since there is no PathFillConcave, fill first the inner part, then the triangles
248 // inner
249 window->DrawList->PathClear();
250 for (int i = 1; i < numPoints * 2; i += 2)
251 window->DrawList->PathLineTo(ImVec2(center.x + innerRadius * sin(i * angle), center.y - innerRadius * cos(i * angle)));
252 window->DrawList->PathFillConvex(fillColor);
253
254 // triangles
255 for (int i = 0; i < numPoints; i++) {
256 window->DrawList->PathClear();
257
258 int pIndex = i * 2;
259 window->DrawList->PathLineTo(ImVec2(center.x + outerRadius * sin(pIndex * angle), center.y - outerRadius * cos(pIndex * angle)));
260 window->DrawList->PathLineTo(ImVec2(center.x + innerRadius * sin((pIndex + 1) * angle), center.y - innerRadius * cos((pIndex + 1) * angle)));
261 window->DrawList->PathLineTo(ImVec2(center.x + innerRadius * sin((pIndex - 1) * angle), center.y - innerRadius * cos((pIndex - 1) * angle)));
262
263 window->DrawList->PathFillConvex(fillColor);
264 }
265 }
266
267 // outline
268 window->DrawList->PathClear();
269 for (int i = 0; i < numPoints * 2; i++) {
270 float radius = i & 1 ? innerRadius : outerRadius;
271 window->DrawList->PathLineTo(ImVec2(center.x + radius * sin(i * angle), center.y - radius * cos(i * angle)));
272 }
273 window->DrawList->PathStroke(ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_Text]), true, 2.0f);
274
275 return ret;
276 }
277 bool FileIcon(const char* label, bool isSelected, ImTextureID icon, ImVec2 size, bool hasPreview, int previewWidth, int previewHeight)
278 {
279 ImGuiStyle& style = ImGui::GetStyle();

Callers 1

m_renderFileDialogMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected