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