| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "Prerequisites/BsPrerequisitesUtil.h" |
| 6 | #include "Math/BsVector2I.h" |
| 7 | #include <X11/X.h> |
| 8 | #include <X11/Xutil.h> |
| 9 | |
| 10 | namespace bs |
| 11 | { |
| 12 | /** @addtogroup Internal-Utility |
| 13 | * @{ |
| 14 | */ |
| 15 | |
| 16 | /** @addtogroup Platform-Utility-Internal |
| 17 | * @{ |
| 18 | */ |
| 19 | |
| 20 | /** Descriptor used for creating a platform specific native window. */ |
| 21 | struct WINDOW_DESC |
| 22 | { |
| 23 | INT32 x, y; |
| 24 | UINT32 width, height; |
| 25 | UINT32 screen; |
| 26 | String title; |
| 27 | bool showDecorations; |
| 28 | bool allowResize; |
| 29 | bool modal; |
| 30 | bool showOnTaskBar; |
| 31 | bool hidden; |
| 32 | ::Window parent; |
| 33 | ::Window external; |
| 34 | XVisualInfo visualInfo; |
| 35 | SPtr<PixelData> background; |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * Represents a X11 window. Note that all accesses (including creation and destruction) to objects of this class must |
| 40 | * be locked by the main X11 lock accessible through LinuxPlatform. |
| 41 | */ |
| 42 | class BS_UTILITY_EXPORT LinuxWindow |
| 43 | { |
| 44 | public: |
| 45 | LinuxWindow(const WINDOW_DESC& desc); |
| 46 | ~LinuxWindow(); |
| 47 | |
| 48 | /** Returns position of the left-most border of the window, relative to the screen. */ |
| 49 | INT32 getLeft() const; |
| 50 | |
| 51 | /** Returns position of the top-most border of the window, relative to the screen. */ |
| 52 | INT32 getTop() const; |
| 53 | |
| 54 | /** Returns width of the window in pixels. */ |
| 55 | UINT32 getWidth() const; |
| 56 | |
| 57 | /** Returns height of the window in pixels. */ |
| 58 | UINT32 getHeight() const; |
| 59 | |
| 60 | /** Hides the window. */ |
| 61 | void hide(); |
| 62 | |
| 63 | /** Shows (unhides) the window. */ |
| 64 | void show(); |
| 65 | |
| 66 | /** Minimizes the window. */ |
| 67 | void minimize(); |
| 68 | |
| 69 | /** Maximizes the window over the entire current screen. */ |
| 70 | void maximize(); |
| 71 | |
| 72 | /** Restores the window to original position and size if it is minimized or maximized. */ |
| 73 | void restore(); |
| 74 | |
| 75 | /** Change the size of the window. */ |
| 76 | void resize(UINT32 width, UINT32 height); |
| 77 | |
| 78 | /** Reposition the window. */ |
| 79 | void move(INT32 left, INT32 top); |
| 80 | |
| 81 | /** Sets the icon to display for the window. */ |
| 82 | void setIcon(const PixelData& icon); |
| 83 | |
| 84 | /** Converts screen position into window local position. */ |
| 85 | Vector2I screenToWindowPos(const Vector2I& screenPos) const; |
| 86 | |
| 87 | /** Converts window local position to screen position. */ |
| 88 | Vector2I windowToScreenPos(const Vector2I& windowPos) const; |
| 89 | |
| 90 | /** |
| 91 | * @name Internal |
| 92 | * @{ |
| 93 | */ |
| 94 | |
| 95 | /** |
| 96 | * Destroys the window, cleaning up any resources and removing it from the display. No further methods should be |
| 97 | * called on this object after it has been destroyed. |
| 98 | */ |
| 99 | void _destroy(); |
| 100 | |
| 101 | /** |
| 102 | * Sets a portion of the window in which the user can click and drag in order to move the window. This is needed |
| 103 | * when window has no title bar, yet you still want to allow the user to drag it by clicking on some specific area |
| 104 | * (e.g. a title bar you manually render). |
| 105 | * |
| 106 | * @param[in] rects Areas of the window (relative to the window origin in top-left corner) in which the drag |
| 107 | * operation in allowed. |
| 108 | */ |
| 109 | void _setDragZones(const Vector<Rect2I>& rects); |
| 110 | |
| 111 | /** |
| 112 | * Notifies the window that user has started dragging the window using a custom drag zone. Provided parameter is the |
| 113 | * event that started the drag. |
| 114 | */ |
| 115 | void _dragStart(const XButtonEvent& event); |
| 116 | |
| 117 | /** Notifies the window the user has stopped the window drag operation. */ |
| 118 | void _dragEnd(); |
| 119 | |
| 120 | /** Returns the internal X11 window handle. */ |
| 121 | ::Window _getXWindow() const; |
| 122 | |
| 123 | /** Toggles between fullscreen and windowed mode. */ |
| 124 | void _setFullscreen(bool fullscreen); |
| 125 | |
| 126 | /** Attaches non-specific user data that can later be retrieved through _getUserData(). */ |
| 127 | void _setUserData(void* data); |
| 128 | |
| 129 | /** Returns user data attached to the object when _setUserData was called. */ |
| 130 | void* _getUserData() const; |
| 131 | |
| 132 | /** @} */ |
| 133 | |
| 134 | private: |
| 135 | /** Checks if the window is currently maximized. */ |
| 136 | bool isMaximized() const; |
| 137 | |
| 138 | /** Checks if the window is currently minimized (iconified). */ |
| 139 | bool isMinimized(); |
| 140 | |
| 141 | /** |
| 142 | * Maximizes a window if @p enable is true. If false restores the window to size/position before maximization |
| 143 | * occurred. |
| 144 | */ |
| 145 | void maximize(bool enable); |
| 146 | |
| 147 | /** |
| 148 | * Minimizes a window if @p enable is true. If false restores the window to size/position before minimization |
| 149 | * occurred. |
| 150 | */ |
| 151 | void minimize(bool enable); |
| 152 | |
| 153 | /** Shows or hides the window icon from the taskbar. */ |
| 154 | void showOnTaskbar(bool enable); |
| 155 | |
| 156 | /** |
| 157 | * Shows or hides window decorations. Decorations include window title bar, border and similar. Essentially anything |
| 158 | * not part of the main rendering area. |
| 159 | */ |
| 160 | void setShowDecorations(bool show); |
| 161 | |
| 162 | /** |
| 163 | * Switches the window between modal and normal mode. Modal window prevents input to their parent window until |
| 164 | * it is dismissed. |
| 165 | */ |
| 166 | void setIsModal(bool modal); |
| 167 | |
| 168 | struct Pimpl; |
| 169 | Pimpl* m; |
| 170 | }; |
| 171 | |
| 172 | /** @} */ |
| 173 | /** @} */ |
| 174 | } |
| 175 | |