74 lines
1.6 KiB
C++
74 lines
1.6 KiB
C++
#include "pch.h"
|
|
#include "log.h"
|
|
#include "node_popup_menu.h"
|
|
#include "node_button_custom.h"
|
|
#include "app.h"
|
|
|
|
Node* NodePopupMenu::clone_instantiate() const
|
|
{
|
|
return new NodePopupMenu();
|
|
}
|
|
|
|
void NodePopupMenu::init()
|
|
{
|
|
SetPosition(0, 0);
|
|
SetWidth(100);
|
|
SetHeight(500);
|
|
SetPositioning(YGPositionTypeAbsolute);
|
|
m_flood_events = true;
|
|
m_mouse_ignore = false;
|
|
m_capture_children = false;
|
|
}
|
|
|
|
kEventResult NodePopupMenu::handle_event(Event* e)
|
|
{
|
|
switch (e->m_type)
|
|
{
|
|
case kEventType::MouseDownL:
|
|
break;
|
|
case kEventType::MouseUpL:
|
|
if (!m_mouse_inside)
|
|
{
|
|
mouse_release();
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < m_children.size(); i++)
|
|
{
|
|
if (m_children[i]->m_mouse_inside)
|
|
{
|
|
if (on_select)
|
|
on_select(this, i);
|
|
break;
|
|
}
|
|
}
|
|
mouse_release();
|
|
}
|
|
destroy();
|
|
break;
|
|
default:
|
|
return kEventResult::Available;
|
|
break;
|
|
}
|
|
return kEventResult::Consumed;
|
|
}
|
|
|
|
void NodePopupMenu::added(Node* parent)
|
|
{
|
|
if (root() == App::I->layout.get(App::I->main_id))
|
|
mouse_capture();
|
|
m_mouse_ignore = false;
|
|
m_flood_events = true;
|
|
m_capture_children = false;
|
|
for (int i = 0; i < m_children.size(); i++)
|
|
{
|
|
if (auto b = std::dynamic_pointer_cast<NodeButtonCustom>(m_children[i]))
|
|
{
|
|
b->on_click = [this, i](Node* target) {
|
|
if (on_select)
|
|
on_select(this, i);
|
|
};
|
|
}
|
|
}
|
|
}
|