Added Summeries
This commit is contained in:
parent
71a22df8bd
commit
8296d9b8a9
47 changed files with 812 additions and 177 deletions
|
|
@ -18,17 +18,80 @@ using Mouse = SM.Base.Controls.Mouse;
|
|||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
/// <summary>
|
||||
/// This provides the main entry, by executing the window.
|
||||
/// </summary>
|
||||
public class GLWindow : GameWindow, IGenericWindow
|
||||
{
|
||||
private Vector2 _flagWindowSize;
|
||||
private Thread _fixedUpdateThread;
|
||||
private WindowFlags _windowFlags;
|
||||
|
||||
public WindowFlags WindowFlags;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Loading { get; private set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public float AspectRatio { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public GenericCamera ViewportCamera { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ForceViewportCamera { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool DrawWhileUnfocused { get; set; } = true;
|
||||
/// <inheritdoc />
|
||||
public bool UpdateWhileUnfocused { get; set; } = false;
|
||||
/// <inheritdoc />
|
||||
public Vector2 WindowSize { get; set; }
|
||||
/// <inheritdoc />
|
||||
public ISetup AppliedSetup { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public new event Action<IGenericWindow> Resize;
|
||||
/// <inheritdoc />
|
||||
public new event Action<IGenericWindow> Load;
|
||||
|
||||
/// <inheritdoc />
|
||||
public GenericScene CurrentScene { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public RenderPipeline CurrentRenderPipeline { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the current window flag.
|
||||
/// </summary>
|
||||
public WindowFlags WindowFlags
|
||||
{
|
||||
get => _windowFlags;
|
||||
set
|
||||
{
|
||||
if (_windowFlags != value)
|
||||
{
|
||||
_windowFlags = value;
|
||||
ChangeWindowFlag(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the window with default values.
|
||||
/// <para>Width: 1280px; Height: 720px; Title: Generic OpenGL Title; WindowFlag: Window</para>
|
||||
/// </summary>
|
||||
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the window with custom values.
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="flags"></param>
|
||||
/// <param name="vSync"></param>
|
||||
public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) :
|
||||
base(width, height, default, title, (GameWindowFlags) flags, DisplayDevice.Default,
|
||||
GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion,
|
||||
|
|
@ -37,39 +100,16 @@ namespace SM.Base.Window
|
|||
VSync = vSync;
|
||||
_flagWindowSize = new Vector2(width, height);
|
||||
|
||||
ChangeWindowFlag(flags);
|
||||
WindowFlags = flags;
|
||||
}
|
||||
|
||||
public bool Loading { get; private set; } = true;
|
||||
public float AspectRatio { get; set; }
|
||||
|
||||
public GenericCamera ViewportCamera { get; set; }
|
||||
public bool ForceViewportCamera { get; set; }
|
||||
|
||||
public bool DrawWhileUnfocused { get; set; } = true;
|
||||
public bool UpdateWhileUnfocused { get; set; } = false;
|
||||
|
||||
public Vector2 WindowSize { get; set; }
|
||||
|
||||
public ISetup AppliedSetup { get; private set; }
|
||||
public new event Action<IGenericWindow> Resize;
|
||||
public new event Action<IGenericWindow> Load;
|
||||
|
||||
public GenericScene CurrentScene { get; private set; }
|
||||
public RenderPipeline CurrentRenderPipeline { get; private set; }
|
||||
|
||||
public void TriggerLoad()
|
||||
{
|
||||
Load?.Invoke(this);
|
||||
}
|
||||
|
||||
public void TriggerResize()
|
||||
{
|
||||
Resize?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A event that gets executed when the window is done loading.
|
||||
/// </summary>
|
||||
public event Action<IGenericWindow> Loaded;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
WindowCode.Load(this);
|
||||
|
|
@ -78,6 +118,7 @@ namespace SM.Base.Window
|
|||
base.OnLoad(e);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
|
@ -94,6 +135,7 @@ namespace SM.Base.Window
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if (!Focused && !UpdateWhileUnfocused) return;
|
||||
|
|
@ -104,6 +146,7 @@ namespace SM.Base.Window
|
|||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnRenderFrame(e);
|
||||
|
|
@ -115,23 +158,40 @@ namespace SM.Base.Window
|
|||
GLDebugging.CheckGLErrors();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnMouseMove(MouseMoveEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
Mouse.MouseMoveEvent(e, this);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public void TriggerLoad()
|
||||
{
|
||||
Load?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void TriggerResize()
|
||||
{
|
||||
Resize?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Update(UpdateContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ApplySetup(ISetup setup)
|
||||
{
|
||||
AppliedSetup = setup;
|
||||
setup.Applied(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetScene(GenericScene scene)
|
||||
{
|
||||
if (Loading)
|
||||
|
|
@ -144,6 +204,7 @@ namespace SM.Base.Window
|
|||
CurrentScene = scene;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetRenderPipeline(RenderPipeline renderPipeline)
|
||||
{
|
||||
if (Loading)
|
||||
|
|
@ -156,34 +217,12 @@ namespace SM.Base.Window
|
|||
CurrentRenderPipeline = renderPipeline;
|
||||
}
|
||||
|
||||
public void ChangeWindowFlag(WindowFlags newFlag)
|
||||
{
|
||||
WindowFlags = newFlag;
|
||||
|
||||
switch (newFlag)
|
||||
{
|
||||
case WindowFlags.Window:
|
||||
Width = (int) _flagWindowSize.X;
|
||||
Height = (int) _flagWindowSize.Y;
|
||||
|
||||
WindowBorder = WindowBorder.Resizable;
|
||||
break;
|
||||
case WindowFlags.BorderlessWindow:
|
||||
WindowBorder = WindowBorder.Hidden;
|
||||
|
||||
X = Screen.PrimaryScreen.Bounds.Left;
|
||||
Y = Screen.PrimaryScreen.Bounds.Top;
|
||||
Width = Screen.PrimaryScreen.Bounds.Width;
|
||||
Height = Screen.PrimaryScreen.Bounds.Height;
|
||||
|
||||
break;
|
||||
case WindowFlags.ExclusiveFullscreen:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the fixed update loop.
|
||||
/// <para>Need to get executed before <see cref="IFixedScriptable"/> can be used.</para>
|
||||
/// </summary>
|
||||
/// <param name="updatesPerSecond"></param>
|
||||
public void RunFixedUpdate(float updatesPerSecond)
|
||||
{
|
||||
Deltatime.FixedUpdateDelta = 1 / (float)updatesPerSecond;
|
||||
|
|
@ -208,5 +247,31 @@ namespace SM.Base.Window
|
|||
Thread.Sleep(waitTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeWindowFlag(WindowFlags newFlag)
|
||||
{
|
||||
switch (newFlag)
|
||||
{
|
||||
case WindowFlags.Window:
|
||||
Width = (int)_flagWindowSize.X;
|
||||
Height = (int)_flagWindowSize.Y;
|
||||
|
||||
WindowBorder = WindowBorder.Resizable;
|
||||
break;
|
||||
case WindowFlags.BorderlessWindow:
|
||||
WindowBorder = WindowBorder.Hidden;
|
||||
|
||||
X = Screen.PrimaryScreen.Bounds.Left;
|
||||
Y = Screen.PrimaryScreen.Bounds.Top;
|
||||
Width = Screen.PrimaryScreen.Bounds.Width;
|
||||
Height = Screen.PrimaryScreen.Bounds.Height;
|
||||
|
||||
break;
|
||||
case WindowFlags.ExclusiveFullscreen:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue