| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "RenderAPI/BsRenderTarget.h"
- #include "RenderAPI/BsVideoModeInfo.h"
- #include "Math/BsVector2I.h"
- namespace bs
- {
- class RenderWindowManager;
- /** @addtogroup RenderAPI
- * @{
- */
- /** Structure that is used for initializing a render window. */
- struct BS_CORE_EXPORT RENDER_WINDOW_DESC
- {
- RENDER_WINDOW_DESC()
- : fullscreen(false), vsync(false), vsyncInterval(1), hidden(false), depthBuffer(true)
- , multisampleCount(0), multisampleHint(""), gamma(false), left(-1), top(-1), title("")
- , showTitleBar(true), showBorder(true), allowResize(true), toolWindow (false), modal(false)
- , hideUntilSwap(false)
- { }
- VideoMode videoMode; /**< Output monitor, frame buffer resize and refresh rate. */
- bool fullscreen; /**< Should the window be opened in fullscreen mode. */
- bool vsync; /**< Should the window wait for vertical sync before swapping buffers. */
- UINT32 vsyncInterval; /**< Determines how many vsync intervals occur per frame. FPS = refreshRate/interval. Usually 1 when vsync active. */
- bool hidden; /**< Should the window be hidden initially. */
- bool depthBuffer; /**< Should the window be created with a depth/stencil buffer. */
- UINT32 multisampleCount; /**< If higher than 1, texture containing multiple samples per pixel is created. */
- String multisampleHint; /**< Hint about what kind of multisampling to use. Render system specific. */
- bool gamma; /**< Should the written color pixels be gamma corrected before write. */
- INT32 left; /**< Window origin on X axis in pixels. -1 == screen center. Relative to monitor provided in videoMode. */
- INT32 top; /**< Window origin on Y axis in pixels. -1 == screen center. Relative to monitor provided in videoMode. */
- String title; /**< Title of the window. */
- bool showTitleBar; /**< Determines if the title-bar should be shown or not. */
- bool showBorder; /**< Determines if the window border should be shown or not. */
- bool allowResize; /**< Determines if the user can resize the window by dragging on the window edges. */
- bool toolWindow; /**< Tool windows have a different look than normal windows and have no task bar entry. */
- bool modal; /**< When a modal window is open all other windows will be locked until modal window is closed. */
- bool hideUntilSwap; /**< Window will be created as hidden and only be shown when the first framebuffer swap happens. */
- NameValuePairList platformSpecific; /**< Platform-specific creation options. */
- };
- /** Contains various properties that describe a render window. */
- class BS_CORE_EXPORT RenderWindowProperties : public RenderTargetProperties
- {
- public:
- RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
- virtual ~RenderWindowProperties() { }
- /** True if window is running in fullscreen mode. */
- bool isFullScreen = false;
- /** Horizontal origin of the window in pixels. */
- INT32 left = 0;
- /** Vertical origin of the window in pixels. */
- INT32 top = 0;
- /** Indicates whether the window currently has keyboard focus. */
- bool hasFocus = false;
- /** True if the window is hidden. */
- bool isHidden = false;
- /** True if the window is modal (blocks interaction with any non-modal window until closed). */
- bool isModal = false;
- /** True if the window is maximized. */
- bool isMaximized = false;
- };
- /**
- * Operating system window with a specific position, size and style. Each window serves as a surface that can be
- * rendered into by RenderAPI operations.
- */
- class BS_CORE_EXPORT RenderWindow : public RenderTarget
- {
- public:
- virtual ~RenderWindow() { }
- /** Converts screen position into window local position. */
- virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
- /** Converts window local position to screen position. */
- virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
- /**
- * Resize the window to specified width and height in pixels.
- *
- * @param[in] width Width of the window in pixels.
- * @param[in] height Height of the window in pixels.
- */
- void resize(UINT32 width, UINT32 height);
- /**
- * Move the window to specified screen coordinates.
- *
- * @param[in] left Position of the left border of the window on the screen.
- * @param[in] top Position of the top border of the window on the screen.
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void move(INT32 left, INT32 top);
- /**
- * Hides the window.
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void hide();
- /**
- * Shows a previously hidden window.
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void show();
- /**
- * @copydoc ct::RenderWindow::minimize
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void minimize();
- /**
- * @copydoc ct::RenderWindow::maximize
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void maximize();
- /**
- * @copydoc ct::RenderWindow::restore
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void restore();
- /**
- * @copydoc ct::RenderWindow::setFullscreen(UINT32, UINT32, float, UINT32)
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
- /**
- * @copydoc ct::RenderWindow::setFullscreen(const VideoMode&)
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void setFullscreen(const VideoMode& videoMode);
- /**
- * @copydoc ct::RenderWindow::setWindowed
- *
- * @note This is an @ref asyncMethod "asynchronous method".
- */
- void setWindowed(UINT32 width, UINT32 height);
- /** Retrieves a core implementation of a render window usable only from the core thread. */
- SPtr<ct::RenderWindow> getCore() const;
- /** Returns properties that describe the render window. */
- const RenderWindowProperties& getProperties() const;
- /** Closes and destroys the window. */
- void destroy() override;
- /**
- * Creates a new render window using the specified options. Optionally makes the created window a child of another
- * window.
- */
- static SPtr<RenderWindow> create(RENDER_WINDOW_DESC& desc, SPtr<RenderWindow> parentWindow = nullptr);
- protected:
- friend class RenderWindowManager;
- RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
- /** Returns render window properties that may be edited. */
- RenderWindowProperties& getMutableProperties();
- /** @copydoc RenderTarget::createCore */
- SPtr<ct::CoreObject> createCore() const override;
- /** Updates window properties from the synced property data. */
- virtual void syncProperties() = 0;
- protected:
- RENDER_WINDOW_DESC mDesc;
- UINT32 mWindowId;
- };
- /** @} */
- namespace ct
- {
- /** @addtogroup RenderAPI-Internal
- * @{
- */
- /** Core thread counterpart of bs::RenderWindow. */
- class BS_CORE_EXPORT RenderWindow : public RenderTarget
- {
- public:
- RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
- virtual ~RenderWindow();
- /**
- * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
- *
- * @param[in] width Width of the window frame buffer in pixels.
- * @param[in] height Height of the window frame buffer in pixels.
- * @param[in] refreshRate Refresh rate of the window in Hertz.
- * @param[in] monitorIdx Index of the monitor to go fullscreen on.
- *
- * @note If the exact provided mode isn't available, closest one is used instead.
- */
- virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
- /**
- * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
- *
- * @param[in] videoMode Mode retrieved from VideoModeInfo in RenderAPI.
- */
- virtual void setFullscreen(const VideoMode& videoMode) { }
- /**
- * Switches the window to windowed mode.
- *
- * @param[in] width Window width in pixels.
- * @param[in] height Window height in pixels.
- */
- virtual void setWindowed(UINT32 width, UINT32 height) { }
- /** Hide or show the window. */
- virtual void setHidden(bool hidden);
- /**
- * Makes the render target active or inactive. (for example in the case of a window, it will hide or restore the
- * window).
- */
- virtual void setActive(bool state);
- /** Minimizes the window to the taskbar. */
- virtual void minimize() { }
- /** Maximizes the window over the entire current screen. */
- virtual void maximize() { }
- /** Restores the window to original position and size if it is minimized or maximized. */
- virtual void restore() { }
- /** Change the size of the window. */
- virtual void resize(UINT32 width, UINT32 height) = 0;
- /** Reposition the window. */
- virtual void move(INT32 left, INT32 top) = 0;
- /** Returns properties that describe the render window. */
- const RenderWindowProperties& getProperties() const;
- /**
- * Called when window is moved or resized.
- *
- * @note Core thread.
- */
- virtual void _windowMovedOrResized();
- /**
- * Called when window has received focus.
- *
- * @note Core thread.
- */
- virtual void _windowFocusReceived();
- /**
- * Called when window has lost focus.
- *
- * @note Core thread.
- */
- virtual void _windowFocusLost();
- /**
- * Called when window has been maximized.
- *
- * @note Core thread.
- */
- virtual void _notifyMaximized();
- /**
- * Called when window has been minimized.
- *
- * @note Core thread.
- */
- virtual void _notifyMinimized();
- /**
- * Called when window has been restored from minimized or maximized state.
- *
- * @note Core thread.
- */
- virtual void _notifyRestored();
- /**
- * Called when the mouse leaves the window.
- *
- * @note Core thread.
- */
- virtual void _notifyMouseLeft();
- protected:
- friend class bs::RenderWindow;
- friend class RenderWindowManager;
- friend class bs::RenderWindowManager;
- /**
- * Returns window properties that are always kept in sync between core and sim threads.
- *
- * @note Used for keeping up what are the most up to date settings.
- */
- virtual RenderWindowProperties& getSyncedProperties() = 0;
- /** Updates window properties from the synced property data. */
- virtual void syncProperties() = 0;
- RENDER_WINDOW_DESC mDesc;
- SpinLock mLock;
- UINT32 mWindowId;
- };
- /** @} */
- }
- }
|