Skip to content

Commit

Permalink
More resizing fixes in FNA
Browse files Browse the repository at this point in the history
Fixed gamepad is connected on first frame after screen restart.
  • Loading branch information
vchelaru committed Nov 15, 2023
1 parent cc44caf commit 59d8709
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
23 changes: 19 additions & 4 deletions Engines/FlatRedBallXNA/FlatRedBall/Input/Xbox360Gamepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,31 +1304,46 @@ public void Clear()
var isConnected = mGamePadState.IsConnected;
var wasConnected = mGamePadState.IsConnected;

#if MONOGAME
#if MONOGAME || FNA
// In MonoGame, calling the GamePadState constructor makes it connected.
if(isConnected)
{
mGamePadState = new GamePadState(new GamePadThumbSticks(), new GamePadTriggers(), new GamePadButtons(), new GamePadDPad());
}
else
{
#if FNA
mGamePadState = new GamePadState();
#endif

#if MONOGAME
mGamePadState = GamePadState.Default;
#endif
}
if(wasConnected)
if (wasConnected)
{
mLastGamePadState = new GamePadState(new GamePadThumbSticks(), new GamePadTriggers(), new GamePadButtons(), new GamePadDPad());
}
else
{
#if FNA
mLastGamePadState = new GamePadState();
#endif

#if MONOGAME
mLastGamePadState = GamePadState.Default;
#endif
}
#else
// XNA doesn't have .Default
mGamePadState = new GamePadState();
// XNA doesn't have .Default
mGamePadState = new GamePadState();
mLastGamePadState = new GamePadState() ;
#endif





mLeftStick.Clear();
mRightStick.Clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ private void WinformsHost_SizeChanged(object sender, SizeChangedEventArgs e)
{
SetGameToEmbeddedGameWindow();

// In FNA, if the game resizes externally, the internal methods for resizing do not get called, so the
// camera doesn't adjust, aspect ratio isn't fixed, etc. We need to force this
if (GlueState.Self.CurrentMainProject is FnaDesktopProject && ViewModel.IsRunning && ViewModel.IsWindowEmbedded)
{
_ = CommandSender.Self.Send(new ForceClientSizeUpdatesDto());
}
}

static double? windowsScaleFactor = null;
Expand Down Expand Up @@ -393,12 +399,7 @@ private void ToolsSidePanel_DragEnter(object sender, DragEventArgs e)
public async void ReactToMainWindowResizeEnd()
{
await ForceRefreshGameArea();
// In FNA, if the game resizes externally, the internal methods for resizing do not get called, so the
// camera doesn't adjust, aspect ratio isn't fixed, etc. We need to force this
if(GlueState.Self.CurrentMainProject is FnaDesktopProject && ViewModel.IsRunning && ViewModel.IsWindowEmbedded)
{
_=CommandSender.Self.Send(new ForceClientSizeUpdatesDto());
}

}

/// <summary>
Expand Down

0 comments on commit 59d8709

Please sign in to comment.