Refactoring.

This commit is contained in:
Harrison Deng 2020-05-28 10:20:54 -05:00
parent fb9bbdd123
commit 93937a8b34
6 changed files with 13 additions and 13 deletions

View File

@ -136,7 +136,7 @@ namespace SlatedGameToolkit.Framework {
Keyboard.OnKeyReleased((Key) SDL_Event.key.keysym.sym); Keyboard.OnKeyReleased((Key) SDL_Event.key.keysym.sym);
break; break;
case SDL.SDL_EventType.SDL_WINDOWEVENT: case SDL.SDL_EventType.SDL_WINDOWEVENT:
WindowHandle handle = WindowManager.HandleFromID(SDL_Event.window.windowID); WindowContext handle = WindowManager.HandleFromID(SDL_Event.window.windowID);
switch (SDL_Event.window.windowEvent) switch (SDL_Event.window.windowEvent)
{ {
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:

View File

@ -31,7 +31,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
/// A handle for a window. /// A handle for a window.
/// This object itself is not thread safe. /// This object itself is not thread safe.
/// </summary> /// </summary>
public sealed class WindowHandle : IDisposable public sealed class WindowContext : IDisposable
{ {
/// <summary> /// <summary>
/// The pointer referencing the SDL window. /// The pointer referencing the SDL window.
@ -260,7 +260,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
/// <summary> /// <summary>
/// Instantiates a window handle. /// Instantiates a window handle.
/// </summary> /// </summary>
public WindowHandle(string title, int x = -1, int y = -1, int width = 640, int height = 480, bool specialRegions = false, WindowOption options = default(WindowOption)) { public WindowContext(string title, int x = -1, int y = -1, int width = 640, int height = 480, bool specialRegions = false, WindowOption options = default(WindowOption)) {
GameEngine.Logger.Information(String.Format("Starting openGL window with title \"{0}\"", title)); GameEngine.Logger.Information(String.Format("Starting openGL window with title \"{0}\"", title));
window = SDL.SDL_CreateWindow(title, x < 0 ? SDL.SDL_WINDOWPOS_CENTERED : x, y < 0 ? SDL.SDL_WINDOWPOS_CENTERED : y, width, height, SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS | (SDL.SDL_WindowFlags) options); window = SDL.SDL_CreateWindow(title, x < 0 ? SDL.SDL_WINDOWPOS_CENTERED : x, y < 0 ? SDL.SDL_WINDOWPOS_CENTERED : y, width, height, SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS | (SDL.SDL_WindowFlags) options);
if (window == null) { if (window == null) {
@ -353,7 +353,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
focusGainedEvent?.Invoke(); focusGainedEvent?.Invoke();
} }
~WindowHandle() { ~WindowContext() {
Dispose(); Dispose();
} }
} }

View File

@ -3,19 +3,19 @@ using System.Collections.Generic;
namespace SlatedGameToolkit.Framework.Graphics.Window namespace SlatedGameToolkit.Framework.Graphics.Window
{ {
internal static class WindowManager { internal static class WindowManager {
private static Dictionary<uint, WindowHandle> existingWindows = new Dictionary<uint, WindowHandle>(); private static Dictionary<uint, WindowContext> existingWindows = new Dictionary<uint, WindowContext>();
internal static void RegisterWindow(WindowHandle windowHandle) { internal static void RegisterWindow(WindowContext windowHandle) {
GameEngine.Logger.Debug("Registering window: " + windowHandle.WindowID); GameEngine.Logger.Debug("Registering window: " + windowHandle.WindowID);
existingWindows.Add(windowHandle.WindowID, windowHandle); existingWindows.Add(windowHandle.WindowID, windowHandle);
} }
internal static void DeregisterWindow(WindowHandle windowHandle) { internal static void DeregisterWindow(WindowContext windowHandle) {
GameEngine.Logger.Debug("Deregistering window: " + windowHandle.WindowID); GameEngine.Logger.Debug("Deregistering window: " + windowHandle.WindowID);
existingWindows.Remove(windowHandle.WindowID); existingWindows.Remove(windowHandle.WindowID);
} }
internal static WindowHandle HandleFromID(uint ID) { internal static WindowContext HandleFromID(uint ID) {
return existingWindows[ID]; return existingWindows[ID];
} }
} }

View File

@ -10,7 +10,7 @@ using SlatedGameToolkit.Framework.StateSystem.States;
namespace SlatedGameToolkit.Framework.StateSystem namespace SlatedGameToolkit.Framework.StateSystem
{ {
public sealed class Manager : IDisposable { public sealed class Manager : IDisposable {
public WindowHandle CurrentWindow { get; private set; } public WindowContext CurrentWindow { get; private set; }
public Thread thread; public Thread thread;
public Colour backgroundColour; public Colour backgroundColour;
private IState currentState; private IState currentState;

View File

@ -5,7 +5,7 @@ namespace SlatedGameToolkit.Framework.StateSystem.States
{ {
public interface IState public interface IState
{ {
WindowHandle CurrentWindow { get; } WindowContext CurrentWindow { get; }
/// <summary> /// <summary>
/// Called when this state should be deactivated. /// Called when this state should be deactivated.

View File

@ -8,9 +8,9 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground
{ {
public class MainState : IState public class MainState : IState
{ {
private WindowHandle window; private WindowContext window;
public WindowHandle CurrentWindow { get { return window;}} public WindowContext CurrentWindow { get { return window;}}
public bool Activate() public bool Activate()
{ {
@ -34,7 +34,7 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground
public void Initialize(Manager manager) public void Initialize(Manager manager)
{ {
window = new WindowHandle("SlatedGameToolkit Playground"); window = new WindowContext("SlatedGameToolkit Playground");
window.RaiseToTop(); window.RaiseToTop();
} }