Inject Windows platform services

This commit is contained in:
2026-06-03 04:14:47 +02:00
parent 0e77ca6ba8
commit ead7f58285
6 changed files with 166 additions and 82 deletions

View File

@@ -5,6 +5,7 @@
#include "texture.h"
#include "image.h"
#include "app.h"
#include "platform_api/platform_services.h"
#include "canvas.h"
#include "keymap.h"
#include "hmd.h"
@@ -351,6 +352,104 @@ std::string win32_open_dir()
return Buffer;
}
namespace {
void invoke_selected_path(
const std::string& path,
const pp::platform::PickedPathCallback& callback)
{
if (!path.empty())
callback(path);
}
std::string build_supported_files_filter(const std::vector<std::string>& types)
{
std::string filter = "Supported Files (";
bool first_type = true;
for (const auto& t : types)
{
filter.append(std::string(first_type ? "" : " ,") + "*." + t);
first_type = false;
}
filter.append(")");
filter.push_back(0);
first_type = true;
for (const auto& t : types)
{
filter.append(std::string(first_type ? "" : ";") + "*." + t);
first_type = false;
}
filter.push_back(0);
return filter;
}
class WindowsPlatformServices final : public pp::platform::PlatformServices {
public:
[[nodiscard]] std::string clipboard_text() override
{
return win32_clipboard_get_text();
}
[[nodiscard]] bool set_clipboard_text(std::string_view text) override
{
return win32_clipboard_set_text(std::string(text));
}
void set_cursor_visible(bool visible) override
{
win32_show_cursor(visible);
}
void set_virtual_keyboard_visible(bool visible) override
{
(void)visible;
}
void display_file(std::string_view path) override
{
(void)path;
}
void share_file(std::string_view path) override
{
(void)path;
}
void pick_image(pp::platform::PickedPathCallback callback) override
{
const std::string path = win32_open_file("Image Files (*.jpg, *.png)\0*.jpg;*.png");
invoke_selected_path(path, callback);
}
void pick_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
{
const std::string filter = build_supported_files_filter(file_types);
const std::string path = win32_open_file(filter.c_str());
invoke_selected_path(path, callback);
}
void pick_save_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
{
const std::string filter = build_supported_files_filter(file_types);
const std::string path = win32_save_file(filter.c_str());
invoke_selected_path(path, callback);
}
void pick_directory(pp::platform::PickedPathCallback callback) override
{
const std::string path = win32_open_dir();
invoke_selected_path(path, callback);
}
};
[[nodiscard]] WindowsPlatformServices& windows_platform_services()
{
static WindowsPlatformServices services;
return services;
}
}
int read_WMI_info()
{
// see: http://win32easy.blogspot.co.uk/2011/03/wmi-in-c-query-everyting-from-your-os.html
@@ -841,6 +940,7 @@ int main(int argc, char** argv)
PIXELFORMATDESCRIPTOR pfd;
App::I = new App();
App::I->set_platform_services(&windows_platform_services());
App::I->initLog();
init_shcore_API();