InterfaceUtil.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Numerics;
  2. using Dalamud.Interface;
  3. using ImGuiNET;
  4. namespace HuntBuddy.Utils;
  5. /// <summary>
  6. /// Interface utilities class.
  7. /// </summary>
  8. public static class InterfaceUtil
  9. {
  10. /// <summary>
  11. /// Draws hunt icons from game images.
  12. /// </summary>
  13. /// <param name="mobHuntEntry"><see cref="MobHuntEntry"/> containing relevant information.</param>
  14. public static void DrawHuntIcon(MobHuntEntry mobHuntEntry)
  15. {
  16. var cursorPos = ImGui.GetCursorScreenPos();
  17. var imageSize = mobHuntEntry.ExpansionId < 3 ? new Vector2(192f, 128f) : new Vector2(210f);
  18. imageSize *= ImGui.GetIO().FontGlobalScale * Plugin.Instance.Configuration.IconScale;
  19. ImGui.InvisibleButton("canvas", imageSize);
  20. var drawList = ImGui.GetWindowDrawList();
  21. if (mobHuntEntry is { ExpansionId: 4, IsEliteMark: false }) // Endwalker uses circle for non elite mobs
  22. {
  23. drawList.AddCircleFilled(
  24. cursorPos + (imageSize / 2f),
  25. imageSize.X / 2f,
  26. Plugin.Instance.Configuration.IconBackgroundColourU32);
  27. }
  28. else
  29. {
  30. drawList.AddRectFilled(
  31. cursorPos,
  32. cursorPos + imageSize,
  33. Plugin.Instance.Configuration.IconBackgroundColourU32);
  34. }
  35. drawList.AddImage(mobHuntEntry.Icon.ImGuiHandle, cursorPos, cursorPos + imageSize);
  36. }
  37. /// <summary>
  38. /// Renders a button with an icon.
  39. /// </summary>
  40. /// <param name="icon">Desired <see cref="FontAwesomeIcon"/> to be rendered.</param>
  41. /// <param name="id">Button ID.</param>
  42. /// <returns>True if pressed.</returns>
  43. public static bool IconButton(FontAwesomeIcon icon, string? id)
  44. {
  45. ImGui.PushFont(UiBuilder.IconFont);
  46. var text = icon.ToIconString();
  47. if (id != null)
  48. {
  49. text += $"##{id}";
  50. }
  51. var result = ImGui.Button(text);
  52. ImGui.PopFont();
  53. return result;
  54. }
  55. /// <summary>
  56. /// Renders a button with an icon.
  57. /// </summary>
  58. /// <param name="icon">Desired <see cref="FontAwesomeIcon"/> to be rendered.</param>
  59. /// <returns>True if pressed.</returns>
  60. public static bool IconButton(FontAwesomeIcon icon) => IconButton(icon, null);
  61. }