Add about menu service boundary
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace pp::app {
|
||||
@@ -31,6 +33,17 @@ struct AboutMenuPlan {
|
||||
int performance_updates_per_iteration = 0;
|
||||
};
|
||||
|
||||
class AboutMenuServices {
|
||||
public:
|
||||
virtual ~AboutMenuServices() = default;
|
||||
|
||||
virtual void show_user_manual() = 0;
|
||||
virtual void show_about_dialog() = 0;
|
||||
virtual void show_whats_new_dialog() = 0;
|
||||
virtual void trigger_crash_test() = 0;
|
||||
virtual void run_performance_test(const AboutMenuPlan& plan) = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline AboutMenuPlan plan_about_menu_command(
|
||||
AboutMenuCommand command,
|
||||
int version_major,
|
||||
@@ -83,4 +96,31 @@ struct AboutMenuPlan {
|
||||
return plan;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_about_menu_plan(
|
||||
const AboutMenuPlan& plan,
|
||||
AboutMenuServices& services)
|
||||
{
|
||||
switch (plan.action) {
|
||||
case AboutMenuAction::show_user_manual:
|
||||
services.show_user_manual();
|
||||
return pp::foundation::Status::success();
|
||||
case AboutMenuAction::show_about_dialog:
|
||||
services.show_about_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case AboutMenuAction::show_whats_new_dialog:
|
||||
services.show_whats_new_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case AboutMenuAction::trigger_crash_test:
|
||||
services.trigger_crash_test();
|
||||
return pp::foundation::Status::success();
|
||||
case AboutMenuAction::run_performance_test:
|
||||
services.run_performance_test(plan);
|
||||
return pp::foundation::Status::success();
|
||||
case AboutMenuAction::no_op_unavailable:
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
return pp::foundation::Status::invalid_argument("unknown about menu action");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -309,6 +309,73 @@ private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
class LegacyAboutMenuServices final : public pp::app::AboutMenuServices {
|
||||
public:
|
||||
explicit LegacyAboutMenuServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void show_user_manual() override
|
||||
{
|
||||
app_.dialog_usermanual();
|
||||
}
|
||||
|
||||
void show_about_dialog() override
|
||||
{
|
||||
app_.dialog_about();
|
||||
}
|
||||
|
||||
void show_whats_new_dialog() override
|
||||
{
|
||||
app_.dialog_whatsnew(true);
|
||||
}
|
||||
|
||||
void trigger_crash_test() override
|
||||
{
|
||||
LOG("crashing");
|
||||
app_.crash_test();
|
||||
}
|
||||
|
||||
void run_performance_test(const pp::app::AboutMenuPlan& plan) override
|
||||
{
|
||||
if (!Canvas::I)
|
||||
return;
|
||||
|
||||
LOG("perf");
|
||||
std::string message;
|
||||
const int performance_iterations = plan.performance_iterations;
|
||||
app_.render_task([&]
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
Canvas::I->stroke_start({ 0, 0, 0 }, 0.9f);
|
||||
for (int i = 0; i < performance_iterations; i++)
|
||||
{
|
||||
Canvas::I->stroke_update({ 100, 100, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 200, 200, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 200, 100, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 100, 200, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 300, 300, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 200, 500, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 500, 500, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 400, 400, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 0, 200, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 200, 0, 0 }, 0.9f);
|
||||
Canvas::I->stroke_draw();
|
||||
}
|
||||
Canvas::I->stroke_end();
|
||||
auto diff = std::chrono::high_resolution_clock::now() - start;
|
||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count();
|
||||
LOG("%lld ms", ms);
|
||||
message = "Time " + std::to_string(ms) + " ms";
|
||||
});
|
||||
app_.message_box("Performance test", message);
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
void execute_main_toolbar_plan(App& app, const pp::app::MainToolbarPlan& plan)
|
||||
{
|
||||
LegacyMainToolbarServices services(app);
|
||||
@@ -317,6 +384,14 @@ void execute_main_toolbar_plan(App& app, const pp::app::MainToolbarPlan& plan)
|
||||
LOG("Main toolbar action failed: %s", status.message);
|
||||
}
|
||||
|
||||
void execute_about_menu_plan(App& app, const pp::app::AboutMenuPlan& plan)
|
||||
{
|
||||
LegacyAboutMenuServices services(app);
|
||||
const auto status = pp::app::execute_about_menu_plan(plan, services);
|
||||
if (!status.ok())
|
||||
LOG("About menu action failed: %s", status.message);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void App::title_update()
|
||||
@@ -1583,8 +1658,7 @@ void App::init_menu_about()
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
if (plan.action == pp::app::AboutMenuAction::show_about_dialog)
|
||||
dialog_about();
|
||||
execute_about_menu_plan(*this, plan);
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
@@ -1600,8 +1674,7 @@ void App::init_menu_about()
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
if (plan.action == pp::app::AboutMenuAction::show_user_manual)
|
||||
dialog_usermanual();
|
||||
execute_about_menu_plan(*this, plan);
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
@@ -1626,8 +1699,7 @@ void App::init_menu_about()
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
if (plan.action == pp::app::AboutMenuAction::show_whats_new_dialog)
|
||||
dialog_whatsnew(true);
|
||||
execute_about_menu_plan(*this, plan);
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
@@ -1644,11 +1716,7 @@ void App::init_menu_about()
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
if (plan.action == pp::app::AboutMenuAction::trigger_crash_test)
|
||||
{
|
||||
LOG("crashing");
|
||||
crash_test();
|
||||
}
|
||||
execute_about_menu_plan(*this, plan);
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
@@ -1667,37 +1735,7 @@ void App::init_menu_about()
|
||||
g_version_fix,
|
||||
true,
|
||||
Canvas::I != nullptr);
|
||||
if (plan.action == pp::app::AboutMenuAction::run_performance_test)
|
||||
{
|
||||
LOG("perf");
|
||||
std::string message;
|
||||
const int performance_iterations = plan.performance_iterations;
|
||||
render_task([&]
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
Canvas::I->stroke_start({ 0, 0, 0 }, 0.9f);
|
||||
for (int i = 0; i < performance_iterations; i++)
|
||||
{
|
||||
Canvas::I->stroke_update({ 100, 100, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 200, 200, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 200, 100, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 100, 200, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 300, 300, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 200, 500, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 500, 500, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 400, 400, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 0, 200, 0 }, 0.9f);
|
||||
Canvas::I->stroke_update({ 200, 0, 0 }, 0.9f);
|
||||
Canvas::I->stroke_draw();
|
||||
}
|
||||
Canvas::I->stroke_end();
|
||||
auto diff = std::chrono::high_resolution_clock::now() - start;
|
||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count();
|
||||
LOG("%lld ms", ms);
|
||||
message = "Time " + std::to_string(ms) + " ms";
|
||||
});
|
||||
message_box("Performance test", message);
|
||||
}
|
||||
execute_about_menu_plan(*this, plan);
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
|
||||
Reference in New Issue
Block a user