Extract node canvas events and preview/node geometry shells

This commit is contained in:
2026-06-16 23:31:30 +02:00
parent dde6123598
commit 6b337b2d87
11 changed files with 446 additions and 333 deletions

View File

@@ -6,172 +6,13 @@
#include <memory>
#include <vector>
#include "app_core/canvas_hotkey.h"
#include "app_core/canvas_tool_ui.h"
#include "app_core/document_animation.h"
#include "app.h"
#include "legacy_node_canvas_draw_services.h"
#include "legacy_node_canvas_state_services.h"
#include "legacy_ui_overlay_services.h"
#include "legacy_canvas_tool_services.h"
#include "legacy_history_services.h"
#include "log.h"
#include "node_canvas.h"
namespace {
pp::app::CanvasHotkeyKey canvas_hotkey_key(kKey key) noexcept
{
switch (key) {
case kKey::AndroidBack:
return pp::app::CanvasHotkeyKey::android_back;
case kKey::KeyAlt:
return pp::app::CanvasHotkeyKey::alt;
case kKey::KeyE:
return pp::app::CanvasHotkeyKey::e;
case kKey::KeyS:
return pp::app::CanvasHotkeyKey::s;
case kKey::KeyTab:
return pp::app::CanvasHotkeyKey::tab;
case kKey::KeyZ:
return pp::app::CanvasHotkeyKey::z;
case kKey::KeyBracketLeft:
return pp::app::CanvasHotkeyKey::bracket_left;
case kKey::KeyBracketRight:
return pp::app::CanvasHotkeyKey::bracket_right;
default:
return pp::app::CanvasHotkeyKey::other;
}
}
pp::app::CanvasHotkeyState canvas_hotkey_state(bool mouse_focused, int touch_finger_count = 0) noexcept
{
pp::app::CanvasHotkeyState state;
state.ctrl_down = App::I && App::I->keys[(int)kKey::KeyCtrl];
state.shift_down = App::I && App::I->keys[(int)kKey::KeyShift];
state.mouse_focused = mouse_focused;
const auto history = pp::panopainter::legacy_history_snapshot();
state.undo_count = history.undo_count;
state.redo_count = history.redo_count;
state.touch_finger_count = touch_finger_count;
return state;
}
void execute_canvas_hotkey_plan(const pp::app::CanvasHotkeyPlan& plan)
{
const auto status = pp::panopainter::execute_legacy_canvas_hotkey_plan(plan);
if (!status.ok())
LOG("Canvas hotkey action failed: %s", status.message);
}
void run_canvas_hotkey(
pp::app::CanvasHotkeyEvent event,
kKey key,
bool mouse_focused,
int touch_finger_count = 0)
{
const auto plan = pp::app::plan_canvas_hotkey(
event,
canvas_hotkey_key(key),
canvas_hotkey_state(mouse_focused, touch_finger_count));
if (plan)
execute_canvas_hotkey_plan(plan.value());
else
LOG("Canvas hotkey planning failed: %s", plan.status().message);
}
void run_canvas_tool_mode(pp::app::CanvasToolMode mode)
{
const auto plan = pp::app::plan_canvas_tool_select(mode);
const auto status = pp::panopainter::execute_legacy_canvas_input_tool_plan(plan);
if (!status.ok())
LOG("Canvas input tool action failed: %s", status.message);
}
[[nodiscard]] kEventResult execute_node_canvas_handle_event(NodeCanvas& node_canvas, Event* e)
{
static bool stylus_eraser = false;
MouseEvent* me = static_cast<MouseEvent*>(e);
KeyEvent* ke = static_cast<KeyEvent*>(e);
GestureEvent* ge = static_cast<GestureEvent*>(e);
TouchEvent* te = static_cast<TouchEvent*>(e);
auto loc = (me->m_pos - node_canvas.m_pos) * node_canvas.root()->m_zoom;
switch (e->m_type)
{
case kEventType::MouseMove:
if (stylus_eraser != me->m_eraser)
{
run_canvas_tool_mode(me->m_eraser ?
pp::app::CanvasToolMode::erase :
pp::app::CanvasToolMode::draw);
stylus_eraser = me->m_eraser;
}
case kEventType::MouseScroll:
case kEventType::MouseDownL:
case kEventType::MouseUpL:
case kEventType::MouseDownR:
case kEventType::MouseUpR:
case kEventType::MouseCancel:
node_canvas.m_canvas->m_cur_pos = loc;
node_canvas.update_cursor();
for (auto& mode : *node_canvas.m_canvas->m_mode)
mode->on_MouseEvent(me, loc);
break;
case kEventType::MouseUnfocus:
(*node_canvas.m_canvas->m_mode)[0]->m_draw_tip = false;
App::I->show_cursor();
break;
case kEventType::MouseFocus:
node_canvas.update_cursor();
break;
case kEventType::KeyDown:
run_canvas_hotkey(
pp::app::CanvasHotkeyEvent::key_down,
ke->m_key,
node_canvas.m_mouse_focus);
for (auto& mode : *node_canvas.m_canvas->m_mode)
mode->on_KeyEvent(ke);
break;
case kEventType::KeyUp:
node_canvas.update_cursor();
run_canvas_hotkey(
pp::app::CanvasHotkeyEvent::key_up,
ke->m_key,
node_canvas.m_mouse_focus);
for (auto& mode : *node_canvas.m_canvas->m_mode)
mode->on_KeyEvent(ke);
break;
case kEventType::GestureStart:
node_canvas.mouse_capture();
for (auto& mode : *node_canvas.m_canvas->m_mode)
mode->on_GestureEvent(ge);
break;
case kEventType::GestureMove:
for (auto& mode : *node_canvas.m_canvas->m_mode)
mode->on_GestureEvent(ge);
break;
case kEventType::GestureEnd:
pp::panopainter::release_legacy_mouse_capture(node_canvas);
for (auto& mode : *node_canvas.m_canvas->m_mode)
mode->on_GestureEvent(ge);
break;
case kEventType::TouchTap:
run_canvas_hotkey(
pp::app::CanvasHotkeyEvent::touch_tap,
kKey::Unknown,
node_canvas.m_mouse_focus,
te->m_finger_count);
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
}
}
Node* NodeCanvas::clone_instantiate() const
{
return new NodeCanvas();
@@ -205,7 +46,7 @@ void NodeCanvas::handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoo
kEventResult NodeCanvas::handle_event(Event* e)
{
Node::handle_event(e);
return execute_node_canvas_handle_event(*this, e);
return pp::panopainter::handle_legacy_node_canvas_event(*this, e);
}
void NodeCanvas::reset_camera()