1 /*****************************************************************************
2  * Copyright (c) 2014-2020 OpenRCT2 developers
3  *
4  * For a complete list of all authors, please refer to contributors.md
5  * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
6  *
7  * OpenRCT2 is licensed under the GNU General Public License version 3.
8  *****************************************************************************/
9 
10 #pragma once
11 
12 #include "../Context.h"
13 #include "../common.h"
14 #include "../config/Config.h"
15 #include "../interface/Cursors.h"
16 
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 struct ScreenCoordsXY;
22 struct rct_drawpixelinfo;
23 struct ITitleSequencePlayer;
24 
25 namespace OpenRCT2
26 {
27     namespace Drawing
28     {
29         struct IDrawingEngineFactory;
30         struct IWeatherDrawer;
31         using DrawWeatherFunc = void (*)(
32             rct_drawpixelinfo* dpi, OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width,
33             int32_t height);
34     } // namespace Drawing
35 
36     namespace Ui
37     {
38         struct IWindowManager;
39 
40         enum class FULLSCREEN_MODE
41         {
42             WINDOWED,
43             FULLSCREEN,
44             FULLSCREEN_DESKTOP,
45         };
46 
47         inline bool operator<(const Resolution& lhs, const Resolution& rhs)
48         {
49             int32_t areaA = lhs.Width * lhs.Height;
50             int32_t areaB = rhs.Width * rhs.Height;
51             if (areaA == areaB)
52             {
53                 return lhs.Width < rhs.Width;
54             }
55             return areaA < areaB;
56         }
57 
58         inline bool operator==(const Resolution& lhs, const Resolution& rhs)
59         {
60             return lhs.Width == rhs.Width && lhs.Height == rhs.Height;
61         }
62 
63         inline bool operator!=(const Resolution& lhs, const Resolution& rhs)
64         {
65             return !(lhs == rhs);
66         }
67 
68         enum class FILE_DIALOG_TYPE
69         {
70             OPEN,
71             SAVE,
72         };
73 
74         struct FileDialogDesc
75         {
76             struct Filter
77             {
78                 std::string Name;    // E.g. "Image Files"
79                 std::string Pattern; // E.g. "*.png;*.jpg;*.gif"
80             };
81 
82             FILE_DIALOG_TYPE Type = FILE_DIALOG_TYPE::OPEN;
83             std::string Title;
84             std::string InitialDirectory;
85             std::string DefaultFilename;
86             std::vector<Filter> Filters;
87         };
88 
89         /**
90          * Represents the window or screen that OpenRCT2 is presented on.
91          */
92         struct IUiContext
93         {
94             virtual ~IUiContext() = default;
95 
96             virtual void Initialise() abstract;
97             virtual void Update() abstract;
98             virtual void Draw(rct_drawpixelinfo* dpi) abstract;
99 
100             // Window
101             virtual void CreateWindow() abstract;
102             virtual void CloseWindow() abstract;
103             virtual void RecreateWindow() abstract;
104             virtual void* GetWindow() abstract;
105             virtual int32_t GetWidth() abstract;
106             virtual int32_t GetHeight() abstract;
107             virtual ScaleQuality GetScaleQuality() abstract;
108             virtual void SetFullscreenMode(FULLSCREEN_MODE mode) abstract;
109             virtual const std::vector<Resolution>& GetFullscreenResolutions() abstract;
110             virtual bool HasFocus() abstract;
111             virtual bool IsMinimised() abstract;
112             virtual bool IsSteamOverlayActive() abstract;
113             virtual void ProcessMessages() abstract;
114             virtual void TriggerResize() abstract;
115 
116             virtual void ShowMessageBox(const std::string& message) abstract;
117 
118             virtual bool HasMenuSupport() abstract;
119             // Creates a menu with a series of options, returns the index of the selected option
120             virtual int32_t ShowMenuDialog(
121                 const std::vector<std::string>& options, const std::string& title, const std::string& text) abstract;
122             virtual void OpenFolder(const std::string& path) abstract;
123             virtual void OpenURL(const std::string& url) abstract;
124             virtual std::string ShowFileDialog(const FileDialogDesc& desc) abstract;
125             virtual std::string ShowDirectoryDialog(const std::string& title) abstract;
126             virtual bool HasFilePicker() const abstract;
127 
128             // Input
129             virtual const CursorState* GetCursorState() abstract;
130             virtual CursorID GetCursor() abstract;
131             virtual void SetCursor(CursorID cursor) abstract;
132             virtual void SetCursorScale(uint8_t scale) abstract;
133             virtual void SetCursorVisible(bool value) abstract;
134             virtual ScreenCoordsXY GetCursorPosition() abstract;
135             virtual void SetCursorPosition(const ScreenCoordsXY& cursorPosition) abstract;
136             virtual void SetCursorTrap(bool value) abstract;
137             virtual const uint8_t* GetKeysState() abstract;
138             virtual const uint8_t* GetKeysPressed() abstract;
139             virtual void SetKeysPressed(uint32_t keysym, uint8_t scancode) abstract;
140 
141             // Drawing
142             [[nodiscard]] virtual std::shared_ptr<Drawing::IDrawingEngineFactory> GetDrawingEngineFactory() abstract;
143             virtual void DrawWeatherAnimation(
144                 OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer, rct_drawpixelinfo* dpi,
145                 OpenRCT2::Drawing::DrawWeatherFunc drawFunc) abstract;
146 
147             // Text input
148             virtual bool IsTextInputActive() abstract;
149             virtual TextInputSession* StartTextInput(utf8* buffer, size_t bufferSize) abstract;
150             virtual void StopTextInput() abstract;
151 
152             // In-game UI
153             virtual IWindowManager* GetWindowManager() abstract;
154 
155             // Clipboard
156             virtual bool SetClipboardText(const utf8* target) abstract;
157 
158             // HACK Until all title logic is moved to libopenrct2ui, we will need to provide some services
159             virtual ITitleSequencePlayer* GetTitleSequencePlayer() abstract;
160         };
161 
162         [[nodiscard]] std::shared_ptr<IUiContext> CreateDummyUiContext();
163     } // namespace Ui
164 } // namespace OpenRCT2
165