Skip to content

Commit

Permalink
Brought over changes from other branch for checking if the cursor is …
Browse files Browse the repository at this point in the history
…in the game window and if the game window is active
  • Loading branch information
vchelaru committed Oct 30, 2024
1 parent 5bcf011 commit b885891
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions GumRuntime/InteractiveGue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ public static void DoUiActivityRecursively(IList<GraphicalUiElement> gues, ICurs
var windowOverBefore = cursor.WindowOver;
var windowPushedBefore = cursor.WindowPushed;

var isInWindow = cursor.X >= 0 && cursor.X < GraphicalUiElement.CanvasWidth &&
cursor.Y >= 0 && cursor.Y < GraphicalUiElement.CanvasHeight;

HandledActions actions = new HandledActions();
cursor.WindowOver = null;
for(int i = gues.Count-1; i > -1; i--)
Expand Down Expand Up @@ -731,13 +734,13 @@ public static void DoUiActivityRecursively(IList<GraphicalUiElement> gues, ICurs
}

// the click/push actions need to be after the UI activity
if (cursor.PrimaryClick)
if (cursor.PrimaryClick && isInWindow)
{
InteractiveGue.DoNextClickActions();

}

if (cursor.PrimaryPush)
if (cursor.PrimaryPush && isInWindow)
{
InteractiveGue.DoNextPushActions();
}
Expand Down
14 changes: 14 additions & 0 deletions MonoGameGum/Forms/FormsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,22 @@ static ContainerRuntime CreateFullscreenContainer()

static List<GraphicalUiElement> innerList = new List<GraphicalUiElement>();

[Obsolete("Use the overload which takes a Game as the first argument, and pass the game instance.")]
public static void Update(GameTime gameTime, GraphicalUiElement rootGue)
{
Update(null, gameTime, rootGue);
}

public static void Update(Game game, GameTime gameTime, GraphicalUiElement rootGue)
{
// tolerate null games for now...
var shouldProcess = game == null || game.IsActive;

if(!shouldProcess)
{
return;
}

cursor.Activity(gameTime.TotalGameTime.TotalSeconds);
keyboard.Activity(gameTime.TotalGameTime.TotalSeconds);
innerList.Clear();
Expand Down

0 comments on commit b885891

Please sign in to comment.