mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-15 15:09:29 +00:00
input scaling on the viewport adapters
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MonoGame.Extended;
|
||||
@@ -13,21 +14,31 @@ namespace Game1
|
||||
private Texture2D[] _backgroundTexture;
|
||||
private Texture2D _backgroundTextureClouds;
|
||||
private Texture2D _backgroundTextureSky;
|
||||
private MouseState _previousMouseState;
|
||||
private ViewportAdapter _viewportAdapter;
|
||||
|
||||
public Game1()
|
||||
{
|
||||
_graphicsDeviceManager = new GraphicsDeviceManager(this);
|
||||
Content.RootDirectory = "Content";
|
||||
IsMouseVisible = true;
|
||||
Window.IsBorderless = false;
|
||||
Window.Position = new Point(50, 50);
|
||||
_graphicsDeviceManager.PreferredBackBufferWidth = 1024;
|
||||
_graphicsDeviceManager.PreferredBackBufferHeight = 768;
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
var viewportAdapter = new ViewportAdapter(GraphicsDevice);
|
||||
_camera = new Camera2D(viewportAdapter);
|
||||
_viewportAdapter = new BoxingViewportAdapter(GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(_viewportAdapter)
|
||||
{
|
||||
Zoom = 0.65f,
|
||||
Position = new Vector2(900, 650)
|
||||
};
|
||||
|
||||
Window.AllowUserResizing = true;
|
||||
Window.ClientSizeChanged += (s,e) => viewportAdapter.OnClientSizeChanged();
|
||||
Window.ClientSizeChanged += (s, e) => _viewportAdapter.OnClientSizeChanged();
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
@@ -98,21 +109,22 @@ namespace Game1
|
||||
|
||||
_previousScrollWheelValue = mouseState.ScrollWheelValue;
|
||||
|
||||
//// look at
|
||||
//if (mouseState.LeftButton == ButtonState.Pressed && _previousMouseState.LeftButton == ButtonState.Released)
|
||||
// _camera.LookAt(_camera.ScreenToWorld(new Vector2(mouseState.X, mouseState.Y)));
|
||||
// look at
|
||||
if (mouseState.LeftButton == ButtonState.Pressed && _previousMouseState.LeftButton == ButtonState.Released)
|
||||
{
|
||||
var p = _viewportAdapter.PointToScreen(mouseState.X, mouseState.Y);
|
||||
Trace.WriteLine(string.Format("{0},{1} => {2},{3}", mouseState.X, mouseState.Y, p.X, p.Y));
|
||||
}
|
||||
|
||||
//_previousMouseState = mouseState;
|
||||
_previousMouseState = mouseState;
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
//private MouseState _previousMouseState;
|
||||
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
|
||||
|
||||
_spriteBatch.Begin(transformMatrix: _camera.GetViewMatrix(new Vector2(0.25f, 1.0f)));
|
||||
_spriteBatch.Draw(_backgroundTextureSky, Vector2.Zero);
|
||||
_spriteBatch.Draw(_backgroundTextureClouds, Vector2.Zero);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace MonoGame.Extended
|
||||
@@ -38,5 +39,11 @@ namespace MonoGame.Extended
|
||||
var y = (viewport.Height / 2) - (height / 2);
|
||||
GraphicsDevice.Viewport = new Viewport(x, y, width, height);
|
||||
}
|
||||
|
||||
public override Point PointToScreen(Point point)
|
||||
{
|
||||
var viewport = GraphicsDevice.Viewport;
|
||||
return base.PointToScreen(point.X - viewport.X, point.Y - viewport.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,12 @@ namespace MonoGame.Extended
|
||||
get { return ActualHeight; }
|
||||
}
|
||||
|
||||
public int ActualWidth
|
||||
public virtual int ActualWidth
|
||||
{
|
||||
get { return GraphicsDevice.Viewport.Width; }
|
||||
}
|
||||
|
||||
public int ActualHeight
|
||||
public virtual int ActualHeight
|
||||
{
|
||||
get { return GraphicsDevice.Viewport.Height; }
|
||||
}
|
||||
@@ -36,6 +36,17 @@ namespace MonoGame.Extended
|
||||
{
|
||||
}
|
||||
|
||||
public virtual Point PointToScreen(Point point)
|
||||
{
|
||||
var matrix = Matrix.Invert(GetScaleMatrix());
|
||||
return Vector2.Transform(point.ToVector2(), matrix).ToPoint();
|
||||
}
|
||||
|
||||
public Point PointToScreen(int x, int y)
|
||||
{
|
||||
return PointToScreen(new Point(x, y));
|
||||
}
|
||||
|
||||
public virtual Matrix GetScaleMatrix()
|
||||
{
|
||||
return Matrix.Identity;
|
||||
|
||||
Reference in New Issue
Block a user