Route VR mode through app preferences

This commit is contained in:
2026-06-04 14:22:39 +02:00
parent f8243566c4
commit 884a6d4940
8 changed files with 79 additions and 23 deletions

View File

@@ -53,6 +53,7 @@ public:
virtual void apply_ui_scale(const ScaleApplicationPlan& plan) = 0;
virtual void apply_viewport_scale(const ScaleApplicationPlan& plan) = 0;
virtual void apply_interface_direction(const InterfaceDirectionPlan& plan) = 0;
virtual bool apply_vr_mode_preference(const StoredBooleanPreferencePlan& plan) = 0;
virtual void apply_vr_controllers_preference(const StoredBooleanPreferencePlan& plan) = 0;
virtual void apply_timelapse_preference(const TimelapsePreferencePlan& plan) = 0;
virtual void apply_canvas_cursor_mode(const StoredIntegerPreferencePlan& plan) = 0;
@@ -120,6 +121,11 @@ public:
return { enabled };
}
[[nodiscard]] constexpr StoredBooleanPreferencePlan plan_vr_mode_preference(bool enabled) noexcept
{
return { enabled };
}
[[nodiscard]] constexpr StoredIntegerPreferencePlan plan_canvas_cursor_mode(int mode) noexcept
{
return { mode };
@@ -151,6 +157,16 @@ public:
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_vr_mode_preference(
bool enabled,
AppPreferenceServices& services)
{
if (!services.apply_vr_mode_preference(plan_vr_mode_preference(enabled))) {
return pp::foundation::Status::invalid_argument("VR mode could not start");
}
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_vr_controllers_preference(
bool enabled,
AppPreferenceServices& services)

View File

@@ -1159,18 +1159,13 @@ void App::init_menu_tools()
vr_btn->find<NodeCheckBox>("tools-vr-check")->on_value_changed = [this, main](Node* target, bool checked)
{
if (checked)
{
if (!vr_start())
{
auto cb = static_cast<NodeCheckBox*>(target);
cb->set_value(false);
message_box("VR Failed", "Couldn't start Virtual Reality mode");
}
}
else
{
vr_stop();
const auto status = pp::panopainter::execute_legacy_vr_mode_preference(
*this,
checked);
if (!status.ok()) {
auto cb = static_cast<NodeCheckBox*>(target);
cb->set_value(false);
message_box("VR Failed", "Couldn't start Virtual Reality mode");
}
};
}

View File

@@ -37,6 +37,16 @@ public:
app_.set_ui_rtl(plan.direction == pp::app::InterfaceDirection::right_to_left);
}
bool apply_vr_mode_preference(const pp::app::StoredBooleanPreferencePlan& plan) override
{
if (plan.value) {
return app_.vr_start();
}
app_.vr_stop();
return true;
}
void apply_vr_controllers_preference(const pp::app::StoredBooleanPreferencePlan& plan) override
{
app_.vr_controllers_enabled = plan.value;
@@ -90,6 +100,12 @@ pp::foundation::Status execute_legacy_interface_direction_preference(App& app, b
return pp::app::execute_interface_direction_preference(right_to_left, services);
}
pp::foundation::Status execute_legacy_vr_mode_preference(App& app, bool enabled)
{
LegacyAppPreferenceServices services(app);
return pp::app::execute_vr_mode_preference(enabled, services);
}
pp::foundation::Status execute_legacy_vr_controllers_preference(App& app, bool enabled)
{
LegacyAppPreferenceServices services(app);

View File

@@ -15,6 +15,9 @@ namespace pp::panopainter {
[[nodiscard]] pp::foundation::Status execute_legacy_interface_direction_preference(
App& app,
bool right_to_left);
[[nodiscard]] pp::foundation::Status execute_legacy_vr_mode_preference(
App& app,
bool enabled);
[[nodiscard]] pp::foundation::Status execute_legacy_vr_controllers_preference(
App& app,
bool enabled);