Skip to content

Commit 5c926ef

Browse files
committed
Make interactables respect PlatformBackend.WantsMouseCapture
1 parent 04e4d96 commit 5c926ef

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

Pulsar4X/Pulsar4X.Client/PulsarMainWindow.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public override void HandleEvent(SDL.Event e)
153153
return;
154154
}
155155

156-
if (!PlatformBackend.WantsMouseCapture() || _state.IsMouseOverMapOverlay)
156+
if (!PlatformBackend.WantsMouseCapture())
157157
{
158158
switch (e.Type)
159159
{
@@ -177,9 +177,6 @@ public override void Update()
177177
{
178178
base.Update();
179179

180-
// Reset map overlay hover state at the start of each frame
181-
_state.IsMouseOverMapOverlay = false;
182-
183180
//update and refresh state for GameDateTimechange
184181
if(_state.Game != null)
185182
{

Pulsar4X/Pulsar4X.Client/Rendering/SystemMapRendering.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ internal SystemMapRendering(SDL3Window window, GlobalUIState state)
6767

6868
var mainWin = (PulsarMainWindow)window;
6969
mainWin.MouseButtonDownOccured += (object sender, SDL.Event e) => {
70+
if (mainWin.PlatformBackend.WantsMouseCapture())
71+
return;
72+
7073
foreach (var i in _interactableGrouped)
7174
{
7275
var key = i.Key;
@@ -87,6 +90,9 @@ internal SystemMapRendering(SDL3Window window, GlobalUIState state)
8790
}
8891
};
8992
mainWin.MouseButtonUpOccured += (object sender, SDL.Event e) => {
93+
if (mainWin.PlatformBackend.WantsMouseCapture())
94+
return;
95+
9096
foreach (var i in _interactableGrouped)
9197
{
9298
var key = i.Key;
@@ -115,6 +121,17 @@ internal SystemMapRendering(SDL3Window window, GlobalUIState state)
115121
{
116122
var item = j.Item;
117123

124+
if (mainWin.PlatformBackend.WantsMouseCapture())
125+
{
126+
if (j.IsHovered)
127+
{
128+
j.IsHovered = false;
129+
if (item.OnPointerExit(e))
130+
return;
131+
}
132+
continue;
133+
}
134+
118135
var c = item.Contains(new (e.Motion.X, e.Motion.Y));
119136

120137
if (j.IsHovered)

Pulsar4X/Pulsar4X.Client/State/GlobalUIState.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ public class GlobalUIState
117117

118118
internal View? SelectedMapView { get; set; } = null;
119119

120-
/// <summary>
121-
/// True when the mouse is hovering over a map overlay (like name icons) that should
122-
/// allow scroll wheel input to pass through to the map for zooming.
123-
/// This is set during rendering and checked during the next frame's event handling.
124-
/// </summary>
125-
internal bool IsMouseOverMapOverlay = false;
126-
127120
// Game Settings
128121
internal GameSettings GameSettings { get; set; }
129122

0 commit comments

Comments
 (0)