added checkbox, slider, layer panel, brushes panel
This commit is contained in:
@@ -13,26 +13,6 @@ App App::I; // singleton
|
||||
#define SHADER_VERSION "#version 150\n"
|
||||
#endif
|
||||
|
||||
static std::vector<std::string> FindAllBrushes(std::string folder)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
std::string search_path = folder + "*.png";
|
||||
WIN32_FIND_DATAA fd;
|
||||
HANDLE hFind = ::FindFirstFileA(search_path.c_str(), &fd);
|
||||
if (hFind != INVALID_HANDLE_VALUE) {
|
||||
do {
|
||||
// read all (real) files in current folder
|
||||
// , delete '!' read other 2 default folder . and ..
|
||||
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
names.push_back(fd.cFileName);
|
||||
}
|
||||
} while (::FindNextFileA(hFind, &fd));
|
||||
::FindClose(hFind);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
|
||||
void App::create()
|
||||
{
|
||||
width = 800;
|
||||
@@ -169,33 +149,18 @@ void App::initLayout()
|
||||
|
||||
layout.on_loaded = [&] {
|
||||
LOG("initializing layout updating after load");
|
||||
static auto icons = FindAllBrushes("data\\Icons\\");
|
||||
if (auto* container = layout[main_id]->find<NodeBorder>("brushes"))
|
||||
{
|
||||
if (auto* tpl = layout[const_hash("tpl-brush-icon")])
|
||||
{
|
||||
for (auto& i : icons)
|
||||
{
|
||||
NodeButtonCustom* btn = (NodeButtonCustom*)tpl->m_children[0]->clone();
|
||||
NodeImage* img = (NodeImage*)btn->m_children[0].get();
|
||||
img->m_path = "data\\Icons\\" + i;
|
||||
img->m_tex_id = const_hash(img->m_path.c_str());
|
||||
img->create();
|
||||
container->add_child(btn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layout[main_id]->update(width, height, zoom);
|
||||
LOG("initializing layout components");
|
||||
sidebar = layout[main_id]->find<NodeBorder>("sidebar");
|
||||
brushes = layout[main_id]->find<NodePanelBrushes>("panel-brushes");
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-close"))
|
||||
{
|
||||
button->on_click = [] { exit(0); };
|
||||
button->on_click = [](Node*) { exit(0); };
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-popup"))
|
||||
{
|
||||
button->on_click = [this] {
|
||||
button->on_click = [this](Node*) {
|
||||
msgbox = new NodeMessageBox();
|
||||
msgbox->m_manager = &layout;
|
||||
msgbox->init();
|
||||
@@ -205,7 +170,7 @@ void App::initLayout()
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-settings"))
|
||||
{
|
||||
button->on_click = [this] {
|
||||
button->on_click = [this](Node*) {
|
||||
settings = new NodeSettings();
|
||||
settings->m_manager = &layout;
|
||||
settings->init();
|
||||
@@ -215,35 +180,41 @@ void App::initLayout()
|
||||
}
|
||||
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-file"))
|
||||
{
|
||||
menu_file->on_click = [=] {
|
||||
menu_file->on_click = [=](Node*) {
|
||||
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
|
||||
popup = (NodePopupMenu*)layout[const_hash("file-menu")]->m_children[0]->clone();
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(pos.x, pos.y);
|
||||
layout[main_id]->add_child(popup);
|
||||
layout[main_id]->update();
|
||||
popup->mouse_capture();
|
||||
popup->m_mouse_ignore = false;
|
||||
};
|
||||
}
|
||||
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-edit"))
|
||||
{
|
||||
menu_file->on_click = [=] {
|
||||
menu_file->on_click = [=](Node*) {
|
||||
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
|
||||
popup = (NodePopupMenu*)layout[const_hash("edit-menu")]->m_children[0]->clone();
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(pos.x, pos.y);
|
||||
layout[main_id]->add_child(popup);
|
||||
layout[main_id]->update();
|
||||
popup->mouse_capture();
|
||||
popup->m_mouse_ignore = false;
|
||||
};
|
||||
}
|
||||
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-layers"))
|
||||
{
|
||||
menu_file->on_click = [=] {
|
||||
menu_file->on_click = [=](Node*) {
|
||||
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
|
||||
popup = (NodePopupMenu*)layout[const_hash("layers-menu")]->m_children[0]->clone();
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(pos.x, pos.y);
|
||||
layout[main_id]->add_child(popup);
|
||||
layout[main_id]->update();
|
||||
popup->mouse_capture();
|
||||
popup->m_mouse_ignore = false;
|
||||
};
|
||||
}
|
||||
if (auto* toolbar = layout[main_id]->find<Node>("toolbar"))
|
||||
@@ -252,7 +223,11 @@ void App::initLayout()
|
||||
}
|
||||
};
|
||||
LOG("initializing layout xml");
|
||||
#ifdef _WIN32
|
||||
layout.load("C:\\Users\\omar\\Desktop\\new_engine\\data\\layout.xml");
|
||||
#else
|
||||
layout.load("data/layout.xml");
|
||||
#endif
|
||||
LOG("initializing layout completed");
|
||||
}
|
||||
|
||||
@@ -344,41 +319,45 @@ void App::resize(float w, float h)
|
||||
main->update(w , h, zoom);
|
||||
}
|
||||
|
||||
void App::mouse_down(int button, float x, float y)
|
||||
bool App::mouse_down(int button, float x, float y)
|
||||
{
|
||||
MouseEvent e;
|
||||
e.m_type = button ? kEventType::MouseDownR : kEventType::MouseDownL;
|
||||
e.m_pos = { x / zoom, y / zoom };
|
||||
layout[main_id]->on_event(&e);
|
||||
auto ret = layout[main_id]->on_event(&e);
|
||||
LOG("mouse click button%d pos %f %f\n", button, x, y);
|
||||
|
||||
if (popup)
|
||||
{
|
||||
layout[main_id]->remove_child(popup);
|
||||
popup = nullptr;
|
||||
}
|
||||
if (button == 1)
|
||||
{
|
||||
popup = (NodePopupMenu*)layout[const_hash("popup-menu")]->m_children[0]->clone();
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(x / zoom, y / zoom);
|
||||
layout[main_id]->add_child(popup);
|
||||
}
|
||||
// if (popup)
|
||||
// {
|
||||
// layout[main_id]->remove_child(popup);
|
||||
// popup = nullptr;
|
||||
// }
|
||||
// if (button == 1)
|
||||
// {
|
||||
// popup = (NodePopupMenu*)layout[const_hash("popup-menu")]->m_children[0]->clone();
|
||||
// popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
// popup->SetPosition(x / zoom, y / zoom);
|
||||
// layout[main_id]->add_child(popup);
|
||||
// }
|
||||
layout[main_id]->update();
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
void App::mouse_move(float x, float y)
|
||||
bool App::mouse_move(float x, float y)
|
||||
{
|
||||
MouseEvent e;
|
||||
e.m_type = kEventType::MouseMove;
|
||||
e.m_pos = { x / zoom, y / zoom };
|
||||
kEventResult ret = kEventResult::Available;
|
||||
if (auto* main = layout[main_id])
|
||||
main->on_event(&e);
|
||||
ret = main->on_event(&e);
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
void App::mouse_up(int button, float x, float y)
|
||||
bool App::mouse_up(int button, float x, float y)
|
||||
{
|
||||
MouseEvent e;
|
||||
e.m_type = button ? kEventType::MouseUpR : kEventType::MouseUpL;
|
||||
e.m_pos = { x / zoom, y / zoom };
|
||||
layout[main_id]->on_event(&e);
|
||||
auto ret = layout[main_id]->on_event(&e);
|
||||
layout[main_id]->update();
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user