From 7b8133988903d94fa0918e0ec152c64bea1fbc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Mon, 16 Nov 2020 21:44:53 +0100 Subject: [PATCH] Window platform implementation now via extension --- GlitchyEngine/src/Application.bf | 1 - .../src/Platform/Windows/WindowsInput.bf | 2 +- .../src/Platform/Windows/WindowsWindow.bf | 22 +++------- GlitchyEngine/src/Program.bf | 3 -- GlitchyEngine/src/Window.bf | 42 +++++++++---------- 5 files changed, 26 insertions(+), 44 deletions(-) diff --git a/GlitchyEngine/src/Application.bf b/GlitchyEngine/src/Application.bf index 0690f31..78c4e2c 100644 --- a/GlitchyEngine/src/Application.bf +++ b/GlitchyEngine/src/Application.bf @@ -1,6 +1,5 @@ using System; using GlitchyEngine.Events; -using GlitchyEngine.Platform.Windows; using GlitchyEngine.Platform.DX11; using GlitchyEngine.ImGui; diff --git a/GlitchyEngine/src/Platform/Windows/WindowsInput.bf b/GlitchyEngine/src/Platform/Windows/WindowsInput.bf index 198dc9c..fdca1c1 100644 --- a/GlitchyEngine/src/Platform/Windows/WindowsInput.bf +++ b/GlitchyEngine/src/Platform/Windows/WindowsInput.bf @@ -12,7 +12,7 @@ namespace GlitchyEngine /// Windows (WinApi) specific implementation of the Input-class extension Input { - /// Represents the state of the input devices on the windows plattform (WinApi that is). + /// Represents the state of the input devices on the windows platform (WinApi that is). struct WindowsInputState { public int8[256] KeyStates; diff --git a/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf b/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf index 5e8f3b7..d255631 100644 --- a/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf +++ b/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf @@ -1,3 +1,4 @@ +#if GE_WINDOWS using System; using DirectX.Common; using DirectX.Windows; @@ -12,20 +13,8 @@ using static System.Windows; namespace GlitchyEngine { -#if GE_WINDOWS + /// The windows specific Window implementation public extension Window - { - public static override Window CreateWindow(WindowDescription description) - { - return new GlitchyEngine.Platform.Windows.WindowsWindow(description); - } - } -#endif -} - -namespace GlitchyEngine.Platform.Windows -{ - public class WindowsWindow : Window { private Windows.HInstance _instanceHandle; private Windows.HWnd _windowHandle; @@ -135,8 +124,6 @@ namespace GlitchyEngine.Platform.Windows } } - - public override StringView Title { get @@ -158,7 +145,7 @@ namespace GlitchyEngine.Platform.Windows public override void* NativeWindow => (void*)(int)_windowHandle; - public this(WindowDescription desc) + public override this(WindowDescription desc) { _minMaxInfo.MaximumTrackingSize.x = int32.MaxValue; _minMaxInfo.MaximumTrackingSize.y = int32.MaxValue; @@ -215,7 +202,7 @@ namespace GlitchyEngine.Platform.Windows private static LRESULT MessageHandler(HWND hwnd, uint32 uMsg, WPARAM wParam, LPARAM lParam) { void* windowPtr = (void*)GetWindowLongPtrW(hwnd, GWL_USERDATA); - WindowsWindow window = (WindowsWindow)Internal.UnsafeCastToObject(windowPtr); + Window window = (Window)Internal.UnsafeCastToObject(windowPtr); if (window == null) { @@ -472,3 +459,4 @@ namespace GlitchyEngine.Platform.Windows } } } +#endif \ No newline at end of file diff --git a/GlitchyEngine/src/Program.bf b/GlitchyEngine/src/Program.bf index a2c792d..3fe0c5a 100644 --- a/GlitchyEngine/src/Program.bf +++ b/GlitchyEngine/src/Program.bf @@ -1,9 +1,6 @@ using System; using GlitchLog; using System.Diagnostics; -using GlitchyEngine.Platform.Windows; - -//using imgui_beef; namespace GlitchyEngine { diff --git a/GlitchyEngine/src/Window.bf b/GlitchyEngine/src/Window.bf index c6720d1..d2a99ef 100644 --- a/GlitchyEngine/src/Window.bf +++ b/GlitchyEngine/src/Window.bf @@ -28,70 +28,73 @@ namespace GlitchyEngine } } - public abstract class Window + public class Window { public delegate void EventCallback(Event e); protected EventCallback _eventCallback ~ delete _; + + public extern this(WindowDescription windowDescription); /** * Gets or Sets the minimum width of the window. */ - public abstract int32 MinWidth {get; set;} + public extern int32 MinWidth {get; set;} /** * Gets or Sets the minimum height of the window. */ - public abstract int32 MinHeight {get; set;} + public extern int32 MinHeight {get; set;} /** * Gets or Sets the maximum width of the window. */ - public abstract int32 MaxWidth {get; set;} + public extern int32 MaxWidth {get; set;} /** * Gets or Sets the maximum height of the window. */ - public abstract int32 MaxHeight {get; set;} + public extern int32 MaxHeight {get; set;} /** * Gets or Sets the width and height of the window. */ - public abstract Point Size {get; set;} + public extern Point Size {get; set;} /** * Gets or Sets the width of the window. */ - public abstract int32 Width {get; set;} + public extern int32 Width {get; set;} /** * Gets or Sets the height of the window. */ - public abstract int32 Height {get; set;} + public extern int32 Height {get; set;} /** * Gets or Sets the position of the upper-left corner of the client area of the window. */ - public abstract Point Position {get; set;} + public extern Point Position {get; set;} /** * Gets or Sets the x-coordinate of the upper-left corner of the client area of the window. */ - public abstract int32 PositionX {get; set;} + public extern int32 PositionX {get; set;} /** * Gets or Sets the y-coordinate of the upper-left corner of the client area of the window. */ - public abstract int32 PositionY {get; set;} + public extern int32 PositionY {get; set;} /** * Gets or Sets the windows title. */ - public abstract StringView Title {get; set;} + public extern StringView Title {get; set;} /** * Gets or Sets whether or not the application uses VSync */ - public abstract bool IsVSync {get; set;} + public extern bool IsVSync {get; set;} - - - public abstract void* NativeWindow {get;} + /** + * Gets a pointer to the platform specific window representation. + */ + public extern void* NativeWindow {get;} public EventCallback EventCallback { @@ -99,11 +102,6 @@ namespace GlitchyEngine set => _eventCallback = value; } - public abstract void Update(); - - /** - * Function used to create a platform specific window. - */ - public static extern Window CreateWindow(WindowDescription description); + public extern void Update(); } }