2020-12-24 08:16:09 +08:00
|
|
|
#pragma once
|
2021-05-10 08:23:02 +08:00
|
|
|
#include <blah/common.h>
|
2021-05-20 02:21:08 +08:00
|
|
|
#include <blah/input.h>
|
2022-02-13 04:19:53 +08:00
|
|
|
#include <blah/filesystem.h>
|
2020-12-24 08:16:09 +08:00
|
|
|
#include <blah/containers/vector.h>
|
|
|
|
|
|
|
|
namespace Blah
|
|
|
|
{
|
|
|
|
struct Config;
|
|
|
|
|
2022-02-12 12:19:14 +08:00
|
|
|
class Platform
|
2020-12-24 08:16:09 +08:00
|
|
|
{
|
2022-02-12 12:19:14 +08:00
|
|
|
public:
|
|
|
|
|
2022-02-13 15:15:12 +08:00
|
|
|
virtual ~Platform() = default;
|
|
|
|
|
2022-02-12 12:19:14 +08:00
|
|
|
// Initialize the Graphics
|
|
|
|
virtual bool init(const Config& config) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Called after the on_startup callback, but before the update loop begins
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void ready() = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Called during shutdown
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void shutdown() = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
2021-02-06 16:13:50 +08:00
|
|
|
// The time, in ticks (microseconds) since the Application was started
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual u64 ticks() = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Called every frame
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void update(InputState& state) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Sleeps the current thread
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void sleep(int milliseconds) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Called to present the window contents
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void present() = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
2022-08-22 08:41:29 +08:00
|
|
|
// Called when the App sets flags
|
|
|
|
virtual void set_app_flags(u32 flags) = 0;
|
|
|
|
|
2020-12-24 08:16:09 +08:00
|
|
|
// Gets the Application Window Title in UTF-8
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual const char* get_title() = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Sets the Application Window Title in UTF-8
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void set_title(const char* title) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Gets the Application Window Position, in Screen Coordinates
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void get_position(int* x, int* y) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Sets the Application Window Position, in Screen Coordinates
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void set_position(int x, int y) = 0;
|
2022-02-10 10:49:47 +08:00
|
|
|
|
2022-01-26 14:50:20 +08:00
|
|
|
// Gets whether the Window has focus
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual bool get_focused() = 0;
|
2022-01-26 14:50:20 +08:00
|
|
|
|
2020-12-24 08:16:09 +08:00
|
|
|
// Gets the Application Window Size, in Screen Coordinates
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void get_size(int* width, int* height) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Sets the Application Window Size, in Screen Coordinates
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void set_size(int width, int height) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Gets the Application Window Drawing Size, in Pixels. This may differ from the Window Size on hi-dpi displays.
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void get_draw_size(int* width, int* height) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Gets the Desktop Content Scale. Gui should be scaled by this value
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual float get_content_scale() = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Returns the absoluate path to the directory that the application was started from
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual const char* app_path() = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Returns the absolute path to the user directory where save data and settings should be stored
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual const char* user_path() = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
2021-05-10 08:23:02 +08:00
|
|
|
// Opens a file and sets the handle, or returns an empty handle if it fails
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual FileRef file_open(const char* path, FileMode mode) = 0;
|
2021-05-10 08:23:02 +08:00
|
|
|
|
2020-12-24 08:16:09 +08:00
|
|
|
// Returns true if a file with the given path exists
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual bool file_exists(const char* path) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Returns true if a file with the given path was deleted
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual bool file_delete(const char* path) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Returns true if a directory with the given path was successfully created
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual bool dir_create(const char* path) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Returns true if a directory with the given path exists
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual bool dir_exists(const char* path) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// Returns true if a directory with the given path was deleted
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual bool dir_delete(const char* path) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// enumerates a directory and appends each file to the given list
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void dir_enumerate(Vector<FilePath>& list, const char* path, bool recursive) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
|
|
|
// opens a directory in the OS file explorer / finder
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void dir_explore(const char* path) = 0;
|
2020-12-24 08:16:09 +08:00
|
|
|
|
2021-12-13 12:41:23 +08:00
|
|
|
// sets the contents of the clipboard
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void set_clipboard(const char* text) = 0;
|
2021-12-13 12:41:23 +08:00
|
|
|
|
|
|
|
// gets the contents of the clipboard into the given string
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual const char* get_clipboard() = 0;
|
2021-12-13 12:41:23 +08:00
|
|
|
|
2022-02-10 10:49:47 +08:00
|
|
|
// Tries to open a URL in a web browser
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void open_url(const char* url) = 0;
|
2022-02-10 10:49:47 +08:00
|
|
|
|
2020-12-24 08:16:09 +08:00
|
|
|
// OpenGL Methods
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void* gl_get_func(const char* name) = 0;
|
|
|
|
virtual void* gl_context_create() = 0;
|
|
|
|
virtual void gl_context_make_current(void* context) = 0;
|
|
|
|
virtual void gl_context_destroy(void* context) = 0;
|
2020-12-29 10:31:06 +08:00
|
|
|
|
|
|
|
// D3D11 Methods
|
2022-02-12 12:19:14 +08:00
|
|
|
virtual void* d3d11_get_hwnd() = 0;
|
|
|
|
|
|
|
|
// Instantiates the Platform object
|
|
|
|
static Platform* try_make_platform(const Config& config);
|
|
|
|
};
|
2020-12-24 08:16:09 +08:00
|
|
|
}
|