using HSUI.Config; using HSUI.Enums; using HSUI.Interface.GeneralElements; using Dalamud.Bindings.ImGui; using System; using System.Numerics; namespace HSUI.Helpers { /// /// Hit test for HSUI hotbars. Used to determine if the cursor is over an HSUI hotbar /// so we only intercept drag-drop releases when the user is actually dropping on our bars. /// public static class ActionBarsHitTestHelper { /// Returns true if the mouse cursor is over any visible HSUI hotbar. public static bool IsMouseOverAnyHSUIHotbar() { try { var hotbarsConfig = ConfigurationManager.Instance?.GetConfigObject(); if (hotbarsConfig == null || !hotbarsConfig.Enabled) return false; var hudOptions = ConfigurationManager.Instance?.GetConfigObject(); Vector2 origin = ImGui.GetMainViewport().Size / 2f; if (hudOptions != null && hudOptions.UseGlobalHudShift) origin += hudOptions.HudOffset; Vector2 mousePos = ImGui.GetMousePos(); HotbarBarConfig?[] barConfigs = new HotbarBarConfig?[] { ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject(), ConfigurationManager.Instance?.GetConfigObject() }; foreach (var barConfig in barConfigs) { if (barConfig == null) continue; Vector2 barSize = ComputeBarSize(barConfig); Vector2 topLeft = Utils.GetAnchoredPosition(origin + barConfig.Position, barSize, barConfig.Anchor); if (mousePos.X >= topLeft.X && mousePos.X < topLeft.X + barSize.X && mousePos.Y >= topLeft.Y && mousePos.Y < topLeft.Y + barSize.Y) { return true; } } return false; } catch { return false; } } private static Vector2 ComputeBarSize(HotbarBarConfig config) { var (cols, _) = config.GetLayoutGrid(); int effectiveCols = Math.Min(cols, config.SlotCount); int effectiveRows = (config.SlotCount + effectiveCols - 1) / effectiveCols; float w = effectiveCols * config.SlotSize.X + (effectiveCols - 1) * config.SlotPadding; float h = effectiveRows * config.SlotSize.Y + (effectiveRows - 1) * config.SlotPadding; return new Vector2(w, h); } } }