Make IWindow interface & make fullscreen work in UWP & OpenGL.

GitOrigin-RevId: 17e3e115481779249f59d68acab6325a78592eaf
This commit is contained in:
Colin McMillen 2019-12-04 15:32:07 -05:00
parent 149ecf8075
commit a33c4d90fd
3 changed files with 16 additions and 4 deletions

7
Jumpy.Shared/IWindow.cs Normal file
View File

@ -0,0 +1,7 @@
using Microsoft.Xna.Framework;
namespace Jumpy {
public interface IWindow {
void SetFullScreen(bool fullScreen, Game game, GraphicsDeviceManager graphics);
}
}

View File

@ -9,6 +9,7 @@
<Import_RootNamespace>Jumpy.Shared</Import_RootNamespace> <Import_RootNamespace>Jumpy.Shared</Import_RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)IWindow.cs" />
<Compile Include="$(MSBuildThisFileDirectory)KeyboardInput.cs" /> <Compile Include="$(MSBuildThisFileDirectory)KeyboardInput.cs" />
<Compile Include="$(MSBuildThisFileDirectory)JumpyGame.cs" /> <Compile Include="$(MSBuildThisFileDirectory)JumpyGame.cs" />
</ItemGroup> </ItemGroup>

View File

@ -10,6 +10,8 @@ namespace Jumpy {
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
SpriteFont font; SpriteFont font;
KeyboardInput keyboardInput = new KeyboardInput(); KeyboardInput keyboardInput = new KeyboardInput();
bool fullScreen = false;
IWindow window;
public JumpyGame() { public JumpyGame() {
graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
@ -18,6 +20,8 @@ namespace Jumpy {
// Performs initialization that's needed before starting to run. // Performs initialization that's needed before starting to run.
protected override void Initialize() { protected override void Initialize() {
window = (IWindow) Services.GetService(typeof(IWindow));
window.SetFullScreen(fullScreen, this, graphics);
base.Initialize(); base.Initialize();
} }
@ -37,10 +41,10 @@ namespace Jumpy {
keyboardInput.Update(); keyboardInput.Update();
List<Keys> keysDown = keyboardInput.NewKeysDown(); List<Keys> keysDown = keyboardInput.NewKeysDown();
//if (keysDown.Contains(Keys.F12)) if (keysDown.Contains(Keys.F12)) {
//{ window.SetFullScreen(!fullScreen, this, graphics);
// SetFullScreen(!fullScreen); fullScreen = !fullScreen;
//} }
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
keysDown.Contains(Keys.Escape)) { keysDown.Contains(Keys.Escape)) {