diff --git a/cmake/PanoPainterSources.cmake b/cmake/PanoPainterSources.cmake index 396bc4bb..61c8304e 100644 --- a/cmake/PanoPainterSources.cmake +++ b/cmake/PanoPainterSources.cmake @@ -34,6 +34,7 @@ set(PP_LEGACY_PAINT_DOCUMENT_SOURCES src/legacy_canvas_object_draw_services.h src/legacy_canvas_projection_services.cpp src/legacy_canvas_projection_services.h + src/legacy_canvas_plane_data.cpp src/legacy_canvas_state_services.cpp src/event.cpp ) @@ -171,6 +172,8 @@ set(PP_PANOPAINTER_UI_SOURCES src/legacy_brush_panel_services.h src/legacy_brush_panel_ui.cpp src/legacy_brush_panel_ui.h + src/legacy_brush_preset_list_services.cpp + src/legacy_brush_preset_list_services.h src/legacy_document_animation_services.cpp src/legacy_document_animation_services.h src/legacy_node_canvas_draw_services.cpp diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 2471a37f..9efcaa7a 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -79,12 +79,12 @@ What is still carrying too much live ownership: Current hotspot files: -- `src/canvas.cpp`: 429 lines +- `src/canvas.cpp`: 396 lines - `src/app_layout.cpp`: 125 lines - `src/canvas_modes.cpp`: 402 lines - `src/node.cpp`: 260 lines -- `src/main.cpp`: 141 lines -- `src/node_panel_brush.cpp`: 337 lines +- `src/main.cpp`: 130 lines +- `src/node_panel_brush.cpp`: 255 lines - `src/node_stroke_preview.cpp`: 545 lines - `src/node_canvas.cpp`: 219 lines - `src/app.cpp`: 171 lines @@ -216,7 +216,9 @@ Current architecture mismatches that must be treated as real blockers: `src/platform_windows/windows_bootstrap_helpers.cpp` instead of `src/main.cpp`, while the Win32 window procedure and retained message-handling shell now also live in `src/platform_windows/windows_window_shell.*` - instead of `src/main.cpp`, while retained input-state zeroing and reverse + instead of `src/main.cpp`, while the `WinMain` argv conversion bridge now + also lives in `src/platform_windows/windows_bootstrap_helpers.*` instead of + staying inline in `src/main.cpp`, while retained input-state zeroing and reverse key-map initialization now also live in `src/platform_windows/windows_window_shell.*` instead of `src/main.cpp`, while the remaining interactive Win32 runtime @@ -267,7 +269,11 @@ Current architecture mismatches that must be treated as real blockers: while `Canvas::draw_objects_direct(...)` and `Canvas::draw_objects(...)` now route through `src/legacy_canvas_object_draw_services.*` instead of staying inline in `src/canvas.cpp`, which trims another coherent object-draw and - viewport-state execution family from the live canvas shell, while + viewport-state execution family from the live canvas shell, while the + static canvas plane geometry/orientation data now also lives in + `src/legacy_canvas_plane_data.cpp` instead of staying inline in + `src/canvas.cpp`, which trims another retained data-ownership pocket from + the live canvas shell, while `Canvas::stroke_draw_samples(...)`, `Canvas::stroke_commit()`, and the larger stroke commit/sample execution family now also route through `src/legacy_canvas_stroke_commit_services.*` instead of staying inline in @@ -305,7 +311,10 @@ Current architecture mismatches that must be treated as real blockers: handling, item construction, and added-state update now also route through `src/legacy_brush_preset_panel_ui.*` instead of staying inline in `src/node_panel_brush.cpp`, which materially thins another retained preset - panel UI pocket, while `NodeCanvas::handle_event()` now also routes + panel UI pocket, while the retained `LegacyBrushPresetListServices` block + now also lives in `src/legacy_brush_preset_list_services.*` instead of + staying inline in `src/node_panel_brush.cpp`, which trims another retained + preset workflow pocket, while `NodeCanvas::handle_event()` now also routes through `execute_node_canvas_handle_event(...)`, which trims another coherent input-routing block from `src/node_canvas.cpp` even though the file is still a live canvas/controller shell, while `NodeCanvas` restore/clear context, diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 7488eaab..e9a289d6 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -148,6 +148,10 @@ Current slice: `src/legacy_canvas_render_shell_services.*` instead of staying inline in `src/canvas.cpp`, which trims another large retained render/context shell from the live canvas owner. +- The static canvas plane geometry/orientation data now also lives in + `src/legacy_canvas_plane_data.cpp` instead of staying inline in + `src/canvas.cpp`, which trims another retained data-ownership pocket from + the live canvas shell. - The `CanvasModePen` and `CanvasModeLine` interaction families now also live in `src/legacy_canvas_mode_pen_line.cpp` instead of staying inline in `src/canvas_modes.cpp`, which materially thins another retained pen/line @@ -651,6 +655,9 @@ Current slice: in `src/platform_windows/windows_window_shell.*` instead of `src/main.cpp`, which materially thins the entry file even though broader runtime/entrypoint composition is still open +- the `WinMain` argv conversion bridge now also lives in + `src/platform_windows/windows_bootstrap_helpers.*` instead of staying inline + in `src/main.cpp`, which trims another Windows-specific entrypoint pocket - retained input-state zeroing and reverse key-map initialization now also live in `src/platform_windows/windows_window_shell.*` instead of `src/main.cpp`, which trims another small but real retained-state pocket from the entry TU @@ -1115,6 +1122,10 @@ Current slice: `src/node_panel_brush.cpp`, which materially thins another retained preset panel UI pocket even though cloud/package worker ownership remains the follow-up. +- The retained `LegacyBrushPresetListServices` block now also lives in + `src/legacy_brush_preset_list_services.*` instead of staying inline in + `src/node_panel_brush.cpp`, which trims another retained preset workflow + pocket while preserving the live list-plan dispatch path. - `NodePanelBrush` brush texture panel init, selection dispatch, popup-close event handling, restore-failure prompt flow, and added-state reset now also live in `src/legacy_brush_panel_ui.*` instead of staying diff --git a/src/canvas.cpp b/src/canvas.cpp index f73cc191..514184c1 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -267,39 +267,6 @@ std::vector Canvas::modes[] = { { new CanvasModeMaskLine, new CanvasModeBasicCamera }, // mask-poly { new CanvasModeFloodFill, new CanvasModeBasicCamera }, // flood-fill }; -glm::vec3 Canvas::m_plane_origin[6] = { - { 0, 0,-1}, // front - { 1, 0, 0}, // right - { 0, 0, 1}, // back - {-1, 0, 0}, // left - { 0, 1, 0}, // top - { 0,-1, 0}, // bottom -}; -glm::vec3 Canvas::m_plane_normal[6] = { - { 0, 0, 1}, // front - {-1, 0, 0}, // right - { 0, 0,-1}, // back - { 1, 0, 0}, // left - { 0,-1, 0}, // top - { 0, 1, 0}, // bottom -}; -glm::vec3 Canvas::m_plane_tangent[6] = { - {0, 1, 0}, // front - {0, 1, 0}, // right - {0, 1, 0}, // back - {0, 1, 0}, // left - {0, 0,-1}, // top - {0, 0, 1}, // bottom -}; -// only rotation -glm::mat4 Canvas::m_plane_transform[6] = { - glm::lookAt(glm::vec3(), { 0, 0,-1}, {0, 1, 0}), // front - glm::lookAt(glm::vec3(), {-1, 0, 0}, {0, 1, 0}), // right - glm::lookAt(glm::vec3(), { 0, 0, 1}, {0, 1, 0}), // back - glm::lookAt(glm::vec3(), { 1, 0, 0}, {0, 1, 0}), // left - glm::lookAt(glm::vec3(), { 0, 1, 0}, {0, 0,-1}), // top - glm::lookAt(glm::vec3(), { 0,-1, 0}, {0, 0, 1}), // bottom -}; void Canvas::stroke_end() { pp::panopainter::legacy_canvas_stroke_end(*this); } void Canvas::stroke_cancel() { pp::panopainter::legacy_canvas_stroke_cancel(*this); } diff --git a/src/legacy_brush_preset_list_services.cpp b/src/legacy_brush_preset_list_services.cpp new file mode 100644 index 00000000..0fe8b2b2 --- /dev/null +++ b/src/legacy_brush_preset_list_services.cpp @@ -0,0 +1,98 @@ +#include "pch.h" + +#include "legacy_brush_preset_list_services.h" + +#include "canvas.h" +#include "legacy_ui_overlay_services.h" + +namespace pp::panopainter { + +LegacyBrushPresetListServices::LegacyBrushPresetListServices(NodePanelBrushPreset& owner) + : owner_(owner) +{ +} + +pp::foundation::Status LegacyBrushPresetListServices::add_current_brush_preset(int target_index) +{ + if (target_index < 0) { + return pp::foundation::Status::out_of_range("brush preset add target is invalid"); + } + if (!Canvas::I || !Canvas::I->m_current_brush) { + return pp::foundation::Status::invalid_argument("current brush must be available to add a preset"); + } + + for (auto p : NodePanelBrushPreset::s_panels) { + p->add_brush(std::make_shared(*Canvas::I->m_current_brush)); + } + return pp::foundation::Status::success(); +} + +void LegacyBrushPresetListServices::remove_brush_preset( + int current_index, + int target_index, + bool selects_target, + bool clears_selection) +{ + for (auto p : NodePanelBrushPreset::s_panels) { + if (current_index < 0 || current_index >= static_cast(p->m_container->m_children.size())) { + continue; + } + + const bool new_current = !p->m_current || p->m_container->get_child_index(p->m_current) == current_index; + pp::panopainter::destroy_legacy_node(*p->m_container->m_children[current_index]); + if (clears_selection) { + p->m_current = nullptr; + } else if (new_current && selects_target) { + p->m_current = static_cast(p->m_container->m_children[target_index].get()); + p->m_current->m_selected = true; + } + } +} + +void LegacyBrushPresetListServices::move_brush_preset(int from_index, int to_index) +{ + for (auto p : NodePanelBrushPreset::s_panels) { + if (from_index >= 0 && from_index < static_cast(p->m_container->m_children.size())) { + p->m_container->move_child(p->m_container->m_children[from_index].get(), to_index); + } + } +} + +void LegacyBrushPresetListServices::select_brush_preset(int index, bool notify_brush_changed) +{ + for (auto p : NodePanelBrushPreset::s_panels) { + if (p->m_current) { + p->m_current->m_selected = false; + } + p->m_current = static_cast(p->m_container->get_child_at(index)); + p->m_current->m_selected = true; + p->m_interacted = true; + } + if (notify_brush_changed && owner_.on_brush_changed) { + owner_.on_brush_changed(&owner_, owner_.m_current->m_brush); + } +} + +void LegacyBrushPresetListServices::clear_brush_presets(bool clears_selection) +{ + for (auto p : NodePanelBrushPreset::s_panels) { + p->m_container->remove_all_children(); + if (clears_selection) { + p->m_current = nullptr; + } + } +} + +void LegacyBrushPresetListServices::update_preset_empty_notification() +{ + for (auto p : NodePanelBrushPreset::s_panels) { + p->m_notification->SetVisibility(p->m_container->m_children.size() == 0); + } +} + +void LegacyBrushPresetListServices::save_preset_list() +{ + owner_.save(); +} + +} // namespace pp::panopainter diff --git a/src/legacy_brush_preset_list_services.h b/src/legacy_brush_preset_list_services.h new file mode 100644 index 00000000..87b821de --- /dev/null +++ b/src/legacy_brush_preset_list_services.h @@ -0,0 +1,28 @@ +#pragma once + +#include "app_core/brush_ui.h" +#include "node_panel_brush.h" + +namespace pp::panopainter { + +class LegacyBrushPresetListServices final : public pp::app::BrushPresetListServices { +public: + explicit LegacyBrushPresetListServices(NodePanelBrushPreset& owner); + + pp::foundation::Status add_current_brush_preset(int target_index) override; + void remove_brush_preset( + int current_index, + int target_index, + bool selects_target, + bool clears_selection) override; + void move_brush_preset(int from_index, int to_index) override; + void select_brush_preset(int index, bool notify_brush_changed) override; + void clear_brush_presets(bool clears_selection) override; + void update_preset_empty_notification() override; + void save_preset_list() override; + +private: + NodePanelBrushPreset& owner_; +}; + +} // namespace pp::panopainter diff --git a/src/legacy_canvas_plane_data.cpp b/src/legacy_canvas_plane_data.cpp new file mode 100644 index 00000000..3e8442d2 --- /dev/null +++ b/src/legacy_canvas_plane_data.cpp @@ -0,0 +1,39 @@ +#include "pch.h" +#include "canvas.h" + +glm::vec3 Canvas::m_plane_origin[6] = { + { 0, 0,-1}, // front + { 1, 0, 0}, // right + { 0, 0, 1}, // back + {-1, 0, 0}, // left + { 0, 1, 0}, // top + { 0,-1, 0}, // bottom +}; + +glm::vec3 Canvas::m_plane_normal[6] = { + { 0, 0, 1}, // front + {-1, 0, 0}, // right + { 0, 0,-1}, // back + { 1, 0, 0}, // left + { 0,-1, 0}, // top + { 0, 1, 0}, // bottom +}; + +glm::vec3 Canvas::m_plane_tangent[6] = { + {0, 1, 0}, // front + {0, 1, 0}, // right + {0, 1, 0}, // back + {0, 1, 0}, // left + {0, 0,-1}, // top + {0, 0, 1}, // bottom +}; + +// only rotation +glm::mat4 Canvas::m_plane_transform[6] = { + glm::lookAt(glm::vec3(), { 0, 0,-1}, {0, 1, 0}), // front + glm::lookAt(glm::vec3(), {-1, 0, 0}, {0, 1, 0}), // right + glm::lookAt(glm::vec3(), { 0, 0, 1}, {0, 1, 0}), // back + glm::lookAt(glm::vec3(), { 1, 0, 0}, {0, 1, 0}), // left + glm::lookAt(glm::vec3(), { 0, 1, 0}, {0, 0,-1}), // top + glm::lookAt(glm::vec3(), { 0,-1, 0}, {0, 0, 1}), // bottom +}; diff --git a/src/main.cpp b/src/main.cpp index 62840991..80a13d1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -152,19 +152,5 @@ int main(int argc, char** argv) int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { - int argc = 0; - - // convert args from char to wchar - auto wargs = CommandLineToArgvW(GetCommandLine(), &argc); - auto argv = new char*[argc + 1]; - for (int i = 0; i < argc; i++) - { - auto len = wcslen(wargs[i]) + 1; - argv[i] = new char[len]; - wcstombs_s(nullptr, argv[i], len, wargs[i], len); - } - - LocalFree(wargs); - - return main(argc, argv); + return pp::platform::windows::run_winmain_entry(main); } diff --git a/src/node_panel_brush.cpp b/src/node_panel_brush.cpp index f62bf7d2..2591a47c 100644 --- a/src/node_panel_brush.cpp +++ b/src/node_panel_brush.cpp @@ -3,6 +3,7 @@ #include "node_panel_brush.h" #include "legacy_brush_panel_ui.h" #include "legacy_brush_preset_panel_ui.h" +#include "legacy_brush_preset_list_services.h" #include "legacy_brush_panel_services.h" #include "app_core/brush_ui.h" #include "legacy_brush_ui_services.h" @@ -194,101 +195,6 @@ Node* NodePanelBrushPreset::clone_instantiate() const } namespace pp::panopainter { - -class LegacyBrushPresetListServices final : public pp::app::BrushPresetListServices { -public: - explicit LegacyBrushPresetListServices(NodePanelBrushPreset& owner) - : owner_(owner) - { - } - - pp::foundation::Status add_current_brush_preset(int target_index) override - { - if (target_index < 0) { - return pp::foundation::Status::out_of_range("brush preset add target is invalid"); - } - if (!Canvas::I || !Canvas::I->m_current_brush) { - return pp::foundation::Status::invalid_argument("current brush must be available to add a preset"); - } - - for (auto p : NodePanelBrushPreset::s_panels) { - p->add_brush(std::make_shared(*Canvas::I->m_current_brush)); - } - return pp::foundation::Status::success(); - } - - void remove_brush_preset( - int current_index, - int target_index, - bool selects_target, - bool clears_selection) override - { - for (auto p : NodePanelBrushPreset::s_panels) { - if (current_index < 0 || current_index >= static_cast(p->m_container->m_children.size())) { - continue; - } - - const bool new_current = !p->m_current || p->m_container->get_child_index(p->m_current) == current_index; - pp::panopainter::destroy_legacy_node(*p->m_container->m_children[current_index]); - if (clears_selection) { - p->m_current = nullptr; - } else if (new_current && selects_target) { - p->m_current = static_cast(p->m_container->m_children[target_index].get()); - p->m_current->m_selected = true; - } - } - } - - void move_brush_preset(int from_index, int to_index) override - { - for (auto p : NodePanelBrushPreset::s_panels) { - if (from_index >= 0 && from_index < static_cast(p->m_container->m_children.size())) { - p->m_container->move_child(p->m_container->m_children[from_index].get(), to_index); - } - } - } - - void select_brush_preset(int index, bool notify_brush_changed) override - { - for (auto p : NodePanelBrushPreset::s_panels) { - if (p->m_current) { - p->m_current->m_selected = false; - } - p->m_current = static_cast(p->m_container->get_child_at(index)); - p->m_current->m_selected = true; - p->m_interacted = true; - } - if (notify_brush_changed && owner_.on_brush_changed) { - owner_.on_brush_changed(&owner_, owner_.m_current->m_brush); - } - } - - void clear_brush_presets(bool clears_selection) override - { - for (auto p : NodePanelBrushPreset::s_panels) { - p->m_container->remove_all_children(); - if (clears_selection) { - p->m_current = nullptr; - } - } - } - - void update_preset_empty_notification() override - { - for (auto p : NodePanelBrushPreset::s_panels) { - p->m_notification->SetVisibility(p->m_container->m_children.size() == 0); - } - } - - void save_preset_list() override - { - owner_.save(); - } - -private: - NodePanelBrushPreset& owner_; -}; - } // namespace pp::panopainter void NodePanelBrushPreset::execute_preset_list_plan(const pp::app::BrushPresetListPlan& plan) diff --git a/src/platform_windows/windows_bootstrap_helpers.cpp b/src/platform_windows/windows_bootstrap_helpers.cpp index da78f921..f1653137 100644 --- a/src/platform_windows/windows_bootstrap_helpers.cpp +++ b/src/platform_windows/windows_bootstrap_helpers.cpp @@ -112,6 +112,24 @@ void ensure_runtime_data_directory() LOG("data files ok"); } +int run_winmain_entry(int (*entry_point)(int, char**)) +{ + int argc = 0; + + auto wargs = CommandLineToArgvW(GetCommandLine(), &argc); + auto argv = new char*[argc + 1]; + for (int i = 0; i < argc; i++) + { + auto len = wcslen(wargs[i]) + 1; + argv[i] = new char[len]; + wcstombs_s(nullptr, argv[i], len, wargs[i], len); + } + + LocalFree(wargs); + + return entry_point(argc, argv); +} + void setup_exception_handler() { // Setup exception handler diff --git a/src/platform_windows/windows_bootstrap_helpers.h b/src/platform_windows/windows_bootstrap_helpers.h index 3b50962b..67df88c0 100644 --- a/src/platform_windows/windows_bootstrap_helpers.h +++ b/src/platform_windows/windows_bootstrap_helpers.h @@ -48,6 +48,7 @@ enum class MainStartupResult void ensure_runtime_data_directory(); void setup_exception_handler(); +int run_winmain_entry(int (*entry_point)(int, char**)); MainWindowStartupState initialize_main_window_startup_state(); void create_main_window(const MainWindowStartupState& startup, HWND& hWnd, HINSTANCE hInst, const wchar_t* window_title); void initialize_pixel_format_descriptor(PIXELFORMATDESCRIPTOR& pixel_format);