From 1e6d4026da0bf195c81a2414c33a577c42f3fd29 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 22 Jul 2021 17:02:27 +0200 Subject: [PATCH] Change `WindowBase` to allow for better code sharing for platforms without advanced windowing --- .../Engine/Platform/Android/AndroidWindow.cpp | 81 ------------------- .../Engine/Platform/Android/AndroidWindow.h | 21 ----- Source/Engine/Platform/Base/WindowBase.cpp | 9 ++- Source/Engine/Platform/Base/WindowBase.h | 62 +++++++++----- 4 files changed, 48 insertions(+), 125 deletions(-) diff --git a/Source/Engine/Platform/Android/AndroidWindow.cpp b/Source/Engine/Platform/Android/AndroidWindow.cpp index 4d3c4ca67..497ef64e4 100644 --- a/Source/Engine/Platform/Android/AndroidWindow.cpp +++ b/Source/Engine/Platform/Android/AndroidWindow.cpp @@ -6,17 +6,8 @@ #include "Engine/Graphics/RenderTask.h" #include -#define DefaultDPI 96 - AndroidWindow::AndroidWindow(const CreateWindowSettings& settings) : WindowBase(settings) -{ - _clientSize = settings.Size; - _dpi = DefaultDPI; - _dpiScale = (float)_dpi / (float)DefaultDPI; -} - -AndroidWindow::~AndroidWindow() { } @@ -52,27 +43,6 @@ void AndroidWindow::Hide() } } -void AndroidWindow::Minimize() -{ -} - -void AndroidWindow::Maximize() -{ -} - -void AndroidWindow::Restore() -{ -} - -void AndroidWindow::BringToFront(bool force) -{ -} - -bool AndroidWindow::IsClosed() const -{ - return _isClosing; -} - void AndroidWindow::SetClientBounds(const Rectangle& clientArea) { if (Vector2::NearEqual(_clientSize, clientArea.Size)) @@ -84,55 +54,4 @@ void AndroidWindow::SetClientBounds(const Rectangle& clientArea) OnResize(width, height); } -void AndroidWindow::SetPosition(const Vector2& position) -{ -} - -void AndroidWindow::SetClientPosition(const Vector2& position) -{ -} - -Vector2 AndroidWindow::GetPosition() const -{ - return Vector2::Zero; -} - -Vector2 AndroidWindow::GetSize() const -{ - return _clientSize; -} - -Vector2 AndroidWindow::GetClientSize() const -{ - return _clientSize; -} - -Vector2 AndroidWindow::ScreenToClient(const Vector2& screenPos) const -{ - return screenPos; -} - -Vector2 AndroidWindow::ClientToScreen(const Vector2& clientPos) const -{ - return clientPos; -} - -void AndroidWindow::SetTitle(const StringView& title) -{ - _title = title; -} - -DragDropEffect AndroidWindow::DoDragDrop(const StringView& data) -{ - return DragDropEffect::None; -} - -void AndroidWindow::StartTrackingMouse(bool useMouseScreenOffset) -{ -} - -void AndroidWindow::EndTrackingMouse() -{ -} - #endif diff --git a/Source/Engine/Platform/Android/AndroidWindow.h b/Source/Engine/Platform/Android/AndroidWindow.h index 85ef626bc..56a71d4f7 100644 --- a/Source/Engine/Platform/Android/AndroidWindow.h +++ b/Source/Engine/Platform/Android/AndroidWindow.h @@ -21,34 +21,13 @@ public: /// The initial window settings. AndroidWindow(const CreateWindowSettings& settings); - /// - /// Finalizes an instance of the class. - /// - ~AndroidWindow(); - public: // [Window] void* GetNativePtr() const override; void Show() override; void Hide() override; - void Minimize() override; - void Maximize() override; - void Restore() override; - bool IsClosed() const override; - void BringToFront(bool force = false) override; void SetClientBounds(const Rectangle& clientArea) override; - void SetPosition(const Vector2& position) override; - void SetClientPosition(const Vector2& position) override; - Vector2 GetPosition() const override; - Vector2 GetSize() const override; - Vector2 GetClientSize() const override; - Vector2 ScreenToClient(const Vector2& screenPos) const override; - Vector2 ClientToScreen(const Vector2& clientPos) const override; - void SetTitle(const StringView& title) override; - DragDropEffect DoDragDrop(const StringView& data) override; - void StartTrackingMouse(bool useMouseScreenOffset) override; - void EndTrackingMouse() override; }; #endif diff --git a/Source/Engine/Platform/Base/WindowBase.cpp b/Source/Engine/Platform/Base/WindowBase.cpp index 77e8e7e15..19dfb3b27 100644 --- a/Source/Engine/Platform/Base/WindowBase.cpp +++ b/Source/Engine/Platform/Base/WindowBase.cpp @@ -81,19 +81,20 @@ WindowBase::WindowBase(const CreateWindowSettings& settings) , _minimized(false) , _maximized(false) , _isClosing(false) + , _showAfterFirstPaint(settings.ShowAfterFirstPaint) , _focused(false) , _swapChain(nullptr) , _settings(settings) , _title(settings.Title) , _cursor(CursorType::Default) + , _clientSize(settings.Size) + , _dpi(96) + , _dpiScale(1.0f) , _trackingMouseOffset(Vector2::Zero) , _isUsingMouseOffset(false) , _isTrackingMouse(false) , RenderTask(nullptr) { - _showAfterFirstPaint = settings.ShowAfterFirstPaint; - _clientSize = Vector2(settings.Size.X, settings.Size.Y); - // Update window location based on start location if (settings.StartPosition == WindowStartPosition::CenterParent || settings.StartPosition == WindowStartPosition::CenterScreen) @@ -522,6 +523,8 @@ void WindowBase::Show() void WindowBase::Hide() { + if (!_visible) + return; _visible = false; _showAfterFirstPaint = _settings.ShowAfterFirstPaint; Hidden(); diff --git a/Source/Engine/Platform/Base/WindowBase.h b/Source/Engine/Platform/Base/WindowBase.h index b432a8a4d..799a3866e 100644 --- a/Source/Engine/Platform/Base/WindowBase.h +++ b/Source/Engine/Platform/Base/WindowBase.h @@ -435,17 +435,23 @@ public: /// /// Minimizes the window. /// - API_FUNCTION() virtual void Minimize() = 0; + API_FUNCTION() virtual void Minimize() + { + } /// /// Maximizes the window. /// - API_FUNCTION() virtual void Maximize() = 0; + API_FUNCTION() virtual void Maximize() + { + } /// /// Restores the window state before minimizing or maximizing. /// - API_FUNCTION() virtual void Restore() = 0; + API_FUNCTION() virtual void Restore() + { + } /// /// Closes the window. @@ -456,8 +462,10 @@ public: /// /// Checks if window is closed. /// - /// True if window is closed, otherwise false. - API_PROPERTY() virtual bool IsClosed() const = 0; + API_PROPERTY() virtual bool IsClosed() const + { + return _isClosing; + } /// /// Checks if window is foreground (the window with which the user is currently working). @@ -470,7 +478,6 @@ public: /// /// Gets the client bounds of the window (client area not including border). /// - /// Client bounds. API_PROPERTY() FORCE_INLINE Rectangle GetClientBounds() const { return Rectangle(GetClientPosition(), GetClientSize()); @@ -480,24 +487,29 @@ public: /// Sets the client bounds of the window (client area not including border). /// /// The client area. - API_PROPERTY() virtual void SetClientBounds(const Rectangle& clientArea) = 0; + API_PROPERTY() virtual void SetClientBounds(const Rectangle& clientArea) + { + } /// /// Gets the window position (in screen coordinates). /// - /// Window position. - API_PROPERTY() virtual Vector2 GetPosition() const = 0; + API_PROPERTY() virtual Vector2 GetPosition() const + { + return Vector2::Zero; + } /// /// Sets the window position (in screen coordinates). /// /// The position. - API_PROPERTY() virtual void SetPosition(const Vector2& position) = 0; + API_PROPERTY() virtual void SetPosition(const Vector2& position) + { + } /// /// Gets the client position of the window (client area not including border). /// - /// The client area position. API_PROPERTY() FORCE_INLINE Vector2 GetClientPosition() const { return ClientToScreen(Vector2::Zero); @@ -507,19 +519,25 @@ public: /// Sets the client position of the window (client area not including border) /// /// The client area position. - API_PROPERTY() virtual void SetClientPosition(const Vector2& position) = 0; + API_PROPERTY() virtual void SetClientPosition(const Vector2& position) + { + } /// /// Gets the window size (including border). /// - /// The window size - API_PROPERTY() virtual Vector2 GetSize() const = 0; + API_PROPERTY() virtual Vector2 GetSize() const + { + return _clientSize; + } /// /// Gets the size of the client area of the window (not including border). /// - /// The window client area size. - API_PROPERTY() virtual Vector2 GetClientSize() const = 0; + API_PROPERTY() virtual Vector2 GetClientSize() const + { + return _clientSize; + } /// /// Sets the size of the client area of the window (not including border). @@ -535,14 +553,20 @@ public: /// /// The screen position. /// The client space position. - API_FUNCTION() virtual Vector2 ScreenToClient(const Vector2& screenPos) const = 0; + API_FUNCTION() virtual Vector2 ScreenToClient(const Vector2& screenPos) const + { + return screenPos; + } /// /// Converts window space location into screen space coordinates. /// /// The client position. /// The screen space position. - API_FUNCTION() virtual Vector2 ClientToScreen(const Vector2& clientPos) const = 0; + API_FUNCTION() virtual Vector2 ClientToScreen(const Vector2& clientPos) const + { + return clientPos; + } /// /// Gets the window DPI setting. @@ -582,7 +606,6 @@ public: /// /// Gets window opacity value (valid only for windows created with SupportsTransparency flag). Opacity values are normalized to range [0;1]. /// - /// Window opacity. API_PROPERTY() virtual float GetOpacity() const { return 1.0f; @@ -599,7 +622,6 @@ public: /// /// Determines whether this window is focused. /// - /// true if this window is focused; otherwise, false. API_PROPERTY() FORCE_INLINE bool IsFocused() const { return _focused;