From 2a2f0c7dd6d27d07fd16dc7dade2059baa2044fe Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 16 Jun 2026 22:18:30 +0200 Subject: [PATCH] Extract node lifecycle, preview runtime, and Win32 input state --- cmake/PanoPainterSources.cmake | 3 + docs/modernization/roadmap.md | 23 ++- docs/modernization/tasks.md | 15 ++ ...y_node_stroke_preview_runtime_services.cpp | 81 ++++++++ ...acy_node_stroke_preview_runtime_services.h | 53 ++++++ src/legacy_ui_node_lifecycle.cpp | 178 ++++++++++++++++++ src/legacy_ui_node_lifecycle.h | 11 ++ src/main.cpp | 28 +-- src/node.cpp | 155 --------------- src/node_stroke_preview.cpp | 92 ++++----- src/platform_windows/windows_window_shell.cpp | 25 +++ src/platform_windows/windows_window_shell.h | 1 + 12 files changed, 420 insertions(+), 245 deletions(-) create mode 100644 src/legacy_node_stroke_preview_runtime_services.h create mode 100644 src/legacy_ui_node_lifecycle.cpp create mode 100644 src/legacy_ui_node_lifecycle.h diff --git a/cmake/PanoPainterSources.cmake b/cmake/PanoPainterSources.cmake index 87da8899..396bc4bb 100644 --- a/cmake/PanoPainterSources.cmake +++ b/cmake/PanoPainterSources.cmake @@ -53,6 +53,8 @@ set(PP_LEGACY_UI_CORE_SOURCES src/legacy_ui_node_loader.h src/legacy_ui_node_event.cpp src/legacy_ui_node_event.h + src/legacy_ui_node_lifecycle.cpp + src/legacy_ui_node_lifecycle.h src/legacy_ui_node_style.cpp src/legacy_ui_node_style.h src/legacy_ui_node_execution.cpp @@ -206,6 +208,7 @@ set(PP_PANOPAINTER_UI_SOURCES src/legacy_node_stroke_preview_draw_services.cpp src/legacy_node_stroke_preview_draw_services.h src/legacy_node_stroke_preview_runtime_services.cpp + src/legacy_node_stroke_preview_runtime_services.h src/node_stroke_preview.cpp src/node_tool_bucket.cpp src/node_usermanual.cpp diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index cd8ce898..2471a37f 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -82,10 +82,10 @@ Current hotspot files: - `src/canvas.cpp`: 429 lines - `src/app_layout.cpp`: 125 lines - `src/canvas_modes.cpp`: 402 lines -- `src/node.cpp`: 389 lines -- `src/main.cpp`: 166 lines +- `src/node.cpp`: 260 lines +- `src/main.cpp`: 141 lines - `src/node_panel_brush.cpp`: 337 lines -- `src/node_stroke_preview.cpp`: 562 lines +- `src/node_stroke_preview.cpp`: 545 lines - `src/node_canvas.cpp`: 219 lines - `src/app.cpp`: 171 lines - `src/app_dialogs.cpp`: 168 lines @@ -216,7 +216,10 @@ 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 the remaining interactive Win32 runtime + instead of `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 pocket for touch registration, render/UI thread startup, GL debug callback hookup, Wintab initialization/skip, icon setup, placement restore, optional VR start, splash dismissal, message loop, and shutdown cleanup now also @@ -248,7 +251,11 @@ Current architecture mismatches that must be treated as real blockers: the remaining immediate preview pass shell now also routes through `execute_legacy_node_stroke_preview_draw_immediate_shell(...)`, which materially reduces the live preview-pass body even though broader - worker/readback flow still remains inline, while + worker/readback flow still remains inline, while the immediate preview + runtime/orchestration block for stroke setup, prepared-stroke construction, + pass planning, shader setup, and live render request assembly now also + routes through `src/legacy_node_stroke_preview_runtime_services.*` instead + of staying inline in `src/node_stroke_preview.cpp`, while `NodeCanvas::draw()` unmerged-pass blend-gate, layer-orientation, and callback-assembly setup now also route through `execute_node_canvas_draw_unmerged_pass(...)`, which trims another coherent @@ -333,7 +340,11 @@ Current architecture mismatches that must be treated as real blockers: `clear_context`, `update`, `update_internal`, and `tick` now also lives in `src/legacy_ui_node_execution.cpp`, while `Node::parse_attributes(...)` now also routes through `src/legacy_ui_node_attributes.*` instead of staying - inline in `src/node.cpp`, + inline in `src/node.cpp`, while the remaining generic `Node` lifecycle/state + pocket for no-op lifecycle hooks, add/remove propagation, move construction, + destruction cleanup, and base clone plumbing now also routes through + `src/legacy_ui_node_lifecycle.*` instead of staying inline in + `src/node.cpp`, while `Canvas` point-trace/unproject/project/camera push-pop-get-set and face-to-shape helpers now also route through `src/legacy_canvas_projection_services.*` instead of staying inline in diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index f290d0a0..7488eaab 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -335,6 +335,13 @@ Current slice: `src/legacy_node_stroke_preview_draw_services.*` instead of staying inline in `src/node_stroke_preview.cpp`, which trims another coherent preview draw-pass pocket while preserving the current runtime-facing shell. +- The immediate preview runtime/orchestration block in + `NodeStrokePreview::draw_stroke_immediate()` for stroke setup, prepared + stroke construction, pass planning, shader setup, and live render request + assembly now also lives in + `src/legacy_node_stroke_preview_runtime_services.*` instead of staying + inline in `src/node_stroke_preview.cpp`, which trims another coherent + preview runtime pocket while preserving the current live draw path. - `NodeCanvas::init()` plus the remaining `NodeCanvas::draw()` outer shell now also live in `src/legacy_node_canvas_draw_services.*` instead of staying inline in `src/node_canvas.cpp`, which materially reduces the live node to a @@ -644,6 +651,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 +- 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 - the remaining interactive Win32 runtime pocket for touch registration, render/UI thread startup, debug GL callback hookup, Wintab init/skip, icon setup, placement restore, optional VR start, splash dismissal, message @@ -802,6 +812,11 @@ Current slice: `Node::GetRTL()` now also lives in `src/legacy_ui_node_style.*` instead of staying inline in `src/node.cpp`, which trims another coherent generic node shell pocket without changing the public surface. +- The remaining generic `Node` lifecycle/state pocket for no-op lifecycle + hooks, add/remove propagation, move construction, destruction cleanup, and + base clone plumbing now also lives in `src/legacy_ui_node_lifecycle.*` + instead of staying inline in `src/node.cpp`, which materially thins another + coherent generic scene-graph shell without changing the public surface. Write scope: - `src/node.cpp` diff --git a/src/legacy_node_stroke_preview_runtime_services.cpp b/src/legacy_node_stroke_preview_runtime_services.cpp index fa6475cf..f077e269 100644 --- a/src/legacy_node_stroke_preview_runtime_services.cpp +++ b/src/legacy_node_stroke_preview_runtime_services.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "legacy_node_stroke_preview_runtime_services.h" #include "log.h" #include "node_stroke_preview.h" #include "texture.h" @@ -21,6 +22,86 @@ #include #include +namespace pp::panopainter { + +bool execute_legacy_node_stroke_preview_immediate_runtime( + const LegacyNodeStrokePreviewImmediateRuntimeRequest& request) +{ + if (!request.brush || + !request.prepare_render_target || + !request.finish_render_target || + !request.set_blend_enabled || + !request.setup_stroke_shader) { + return false; + } + + const glm::vec2 render_target_size = { + static_cast(request.preview_rtt.getWidth()), + static_cast(request.preview_rtt.getHeight()), + }; + const auto stroke_setup = plan_legacy_node_stroke_preview_stroke_setup( + LegacyNodeStrokePreviewStrokeSetupRequest { + .preview_size = request.preview_size, + .zoom = request.zoom, + .brush_tip_size = request.brush->m_tip_size, + .stroke_max_size_override = request.stroke_max_size_override, + .pad_override = request.pad_override, + .tip_size_pressure = request.brush->m_tip_size_pressure, + .dual_enabled = request.brush->m_dual_enabled, + .dual_size = request.brush->m_dual_size, + .pattern_scale = request.brush->m_pattern_scale, + .pattern_flipx = request.brush->m_pattern_flipx, + .pattern_flipy = request.brush->m_pattern_flipy, + }); + const auto prepared_strokes = prepare_legacy_node_stroke_preview_strokes( + request.brush, + stroke_setup, + request.camera_fov, + request.camera_rot); + const glm::mat4 ortho_proj = glm::ortho(0, render_target_size.x, 0, render_target_size.y, -1, 1); + + request.prepare_render_target(); + request.set_blend_enabled(false); + + const auto pass_orchestration = plan_legacy_node_stroke_preview_pass_orchestration( + make_legacy_node_stroke_preview_pass_orchestration_request( + request.render_device_features, + render_target_size, + *request.brush, + ortho_proj)); + request.setup_stroke_shader(pass_orchestration.stroke_shader); + const bool sequence_ok = execute_legacy_node_stroke_preview_live_render_passes( + LegacyNodeStrokePreviewLiveRenderRequest { + .brush = *request.brush, + .pass_orchestration = pass_orchestration, + .prepared_strokes = prepared_strokes, + .stroke_texture = request.preview_stroke_texture, + .mixer_rtt = request.preview_rtt_mixer, + .render_target = request.preview_rtt, + .background_texture = request.preview_background_texture, + .dual_texture = request.preview_dual_texture, + .preview_texture = request.preview_image_texture, + .linear_sampler = request.linear_sampler, + .repeat_sampler = request.repeat_sampler, + .zoom = request.zoom, + .min_flow = request.min_flow, + .copy_stroke_destination = pass_orchestration.copy_stroke_destination, + .size = render_target_size, + .bind_dual_pass_textures = request.bind_dual_pass_textures, + .capture_background = request.capture_background, + .compute_frames = request.compute_frames, + .draw_samples = request.draw_samples, + .draw_mix = request.draw_mix, + .unbind_mixer_texture = request.unbind_mixer_texture, + .bind_pattern_texture = request.bind_pattern_texture, + .draw_composite = request.draw_composite, + }); + request.finish_render_target(); + return sequence_ok; +} + +} // namespace pp::panopainter + std::atomic_int NodeStrokePreview::s_instances{ 0 }; std::atomic_bool NodeStrokePreview::s_running{ false }; std::mutex NodeStrokePreview::s_render_mutex; diff --git a/src/legacy_node_stroke_preview_runtime_services.h b/src/legacy_node_stroke_preview_runtime_services.h new file mode 100644 index 00000000..8d54038b --- /dev/null +++ b/src/legacy_node_stroke_preview_runtime_services.h @@ -0,0 +1,53 @@ +#pragma once + +#include "../libs/glm/glm/ext/matrix_float4x4.hpp" +#include "../libs/glm/glm/ext/vector_float2.hpp" + +#include "brush.h" +#include "legacy_node_stroke_preview_draw_services.h" +#include "renderer_api/renderer_api.h" +#include "rtt.h" +#include "texture.h" + +#include +#include +#include + +namespace pp::panopainter { + +struct LegacyNodeStrokePreviewImmediateRuntimeRequest { + const std::shared_ptr& brush; + glm::vec2 preview_size {}; + float zoom = 1.0f; + float min_flow = 0.0f; + float stroke_max_size_override = 0.0f; + float pad_override = NAN; + float camera_fov = 0.0f; + glm::mat4 camera_rot { 1.0f }; + pp::renderer::RenderDeviceFeatures render_device_features {}; + RTT& preview_rtt; + RTT& preview_rtt_mixer; + Texture2D& preview_stroke_texture; + Texture2D& preview_dual_texture; + Texture2D& preview_background_texture; + Texture2D& preview_image_texture; + Sampler& linear_sampler; + Sampler& repeat_sampler; + std::function prepare_render_target; + std::function finish_render_target; + std::function set_blend_enabled; + std::function setup_stroke_shader; + std::function bind_dual_pass_textures; + std::function capture_background; + std::function(const Stroke&, float)> compute_frames; + std::function&, Texture2D&, bool)> draw_samples; + std::function draw_mix; + std::function unbind_mixer_texture; + std::function bind_pattern_texture; + std::function draw_composite; +}; + +[[nodiscard]] bool execute_legacy_node_stroke_preview_immediate_runtime( + const LegacyNodeStrokePreviewImmediateRuntimeRequest& request); + +} // namespace pp::panopainter diff --git a/src/legacy_ui_node_lifecycle.cpp b/src/legacy_ui_node_lifecycle.cpp new file mode 100644 index 00000000..362c1b10 --- /dev/null +++ b/src/legacy_ui_node_lifecycle.cpp @@ -0,0 +1,178 @@ +#include "pch.h" +#include "legacy_ui_node_lifecycle.h" + +#include "node.h" + +namespace pp::panopainter +{ +void legacy_ui_node_move_construct(Node& dest, Node&& src) +{ + dest.m_name = std::move(src.m_name); + dest.m_nodeID_s = std::move(src.m_nodeID_s); + dest.m_children = std::move(src.m_children); + dest.m_nodeID = src.m_nodeID; + dest.m_display = src.m_display; + dest.m_parent = src.m_parent; + dest.y_node = src.y_node; + dest.m_pos = src.m_pos; + dest.m_size = src.m_size; + dest.m_clip = src.m_clip; + dest.m_zoom = src.m_zoom; + dest.m_mouse_ignore = src.m_mouse_ignore; + src.y_node = nullptr; + src.m_parent = nullptr; + + dest.set_manager(src.m_manager); + for (auto& child : dest.m_children) + child->m_parent = &dest; + + dest.current_mouse_capture = src.current_mouse_capture; + dest.current_key_capture = src.current_key_capture; + dest.m_mouse_captured = src.m_mouse_captured; + dest.m_key_captured = src.m_key_captured; + + dest.m_proj = src.m_proj; + dest.m_mvp = src.m_mvp; + dest.m_mouse_inside = src.m_mouse_inside; + dest.m_flood_events = src.m_flood_events; + dest.m_force_mouse_capture = src.m_force_mouse_capture; + dest.m_capture_children = src.m_capture_children; + dest.m_destroyed = false; // src.m_destroyed + + dest.m_scale = src.m_scale; + dest.m_pos_origin = src.m_pos_origin; + dest.m_pos_offset = src.m_pos_offset; + dest.m_pos_offset_childred = src.m_pos_offset_childred; + dest.m_clip_uncut = src.m_clip_uncut; + + dest.auto_width = src.auto_width; + dest.auto_height = src.auto_height; +} + +void legacy_ui_node_destroy(Node& node) +{ + node.m_children.clear(); + if (node.y_node) + YGNodeFree(node.y_node); + if (node.y_placeholder) + YGNodeFree(node.y_placeholder); +} + +void legacy_ui_node_clone_copy(const Node& src, Node& dest) +{ + YGNodeCopyStyle(dest.y_node, src.y_node); + dest.set_manager(src.m_manager); + + dest.m_name = src.m_name; + dest.m_nodeID_s = src.m_nodeID_s; + dest.m_nodeID = src.m_nodeID; + dest.m_display = src.m_display; + dest.m_pos = src.m_pos; + dest.m_size = src.m_size; + dest.m_clip = src.m_clip; + dest.m_flood_events = src.m_flood_events; + dest.m_force_mouse_capture = src.m_force_mouse_capture; + + dest.current_mouse_capture = src.current_mouse_capture; + dest.current_key_capture = src.current_key_capture; + dest.m_mouse_captured = src.m_mouse_captured; + dest.m_key_captured = src.m_key_captured; + dest.m_proj = src.m_proj; + dest.m_mvp = src.m_mvp; + dest.m_mouse_inside = src.m_mouse_inside; + dest.m_capture_children = src.m_capture_children; + dest.m_destroyed = false; // src.m_destroyed + dest.m_scale = src.m_scale; + dest.m_pos_origin = src.m_pos_origin; + dest.m_pos_offset = src.m_pos_offset; + dest.m_pos_offset_childred = src.m_pos_offset_childred; + dest.m_clip_uncut = src.m_clip_uncut; + + dest.auto_width = src.auto_width; + dest.auto_height = src.auto_height; +} + +void legacy_ui_node_clone_children(const Node& src, Node& dest) +{ + for (auto& child : src.m_children) + { + std::shared_ptr clone = child->clone(); + dest.m_children.push_back(clone); + clone->m_parent = &dest; + clone->set_manager(dest.m_manager); + clone->loaded(); + YGNodeInsertChild(dest.y_node, clone->y_node, YGNodeGetChildCount(dest.y_node)); + } +} +} + +void Node::create() +{ +} + +void Node::init() +{ +} + +void Node::loaded() +{ +} + +void Node::added(Node* parent) +{ + for (auto& child : m_children) + child->added(this); +} + +void Node::removed(Node* parent) +{ + for (auto current = m_parent; current; current = current->m_parent) + if (current->child_mouse_focus.get() == this) + current->child_mouse_focus = nullptr; +} + +Node&& Node::operator=(Node&& o) +{ + return std::forward(o); +} + +Node::Node() +{ + y_node = YGNodeNew(); + YGNodeSetContext(y_node, this); + y_placeholder = nullptr; +} + +Node::Node(Node&& o) +{ + pp::panopainter::legacy_ui_node_move_construct(*this, std::move(o)); +} + +Node::~Node() +{ + pp::panopainter::legacy_ui_node_destroy(*this); +} + +void Node::draw() +{ +} + +Node* Node::clone_instantiate() const +{ + return new Node(); +} + +void Node::clone_copy(Node* dest) const +{ + pp::panopainter::legacy_ui_node_clone_copy(*this, *dest); +} + +void Node::clone_children(Node* dest) const +{ + pp::panopainter::legacy_ui_node_clone_children(*this, *dest); +} + +void Node::clone_finalize(Node* dest) const +{ + /* find controllers and stuff */ +} diff --git a/src/legacy_ui_node_lifecycle.h b/src/legacy_ui_node_lifecycle.h new file mode 100644 index 00000000..8d5214db --- /dev/null +++ b/src/legacy_ui_node_lifecycle.h @@ -0,0 +1,11 @@ +#pragma once + +class Node; + +namespace pp::panopainter +{ +void legacy_ui_node_move_construct(Node& dest, Node&& src); +void legacy_ui_node_destroy(Node& node); +void legacy_ui_node_clone_copy(const Node& src, Node& dest); +void legacy_ui_node_clone_children(const Node& src, Node& dest); +} diff --git a/src/main.cpp b/src/main.cpp index e65a4179..62840991 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,6 @@ #include "image.h" #include "app.h" #include "canvas.h" -#include "keymap.h" #include "platform_windows/windows_bootstrap_helpers.h" #include "platform_windows/windows_platform_services.h" #include "platform_windows/windows_lifecycle_shell.h" @@ -75,30 +74,6 @@ void win32_update_fps(int frames) })); } -// create a reverse map from kKey to VK_XXX -void init_vk_map() -{ - auto& state = retained_state(); - for (int k = 1; k < 256; k++) // ignore kKey::Unknown = 0 - { - for (int vk = 0; vk < 256; vk++) - { - if (k == (int)convert_key(vk)) - { - if (state.vkey_map.find((kKey)k) == state.vkey_map.end()) - { - state.vkey_map.insert({ (kKey)k, vk }); - } - else - { - LOG("KEY MAP COLLISION %d and %d maps to %d", - (int)vk, (int)state.vkey_map[(kKey)k], (int)k); - } - } - } - } -} - bool win32_vr_start() { auto& state = retained_state(); @@ -133,7 +108,7 @@ int main(int argc, char** argv) pp::platform::windows::SplashScreen splash(GetModuleHandle(NULL)); - init_vk_map(); + pp::platform::windows::initialize_retained_input_state(); pp::platform::windows::setup_exception_handler(); @@ -141,7 +116,6 @@ int main(int argc, char** argv) App::I->create(); - memset(&state.keys, 0, sizeof(state.keys)); auto startup = pp::platform::windows::initialize_main_window_startup_state(); auto context = pp::platform::windows::OpenGlWindowContext {}; switch (pp::platform::windows::initialize_main_window_and_gl(startup, state.hWnd, state.hInst, state.window_title, context)) diff --git a/src/node.cpp b/src/node.cpp index ea475127..2c611af3 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -49,34 +49,6 @@ void Node::handle_parent_resize(glm::vec2 old_size, glm::vec2 new_size) } -void Node::create() -{ - -} - -void Node::init() -{ - -} - -void Node::loaded() -{ - -} - -void Node::added(Node* parent) -{ - for (auto& c : m_children) - c->added(this); -} - -void Node::removed(Node* parent) -{ - for (auto p = m_parent; p; p = p->m_parent) - if (p->child_mouse_focus.get() == this) - p->child_mouse_focus = nullptr; -} - void Node::mouse_capture() { pp::panopainter::legacy_ui_node_mouse_capture(*this); @@ -97,71 +69,6 @@ void Node::key_release() pp::panopainter::legacy_ui_node_key_release(*this); } -Node&& Node::operator=(Node&& o) -{ - return std::forward(o); -} - -Node::Node() -{ - y_node = YGNodeNew(); - YGNodeSetContext(y_node, this); - y_placeholder = nullptr; -} - -Node::Node(Node&& o) -{ - m_name = std::move(o.m_name); - m_nodeID_s = std::move(o.m_nodeID_s); - m_children = std::move(o.m_children); - m_nodeID = o.m_nodeID; - m_display = o.m_display; - m_parent = o.m_parent; - y_node = o.y_node; - m_pos = o.m_pos; - m_size = o.m_size; - m_clip = o.m_clip; - m_zoom = o.m_zoom; - m_mouse_ignore = o.m_mouse_ignore; - o.y_node = nullptr; - o.m_parent = nullptr; - - set_manager(o.m_manager); - for (auto& c : m_children) - c->m_parent = this; - - current_mouse_capture = o.current_mouse_capture; - current_key_capture = o.current_key_capture; - m_mouse_captured = o.m_mouse_captured; - m_key_captured = o.m_key_captured; - - m_proj = o.m_proj; - m_mvp = o.m_mvp; - m_mouse_inside = o.m_mouse_inside; - m_flood_events = o.m_flood_events; - m_force_mouse_capture = o.m_force_mouse_capture; - m_capture_children = o.m_capture_children; - m_destroyed = false;// o.m_destroyed; - - m_scale = o.m_scale; - m_pos_origin = o.m_pos_origin; - m_pos_offset = o.m_pos_offset; - m_pos_offset_childred = o.m_pos_offset_childred; - m_clip_uncut = o.m_clip_uncut; - - auto_width = o.auto_width; - auto_height = o.auto_height; -} - -Node::~Node() -{ - m_children.clear(); - if (y_node) - YGNodeFree(y_node); - if (y_placeholder) - YGNodeFree(y_placeholder); -} - void Node::SetWidth(float value) { pp::panopainter::legacy_ui_node_set_width(*this, value); @@ -412,65 +319,3 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node, bool skip_children pp::panopainter::load_legacy_ui_children(*this, *x_node); loaded(); } - -void Node::draw() -{ - -} - -Node* Node::clone_instantiate() const -{ - return new Node(); -} - -void Node::clone_copy(Node* dest) const -{ - YGNodeCopyStyle(dest->y_node, y_node); - dest->set_manager(m_manager); - - dest->m_name = m_name; - dest->m_nodeID_s = m_nodeID_s; - dest->m_nodeID = m_nodeID; - dest->m_display = m_display; - dest->m_pos = m_pos; - dest->m_size = m_size; - dest->m_clip = m_clip; - dest->m_flood_events = m_flood_events; - dest->m_force_mouse_capture = m_force_mouse_capture; - - dest->current_mouse_capture = current_mouse_capture; - dest->current_key_capture = current_key_capture; - dest->m_mouse_captured = m_mouse_captured; - dest->m_key_captured = m_key_captured; - dest->m_proj = m_proj; - dest->m_mvp = m_mvp; - dest->m_mouse_inside = m_mouse_inside; - dest->m_capture_children = m_capture_children; - dest->m_destroyed = false;// m_destroyed; - dest->m_scale = m_scale; - dest->m_pos_origin = m_pos_origin; - dest->m_pos_offset = m_pos_offset; - dest->m_pos_offset_childred = m_pos_offset_childred; - dest->m_clip_uncut = m_clip_uncut; - - dest->auto_width = auto_width; - dest->auto_height = auto_height; -} - -void Node::clone_children(Node* dest) const -{ - for (auto& c : m_children) - { - std::shared_ptr cn = c->clone(); - dest->m_children.push_back(cn); - cn->m_parent = dest; - cn->set_manager(dest->m_manager); - cn->loaded(); - YGNodeInsertChild(dest->y_node, cn->y_node, YGNodeGetChildCount(dest->y_node)); - } -} - -void Node::clone_finalize(Node* dest) const -{ - /* find controllers and stuff */ -} diff --git a/src/node_stroke_preview.cpp b/src/node_stroke_preview.cpp index 41bfe76e..c6ad8348 100644 --- a/src/node_stroke_preview.cpp +++ b/src/node_stroke_preview.cpp @@ -13,6 +13,7 @@ #include "legacy_canvas_stroke_shader_services.h" #include "legacy_canvas_stroke_services.h" #include "legacy_node_stroke_preview_execution_services.h" +#include "legacy_node_stroke_preview_runtime_services.h" #include "legacy_ui_gl_dispatch.h" #include "paint_renderer/compositor.h" #include "renderer_gl/opengl_capabilities.h" @@ -506,66 +507,45 @@ void NodeStrokePreview::draw_stroke_immediate() const auto vp = query_stroke_preview_viewport(); const auto cc = query_stroke_preview_clear_color(); - - float zoom = root()->m_zoom; - - glm::vec2 size = { m_rtt.getWidth(), m_rtt.getHeight() }; - const auto stroke_setup = pp::panopainter::plan_legacy_node_stroke_preview_stroke_setup( - pp::panopainter::LegacyNodeStrokePreviewStrokeSetupRequest { + const glm::vec2 size = { m_rtt.getWidth(), m_rtt.getHeight() }; + const float zoom = root()->m_zoom; + const bool sequence_ok = pp::panopainter::execute_legacy_node_stroke_preview_immediate_runtime( + pp::panopainter::LegacyNodeStrokePreviewImmediateRuntimeRequest { + .brush = m_brush, .preview_size = m_size, .zoom = zoom, - .brush_tip_size = m_brush->m_tip_size, + .min_flow = m_min_flow, .stroke_max_size_override = m_max_size, .pad_override = m_pad_override, - .tip_size_pressure = m_brush->m_tip_size_pressure, - .dual_enabled = m_brush->m_dual_enabled, - .dual_size = m_brush->m_dual_size, - .pattern_scale = m_brush->m_pattern_scale, - .pattern_flipx = m_brush->m_pattern_flipx, - .pattern_flipy = m_brush->m_pattern_flipy, - }); - glm::mat4 ortho_proj = glm::ortho(0, size.x, 0, size.y, -1, 1); - apply_stroke_preview_viewport(0, 0, m_rtt.getWidth(), m_rtt.getHeight()); - m_rtt.bindFramebuffer(); - m_rtt.clear(); - bind_stroke_preview_live_samplers( - m_sampler_mipmap, - m_sampler_linear, - m_sampler_linear_repeat); - - const auto& b = m_brush; - - auto prepared_strokes = pp::panopainter::prepare_legacy_node_stroke_preview_strokes( - b, - stroke_setup, - Canvas::I->m_cam_fov, - Canvas::I->m_cam_rot); - - apply_stroke_preview_capability(pp::renderer::gl::blend_state(), false); - const auto pass_orchestration = pp::panopainter::plan_legacy_node_stroke_preview_pass_orchestration( - pp::panopainter::make_legacy_node_stroke_preview_pass_orchestration_request( - stroke_preview_render_device_features(), - size, - *b, - ortho_proj)); - pp::panopainter::setup_legacy_stroke_shader(pass_orchestration.stroke_shader); - const bool sequence_ok = pp::panopainter::execute_legacy_node_stroke_preview_live_render_passes( - pp::panopainter::LegacyNodeStrokePreviewLiveRenderRequest { - .brush = *b, - .pass_orchestration = pass_orchestration, - .prepared_strokes = prepared_strokes, - .stroke_texture = m_tex, - .mixer_rtt = m_rtt_mixer, - .render_target = m_rtt, - .background_texture = m_tex_background, - .dual_texture = m_tex_dual, - .preview_texture = m_tex_preview, + .camera_fov = Canvas::I->m_cam_fov, + .camera_rot = Canvas::I->m_cam_rot, + .render_device_features = stroke_preview_render_device_features(), + .preview_rtt = m_rtt, + .preview_rtt_mixer = m_rtt_mixer, + .preview_stroke_texture = m_tex, + .preview_dual_texture = m_tex_dual, + .preview_background_texture = m_tex_background, + .preview_image_texture = m_tex_preview, .linear_sampler = m_sampler_linear, .repeat_sampler = m_sampler_linear_repeat, - .zoom = zoom, - .min_flow = m_min_flow, - .copy_stroke_destination = pass_orchestration.copy_stroke_destination, - .size = size, + .prepare_render_target = [&] { + apply_stroke_preview_viewport(0, 0, m_rtt.getWidth(), m_rtt.getHeight()); + m_rtt.bindFramebuffer(); + m_rtt.clear(); + bind_stroke_preview_live_samplers( + m_sampler_mipmap, + m_sampler_linear, + m_sampler_linear_repeat); + }, + .finish_render_target = [&] { + m_rtt.unbindFramebuffer(); + }, + .set_blend_enabled = [&](bool enabled) { + apply_stroke_preview_capability(pp::renderer::gl::blend_state(), enabled); + }, + .setup_stroke_shader = [](const pp::panopainter::LegacyStrokeShaderSetupUniforms& uniforms) { + pp::panopainter::setup_legacy_stroke_shader(uniforms); + }, .bind_dual_pass_textures = [](const Brush& dual_brush) { bind_stroke_preview_dual_pass_textures(dual_brush); }, @@ -592,7 +572,7 @@ void NodeStrokePreview::draw_stroke_immediate() m_rtt_mixer.unbindTexture(); }, .bind_pattern_texture = [&] { - b->m_pattern_texture ? b->m_pattern_texture->bind() : unbind_texture_2d(); + m_brush->m_pattern_texture ? m_brush->m_pattern_texture->bind() : unbind_texture_2d(); }, .draw_composite = [&] { m_plane.draw_fill(); @@ -600,8 +580,6 @@ void NodeStrokePreview::draw_stroke_immediate() }); assert(sequence_ok); - m_rtt.unbindFramebuffer(); - apply_stroke_preview_viewport(vp.x, vp.y, vp.width, vp.height); apply_stroke_preview_clear_color(cc); } diff --git a/src/platform_windows/windows_window_shell.cpp b/src/platform_windows/windows_window_shell.cpp index 1d5aa800..3249c2c2 100644 --- a/src/platform_windows/windows_window_shell.cpp +++ b/src/platform_windows/windows_window_shell.cpp @@ -13,6 +13,31 @@ void destroy_window(); namespace pp::platform::windows { +void initialize_retained_input_state() +{ + auto& state = retained_state(); + memset(&state.keys, 0, sizeof(state.keys)); + for (int k = 1; k < 256; ++k) // ignore kKey::Unknown = 0 + { + for (int vk = 0; vk < 256; ++vk) + { + if (k != (int)convert_key(vk)) + continue; + + auto key = (kKey)k; + if (state.vkey_map.find(key) == state.vkey_map.end()) + { + state.vkey_map.insert({ key, vk }); + } + else + { + LOG("KEY MAP COLLISION %d and %d maps to %d", + vk, state.vkey_map[key], k); + } + } + } +} + RetainedState& retained_state() { static RetainedState state; diff --git a/src/platform_windows/windows_window_shell.h b/src/platform_windows/windows_window_shell.h index f8ac928a..c4456a27 100644 --- a/src/platform_windows/windows_window_shell.h +++ b/src/platform_windows/windows_window_shell.h @@ -19,6 +19,7 @@ struct RetainedState namespace pp::platform::windows { +void initialize_retained_input_state(); RetainedState& retained_state(); LRESULT CALLBACK main_window_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);