371{
372 bool windowFocused = ImGui::IsWindowFocused();
373 ImGuiNodeEditor::SetCurrentEditor(context);
374 ImGuiNodeEditor::Begin(name.c_str());
375 ImGuiNodeEditor::EnableShortcuts(windowFocused);
376
377 for (auto &it : nodes)
378 {
379 it.second->Render();
380 }
381
382 outputNode->Render();
383
384 for (auto &it : links)
385 {
386 ImGuiNodeEditor::Link(it.second->id, it.second->from->id, it.second->to->id, it.second->color, it.second->thickness);
387 }
388
389 if (ImGuiNodeEditor::BeginCreate())
390 {
391 ImGuiNodeEditor::PinId iPid, oPid;
392
393 if (ImGuiNodeEditor::QueryNewLink(&iPid, &oPid))
394 {
395 if (iPid && oPid)
396 {
397 if (ImGuiNodeEditor::AcceptNewItem())
398 {
400 link->from = pins[iPid.Get()];
401 link->to = pins[oPid.Get()];
402 bool lnkFrm = link->from->ValidateLink(link);
403 bool lnkTo = link->to->ValidateLink(link);
404
405 if (lnkFrm && lnkTo)
406 {
407 link->from->Link(link);
408 link->to->Link(link);
409 links[link->_id.Get()] = link;
410 ImGuiNodeEditor::Link(link->id, link->from->id, link->to->id);
411 }
412 }
413 }
414
415 else if(iPid)
416 {
418
419 if(pin->IsLinked())
420 {
421 DeleteLink(pin->link);
422 }
423 }
424
425 else if (oPid)
426 {
428
429 if (pin->IsLinked())
430 {
431 DeleteLink(pin->link);
432 }
433 }
434 }
435
436 ImGuiNodeEditor::PinId nPid;
437
438 if (config.makeNodeFunc && ImGuiNodeEditor::QueryNewNode(&nPid))
439 {
440 if (ImGuiNodeEditor::AcceptNewItem())
441 {
443
444 if (pin->IsLinked())
445 {
446 DeleteLink(pin->link);
447 }
448
449 else
450 {
451 config.makeNodeFunc();
452 }
453 }
454 }
455 }
456
457 ImGuiNodeEditor::EndCreate();
458
459 if (ImGuiNodeEditor::BeginDelete())
460 {
461 ImGuiNodeEditor::NodeId nId;
462
463 if (ImGuiNodeEditor::QueryDeletedNode(&nId))
464 {
465 if (nId && ImGuiNodeEditor::AcceptDeletedItem())
466 {
467 if (!(outputNode && nId == outputNode->_id))
468 {
470 DeleteNode(node);
471 }
472 }
473 }
474
475 else
476 {
477 ImGuiNodeEditor::LinkId lId;
478
479 if (ImGuiNodeEditor::QueryDeletedLink(&lId))
480 {
481 if (lId && ImGuiNodeEditor::AcceptDeletedItem())
482 {
484 DeleteLink(link);
485 }
486 }
487 }
488 }
489
490 ImGuiNodeEditor::EndDelete();
491 ImGuiNodeEditor::NodeId sNode;
492 ImGuiNodeEditor::GetSelectedNodes(&sNode, 1);
493
494 if (ImGui::IsWindowFocused())
495 {
496 GLFWwindow *wind = Application::Get()->GetWindow()->GetNativeWindow();
497
498 if (glfwGetKey(wind, GLFW_KEY_RIGHT_SHIFT) || glfwGetKey(wind, GLFW_KEY_LEFT_SHIFT))
499 {
500 if (glfwGetKey(wind, GLFW_KEY_D) && sNode)
501 {
502 if (!(sNode.Get() == outputNode->_id.Get()))
503 {
504 NodeEditorNode *node = (config.insNodeFunc(nodes[sNode.Get()]->Save()));
505 ImVec2 prePos = ImGuiNodeEditor::GetNodePosition(sNode);
506 ImGuiNodeEditor::SetNodePosition(node->_id, ImVec2(prePos.x + 10, prePos.y + 10));
507 ImGuiNodeEditor::DeselectNode(sNode);
509 }
510 }
511 }
512 }
513
514 for(auto &it : nodes)
515 {
516 if(it.second->reqNodePosLoad)
517 {
518 ImGuiNodeEditor::SetNodePosition(it.second->_id, it.second->nodePosition);
519 it.second->reqNodePosLoad = false;
520 }
521
522 else
523 {
524 it.second->nodePosition = ImGuiNodeEditor::GetNodePosition(it.second->_id);
525 }
526 }
527
528 if (config.updateFunc)
529 {
530 config.updateFunc();
531 }
532
533 ImGuiNodeEditor::End();
534 ImGuiNodeEditor::SetCurrentEditor(nullptr);
535}