Extract about menu action planning
This commit is contained in:
86
src/app_core/about_menu.h
Normal file
86
src/app_core/about_menu.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace pp::app {
|
||||
|
||||
enum class AboutMenuCommand {
|
||||
help_guide,
|
||||
about_app,
|
||||
whats_new,
|
||||
induce_crash,
|
||||
performance_test,
|
||||
};
|
||||
|
||||
enum class AboutMenuAction {
|
||||
show_user_manual,
|
||||
show_about_dialog,
|
||||
show_whats_new_dialog,
|
||||
trigger_crash_test,
|
||||
run_performance_test,
|
||||
no_op_unavailable,
|
||||
};
|
||||
|
||||
struct AboutMenuPlan {
|
||||
AboutMenuCommand command = AboutMenuCommand::help_guide;
|
||||
AboutMenuAction action = AboutMenuAction::show_user_manual;
|
||||
std::string label;
|
||||
bool closes_root_popup = true;
|
||||
bool requires_canvas = false;
|
||||
int performance_iterations = 0;
|
||||
int performance_updates_per_iteration = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline AboutMenuPlan plan_about_menu_command(
|
||||
AboutMenuCommand command,
|
||||
int version_major,
|
||||
int version_minor,
|
||||
int version_fix,
|
||||
bool diagnostics_available = true,
|
||||
bool has_canvas = true)
|
||||
{
|
||||
AboutMenuPlan plan;
|
||||
plan.command = command;
|
||||
|
||||
switch (command) {
|
||||
case AboutMenuCommand::help_guide:
|
||||
plan.action = AboutMenuAction::show_user_manual;
|
||||
plan.label = "Help Guide";
|
||||
break;
|
||||
case AboutMenuCommand::about_app:
|
||||
plan.action = AboutMenuAction::show_about_dialog;
|
||||
plan.label = "About PanoPainter";
|
||||
break;
|
||||
case AboutMenuCommand::whats_new:
|
||||
plan.action = AboutMenuAction::show_whats_new_dialog;
|
||||
plan.label = "What's new in "
|
||||
+ std::to_string(version_major)
|
||||
+ "."
|
||||
+ std::to_string(version_minor)
|
||||
+ "."
|
||||
+ std::to_string(version_fix)
|
||||
+ "?";
|
||||
break;
|
||||
case AboutMenuCommand::induce_crash:
|
||||
plan.label = "Induce crash";
|
||||
plan.action = diagnostics_available
|
||||
? AboutMenuAction::trigger_crash_test
|
||||
: AboutMenuAction::no_op_unavailable;
|
||||
plan.closes_root_popup = diagnostics_available;
|
||||
break;
|
||||
case AboutMenuCommand::performance_test:
|
||||
plan.label = has_canvas ? "Performance test" : "Performance test (No canvas)";
|
||||
plan.requires_canvas = true;
|
||||
plan.performance_iterations = 100;
|
||||
plan.performance_updates_per_iteration = 10;
|
||||
plan.action = has_canvas
|
||||
? AboutMenuAction::run_performance_test
|
||||
: AboutMenuAction::no_op_unavailable;
|
||||
plan.closes_root_popup = has_canvas;
|
||||
break;
|
||||
}
|
||||
|
||||
return plan;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "node_progress_bar.h"
|
||||
#include "node_dialog_picker.h"
|
||||
#include "node_panel_floating.h"
|
||||
#include "app_core/about_menu.h"
|
||||
#include "app_core/app_preferences.h"
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "app_core/canvas_tool_ui.h"
|
||||
@@ -1495,76 +1496,131 @@ void App::init_menu_about()
|
||||
layout[main_id]->add_child(popup);
|
||||
|
||||
popup->find<NodeButtonCustom>("about-app")->on_click = [this, popup](Node*) {
|
||||
dialog_about();
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
const auto plan = pp::app::plan_about_menu_command(
|
||||
pp::app::AboutMenuCommand::about_app,
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
if (plan.action == pp::app::AboutMenuAction::show_about_dialog)
|
||||
dialog_about();
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
}
|
||||
};
|
||||
|
||||
popup->find<NodeButtonCustom>("about-doc")->on_click = [this, popup](Node*) {
|
||||
// auto path = Asset::absolute("data/doc/test.pdf");
|
||||
// display_file(path);
|
||||
dialog_usermanual();
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
const auto plan = pp::app::plan_about_menu_command(
|
||||
pp::app::AboutMenuCommand::help_guide,
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
if (plan.action == pp::app::AboutMenuAction::show_user_manual)
|
||||
dialog_usermanual();
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
}
|
||||
};
|
||||
|
||||
if (auto item = popup->find<NodeButtonCustom>("about-news"))
|
||||
{
|
||||
if (auto text = item->find<NodeText>("menu-label"))
|
||||
{
|
||||
static char label[128];
|
||||
sprintf(label, "What's new in %d.%d.%d?", g_version_major, g_version_minor, g_version_fix);
|
||||
text->set_text(label);
|
||||
const auto plan = pp::app::plan_about_menu_command(
|
||||
pp::app::AboutMenuCommand::whats_new,
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
text->set_text(plan.label.c_str());
|
||||
}
|
||||
item->on_click = [this, popup](Node*) {
|
||||
dialog_whatsnew(true);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
const auto plan = pp::app::plan_about_menu_command(
|
||||
pp::app::AboutMenuCommand::whats_new,
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
if (plan.action == pp::app::AboutMenuAction::show_whats_new_dialog)
|
||||
dialog_whatsnew(true);
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (auto b = popup->find<NodeButtonCustom>("about-crash"))
|
||||
{
|
||||
b->on_click = [this, popup](Node*) {
|
||||
LOG("crashing");
|
||||
crash_test();
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
const auto plan = pp::app::plan_about_menu_command(
|
||||
pp::app::AboutMenuCommand::induce_crash,
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix);
|
||||
if (plan.action == pp::app::AboutMenuAction::trigger_crash_test)
|
||||
{
|
||||
LOG("crashing");
|
||||
crash_test();
|
||||
}
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (auto b = popup->find<NodeButtonCustom>("about-perf"))
|
||||
{
|
||||
b->on_click = [this, popup](Node*) {
|
||||
LOG("perf");
|
||||
static char str[256];
|
||||
render_task([&]
|
||||
const auto plan = pp::app::plan_about_menu_command(
|
||||
pp::app::AboutMenuCommand::performance_test,
|
||||
g_version_major,
|
||||
g_version_minor,
|
||||
g_version_fix,
|
||||
true,
|
||||
Canvas::I != nullptr);
|
||||
if (plan.action == pp::app::AboutMenuAction::run_performance_test)
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
Canvas::I->stroke_start({ 0, 0, 0 }, 0.9f);
|
||||
for (int i = 0; i < 100; i++)
|
||||
LOG("perf");
|
||||
std::string message;
|
||||
const int performance_iterations = plan.performance_iterations;
|
||||
render_task([&]
|
||||
{
|
||||
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);
|
||||
sprintf(str, "Time %lld ms", ms);
|
||||
});
|
||||
message_box("Performance test", str);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
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);
|
||||
}
|
||||
if (plan.closes_root_popup)
|
||||
{
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user