Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
platform.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 natinusala
3 Copyright 2023 xfangfang
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#pragma once
19
20#include <functional>
21#include <string>
22#include <vector>
23#include <aurore/core/audio.hpp>
24#include <aurore/core/font.hpp>
25#include <aurore/core/i18n.hpp>
26#include <aurore/core/ime.hpp>
27#include <aurore/core/input.hpp>
28#include <aurore/core/theme.hpp>
29#include <aurore/core/video.hpp>
30
31namespace aurore
32{
33
34// Interface to provide everything platform specific required to run Aurore: graphics context, inputs, audio...
35// The best platform is automatically selected when the application starts, and cannot be changed by the user at the moment
37{
38 public:
39 virtual ~Platform() = default;
40 ;
41
46 virtual void createWindow(std::string title, uint32_t width, uint32_t height, float windowXPos = NAN, float windowYPos = NAN) = 0;
47
53 virtual void restoreWindow() {};
54
60 virtual void setWindowSize(uint32_t windowWidth, uint32_t windowHeight) {};
61
67 virtual void setWindowSizeLimits(uint32_t windowMinWidth, uint32_t windowMinHeight, uint32_t windowMaxWidth, uint32_t windowMaxHeight) {};
68
74 virtual void setWindowPosition(int windowXPos, int windowYPos) {};
75
83 virtual void setWindowState(uint32_t windowWidth, uint32_t windowHeight, int windowXPos, int windowYPos) {};
84
88 virtual std::string getName() = 0;
89
93 virtual bool hasWirelessConnection() { return false; };
94
98 virtual int getWirelessLevel() = 0;
99
103 virtual bool hasEthernetConnection() { return false; };
104
108 virtual std::string getIpAddress() = 0;
109
113 virtual std::string getDnsServer() = 0;
114
118 virtual bool canShowBatteryLevel() { return true; }
119
123 virtual bool canShowWirelessLevel() { return true; }
124
128 virtual int getBatteryLevel() = 0;
129
133 virtual bool isBatteryCharging() = 0;
134
142 virtual void disableScreenDimming(bool disable, const std::string& reason = "disable dimming", const std::string& app = "aurore") = 0;
143
147 virtual bool isScreenDimmingDisabled() = 0;
148
154 virtual void setBacklightBrightness(float brightness) = 0;
155
160 virtual float getBacklightBrightness() = 0;
161
165 virtual bool canSetBacklightBrightness() = 0;
166
170 virtual void setWindowAlwaysOnTop(bool enable) { }
171
177 virtual bool mainLoopIteration() = 0;
178
179 virtual bool runLoop(const std::function<bool()>& runLoopImpl) { return runLoopImpl(); }
180
190
194 virtual void setThemeVariant(ThemeVariant theme) = 0;
195
206 virtual std::string getLocale() = 0;
207
213
219
225
230 virtual ImeManager* getImeManager() = 0;
231
236 virtual FontLoader* getFontLoader() = 0;
237
241 virtual bool isApplicationMode() = 0;
242
246 virtual void exitToHomeMode(bool value) = 0;
247
252
258 virtual void openBrowser(std::string url) = 0;
259
264 static bool isBrowserUrl(const std::string& url);
265
269 static inline std::vector<std::string> BROWSER_URL_SCHEMES = { "http", "https" };
270
274 virtual void pasteToClipboard(const std::string& text) {};
275
279 virtual std::string pasteFromClipboard() { return ""; };
280
285
291 static void setFactory(std::function<Platform*()> factory) { Platform::factory = std::move(factory); }
292
296 // From the text itself, not LOCALE_AUTO: that is another const string in
297 // each file (internal linkage), not yet built when this inline one is.
298 static inline std::string APP_LOCALE_DEFAULT = "auto";
299
300 private:
301 static inline std::function<Platform*()> factory;
302};
303
304} // namespace aurore
Definition video.hpp:30
Definition audio.hpp:45
Definition font.hpp:42
Definition ime.hpp:41
Definition input.hpp:334
Definition platform.hpp:37
virtual bool hasWirelessConnection()
Definition platform.hpp:93
static std::vector< std::string > BROWSER_URL_SCHEMES
Definition platform.hpp:269
virtual void setWindowSizeLimits(uint32_t windowMinWidth, uint32_t windowMinHeight, uint32_t windowMaxWidth, uint32_t windowMaxHeight)
Definition platform.hpp:67
virtual void setBacklightBrightness(float brightness)=0
virtual bool isBatteryCharging()=0
virtual bool canShowBatteryLevel()
Definition platform.hpp:118
virtual ~Platform()=default
virtual ThemeVariant getThemeVariant()=0
virtual std::string getDnsServer()=0
virtual int getBatteryLevel()=0
virtual float getBacklightBrightness()=0
virtual InputManager * getInputManager()=0
virtual bool canSetBacklightBrightness()=0
virtual bool mainLoopIteration()=0
virtual FontLoader * getFontLoader()=0
virtual std::string getName()=0
virtual void setWindowAlwaysOnTop(bool enable)
Definition platform.hpp:170
virtual void setWindowPosition(int windowXPos, int windowYPos)
Definition platform.hpp:74
virtual void openBrowser(std::string url)=0
virtual void setThemeVariant(ThemeVariant theme)=0
virtual VideoContext * getVideoContext()=0
virtual void pasteToClipboard(const std::string &text)
Definition platform.hpp:274
virtual void restoreWindow()
Definition platform.hpp:53
virtual void setWindowSize(uint32_t windowWidth, uint32_t windowHeight)
Definition platform.hpp:60
virtual void forceEnableGamePlayRecording()=0
virtual void setWindowState(uint32_t windowWidth, uint32_t windowHeight, int windowXPos, int windowYPos)
Definition platform.hpp:83
virtual bool hasEthernetConnection()
Definition platform.hpp:103
virtual void exitToHomeMode(bool value)=0
static void setFactory(std::function< Platform *()> factory)
Definition platform.hpp:291
virtual void disableScreenDimming(bool disable, const std::string &reason="disable dimming", const std::string &app="aurore")=0
virtual ImeManager * getImeManager()=0
virtual AudioPlayer * getAudioPlayer()=0
virtual void createWindow(std::string title, uint32_t width, uint32_t height, float windowXPos=NAN, float windowYPos=NAN)=0
static std::string APP_LOCALE_DEFAULT
Definition platform.hpp:298
virtual std::string getIpAddress()=0
virtual std::string pasteFromClipboard()
Definition platform.hpp:279
virtual bool isScreenDimmingDisabled()=0
virtual std::string getLocale()=0
static Platform * createPlatform()
virtual bool runLoop(const std::function< bool()> &runLoopImpl)
Definition platform.hpp:179
virtual int getWirelessLevel()=0
virtual bool isApplicationMode()=0
static bool isBrowserUrl(const std::string &url)
virtual bool canShowWirelessLevel()
Definition platform.hpp:123
Definition actions.hpp:25
ThemeVariant
The two sets of colours every theme has: light and dark.
Definition theme.hpp:37
Definition text.hpp:13