Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
prism/engine/platform/include/platform.hpp

181 lines
5.4 KiB
C++
Raw Normal View History

2020-08-11 12:07:21 -04:00
#pragma once
#include <functional>
#include <string>
#include <string_view>
#include "common.hpp"
/// Requestable window flags, which may or may not be respected by the platform.
enum class WindowFlags {
None = 0,
Resizable = 2,
Borderless = 4,
Hidden = 8
2020-08-11 12:07:21 -04:00
};
inline WindowFlags operator|(const WindowFlags a, const WindowFlags b) {
return static_cast<WindowFlags>(static_cast<int>(a) | static_cast<int>(b));
}
inline bool operator&(const WindowFlags a, const WindowFlags b) {
return static_cast<int>(a) & static_cast<int>(b);
}
2020-08-11 12:07:21 -04:00
/// Represents a button. This includes keyboard, gamepad and mouse buttons.
enum class InputButton {
Invalid,
C,
V,
X,
Y,
Z,
Backspace,
Enter,
W,
A,
S,
D,
Q,
Shift,
Alt,
Super,
Escape,
Tab,
Ctrl,
Space,
LeftArrow,
RightArrow,
// gamepad inputs
ButtonA,
ButtonB,
ButtonX,
ButtonY,
DPadUp,
DPadDown,
DPadLeft,
DPadRight,
// mouse inputs
MouseLeft,
MouseRight
};
enum class PlatformFeature {
Windowing
};
2020-09-22 12:27:41 -04:00
/// On platforms that has a GUI with a seperate light/dark mode.
enum class PlatformTheme {
Light,
Dark
};
2020-08-11 12:07:21 -04:00
namespace platform {
using window_ptr = void*;
2020-08-11 12:07:21 -04:00
/// Returns a human readable platform name, e.g. Linux.
const char* get_name();
2020-09-22 12:27:41 -04:00
/// Returns the current platform theme.
PlatformTheme get_theme();
2020-08-11 12:07:21 -04:00
/// Queries whether or not the platform supports a certain feature.
bool supports_feature(PlatformFeature feature);
2020-08-11 12:07:21 -04:00
/** Opens a new window.
@param title The title of the window.
@param rect The requested size and position of the window.
@param flags The requested window flags.
@note Depending on the platform, some of these parameters might be unused. The best practice is to always assume that none of them may be used.
@note On platforms that do not support the Windowing feature, calling open_window more than once is not supported. In this case, the same identifier is returned.
@return A valid window identifier.
*/
window_ptr open_window(std::string_view title, prism::Rectangle rect, WindowFlags flags);
bool is_main_window(window_ptr index);
2020-08-11 12:07:21 -04:00
2021-03-01 14:40:02 -05:00
// for vulkan usage
void* create_native_surface(window_ptr window, void* instance);
2021-03-01 14:40:02 -05:00
std::vector<const char*> get_native_surface_extension();
2020-08-11 12:07:21 -04:00
/** Closes a window.
@param index The window to close.
*/
void close_window(window_ptr window);
2020-08-11 12:07:21 -04:00
/// Forces the platform to quit the application. This is not related to Engine::quit().
void force_quit();
/// Gets the content scale for the monitor. 1.0 would be 1x scale, 2.0 would be 2x scale, etc.
float get_monitor_dpi();
2020-08-11 12:07:21 -04:00
/// Get the monitor resolution.
2020-08-13 07:48:50 -04:00
prism::Rectangle get_monitor_resolution();
2020-08-11 12:07:21 -04:00
/// Get the monitor work area. For example on macOS this may exclude the areas of the menu bar and dock.
2020-08-13 07:48:50 -04:00
prism::Rectangle get_monitor_work_area();
2020-08-11 12:07:21 -04:00
/// Get the window position.
prism::Offset get_window_position(window_ptr window);
2020-08-11 12:07:21 -04:00
/// Get the window size, note that in hidpi scenarios this is the non-scaled resolution.
prism::Extent get_window_size(window_ptr window);
2020-08-11 12:07:21 -04:00
/// Get the window's drawable size. Always use this instead of manually multiplying the window size by the content scale.
prism::Extent get_window_drawable_size(window_ptr window);
2020-08-11 12:07:21 -04:00
/// Query whether or not the window is focused.
bool is_window_focused(window_ptr window);
2020-08-11 12:07:21 -04:00
/// If possible, try to manually focus the window.
void set_window_focused(window_ptr window);
2020-08-11 12:07:21 -04:00
/// Sets the window position to the offset provided.
void set_window_position(window_ptr window, prism::Offset offset);
2020-08-11 12:07:21 -04:00
/// Sets the window to the specified size. The platform will handle the subsequent resize events.
void set_window_size(window_ptr window, prism::Extent extent);
2020-08-11 12:07:21 -04:00
/// Sets the window title.
void set_window_title(window_ptr window, std::string_view title);
2020-08-11 12:07:21 -04:00
/// Show window
void show_window(window_ptr window);
2020-08-11 12:07:21 -04:00
/// Queries whether or not the button is currently pressed.
bool get_key_down(InputButton key);
2020-08-11 12:07:21 -04:00
/// If available for the InputButton, returns the platform-specific keycode.
int get_keycode(InputButton key);
2020-08-11 12:07:21 -04:00
/// Returns the current moue cursor position, relative to the window.
2020-08-13 07:48:50 -04:00
prism::Offset get_cursor_position();
2020-08-11 12:07:21 -04:00
/// Returns the current moue cursor position, relative to the monitor.
2020-08-13 07:48:50 -04:00
prism::Offset get_screen_cursor_position();
2020-08-11 12:07:21 -04:00
/// Queries whether or not the mouse button requested is pressed or not.
bool get_mouse_button_down(int button);
2020-08-11 12:07:21 -04:00
/// Returns the current mouse wheel delta on both axes.
std::tuple<float, float> get_wheel_delta();
/// Returns the current right stick axes values from 0->1
std::tuple<float, float> get_right_stick_position();
/// Returns the current left stick axes values from 0->1
std::tuple<float, float> get_left_stick_position();
/// On platforms that support moue capture, this will lock the mouse cursor to the window and hide it.
void capture_mouse(bool capture);
2020-08-11 12:07:21 -04:00
// TODO: right now the OS intercepting and saying "We dont want text input anymore" ala software keyboards is NOT supported yet
void begin_text_input();
2020-08-11 12:07:21 -04:00
void end_text_input();
2020-08-11 12:07:21 -04:00
}