ViewportAdapter.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Graphics;
  4. namespace MonoGame.Extended.ViewportAdapters
  5. {
  6. public abstract class ViewportAdapter : IDisposable
  7. {
  8. protected ViewportAdapter(GraphicsDevice graphicsDevice)
  9. {
  10. GraphicsDevice = graphicsDevice;
  11. }
  12. public virtual void Dispose()
  13. {
  14. }
  15. public GraphicsDevice GraphicsDevice { get; }
  16. public Viewport Viewport => GraphicsDevice.Viewport;
  17. public abstract int VirtualWidth { get; }
  18. public abstract int VirtualHeight { get; }
  19. public abstract int ViewportWidth { get; }
  20. public abstract int ViewportHeight { get; }
  21. public Rectangle BoundingRectangle => new Rectangle(0, 0, VirtualWidth, VirtualHeight);
  22. public Point Center => BoundingRectangle.Center;
  23. public abstract Matrix GetScaleMatrix();
  24. public Point PointToScreen(Point point)
  25. {
  26. return PointToScreen(point.X, point.Y);
  27. }
  28. public virtual Point PointToScreen(int x, int y)
  29. {
  30. var scaleMatrix = GetScaleMatrix();
  31. var invertedMatrix = Matrix.Invert(scaleMatrix);
  32. return Vector2.Transform(new Vector2(x, y), invertedMatrix).ToPoint();
  33. }
  34. public virtual void Reset()
  35. {
  36. }
  37. }
  38. }