Browse Source

WIP: Beginning to improve composition.

* Added code to change the windowing in Sample.Sprites to test
      composition and camera movements.
    * Added the ability to change the window title.
improved_timing
Ian Burgmyer 5 years ago
parent
commit
db8107632c
  1. 11
      DotSDL/Graphics/SdlWindow.cs
  2. 8
      DotSDL/Interop/Core/Video.cs
  3. 1
      Samples/Sample.Sprites/Player.cs
  4. 25
      Samples/Sample.Sprites/Window.cs

11
DotSDL/Graphics/SdlWindow.cs

@ -11,6 +11,7 @@ namespace DotSDL.Graphics {
public class SdlWindow : IResourceObject {
private readonly SdlInit _sdlInit = SdlInit.Instance;
private readonly ResourceManager _resources = ResourceManager.Instance;
private string _windowTitle;
private readonly IntPtr _window;
private readonly IntPtr _renderer;
@ -39,6 +40,15 @@ namespace DotSDL.Graphics {
/// <summary>Gets the height of this <see cref="SdlWindow"/>.</summary>
public int WindowHeight { get; }
/// <summary>Gets or sets the title of this <see cref="SdlWindow"/>.</summary>
public string WindowTitle {
get => _windowTitle;
set {
_windowTitle = value;
Video.SetWindowTitle(_window, _windowTitle);
}
}
/// <summary>Gets the width of the rendering target used by this <see cref="SdlWindow"/>.</summary>
public int TextureWidth { get; }
/// <summary>Gets the height of the rendering target used by this <see cref="SdlWindow"/>.</summary>
@ -148,6 +158,7 @@ namespace DotSDL.Graphics {
public SdlWindow(string title, Point position, int windowWidth, int windowHeight, int textureWidth, int textureHeight, ScalingQuality scalingQuality) {
_sdlInit.InitSubsystem(Init.SubsystemFlags.Video);
_windowTitle = title;
_window = Video.CreateWindow(title, position.X, position.Y, windowWidth, windowHeight, Video.WindowFlags.Hidden);
_renderer = Render.CreateRenderer(_window, -1, Render.RendererFlags.Accelerated);

8
DotSDL/Interop/Core/Video.cs

@ -103,6 +103,14 @@ namespace DotSDL.Interop.Core {
[DllImport(Meta.CoreLib, EntryPoint = "SDL_GetWindowID", CallingConvention = CallingConvention.Cdecl)]
internal static extern uint GetWindowId(IntPtr window);
/// <summary>
/// Sets the title of an SDL window.
/// </summary>
/// <param name="window">The window to set the title of.</param>
/// <param name="title">The string to set the window title to.</param>
[DllImport(Meta.CoreLib, EntryPoint = "SDL_SetWindowTitle", CallingConvention = CallingConvention.Cdecl)]
internal static extern void SetWindowTitle(IntPtr window, string title);
/// <summary>
/// Shows an SDL window.
/// </summary>

1
Samples/Sample.Sprites/Player.cs

@ -39,7 +39,6 @@ namespace Sample.Sprites {
// Increase the brightness and alpha as we move further inside.
_color.A = (byte)(baseAlpha + ((float)Radius - x + 1) / Radius * (255 - baseAlpha));
System.Console.WriteLine(_color.A);
var newR = (short)(_color.R * 1.1);
_color.R = (byte)(newR > 255 ? 255 : newR);

25
Samples/Sample.Sprites/Window.cs

@ -155,6 +155,31 @@ namespace Sample.Sprites {
_player1.Move(_player1Delta);
_player2.Move(_player2Delta);
var x1 = _player1.Position.X <= _player2.Position.X
? _player1.Position.X - (_player1.Width * _player1.Scale.X)
: _player2.Position.X - (_player2.Width * _player2.Scale.X);
var x2 = _player1.Position.X >= _player2.Position.X
? _player1.Position.X + (_player1.Width * _player1.Scale.X)
: _player2.Position.X + (_player2.Width * _player2.Scale.X);
var y1 = _player1.Position.Y <= _player2.Position.Y
? _player1.Position.Y - (_player1.Height * _player1.Scale.Y)
: _player2.Position.Y - (_player2.Height * _player2.Scale.Y);
var y2 = _player1.Position.Y >= _player2.Position.Y
? _player1.Position.Y + (_player1.Height * _player1.Scale.Y)
: _player2.Position.Y + (_player2.Height * _player2.Scale.Y);
x1 = x1 < 0 ? 0 : x1;
x2 = x2 >= Background.Width ? Background.Width : x2;
y1 = y1 < 0 ? 0 : y1;
y2 = y2 >= Background.Height ? Background.Height : y2;
Background.Clipping.Position.X = (int)x1;
Background.Clipping.Position.Y = (int)y1;
Background.Clipping.Size.X = (int)(x2 - x1);
Background.Clipping.Size.Y = (int)(y2 - y1);
WindowTitle = $"({(int)x1} {(int)y2}), ({(int)(x2 - x1)}, {(int)(y2 - y1)}) / ({Background.Width}, {Background.Height})";
/*_camX += _deltaX;
_camY += _deltaY;

Loading…
Cancel
Save