More nullable fixes, make SetTransform a part of base Renderer.

This commit is contained in:
2024-01-21 17:58:11 +01:00
parent 5f4e32e2e0
commit 5bb16350f3
8 changed files with 59 additions and 59 deletions

View File

@@ -107,14 +107,7 @@ namespace DaggerFramework.Rendering
public override void DrawCircle(float radius, Color color)
{
Raylib.DrawCircle((int)_position.X, (int)_position.Y, radius, DaggerColorToRaylibColor(color));
}
public override void SetTransform(Vector2 position, Vector2 offset, float rotation = 0)
{
_position = position;
_offset = offset;
_rotation = rotation;
Raylib.DrawCircle((int)transformPosition.X, (int)transformPosition.Y, radius, DaggerColorToRaylibColor(color));
}
public override void DrawTexture(Texture2d texture, Color tint)
@@ -124,7 +117,7 @@ namespace DaggerFramework.Rendering
LoadTexture(texture);
}
Raylib.DrawTextureV(_texturePool[texture.Handle], _position, DaggerColorToRaylibColor(tint));
Raylib.DrawTextureV(_texturePool[texture.Handle], transformPosition, DaggerColorToRaylibColor(tint));
}
public override void DrawRectangle(Vector2 size, Color color)
@@ -132,16 +125,16 @@ namespace DaggerFramework.Rendering
// Raylib.DrawRectangleV(_position, size, SystemColorToRaylibColor(color));
Raylib.DrawRectanglePro(new Rectangle()
{
x = _position.X,
y = _position.Y,
x = transformPosition.X,
y = transformPosition.Y,
width = size.X,
height = size.Y
}, _offset, _rotation, DaggerColorToRaylibColor(color));
}, transformOffset, transformRotation, DaggerColorToRaylibColor(color));
}
public override void DrawDebugText(string text, int fontSize, Color color)
{
Raylib.DrawText(text, (int)_position.X, (int)_position.Y, fontSize, DaggerColorToRaylibColor(color));
Raylib.DrawText(text, (int)transformPosition.X, (int)transformPosition.Y, fontSize, DaggerColorToRaylibColor(color));
}
public override void DrawSdfText(string text, int fontSize, Color color)
@@ -191,7 +184,7 @@ namespace DaggerFramework.Rendering
}
var rayFont = _fontPool[font.Handle];
Raylib.DrawTextPro(rayFont, text, _position, Vector2.Zero, _rotation, font.Size, 0.0f, DaggerColorToRaylibColor(color));
Raylib.DrawTextPro(rayFont, text, transformPosition, transformOffset, transformRotation, font.Size, 0.0f, DaggerColorToRaylibColor(color));
}
protected override int GetMonitorWidth(int monitorId)
@@ -266,8 +259,6 @@ namespace DaggerFramework.Rendering
private List<Texture2D> _texturePool = new();
private List<Raylib_cs.Font> _fontPool = new();
private Vector2 _position, _offset;
private float _rotation;
private Vector2 _windowSize;
private bool _vsync;
private string _windowTitle = string.Empty;

View File

@@ -79,13 +79,25 @@ namespace DaggerFramework.Rendering
/// <param name="color">Background color.</param>
public abstract void ClearBackground(Color color);
public void ResetTransform()
{
transformPosition = Vector2.Zero;
transformOffset = Vector2.Zero;
transformRotation = 0.0f;
}
/// <summary>
/// Sets transforms for the next draw operation.
/// </summary>
/// <param name="position">Global transform position.</param>
/// <param name="offset">Local offset point around which shapes will rotate.</param>
/// <param name="rotation">Rotation.</param>
public abstract void SetTransform(Vector2 position, Vector2 offset, float rotation = 0.0f);
public void SetTransform(Vector2 position, Vector2 offset, float rotation = 0.0f)
{
transformPosition = position;
transformOffset = offset;
transformRotation = rotation;
}
/// <summary>
/// Sets the transform for the next draw operation.
/// </summary>
@@ -127,6 +139,9 @@ namespace DaggerFramework.Rendering
/// <param name="id">Texture to draw.</param>
/// <param name="tint">Texture tint.</param>
public abstract void DrawTexture(Texture2d texture, Color tint);
protected Vector2 transformPosition, transformOffset;
protected float transformRotation;
}
public enum Msaa

View File

@@ -100,12 +100,6 @@ namespace DaggerFramework.Rendering
return;
}
/// <inheritdoc />
public override void SetTransform(Vector2 position, Vector2 offset, float rotation = 0)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override void SetTransform(Matrix4x4 transform)
{

View File

@@ -6,7 +6,7 @@ namespace DaggerFramework.SceneGraph
public class EntityLayer : Layer
{
public List<Entity> Entities { get => _entities; }
public Camera2d CurrentCamera { get; set; }
public Camera2d? CurrentCamera { get; set; }
public EntityLayer(List<Entity> entities)
{
@@ -76,8 +76,7 @@ namespace DaggerFramework.SceneGraph
protected override void OnBeginDraw(Renderer renderer)
{
var hasCamera = CurrentCamera != null;
if (hasCamera)
if (CurrentCamera is not null)
{
renderer.BeginCamera2d(CurrentCamera.Offset, CurrentCamera.Position, 0f, CurrentCamera.Zoom);
}
@@ -85,8 +84,7 @@ namespace DaggerFramework.SceneGraph
protected override void OnEndDraw(Renderer renderer)
{
var hasCamera = CurrentCamera != null;
if (hasCamera)
if (CurrentCamera is not null)
{
renderer.EndCamera2d();
}

View File

@@ -72,6 +72,8 @@ namespace DaggerFramework.SceneGraph
layer.BeginDraw(_renderer);
layer.Draw(_renderer);
}
Renderer.ResetTransform();
}
public void EndDraw()