From 93937a8b34c849d83e548905e6821e96b24fbf7f Mon Sep 17 00:00:00 2001 From: Harrison Date: Thu, 28 May 2020 10:20:54 -0500 Subject: [PATCH] Refactoring. --- src/SlatedGameToolkit.Framework/GameEngine.cs | 2 +- .../Graphics/Window/{WindowHandle.cs => WindowContext.cs} | 6 +++--- .../Graphics/Window/WindowManager.cs | 8 ++++---- src/SlatedGameToolkit.Framework/StateSystem/Manager.cs | 2 +- .../StateSystem/States/IState.cs | 2 +- .../Utilities/GraphicalPlayground/MainState.cs | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) rename src/SlatedGameToolkit.Framework/Graphics/Window/{WindowHandle.cs => WindowContext.cs} (98%) diff --git a/src/SlatedGameToolkit.Framework/GameEngine.cs b/src/SlatedGameToolkit.Framework/GameEngine.cs index 76159dd..2b0724f 100644 --- a/src/SlatedGameToolkit.Framework/GameEngine.cs +++ b/src/SlatedGameToolkit.Framework/GameEngine.cs @@ -136,7 +136,7 @@ namespace SlatedGameToolkit.Framework { Keyboard.OnKeyReleased((Key) SDL_Event.key.keysym.sym); break; 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) { case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: diff --git a/src/SlatedGameToolkit.Framework/Graphics/Window/WindowHandle.cs b/src/SlatedGameToolkit.Framework/Graphics/Window/WindowContext.cs similarity index 98% rename from src/SlatedGameToolkit.Framework/Graphics/Window/WindowHandle.cs rename to src/SlatedGameToolkit.Framework/Graphics/Window/WindowContext.cs index ed0f2c5..5068c27 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Window/WindowHandle.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Window/WindowContext.cs @@ -31,7 +31,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window /// A handle for a window. /// This object itself is not thread safe. /// - public sealed class WindowHandle : IDisposable + public sealed class WindowContext : IDisposable { /// /// The pointer referencing the SDL window. @@ -260,7 +260,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window /// /// Instantiates a window handle. /// - 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)); 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) { @@ -353,7 +353,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window focusGainedEvent?.Invoke(); } - ~WindowHandle() { + ~WindowContext() { Dispose(); } } diff --git a/src/SlatedGameToolkit.Framework/Graphics/Window/WindowManager.cs b/src/SlatedGameToolkit.Framework/Graphics/Window/WindowManager.cs index 96ef224..8c9b9a0 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Window/WindowManager.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Window/WindowManager.cs @@ -3,19 +3,19 @@ using System.Collections.Generic; namespace SlatedGameToolkit.Framework.Graphics.Window { internal static class WindowManager { - private static Dictionary existingWindows = new Dictionary(); + private static Dictionary existingWindows = new Dictionary(); - internal static void RegisterWindow(WindowHandle windowHandle) { + internal static void RegisterWindow(WindowContext windowHandle) { GameEngine.Logger.Debug("Registering window: " + windowHandle.WindowID); existingWindows.Add(windowHandle.WindowID, windowHandle); } - internal static void DeregisterWindow(WindowHandle windowHandle) { + internal static void DeregisterWindow(WindowContext windowHandle) { GameEngine.Logger.Debug("Deregistering window: " + windowHandle.WindowID); existingWindows.Remove(windowHandle.WindowID); } - internal static WindowHandle HandleFromID(uint ID) { + internal static WindowContext HandleFromID(uint ID) { return existingWindows[ID]; } } diff --git a/src/SlatedGameToolkit.Framework/StateSystem/Manager.cs b/src/SlatedGameToolkit.Framework/StateSystem/Manager.cs index 606cccd..62a99ee 100644 --- a/src/SlatedGameToolkit.Framework/StateSystem/Manager.cs +++ b/src/SlatedGameToolkit.Framework/StateSystem/Manager.cs @@ -10,7 +10,7 @@ using SlatedGameToolkit.Framework.StateSystem.States; namespace SlatedGameToolkit.Framework.StateSystem { public sealed class Manager : IDisposable { - public WindowHandle CurrentWindow { get; private set; } + public WindowContext CurrentWindow { get; private set; } public Thread thread; public Colour backgroundColour; private IState currentState; diff --git a/src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs b/src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs index 1cdc29b..3e53871 100644 --- a/src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs +++ b/src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs @@ -5,7 +5,7 @@ namespace SlatedGameToolkit.Framework.StateSystem.States { public interface IState { - WindowHandle CurrentWindow { get; } + WindowContext CurrentWindow { get; } /// /// Called when this state should be deactivated. diff --git a/src/SlatedGameToolkit.Tools/Utilities/GraphicalPlayground/MainState.cs b/src/SlatedGameToolkit.Tools/Utilities/GraphicalPlayground/MainState.cs index bca2537..db43ae4 100644 --- a/src/SlatedGameToolkit.Tools/Utilities/GraphicalPlayground/MainState.cs +++ b/src/SlatedGameToolkit.Tools/Utilities/GraphicalPlayground/MainState.cs @@ -8,9 +8,9 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground { 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() { @@ -34,7 +34,7 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground public void Initialize(Manager manager) { - window = new WindowHandle("SlatedGameToolkit Playground"); + window = new WindowContext("SlatedGameToolkit Playground"); window.RaiseToTop(); }