// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #if PLATFORM_WINDOWS #include "Engine/Platform/Base/WindowBase.h" #include "Engine/Platform/Platform.h" #include "WindowsInput.h" /// /// Implementation of the window class for Windows platform /// class FLAXENGINE_API WindowsWindow : public WindowBase #if USE_EDITOR , public Windows::IDropTarget #endif { friend WindowsPlatform; private: Windows::HWND _handle; #if USE_EDITOR Windows::ULONG _refCount; #endif bool _isResizing = false; bool _isSwitchingFullScreen = false; bool _trackingMouse = false; bool _clipCursorSet = false; bool _isDuringMaximize = false; Windows::HANDLE _monitor = nullptr; Windows::LONG _clipCursorRect[4]; int32 _regionWidth = 0, _regionHeight = 0; public: /// /// Initializes a new instance of the class. /// /// The initial window settings. WindowsWindow(const CreateWindowSettings& settings); /// /// Finalizes an instance of the class. /// ~WindowsWindow(); public: /// /// Gets the window handle. /// /// The window handle. FORCE_INLINE Windows::HWND GetHWND() const { return _handle; } /// /// Checks if the window has valid handle created. /// /// True if has valid handle, otherwise false. FORCE_INLINE bool HasHWND() const { return _handle != nullptr; } /// /// Gets the information about screen which contains window. /// /// The x position. /// The y position. /// The width. /// The height. void GetScreenInfo(int32& x, int32& y, int32& width, int32& height) const; public: /// /// The Windows messages procedure. /// /// The mMessage. /// The first parameter. /// The second parameter. /// The result. Windows::LRESULT WndProc(Windows::UINT msg, Windows::WPARAM wParam, Windows::LPARAM lParam); private: void CheckForWindowResize(); void UpdateCursor() const; void UpdateRegion(); public: // [WindowBase] void* GetNativePtr() const override; void Show() override; void Hide() override; void Minimize() override; void Maximize() override; void SetBorderless(bool isBorderless, bool maximized = false) override; void Restore() override; bool IsClosed() const override; bool IsForegroundWindow() const override; void BringToFront(bool force = false) override; void SetClientBounds(const Rectangle& clientArea) override; void SetPosition(const Float2& position) override; void SetClientPosition(const Float2& position) override; void SetIsFullscreen(bool isFullscreen) override; Float2 GetPosition() const override; Float2 GetSize() const override; Float2 GetClientSize() const override; Float2 ScreenToClient(const Float2& screenPos) const override; Float2 ClientToScreen(const Float2& clientPos) const override; void FlashWindow() override; float GetOpacity() const override; void SetOpacity(float opacity) override; void Focus() override; void SetTitle(const StringView& title) override; DragDropEffect DoDragDrop(const StringView& data) override; void StartTrackingMouse(bool useMouseScreenOffset) override; void EndTrackingMouse() override; void StartClippingCursor(const Rectangle& bounds) override; void EndClippingCursor() override; void SetCursor(CursorType type) override; #if USE_EDITOR // [IUnknown] Windows::HRESULT __stdcall QueryInterface(const Windows::IID& id, void** ppvObject) override; Windows::ULONG __stdcall AddRef() override; Windows::ULONG __stdcall Release() override; // [IDropTarget] Windows::HRESULT __stdcall DragEnter(Windows::IDataObject* pDataObj, Windows::DWORD grfKeyState, Windows::POINTL pt, Windows::DWORD* pdwEffect) override; Windows::HRESULT __stdcall DragOver(Windows::DWORD grfKeyState, Windows::POINTL pt, Windows::DWORD* pdwEffect) override; Windows::HRESULT __stdcall DragLeave() override; Windows::HRESULT __stdcall Drop(Windows::IDataObject* pDataObj, Windows::DWORD grfKeyState, Windows::POINTL pt, Windows::DWORD* pdwEffect) override; #endif }; #endif