37 lines
1.7 KiB
C#
37 lines
1.7 KiB
C#
using System.Runtime.CompilerServices;
|
|
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using Syntriax.Engine.Core;
|
|
|
|
namespace Syntriax.Engine.Integration.MonoGame;
|
|
|
|
public static class EngineConverterExtensions
|
|
{
|
|
public readonly static Vector2D screenScale = Vector2D.Down + Vector2D.Right;
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static UniverseTime ToEngineTime(this GameTime gameTime) => new(gameTime.TotalGameTime, gameTime.ElapsedGameTime);
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static Vector2D ToVector2D(this Vector2 vector) => new(vector.X, vector.Y);
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static Color ToColor(this ColorRGBA rgba) => new(rgba.R, rgba.G, rgba.B, rgba.A);
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static Vector2D ToVector2D(this Point point) => new(point.X, point.Y);
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static Vector2 ToVector2(this Vector2D vector) => new(vector.X, vector.Y);
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static Vector2 ToDisplayVector2(this Vector2D vector) => vector.Scale(screenScale).ToVector2();
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static Vector2D ApplyDisplayScale(this Vector2D vector) => vector.Scale(screenScale);
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static Rectangle ToDisplayRectangle(this Rectangle rectangle, DisplayMode displayMode) => new()
|
|
{
|
|
X = rectangle.X,
|
|
Y = displayMode.Height - rectangle.Y - rectangle.Height,
|
|
Width = rectangle.Width,
|
|
Height = rectangle.Height
|
|
};
|
|
}
|