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 {
|
2021-10-13 10:55:20 -04:00
|
|
|
None = 0,
|
|
|
|
Resizable = 2,
|
|
|
|
Borderless = 4,
|
|
|
|
Hidden = 8
|
2020-08-11 12:07:21 -04:00
|
|
|
};
|
|
|
|
|
2021-10-13 10:55:20 -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 {
|
2021-10-12 10:22:16 -04:00
|
|
|
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();
|
2021-10-12 10:22:16 -04:00
|
|
|
|
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.
|
2021-10-12 10:22:16 -04:00
|
|
|
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.
|
|
|
|
*/
|
2021-10-12 10:22:16 -04:00
|
|
|
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
|
2021-10-12 10:22:16 -04:00
|
|
|
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.
|
|
|
|
*/
|
2021-10-12 10:22:16 -04:00
|
|
|
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();
|
2021-10-12 10:22:16 -04:00
|
|
|
|
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.
|
2021-10-12 10:22:16 -04:00
|
|
|
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.
|
2021-10-12 10:22:16 -04:00
|
|
|
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.
|
2021-10-12 10:22:16 -04:00
|
|
|
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.
|
2021-10-12 10:22:16 -04:00
|
|
|
bool is_window_focused(window_ptr window);
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
/// If possible, try to manually focus the window.
|
2021-10-12 10:22:16 -04:00
|
|
|
void set_window_focused(window_ptr window);
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
/// Sets the window position to the offset provided.
|
2021-10-12 10:22:16 -04:00
|
|
|
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.
|
2021-10-12 10:22:16 -04:00
|
|
|
void set_window_size(window_ptr window, prism::Extent extent);
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
/// Sets the window title.
|
2021-10-12 10:22:16 -04:00
|
|
|
void set_window_title(window_ptr window, std::string_view title);
|
2020-08-11 12:07:21 -04:00
|
|
|
|
2021-10-13 10:55:20 -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.
|
2021-10-12 10:22:16 -04:00
|
|
|
bool get_key_down(InputButton key);
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
/// If available for the InputButton, returns the platform-specific keycode.
|
2021-10-12 10:22:16 -04:00
|
|
|
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.
|
2021-10-12 10:22:16 -04:00
|
|
|
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.
|
2021-10-12 10:22:16 -04:00
|
|
|
void capture_mouse(bool capture);
|
2020-08-11 12:07:21 -04:00
|
|
|
|
2021-10-07 17:46:28 -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
|
|
|
|
2021-10-12 10:22:16 -04:00
|
|
|
void end_text_input();
|
2020-08-11 12:07:21 -04:00
|
|
|
}
|