Thin node loader, Win32 wrappers, and canvas mode shells

This commit is contained in:
2026-06-17 00:10:39 +02:00
parent acee4db356
commit 371095770d
9 changed files with 302 additions and 289 deletions

View File

@@ -9,6 +9,8 @@
#include "legacy_ui_gl_dispatch.h"
#include "renderer_gl/opengl_capabilities.h"
NodeCanvas* CanvasMode::node;
namespace pp::legacy_canvas_mode {
void set_canvas_mode_active_texture_unit(std::uint32_t unit_index)
@@ -188,3 +190,174 @@ void CanvasModeCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
break;
}
}
void CanvasModeGrid::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
{
if (Canvas::I->m_touch_lock && me->m_source == kEventSource::Touch)
return;
switch (me->m_type)
{
case kEventType::MouseDownL:
{
node->mouse_capture();
glm::vec3 ro, rd, hit_o, hit_d;
glm::vec2 fb_pos;
if (Canvas::I->point_trace(loc, ro, rd, hit_o, fb_pos, hit_d, m_plane_id))
{
m_action = std::make_unique<ActionModeGrid>();
m_action->m_mode = this;
m_action->m_highlight = m_highlight;
m_action->m_selected_index = m_selected_index;
m_action->m_lines = m_lines;
int select = -1;
for (int i = 0; i < m_lines.size(); i++)
{
auto const& l = m_lines[i];
float d = lines_distance(ro, ro + rd * 10.f, l.o - l.d * 10.f, l.o + l.d * 10.f);
if (d < 0.03f)
select = i;
}
if (select == -1)
{
m_lines.push_back({ hit_o, hit_d });
m_selected_index = (int)m_lines.size() - 1;
m_highlight = false;
m_added = true;
}
else
{
m_selected_index = select;
m_highlight = true;
m_added = false;
}
origin = hit_o;
dir = hit_d;
m_dragging = true;
}
break;
}
case kEventType::MouseUpL:
pp::panopainter::release_legacy_mouse_capture(*node);
m_dragging = false;
ActionManager::add(m_action.release());
//commit();
break;
case kEventType::MouseMove:
{
glm::vec3 ro, rd, hit_o, hit_d;
glm::vec2 hit_fb;
if (m_dragging && Canvas::I->point_trace_plane(loc, ro, rd, hit_o, hit_d, hit_fb, m_plane_id))
{
m_lines[m_selected_index] = { hit_o, hit_d };
origin = hit_o;
dir = hit_d;
m_dragging = true;
}
break;
}
case kEventType::MouseCancel:
if (m_dragging && m_selected_index == m_lines.size() - 1)
m_lines.pop_back();
m_dragging = false;
pp::panopainter::release_legacy_mouse_capture(*node);
break;
default:
break;
}
}
void CanvasModeGrid::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const glm::mat4& camera)
{
const glm::vec4 blue(0, 0, 1, 1);
const glm::vec4 red(1, 0, 0, 1);
for (int i = 0; i < m_lines.size(); i++)
{
auto const& l = m_lines[i];
auto origin = l.o;
auto dir = l.d;
pp::panopainter::setup_legacy_vr_color_shader({
.color = m_highlight && i == m_selected_index ? blue : red,
.mvp = proj * camera,
});
static glm::vec4 AB[2];
AB[0] = { origin - dir * 10.f, 1 };
AB[1] = { origin + dir * 10.f, 1 };
m_line.update_vertices(AB);
m_line.draw_stroke();
}
}
void CanvasModeGrid::init()
{
m_line.create();
}
void CanvasModeGrid::commit()
{
auto drawer = [this](const glm::mat4& camera, const glm::mat4& proj) {
pp::panopainter::setup_legacy_vr_color_shader({
.color = { 1, 0, 0, 1 },
.mvp = proj * camera,
});
static glm::vec4 AB[2];
AB[0] = { origin - dir * 10.f, 1 };
AB[1] = { origin + dir * 10.f, 1 };
m_line.update_vertices(AB);
m_line.draw_stroke();
};
Canvas::I->draw_objects(std::bind(drawer, std::placeholders::_1, std::placeholders::_2), Canvas::I->layer().m_frame_index, true);
}
void CanvasModeGrid::clear()
{
auto a = new ActionModeGrid;
a->m_mode = this;
a->m_highlight = m_highlight;
a->m_selected_index = m_selected_index;
a->m_lines = m_lines;
ActionManager::add(a);
m_lines.clear();
}
void CanvasModeGrid::leave(kCanvasMode next)
{
m_selected_index = -1;
}
void CanvasModeGrid::on_KeyEvent(KeyEvent* ke)
{
if ((ke->m_key == kKey::KeyBackspace || ke->m_key == kKey::KeyDel)
&& ke->m_type == kEventType::KeyUp)
{
if (m_highlight)
{
auto a = new ActionModeGrid;
a->m_mode = this;
a->m_highlight = m_highlight;
a->m_selected_index = m_selected_index;
a->m_lines = m_lines;
ActionManager::add(a);
m_lines.erase(m_lines.begin() + m_selected_index);
m_highlight = false;
}
}
}
Action* ActionModeGrid::get_redo()
{
auto a = new ActionModeGrid;
a->m_mode = m_mode;
a->m_highlight = m_mode->m_highlight;
a->m_selected_index = m_mode->m_selected_index;
a->m_lines = m_mode->m_lines;
return a;
}
void ActionModeGrid::undo()
{
m_mode->m_highlight = m_highlight;
m_mode->m_selected_index = m_selected_index;
m_mode->m_lines = m_lines;
}