add imnodes and neo sequencer
This commit is contained in:
parent
2a8dae2bf6
commit
79c5e7f3a4
|
@ -30,11 +30,7 @@ globalThis.class_use = function(script, config, base, callback)
|
||||||
if (callback) callback(padawan);
|
if (callback) callback(padawan);
|
||||||
|
|
||||||
var script = Resources.replstrs(file);
|
var script = Resources.replstrs(file);
|
||||||
script = `(function() {
|
script = `(function() { var self = this; var $ = this.__proto__; ${script}; })`;
|
||||||
var self = this;
|
|
||||||
var $ = this.__proto__;
|
|
||||||
${script};
|
|
||||||
})`;
|
|
||||||
|
|
||||||
var fn = os.eval(file,script);
|
var fn = os.eval(file,script);
|
||||||
fn.call(padawan);
|
fn.call(padawan);
|
||||||
|
|
|
@ -192,9 +192,8 @@ var entity = {
|
||||||
for (var path of text) use(path,ent);
|
for (var path of text) use(path,ent);
|
||||||
profile.cache("ENTITY TIME", ent.ur.name);
|
profile.cache("ENTITY TIME", ent.ur.name);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ent.reparent(this);
|
ent.reparent(this);
|
||||||
|
|
||||||
for (var [prop, p] of Object.entries(ent)) {
|
for (var [prop, p] of Object.entries(ent)) {
|
||||||
if (!p) continue;
|
if (!p) continue;
|
||||||
if (typeof p !== 'object') continue;
|
if (typeof p !== 'object') continue;
|
||||||
|
@ -206,7 +205,7 @@ var entity = {
|
||||||
|
|
||||||
check_registers(ent);
|
check_registers(ent);
|
||||||
|
|
||||||
if (ent.load instanceof Function) ent.load();
|
if (ent.awake instanceof Function) ent.awake();
|
||||||
if (sim.playing()) {
|
if (sim.playing()) {
|
||||||
ent._started = true;
|
ent._started = true;
|
||||||
if (ent.start instanceof Function) ent.start();
|
if (ent.start instanceof Function) ent.start();
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
#include "sokol/sokol_app.h"
|
#include "sokol/sokol_app.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "implot.h"
|
#include "implot.h"
|
||||||
|
#include "imnodes.h"
|
||||||
|
#Include "imgui_neo_sequencer.h"
|
||||||
|
|
||||||
#define SOKOL_IMPL
|
#define SOKOL_IMPL
|
||||||
#include "sokol/util/sokol_imgui.h"
|
#include "sokol/util/sokol_imgui.h"
|
||||||
#include "sokol/util/sokol_gfx_imgui.h"
|
#include "sokol/util/sokol_gfx_imgui.h"
|
||||||
|
@ -247,7 +250,7 @@ JSC_CCALL(imgui_tablenextrow, ImGui::TableNextRow())
|
||||||
JSC_CCALL(imgui_tablenextcolumn, ImGui::TableNextColumn())
|
JSC_CCALL(imgui_tablenextcolumn, ImGui::TableNextColumn())
|
||||||
|
|
||||||
JSC_SCALL(imgui_dnd,
|
JSC_SCALL(imgui_dnd,
|
||||||
if (ImGui::BeginDragDropSource(NULL)) {
|
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
|
||||||
double n = js2number(argv[1]);
|
double n = js2number(argv[1]);
|
||||||
ImGui::SetDragDropPayload(str, &n, sizeof(n));
|
ImGui::SetDragDropPayload(str, &n, sizeof(n));
|
||||||
script_call_sym(argv[2],0,NULL);
|
script_call_sym(argv[2],0,NULL);
|
||||||
|
@ -265,6 +268,80 @@ JSC_SCALL(imgui_dndtarget,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
JSC_SCALL(imgui_color,
|
||||||
|
int n = js_arrlen(argv[1]);
|
||||||
|
float color[n];
|
||||||
|
js2floatarr(argv[1],n,color);
|
||||||
|
|
||||||
|
if (n == 3)
|
||||||
|
ImGui::ColorEdit3(str, color);
|
||||||
|
else if (n == 4)
|
||||||
|
ImGui::ColorEdit4(str, color);
|
||||||
|
|
||||||
|
ret = floatarr2js(n, color);
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(imgui_startnode,
|
||||||
|
ImNodes::BeginNodeEditor();
|
||||||
|
script_call_sym(argv[0],0,NULL);
|
||||||
|
ImNodes::EndNodeEditor();
|
||||||
|
int start_attr;
|
||||||
|
int end_attr;
|
||||||
|
if (ImNodes::IsLinkCreated(&start_attr, &end_attr))
|
||||||
|
{
|
||||||
|
JSValue ab[2];
|
||||||
|
ab[0] = number2js(start_attr);
|
||||||
|
ab[1] = number2js(end_attr);
|
||||||
|
script_call_sym(argv[1], 2, ab);
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++) JS_FreeValue(js, ab[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int node_id;
|
||||||
|
if (ImNodes::IsNodeHovered(&node_id))
|
||||||
|
{
|
||||||
|
JSValue a = number2js(node_id);
|
||||||
|
script_call_sym(argv[2],1,&a);
|
||||||
|
JS_FreeValue(js,a);
|
||||||
|
}
|
||||||
|
|
||||||
|
int link_id;
|
||||||
|
if (ImNodes::IsLinkHovered(&link_id))
|
||||||
|
{
|
||||||
|
JSValue a = number2js(link_id);
|
||||||
|
script_call_sym(argv[3],1,&a);
|
||||||
|
JS_FreeValue(js,a);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(imgui_node,
|
||||||
|
ImNodes::BeginNode(js2number(argv[0]));
|
||||||
|
script_call_sym(argv[1],0,NULL);
|
||||||
|
ImNodes::EndNode();
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(imgui_nodein,
|
||||||
|
ImNodes::BeginInputAttribute(js2number(argv[0]));
|
||||||
|
script_call_sym(argv[1],0,NULL);
|
||||||
|
ImNodes::EndInputAttribute();
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(imgui_nodeout,
|
||||||
|
ImNodes::BeginOutputAttribute(js2number(argv[0]));
|
||||||
|
script_call_sym(argv[1],0,NULL);
|
||||||
|
ImNodes::EndOutputAttribute();
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(imgui_nodelink,
|
||||||
|
ImNodes::Link(js2number(argv[0]), js2number(argv[1]), js2number(argv[2]));
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(imgui_nodemini, ImNodes::MiniMap(js2number(argv[0])))
|
||||||
|
|
||||||
|
JSC_SCALL(imgui_sequencer,
|
||||||
|
ImGui::BeginNeoSequencer(str,
|
||||||
|
)
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_imgui_funcs[] = {
|
static const JSCFunctionListEntry js_imgui_funcs[] = {
|
||||||
MIST_FUNC_DEF(imgui, window, 2),
|
MIST_FUNC_DEF(imgui, window, 2),
|
||||||
MIST_FUNC_DEF(imgui, menu, 2),
|
MIST_FUNC_DEF(imgui, menu, 2),
|
||||||
|
@ -302,7 +379,15 @@ static const JSCFunctionListEntry js_imgui_funcs[] = {
|
||||||
MIST_FUNC_DEF(imgui, tablenextcolumn,0),
|
MIST_FUNC_DEF(imgui, tablenextcolumn,0),
|
||||||
MIST_FUNC_DEF(imgui, tablenextrow,0),
|
MIST_FUNC_DEF(imgui, tablenextrow,0),
|
||||||
MIST_FUNC_DEF(imgui, dnd, 3),
|
MIST_FUNC_DEF(imgui, dnd, 3),
|
||||||
MIST_FUNC_DEF(imgui, dndtarget, 2)
|
MIST_FUNC_DEF(imgui, dndtarget, 2),
|
||||||
|
MIST_FUNC_DEF(imgui, color, 2),
|
||||||
|
MIST_FUNC_DEF(imgui, startnode, 1),
|
||||||
|
MIST_FUNC_DEF(imgui, node, 2),
|
||||||
|
MIST_FUNC_DEF(imgui, nodein, 2),
|
||||||
|
MIST_FUNC_DEF(imgui, nodeout, 2),
|
||||||
|
MIST_FUNC_DEF(imgui, nodelink, 3),
|
||||||
|
MIST_FUNC_DEF(imgui, nodemini, 1),
|
||||||
|
MIST_FUNC_DEF(imgui, sequencer, 4),
|
||||||
};
|
};
|
||||||
|
|
||||||
static int started = 0;
|
static int started = 0;
|
||||||
|
@ -316,6 +401,7 @@ JSValue gui_init(JSContext *js)
|
||||||
sgimgui_init(&sgimgui, &desc);
|
sgimgui_init(&sgimgui, &desc);
|
||||||
|
|
||||||
ImPlot::CreateContext();
|
ImPlot::CreateContext();
|
||||||
|
ImNodes::CreateContext();
|
||||||
|
|
||||||
JSValue imgui = JS_NewObject(js);
|
JSValue imgui = JS_NewObject(js);
|
||||||
JS_SetPropertyFunctionList(js, imgui, js_imgui_funcs, countof(js_imgui_funcs));
|
JS_SetPropertyFunctionList(js, imgui, js_imgui_funcs, countof(js_imgui_funcs));
|
||||||
|
|
167
source/engine/thirdparty/imgui/imgui_neo_internal.cpp
vendored
Normal file
167
source/engine/thirdparty/imgui/imgui_neo_internal.cpp
vendored
Normal file
|
@ -0,0 +1,167 @@
|
||||||
|
//
|
||||||
|
// Created by Matty on 2022-01-28.
|
||||||
|
//
|
||||||
|
|
||||||
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
|
||||||
|
#include "imgui_neo_internal.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace ImGui {
|
||||||
|
void RenderNeoSequencerBackground(const ImVec4 &color, const ImVec2 & cursor, const ImVec2 &size, ImDrawList * drawList, float sequencerRounding) {
|
||||||
|
if(!drawList) drawList = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
const ImRect area = {cursor, cursor + size};
|
||||||
|
|
||||||
|
drawList->AddRectFilled(area.Min, area.Max, ColorConvertFloat4ToU32(color), sequencerRounding);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderNeoSequencerTopBarBackground(const ImVec4 &color, const ImVec2 &cursor, const ImVec2 &size,
|
||||||
|
ImDrawList *drawList, float sequencerRounding) {
|
||||||
|
if(!drawList) drawList = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
const ImRect barArea = {cursor, cursor + size};
|
||||||
|
|
||||||
|
drawList->AddRectFilled(barArea.Min, barArea.Max, ColorConvertFloat4ToU32(color), sequencerRounding);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RenderNeoSequencerTopBarOverlay(float zoom, float valuesWidth,uint32_t startFrame, uint32_t endFrame, uint32_t offsetFrame, const ImVec2 &cursor, const ImVec2 &size,
|
||||||
|
ImDrawList *drawList, bool drawFrameLines,
|
||||||
|
bool drawFrameText, float maxPixelsPerTick) {
|
||||||
|
if(!drawList) drawList = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
const auto & style = GetStyle();
|
||||||
|
|
||||||
|
const ImRect barArea = {cursor + ImVec2{style.FramePadding.x + valuesWidth,style.FramePadding.y}, cursor + size };
|
||||||
|
|
||||||
|
const uint32_t viewEnd = endFrame + offsetFrame;
|
||||||
|
const uint32_t viewStart = startFrame + offsetFrame;
|
||||||
|
|
||||||
|
if(drawFrameLines) {
|
||||||
|
const auto count = (int32_t)((float)((viewEnd + 1) - viewStart) / zoom);
|
||||||
|
|
||||||
|
int32_t counter = 0;
|
||||||
|
uint32_t primaryFrames = pow(10, counter++);
|
||||||
|
uint32_t secondaryFrames = pow(10, counter);
|
||||||
|
|
||||||
|
float perFrameWidth = GetPerFrameWidth(size.x, valuesWidth, endFrame, startFrame, zoom);
|
||||||
|
|
||||||
|
if(perFrameWidth <= 0.0f) return;
|
||||||
|
|
||||||
|
while (perFrameWidth < maxPixelsPerTick)
|
||||||
|
{
|
||||||
|
primaryFrames = pow(10, counter++);
|
||||||
|
secondaryFrames = pow(10, counter);
|
||||||
|
|
||||||
|
perFrameWidth *= (float)primaryFrames;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(primaryFrames == 0 || secondaryFrames == 0) {
|
||||||
|
primaryFrames = 1;
|
||||||
|
secondaryFrames = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int32_t i = 0; i < count; i++) {
|
||||||
|
|
||||||
|
const auto primaryFrame = ((viewStart + i) % primaryFrames == 0);
|
||||||
|
const auto secondaryFrame = ((viewStart + i) % secondaryFrames == 0);
|
||||||
|
|
||||||
|
if(!primaryFrame && !secondaryFrame) continue;
|
||||||
|
|
||||||
|
const auto lineHeight = secondaryFrame ? barArea.GetSize().y : barArea.GetSize().y / 2.0f;
|
||||||
|
|
||||||
|
const ImVec2 p1 = {barArea.Min.x + (float)i * (perFrameWidth / (float)primaryFrames), barArea.Max.y};
|
||||||
|
const ImVec2 p2 = {barArea.Min.x + (float)i * (perFrameWidth / (float)primaryFrames), barArea.Max.y - lineHeight};
|
||||||
|
|
||||||
|
drawList->AddLine(p1,p2, IM_COL32_WHITE, 1.0f);
|
||||||
|
|
||||||
|
if(drawFrameText && secondaryFrame) {
|
||||||
|
char text[10];
|
||||||
|
const auto printRes = snprintf(text, sizeof(text), "%i", viewStart + i);
|
||||||
|
if(printRes > 0) {
|
||||||
|
drawList->AddText(NULL, 0, {p1.x + 2.0f, barArea.Min.y }, IM_COL32_WHITE,text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderNeoTimelineLabel(const char * label,const ImVec2 & cursor,const ImVec2 & size, const ImVec4& color,bool isGroup, bool isOpen, ImDrawList *drawList)
|
||||||
|
{
|
||||||
|
const auto& imStyle = GetStyle();
|
||||||
|
|
||||||
|
if(!drawList) drawList = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
auto c = cursor;
|
||||||
|
|
||||||
|
if(isGroup) {
|
||||||
|
RenderArrow(drawList,c,IM_COL32_WHITE,isOpen ? ImGuiDir_Down : ImGuiDir_Right);
|
||||||
|
c.x += size.y + imStyle.ItemSpacing.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawList->AddText(c,ColorConvertFloat4ToU32(color),label, FindRenderedTextEnd(label));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderNeoTimelinesBorder(const ImVec4 &color, const ImVec2 &cursor, const ImVec2 &size, ImDrawList *drawList,
|
||||||
|
float rounding, float borderSize)
|
||||||
|
{
|
||||||
|
if(!drawList) drawList = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
drawList->AddRect(cursor,cursor + size,ColorConvertFloat4ToU32(color),rounding, 0, borderSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderNeoTimelane(bool selected,const ImVec2 & cursor, const ImVec2& size, const ImVec4& highlightColor, ImDrawList *drawList) {
|
||||||
|
if(!drawList) drawList = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
if(selected) {
|
||||||
|
const ImRect area = {cursor, cursor + size};
|
||||||
|
drawList->AddRectFilled(area.Min, area.Max, ColorConvertFloat4ToU32(highlightColor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetPerFrameWidth(float totalSizeX, float valuesWidth, uint32_t endFrame, uint32_t startFrame, float zoom) {
|
||||||
|
const auto& imStyle = GetStyle();
|
||||||
|
|
||||||
|
const auto size = totalSizeX - valuesWidth - imStyle.FramePadding.x;
|
||||||
|
|
||||||
|
auto count = (endFrame + 1) - startFrame;
|
||||||
|
|
||||||
|
return ((size / (float)count) * zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Vec2Pair {
|
||||||
|
ImVec2 a;
|
||||||
|
ImVec2 b;
|
||||||
|
};
|
||||||
|
|
||||||
|
static Vec2Pair getCurrentFrameLine(const ImRect & pointerBB, float timelineHeight) {
|
||||||
|
const auto center = ImVec2{pointerBB.Min.x, pointerBB.Max.y} + ImVec2{pointerBB.GetSize().x / 2.0f, 0};
|
||||||
|
|
||||||
|
return Vec2Pair{ center, center + ImVec2{0, timelineHeight} };
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderNeoSequencerCurrentFrame(const ImVec4 &color, const ImVec4 &topColor, const ImRect &pointerBB,
|
||||||
|
float timelineHeight, float lineWidth, ImDrawList *drawList) {
|
||||||
|
if(!drawList) drawList = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
const auto pair = getCurrentFrameLine(pointerBB, timelineHeight);
|
||||||
|
|
||||||
|
drawList->AddLine(pair.a, pair.b, ColorConvertFloat4ToU32(color), lineWidth);
|
||||||
|
|
||||||
|
drawList->PopClipRect();
|
||||||
|
|
||||||
|
{ //Top pointer has custom shape, we have to create it
|
||||||
|
const auto size = pointerBB.GetSize();
|
||||||
|
ImVec2 pts[5];
|
||||||
|
pts[0] = pointerBB.Min;
|
||||||
|
pts[1] = pointerBB.Min + ImVec2{size.x, 0};
|
||||||
|
pts[2] = pointerBB.Min + ImVec2{size.x, size.y * 0.85f};
|
||||||
|
pts[3] = pointerBB.Min + ImVec2{size.x / 2, size.y};
|
||||||
|
pts[4] = pointerBB.Min + ImVec2{0, size.y * 0.85f};
|
||||||
|
|
||||||
|
drawList->AddConvexPolyFilled(pts, sizeof(pts) / sizeof(*pts), ColorConvertFloat4ToU32(topColor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
source/engine/thirdparty/imgui/imgui_neo_internal.h
vendored
Normal file
24
source/engine/thirdparty/imgui/imgui_neo_internal.h
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
//
|
||||||
|
// Created by Matty on 2022-01-28.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef IMGUI_NEO_INTERNAL_H
|
||||||
|
#define IMGUI_NEO_INTERNAL_H
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace ImGui {
|
||||||
|
IMGUI_API void RenderNeoSequencerBackground(const ImVec4& color, const ImVec2 & cursor, const ImVec2& size, ImDrawList * drawList = nullptr, float sequencerRounding = 0.0f);
|
||||||
|
IMGUI_API void RenderNeoSequencerTopBarBackground(const ImVec4& color, const ImVec2 & cursor, const ImVec2& size, ImDrawList * drawList = nullptr, float sequencerRounding = 0.0f);
|
||||||
|
IMGUI_API void RenderNeoSequencerTopBarOverlay(float zoom, float valuesWidth,uint32_t startFrame, uint32_t endFrame, uint32_t offsetFrame, const ImVec2 &cursor, const ImVec2& size, ImDrawList * drawList = nullptr, bool drawFrameLines = true, bool drawFrameText = true, float maxPixelsPerTick = -1.0f);
|
||||||
|
IMGUI_API void RenderNeoTimelineLabel(const char * label,const ImVec2 & cursor,const ImVec2 & size, const ImVec4& color,bool isGroup = false, bool isOpen = false, ImDrawList *drawList = nullptr );
|
||||||
|
IMGUI_API void RenderNeoTimelane(bool selected,const ImVec2 & cursor, const ImVec2& size, const ImVec4& highlightColor, ImDrawList *drawList = nullptr);
|
||||||
|
IMGUI_API void RenderNeoTimelinesBorder(const ImVec4& color, const ImVec2 & cursor, const ImVec2& size, ImDrawList * drawList = nullptr, float rounding = 0.0f, float borderSize = 1.0f);
|
||||||
|
IMGUI_API void RenderNeoSequencerCurrentFrame(const ImVec4& color,const ImVec4 & topColor,const ImRect & pointerBB ,float timelineHeight, float lineWidth = 1.0f, ImDrawList * drawList = nullptr);
|
||||||
|
|
||||||
|
IMGUI_API float GetPerFrameWidth(float totalSizeX, float valuesWidth, uint32_t endFrame, uint32_t startFrame, float zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //IMGUI_NEO_INTERNAL_H
|
1376
source/engine/thirdparty/imgui/imgui_neo_sequencer.cpp
vendored
Normal file
1376
source/engine/thirdparty/imgui/imgui_neo_sequencer.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
155
source/engine/thirdparty/imgui/imgui_neo_sequencer.h
vendored
Normal file
155
source/engine/thirdparty/imgui/imgui_neo_sequencer.h
vendored
Normal file
|
@ -0,0 +1,155 @@
|
||||||
|
//
|
||||||
|
// Created by Matty on 2022-01-28.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef IMGUI_NEO_SEQUENCER_H
|
||||||
|
#define IMGUI_NEO_SEQUENCER_H
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
typedef int ImGuiNeoSequencerFlags;
|
||||||
|
typedef int ImGuiNeoSequencerCol;
|
||||||
|
typedef int ImGuiNeoTimelineFlags;
|
||||||
|
typedef int ImGuiNeoTimelineIsSelectedFlags;
|
||||||
|
|
||||||
|
// Flags for ImGui::BeginNeoSequencer()
|
||||||
|
enum ImGuiNeoSequencerFlags_
|
||||||
|
{
|
||||||
|
ImGuiNeoSequencerFlags_None = 0 ,
|
||||||
|
ImGuiNeoSequencerFlags_AllowLengthChanging = 1 << 0, // Allows changing length of sequence
|
||||||
|
ImGuiNeoSequencerFlags_EnableSelection = 1 << 1, // Enables selection of keyframes
|
||||||
|
ImGuiNeoSequencerFlags_HideZoom = 1 << 2, // Disables zoom bar
|
||||||
|
//ImGuiNeoSequencerFlags_PH = 1 << 3, // PLACEHOLDER
|
||||||
|
ImGuiNeoSequencerFlags_AlwaysShowHeader = 1 << 4, // Enables overlay header, keeping it visible when scrolling
|
||||||
|
|
||||||
|
// Selection options, only work with enable selection flag
|
||||||
|
ImGuiNeoSequencerFlags_Selection_EnableDragging = 1 << 5,
|
||||||
|
ImGuiNeoSequencerFlags_Selection_EnableDeletion = 1 << 6,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Flags for ImGui::BeginNeoTimeline()
|
||||||
|
enum ImGuiNeoTimelineFlags_
|
||||||
|
{
|
||||||
|
ImGuiNeoTimelineFlags_None = 0 ,
|
||||||
|
ImGuiNeoTimelineFlags_AllowFrameChanging = 1 << 0,
|
||||||
|
ImGuiNeoTimelineFlags_Group = 1 << 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Flags for ImGui::IsNeoTimelineSelected()
|
||||||
|
enum ImGuiNeoTimelineIsSelectedFlags_
|
||||||
|
{
|
||||||
|
ImGuiNeoTimelineIsSelectedFlags_None = 0 ,
|
||||||
|
ImGuiNeoTimelineIsSelectedFlags_NewlySelected = 1 << 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImGuiNeoSequencerCol_
|
||||||
|
{
|
||||||
|
ImGuiNeoSequencerCol_Bg,
|
||||||
|
ImGuiNeoSequencerCol_TopBarBg,
|
||||||
|
ImGuiNeoSequencerCol_SelectedTimeline,
|
||||||
|
ImGuiNeoSequencerCol_TimelineBorder,
|
||||||
|
ImGuiNeoSequencerCol_TimelinesBg,
|
||||||
|
ImGuiNeoSequencerCol_FramePointer,
|
||||||
|
ImGuiNeoSequencerCol_FramePointerHovered,
|
||||||
|
ImGuiNeoSequencerCol_FramePointerPressed,
|
||||||
|
ImGuiNeoSequencerCol_Keyframe,
|
||||||
|
ImGuiNeoSequencerCol_KeyframeHovered,
|
||||||
|
ImGuiNeoSequencerCol_KeyframePressed,
|
||||||
|
ImGuiNeoSequencerCol_KeyframeSelected,
|
||||||
|
ImGuiNeoSequencerCol_FramePointerLine,
|
||||||
|
|
||||||
|
ImGuiNeoSequencerCol_ZoomBarBg,
|
||||||
|
ImGuiNeoSequencerCol_ZoomBarSlider,
|
||||||
|
ImGuiNeoSequencerCol_ZoomBarSliderHovered,
|
||||||
|
ImGuiNeoSequencerCol_ZoomBarSliderEnds,
|
||||||
|
ImGuiNeoSequencerCol_ZoomBarSliderEndsHovered,
|
||||||
|
|
||||||
|
ImGuiNeoSequencerCol_SelectionBorder,
|
||||||
|
ImGuiNeoSequencerCol_Selection,
|
||||||
|
|
||||||
|
ImGuiNeoSequencerCol_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImGuiNeoSequencerStyle {
|
||||||
|
float SequencerRounding = 2.5f; // Corner rounding around whole sequencer
|
||||||
|
float TopBarHeight = 0.0f; // Value <= 0.0f = Height is calculated by FontSize + FramePadding.y * 2.0f
|
||||||
|
bool TopBarShowFrameLines = true; // Show line for every frame in top bar
|
||||||
|
bool TopBarShowFrameTexts = true; // Show frame number every 10th frame
|
||||||
|
ImVec2 ItemSpacing = {4.0f,0.5f};
|
||||||
|
float DepthItemSpacing = 10.0f; // Amount of text offset per depth level in timeline values
|
||||||
|
float TopBarSpacing = 3.0f; // Space between top bar and timeline
|
||||||
|
float TimelineBorderSize = 1.0f;
|
||||||
|
float CurrentFramePointerSize = 7.0f; // Size of pointing arrow above current frame line
|
||||||
|
float CurrentFrameLineWidth = 1.0f; // Width of line showing current frame over timeline
|
||||||
|
float ZoomHeightScale = 1.0f; // Scale of Zoom bar, base height is font size
|
||||||
|
float CollidedKeyframeOffset = 3.5f; // Offset on which colliding keyframes are rendered
|
||||||
|
|
||||||
|
float MaxSizePerTick = 4.0f; // Maximum amount of pixels per tick on timeline (if less pixels is present, ticks are not rendered)
|
||||||
|
|
||||||
|
ImVec4 Colors[ImGuiNeoSequencerCol_COUNT];
|
||||||
|
|
||||||
|
ImGuiKey ModRemoveKey = ImGuiMod_Ctrl; // Key mod which when held removes selected keyframes from present selection
|
||||||
|
ImGuiKey ModAddKey = ImGuiMod_Shift; // Key mod which when held adds selected keyframes to present selection
|
||||||
|
|
||||||
|
ImGuiNeoSequencerStyle();
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace ImGui {
|
||||||
|
typedef int32_t FrameIndexType;
|
||||||
|
|
||||||
|
IMGUI_API const ImVec4& GetStyleNeoSequencerColorVec4(ImGuiNeoSequencerCol idx);
|
||||||
|
IMGUI_API ImGuiNeoSequencerStyle& GetNeoSequencerStyle();
|
||||||
|
|
||||||
|
IMGUI_API void PushNeoSequencerStyleColor(ImGuiNeoSequencerCol idx, ImU32 col);
|
||||||
|
IMGUI_API void PushNeoSequencerStyleColor(ImGuiNeoSequencerCol idx, const ImVec4& col);
|
||||||
|
IMGUI_API void PopNeoSequencerStyleColor(int count = 1);
|
||||||
|
|
||||||
|
IMGUI_API bool BeginNeoSequencer(const char* id, FrameIndexType * frame, FrameIndexType * startFrame, FrameIndexType * endFrame,const ImVec2& size = ImVec2(0, 0),ImGuiNeoSequencerFlags flags = ImGuiNeoSequencerFlags_None);
|
||||||
|
IMGUI_API void EndNeoSequencer(); //Call only when BeginNeoSequencer() returns true!!
|
||||||
|
|
||||||
|
IMGUI_API bool BeginNeoGroup(const char* label, bool* open = nullptr);
|
||||||
|
IMGUI_API void EndNeoGroup();
|
||||||
|
|
||||||
|
IMGUI_API bool BeginNeoTimeline(const char* label,FrameIndexType ** keyframes, uint32_t keyframeCount, bool * open = nullptr, ImGuiNeoTimelineFlags flags = ImGuiNeoTimelineFlags_None);
|
||||||
|
IMGUI_API void EndNeoTimeLine(); //Call only when BeginNeoTimeline() returns true!!
|
||||||
|
|
||||||
|
// Fully customizable timeline with per key callback
|
||||||
|
IMGUI_API bool BeginNeoTimelineEx(const char* label, bool * open = nullptr, ImGuiNeoTimelineFlags flags = ImGuiNeoTimelineFlags_None);
|
||||||
|
IMGUI_API void NeoKeyframe(int32_t* value);
|
||||||
|
|
||||||
|
IMGUI_API bool IsNeoKeyframeHovered();
|
||||||
|
IMGUI_API bool IsNeoKeyframeSelected();
|
||||||
|
IMGUI_API bool IsNeoKeyframeRightClicked();
|
||||||
|
|
||||||
|
|
||||||
|
// Selection API
|
||||||
|
// DON'T delete keyframes while dragging, internal buffer will get corrupted
|
||||||
|
// Order for deletion is generally:
|
||||||
|
// CanDelete? -> DataSize? -> GetData() -> Delete your data -> ClearSelection()
|
||||||
|
IMGUI_API void NeoClearSelection(); // Clears selection
|
||||||
|
IMGUI_API bool NeoIsSelecting(); // Are we currently selecting?
|
||||||
|
IMGUI_API bool NeoHasSelection(); // Is anything selected?
|
||||||
|
IMGUI_API bool NeoIsDraggingSelection(); // Are we dragging selection?
|
||||||
|
IMGUI_API bool NeoCanDeleteSelection(); // Can selection deletion be done?
|
||||||
|
IMGUI_API bool IsNeoKeyframeSelectionRightClicked(); // Is selection rightclicked?
|
||||||
|
|
||||||
|
// Call only in BeginNeoTimeline / EndNeoTimeLine scope, returns selection per timeline and size per timeline
|
||||||
|
IMGUI_API uint32_t GetNeoKeyframeSelectionSize();
|
||||||
|
IMGUI_API void GetNeoKeyframeSelection(FrameIndexType * selection);
|
||||||
|
|
||||||
|
|
||||||
|
// Sets currently selected timeline inside BeginNeoSequencer scope
|
||||||
|
IMGUI_API void SetSelectedTimeline(const char* timelineLabel);
|
||||||
|
|
||||||
|
IMGUI_API bool IsNeoTimelineSelected(ImGuiNeoTimelineIsSelectedFlags flags = ImGuiNeoTimelineIsSelectedFlags_None);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
// C++ helper
|
||||||
|
IMGUI_API bool BeginNeoTimeline(const char* label,std::vector<int32_t> & keyframes ,bool * open = nullptr, ImGuiNeoTimelineFlags flags = ImGuiNeoTimelineFlags_None);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //IMGUI_NEO_SEQUENCER_H
|
3261
source/engine/thirdparty/imgui/imnodes.cpp
vendored
Normal file
3261
source/engine/thirdparty/imgui/imnodes.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
438
source/engine/thirdparty/imgui/imnodes.h
vendored
Normal file
438
source/engine/thirdparty/imgui/imnodes.h
vendored
Normal file
|
@ -0,0 +1,438 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
#ifdef IMNODES_USER_CONFIG
|
||||||
|
#include IMNODES_USER_CONFIG
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IMNODES_NAMESPACE
|
||||||
|
#define IMNODES_NAMESPACE ImNodes
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int ImNodesCol; // -> enum ImNodesCol_
|
||||||
|
typedef int ImNodesStyleVar; // -> enum ImNodesStyleVar_
|
||||||
|
typedef int ImNodesStyleFlags; // -> enum ImNodesStyleFlags_
|
||||||
|
typedef int ImNodesPinShape; // -> enum ImNodesPinShape_
|
||||||
|
typedef int ImNodesAttributeFlags; // -> enum ImNodesAttributeFlags_
|
||||||
|
typedef int ImNodesMiniMapLocation; // -> enum ImNodesMiniMapLocation_
|
||||||
|
|
||||||
|
enum ImNodesCol_
|
||||||
|
{
|
||||||
|
ImNodesCol_NodeBackground = 0,
|
||||||
|
ImNodesCol_NodeBackgroundHovered,
|
||||||
|
ImNodesCol_NodeBackgroundSelected,
|
||||||
|
ImNodesCol_NodeOutline,
|
||||||
|
ImNodesCol_TitleBar,
|
||||||
|
ImNodesCol_TitleBarHovered,
|
||||||
|
ImNodesCol_TitleBarSelected,
|
||||||
|
ImNodesCol_Link,
|
||||||
|
ImNodesCol_LinkHovered,
|
||||||
|
ImNodesCol_LinkSelected,
|
||||||
|
ImNodesCol_Pin,
|
||||||
|
ImNodesCol_PinHovered,
|
||||||
|
ImNodesCol_BoxSelector,
|
||||||
|
ImNodesCol_BoxSelectorOutline,
|
||||||
|
ImNodesCol_GridBackground,
|
||||||
|
ImNodesCol_GridLine,
|
||||||
|
ImNodesCol_GridLinePrimary,
|
||||||
|
ImNodesCol_MiniMapBackground,
|
||||||
|
ImNodesCol_MiniMapBackgroundHovered,
|
||||||
|
ImNodesCol_MiniMapOutline,
|
||||||
|
ImNodesCol_MiniMapOutlineHovered,
|
||||||
|
ImNodesCol_MiniMapNodeBackground,
|
||||||
|
ImNodesCol_MiniMapNodeBackgroundHovered,
|
||||||
|
ImNodesCol_MiniMapNodeBackgroundSelected,
|
||||||
|
ImNodesCol_MiniMapNodeOutline,
|
||||||
|
ImNodesCol_MiniMapLink,
|
||||||
|
ImNodesCol_MiniMapLinkSelected,
|
||||||
|
ImNodesCol_MiniMapCanvas,
|
||||||
|
ImNodesCol_MiniMapCanvasOutline,
|
||||||
|
ImNodesCol_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImNodesStyleVar_
|
||||||
|
{
|
||||||
|
ImNodesStyleVar_GridSpacing = 0,
|
||||||
|
ImNodesStyleVar_NodeCornerRounding,
|
||||||
|
ImNodesStyleVar_NodePadding,
|
||||||
|
ImNodesStyleVar_NodeBorderThickness,
|
||||||
|
ImNodesStyleVar_LinkThickness,
|
||||||
|
ImNodesStyleVar_LinkLineSegmentsPerLength,
|
||||||
|
ImNodesStyleVar_LinkHoverDistance,
|
||||||
|
ImNodesStyleVar_PinCircleRadius,
|
||||||
|
ImNodesStyleVar_PinQuadSideLength,
|
||||||
|
ImNodesStyleVar_PinTriangleSideLength,
|
||||||
|
ImNodesStyleVar_PinLineThickness,
|
||||||
|
ImNodesStyleVar_PinHoverRadius,
|
||||||
|
ImNodesStyleVar_PinOffset,
|
||||||
|
ImNodesStyleVar_MiniMapPadding,
|
||||||
|
ImNodesStyleVar_MiniMapOffset,
|
||||||
|
ImNodesStyleVar_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImNodesStyleFlags_
|
||||||
|
{
|
||||||
|
ImNodesStyleFlags_None = 0,
|
||||||
|
ImNodesStyleFlags_NodeOutline = 1 << 0,
|
||||||
|
ImNodesStyleFlags_GridLines = 1 << 2,
|
||||||
|
ImNodesStyleFlags_GridLinesPrimary = 1 << 3,
|
||||||
|
ImNodesStyleFlags_GridSnapping = 1 << 4
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImNodesPinShape_
|
||||||
|
{
|
||||||
|
ImNodesPinShape_Circle,
|
||||||
|
ImNodesPinShape_CircleFilled,
|
||||||
|
ImNodesPinShape_Triangle,
|
||||||
|
ImNodesPinShape_TriangleFilled,
|
||||||
|
ImNodesPinShape_Quad,
|
||||||
|
ImNodesPinShape_QuadFilled
|
||||||
|
};
|
||||||
|
|
||||||
|
// This enum controls the way the attribute pins behave.
|
||||||
|
enum ImNodesAttributeFlags_
|
||||||
|
{
|
||||||
|
ImNodesAttributeFlags_None = 0,
|
||||||
|
// Allow detaching a link by left-clicking and dragging the link at a pin it is connected to.
|
||||||
|
// NOTE: the user has to actually delete the link for this to work. A deleted link can be
|
||||||
|
// detected by calling IsLinkDestroyed() after EndNodeEditor().
|
||||||
|
ImNodesAttributeFlags_EnableLinkDetachWithDragClick = 1 << 0,
|
||||||
|
// Visual snapping of an in progress link will trigger IsLink Created/Destroyed events. Allows
|
||||||
|
// for previewing the creation of a link while dragging it across attributes. See here for demo:
|
||||||
|
// https://github.com/Nelarius/imnodes/issues/41#issuecomment-647132113 NOTE: the user has to
|
||||||
|
// actually delete the link for this to work. A deleted link can be detected by calling
|
||||||
|
// IsLinkDestroyed() after EndNodeEditor().
|
||||||
|
ImNodesAttributeFlags_EnableLinkCreationOnSnap = 1 << 1
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImNodesIO
|
||||||
|
{
|
||||||
|
struct EmulateThreeButtonMouse
|
||||||
|
{
|
||||||
|
EmulateThreeButtonMouse();
|
||||||
|
|
||||||
|
// The keyboard modifier to use in combination with mouse left click to pan the editor view.
|
||||||
|
// Set to NULL by default. To enable this feature, set the modifier to point to a boolean
|
||||||
|
// indicating the state of a modifier. For example,
|
||||||
|
//
|
||||||
|
// ImNodes::GetIO().EmulateThreeButtonMouse.Modifier = &ImGui::GetIO().KeyAlt;
|
||||||
|
const bool* Modifier;
|
||||||
|
} EmulateThreeButtonMouse;
|
||||||
|
|
||||||
|
struct LinkDetachWithModifierClick
|
||||||
|
{
|
||||||
|
LinkDetachWithModifierClick();
|
||||||
|
|
||||||
|
// Pointer to a boolean value indicating when the desired modifier is pressed. Set to NULL
|
||||||
|
// by default. To enable the feature, set the modifier to point to a boolean indicating the
|
||||||
|
// state of a modifier. For example,
|
||||||
|
//
|
||||||
|
// ImNodes::GetIO().LinkDetachWithModifierClick.Modifier = &ImGui::GetIO().KeyCtrl;
|
||||||
|
//
|
||||||
|
// Left-clicking a link with this modifier pressed will detach that link. NOTE: the user has
|
||||||
|
// to actually delete the link for this to work. A deleted link can be detected by calling
|
||||||
|
// IsLinkDestroyed() after EndNodeEditor().
|
||||||
|
const bool* Modifier;
|
||||||
|
} LinkDetachWithModifierClick;
|
||||||
|
|
||||||
|
struct MultipleSelectModifier
|
||||||
|
{
|
||||||
|
MultipleSelectModifier();
|
||||||
|
|
||||||
|
// Pointer to a boolean value indicating when the desired modifier is pressed. Set to NULL
|
||||||
|
// by default. To enable the feature, set the modifier to point to a boolean indicating the
|
||||||
|
// state of a modifier. For example,
|
||||||
|
//
|
||||||
|
// ImNodes::GetIO().MultipleSelectModifier.Modifier = &ImGui::GetIO().KeyCtrl;
|
||||||
|
//
|
||||||
|
// Left-clicking a node with this modifier pressed will add the node to the list of
|
||||||
|
// currently selected nodes. If this value is NULL, the Ctrl key will be used.
|
||||||
|
const bool* Modifier;
|
||||||
|
} MultipleSelectModifier;
|
||||||
|
|
||||||
|
// Holding alt mouse button pans the node area, by default middle mouse button will be used
|
||||||
|
// Set based on ImGuiMouseButton values
|
||||||
|
int AltMouseButton;
|
||||||
|
|
||||||
|
// Panning speed when dragging an element and mouse is outside the main editor view.
|
||||||
|
float AutoPanningSpeed;
|
||||||
|
|
||||||
|
ImNodesIO();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImNodesStyle
|
||||||
|
{
|
||||||
|
float GridSpacing;
|
||||||
|
|
||||||
|
float NodeCornerRounding;
|
||||||
|
ImVec2 NodePadding;
|
||||||
|
float NodeBorderThickness;
|
||||||
|
|
||||||
|
float LinkThickness;
|
||||||
|
float LinkLineSegmentsPerLength;
|
||||||
|
float LinkHoverDistance;
|
||||||
|
|
||||||
|
// The following variables control the look and behavior of the pins. The default size of each
|
||||||
|
// pin shape is balanced to occupy approximately the same surface area on the screen.
|
||||||
|
|
||||||
|
// The circle radius used when the pin shape is either ImNodesPinShape_Circle or
|
||||||
|
// ImNodesPinShape_CircleFilled.
|
||||||
|
float PinCircleRadius;
|
||||||
|
// The quad side length used when the shape is either ImNodesPinShape_Quad or
|
||||||
|
// ImNodesPinShape_QuadFilled.
|
||||||
|
float PinQuadSideLength;
|
||||||
|
// The equilateral triangle side length used when the pin shape is either
|
||||||
|
// ImNodesPinShape_Triangle or ImNodesPinShape_TriangleFilled.
|
||||||
|
float PinTriangleSideLength;
|
||||||
|
// The thickness of the line used when the pin shape is not filled.
|
||||||
|
float PinLineThickness;
|
||||||
|
// The radius from the pin's center position inside of which it is detected as being hovered
|
||||||
|
// over.
|
||||||
|
float PinHoverRadius;
|
||||||
|
// Offsets the pins' positions from the edge of the node to the outside of the node.
|
||||||
|
float PinOffset;
|
||||||
|
|
||||||
|
// Mini-map padding size between mini-map edge and mini-map content.
|
||||||
|
ImVec2 MiniMapPadding;
|
||||||
|
// Mini-map offset from the screen side.
|
||||||
|
ImVec2 MiniMapOffset;
|
||||||
|
|
||||||
|
// By default, ImNodesStyleFlags_NodeOutline and ImNodesStyleFlags_Gridlines are enabled.
|
||||||
|
ImNodesStyleFlags Flags;
|
||||||
|
// Set these mid-frame using Push/PopColorStyle. You can index this color array with with a
|
||||||
|
// ImNodesCol value.
|
||||||
|
unsigned int Colors[ImNodesCol_COUNT];
|
||||||
|
|
||||||
|
ImNodesStyle();
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImNodesMiniMapLocation_
|
||||||
|
{
|
||||||
|
ImNodesMiniMapLocation_BottomLeft,
|
||||||
|
ImNodesMiniMapLocation_BottomRight,
|
||||||
|
ImNodesMiniMapLocation_TopLeft,
|
||||||
|
ImNodesMiniMapLocation_TopRight,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImGuiContext;
|
||||||
|
struct ImVec2;
|
||||||
|
|
||||||
|
struct ImNodesContext;
|
||||||
|
|
||||||
|
// An editor context corresponds to a set of nodes in a single workspace (created with a single
|
||||||
|
// Begin/EndNodeEditor pair)
|
||||||
|
//
|
||||||
|
// By default, the library creates an editor context behind the scenes, so using any of the imnodes
|
||||||
|
// functions doesn't require you to explicitly create a context.
|
||||||
|
struct ImNodesEditorContext;
|
||||||
|
|
||||||
|
// Callback type used to specify special behavior when hovering a node in the minimap
|
||||||
|
#ifndef ImNodesMiniMapNodeHoveringCallback
|
||||||
|
typedef void (*ImNodesMiniMapNodeHoveringCallback)(int, void*);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ImNodesMiniMapNodeHoveringCallbackUserData
|
||||||
|
typedef void* ImNodesMiniMapNodeHoveringCallbackUserData;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace IMNODES_NAMESPACE
|
||||||
|
{
|
||||||
|
// Call this function if you are compiling imnodes in to a dll, separate from ImGui. Calling this
|
||||||
|
// function sets the GImGui global variable, which is not shared across dll boundaries.
|
||||||
|
void SetImGuiContext(ImGuiContext* ctx);
|
||||||
|
|
||||||
|
ImNodesContext* CreateContext();
|
||||||
|
void DestroyContext(ImNodesContext* ctx = NULL); // NULL = destroy current context
|
||||||
|
ImNodesContext* GetCurrentContext();
|
||||||
|
void SetCurrentContext(ImNodesContext* ctx);
|
||||||
|
|
||||||
|
ImNodesEditorContext* EditorContextCreate();
|
||||||
|
void EditorContextFree(ImNodesEditorContext*);
|
||||||
|
void EditorContextSet(ImNodesEditorContext*);
|
||||||
|
ImVec2 EditorContextGetPanning();
|
||||||
|
void EditorContextResetPanning(const ImVec2& pos);
|
||||||
|
void EditorContextMoveToNode(const int node_id);
|
||||||
|
|
||||||
|
ImNodesIO& GetIO();
|
||||||
|
|
||||||
|
// Returns the global style struct. See the struct declaration for default values.
|
||||||
|
ImNodesStyle& GetStyle();
|
||||||
|
// Style presets matching the dear imgui styles of the same name. If dest is NULL, the active
|
||||||
|
// context's ImNodesStyle instance will be used as the destination.
|
||||||
|
void StyleColorsDark(ImNodesStyle* dest = NULL); // on by default
|
||||||
|
void StyleColorsClassic(ImNodesStyle* dest = NULL);
|
||||||
|
void StyleColorsLight(ImNodesStyle* dest = NULL);
|
||||||
|
|
||||||
|
// The top-level function call. Call this before calling BeginNode/EndNode. Calling this function
|
||||||
|
// will result the node editor grid workspace being rendered.
|
||||||
|
void BeginNodeEditor();
|
||||||
|
void EndNodeEditor();
|
||||||
|
|
||||||
|
// Add a navigable minimap to the editor; call before EndNodeEditor after all
|
||||||
|
// nodes and links have been specified
|
||||||
|
void MiniMap(
|
||||||
|
const float minimap_size_fraction = 0.2f,
|
||||||
|
const ImNodesMiniMapLocation location = ImNodesMiniMapLocation_TopLeft,
|
||||||
|
const ImNodesMiniMapNodeHoveringCallback node_hovering_callback = NULL,
|
||||||
|
const ImNodesMiniMapNodeHoveringCallbackUserData node_hovering_callback_data = NULL);
|
||||||
|
|
||||||
|
// Use PushColorStyle and PopColorStyle to modify ImNodesStyle::Colors mid-frame.
|
||||||
|
void PushColorStyle(ImNodesCol item, unsigned int color);
|
||||||
|
void PopColorStyle();
|
||||||
|
void PushStyleVar(ImNodesStyleVar style_item, float value);
|
||||||
|
void PushStyleVar(ImNodesStyleVar style_item, const ImVec2& value);
|
||||||
|
void PopStyleVar(int count = 1);
|
||||||
|
|
||||||
|
// id can be any positive or negative integer, but INT_MIN is currently reserved for internal use.
|
||||||
|
void BeginNode(int id);
|
||||||
|
void EndNode();
|
||||||
|
|
||||||
|
ImVec2 GetNodeDimensions(int id);
|
||||||
|
|
||||||
|
// Place your node title bar content (such as the node title, using ImGui::Text) between the
|
||||||
|
// following function calls. These functions have to be called before adding any attributes, or the
|
||||||
|
// layout of the node will be incorrect.
|
||||||
|
void BeginNodeTitleBar();
|
||||||
|
void EndNodeTitleBar();
|
||||||
|
|
||||||
|
// Attributes are ImGui UI elements embedded within the node. Attributes can have pin shapes
|
||||||
|
// rendered next to them. Links are created between pins.
|
||||||
|
//
|
||||||
|
// The activity status of an attribute can be checked via the IsAttributeActive() and
|
||||||
|
// IsAnyAttributeActive() function calls. This is one easy way of checking for any changes made to
|
||||||
|
// an attribute's drag float UI, for instance.
|
||||||
|
//
|
||||||
|
// Each attribute id must be unique.
|
||||||
|
|
||||||
|
// Create an input attribute block. The pin is rendered on left side.
|
||||||
|
void BeginInputAttribute(int id, ImNodesPinShape shape = ImNodesPinShape_CircleFilled);
|
||||||
|
void EndInputAttribute();
|
||||||
|
// Create an output attribute block. The pin is rendered on the right side.
|
||||||
|
void BeginOutputAttribute(int id, ImNodesPinShape shape = ImNodesPinShape_CircleFilled);
|
||||||
|
void EndOutputAttribute();
|
||||||
|
// Create a static attribute block. A static attribute has no pin, and therefore can't be linked to
|
||||||
|
// anything. However, you can still use IsAttributeActive() and IsAnyAttributeActive() to check for
|
||||||
|
// attribute activity.
|
||||||
|
void BeginStaticAttribute(int id);
|
||||||
|
void EndStaticAttribute();
|
||||||
|
|
||||||
|
// Push a single AttributeFlags value. By default, only AttributeFlags_None is set.
|
||||||
|
void PushAttributeFlag(ImNodesAttributeFlags flag);
|
||||||
|
void PopAttributeFlag();
|
||||||
|
|
||||||
|
// Render a link between attributes.
|
||||||
|
// The attributes ids used here must match the ids used in Begin(Input|Output)Attribute function
|
||||||
|
// calls. The order of start_attr and end_attr doesn't make a difference for rendering the link.
|
||||||
|
void Link(int id, int start_attribute_id, int end_attribute_id);
|
||||||
|
|
||||||
|
// Enable or disable the ability to click and drag a specific node.
|
||||||
|
void SetNodeDraggable(int node_id, const bool draggable);
|
||||||
|
|
||||||
|
// The node's position can be expressed in three coordinate systems:
|
||||||
|
// * screen space coordinates, -- the origin is the upper left corner of the window.
|
||||||
|
// * editor space coordinates -- the origin is the upper left corner of the node editor window
|
||||||
|
// * grid space coordinates, -- the origin is the upper left corner of the node editor window,
|
||||||
|
// translated by the current editor panning vector (see EditorContextGetPanning() and
|
||||||
|
// EditorContextResetPanning())
|
||||||
|
|
||||||
|
// Use the following functions to get and set the node's coordinates in these coordinate systems.
|
||||||
|
|
||||||
|
void SetNodeScreenSpacePos(int node_id, const ImVec2& screen_space_pos);
|
||||||
|
void SetNodeEditorSpacePos(int node_id, const ImVec2& editor_space_pos);
|
||||||
|
void SetNodeGridSpacePos(int node_id, const ImVec2& grid_pos);
|
||||||
|
|
||||||
|
ImVec2 GetNodeScreenSpacePos(const int node_id);
|
||||||
|
ImVec2 GetNodeEditorSpacePos(const int node_id);
|
||||||
|
ImVec2 GetNodeGridSpacePos(const int node_id);
|
||||||
|
|
||||||
|
// If ImNodesStyleFlags_GridSnapping is enabled, snap the specified node's origin to the grid.
|
||||||
|
void SnapNodeToGrid(int node_id);
|
||||||
|
|
||||||
|
// Returns true if the current node editor canvas is being hovered over by the mouse, and is not
|
||||||
|
// blocked by any other windows.
|
||||||
|
bool IsEditorHovered();
|
||||||
|
// The following functions return true if a UI element is being hovered over by the mouse cursor.
|
||||||
|
// Assigns the id of the UI element being hovered over to the function argument. Use these functions
|
||||||
|
// after EndNodeEditor() has been called.
|
||||||
|
bool IsNodeHovered(int* node_id);
|
||||||
|
bool IsLinkHovered(int* link_id);
|
||||||
|
bool IsPinHovered(int* attribute_id);
|
||||||
|
|
||||||
|
// Use The following two functions to query the number of selected nodes or links in the current
|
||||||
|
// editor. Use after calling EndNodeEditor().
|
||||||
|
int NumSelectedNodes();
|
||||||
|
int NumSelectedLinks();
|
||||||
|
// Get the selected node/link ids. The pointer argument should point to an integer array with at
|
||||||
|
// least as many elements as the respective NumSelectedNodes/NumSelectedLinks function call
|
||||||
|
// returned.
|
||||||
|
void GetSelectedNodes(int* node_ids);
|
||||||
|
void GetSelectedLinks(int* link_ids);
|
||||||
|
// Clears the list of selected nodes/links. Useful if you want to delete a selected node or link.
|
||||||
|
void ClearNodeSelection();
|
||||||
|
void ClearLinkSelection();
|
||||||
|
// Use the following functions to add or remove individual nodes or links from the current editors
|
||||||
|
// selection. Note that all functions require the id to be an existing valid id for this editor.
|
||||||
|
// Select-functions has the precondition that the object is currently considered unselected.
|
||||||
|
// Clear-functions has the precondition that the object is currently considered selected.
|
||||||
|
// Preconditions listed above can be checked via IsNodeSelected/IsLinkSelected if not already
|
||||||
|
// known.
|
||||||
|
void SelectNode(int node_id);
|
||||||
|
void ClearNodeSelection(int node_id);
|
||||||
|
bool IsNodeSelected(int node_id);
|
||||||
|
void SelectLink(int link_id);
|
||||||
|
void ClearLinkSelection(int link_id);
|
||||||
|
bool IsLinkSelected(int link_id);
|
||||||
|
|
||||||
|
// Was the previous attribute active? This will continuously return true while the left mouse button
|
||||||
|
// is being pressed over the UI content of the attribute.
|
||||||
|
bool IsAttributeActive();
|
||||||
|
// Was any attribute active? If so, sets the active attribute id to the output function argument.
|
||||||
|
bool IsAnyAttributeActive(int* attribute_id = NULL);
|
||||||
|
|
||||||
|
// Use the following functions to query a change of state for an existing link, or new link. Call
|
||||||
|
// these after EndNodeEditor().
|
||||||
|
|
||||||
|
// Did the user start dragging a new link from a pin?
|
||||||
|
bool IsLinkStarted(int* started_at_attribute_id);
|
||||||
|
// Did the user drop the dragged link before attaching it to a pin?
|
||||||
|
// There are two different kinds of situations to consider when handling this event:
|
||||||
|
// 1) a link which is created at a pin and then dropped
|
||||||
|
// 2) an existing link which is detached from a pin and then dropped
|
||||||
|
// Use the including_detached_links flag to control whether this function triggers when the user
|
||||||
|
// detaches a link and drops it.
|
||||||
|
bool IsLinkDropped(int* started_at_attribute_id = NULL, bool including_detached_links = true);
|
||||||
|
// Did the user finish creating a new link?
|
||||||
|
bool IsLinkCreated(
|
||||||
|
int* started_at_attribute_id,
|
||||||
|
int* ended_at_attribute_id,
|
||||||
|
bool* created_from_snap = NULL);
|
||||||
|
bool IsLinkCreated(
|
||||||
|
int* started_at_node_id,
|
||||||
|
int* started_at_attribute_id,
|
||||||
|
int* ended_at_node_id,
|
||||||
|
int* ended_at_attribute_id,
|
||||||
|
bool* created_from_snap = NULL);
|
||||||
|
|
||||||
|
// Was an existing link detached from a pin by the user? The detached link's id is assigned to the
|
||||||
|
// output argument link_id.
|
||||||
|
bool IsLinkDestroyed(int* link_id);
|
||||||
|
|
||||||
|
// Use the following functions to write the editor context's state to a string, or directly to a
|
||||||
|
// file. The editor context is serialized in the INI file format.
|
||||||
|
|
||||||
|
const char* SaveCurrentEditorStateToIniString(size_t* data_size = NULL);
|
||||||
|
const char* SaveEditorStateToIniString(
|
||||||
|
const ImNodesEditorContext* editor,
|
||||||
|
size_t* data_size = NULL);
|
||||||
|
|
||||||
|
void LoadCurrentEditorStateFromIniString(const char* data, size_t data_size);
|
||||||
|
void LoadEditorStateFromIniString(ImNodesEditorContext* editor, const char* data, size_t data_size);
|
||||||
|
|
||||||
|
void SaveCurrentEditorStateToIniFile(const char* file_name);
|
||||||
|
void SaveEditorStateToIniFile(const ImNodesEditorContext* editor, const char* file_name);
|
||||||
|
|
||||||
|
void LoadCurrentEditorStateFromIniFile(const char* file_name);
|
||||||
|
void LoadEditorStateFromIniFile(ImNodesEditorContext* editor, const char* file_name);
|
||||||
|
} // namespace IMNODES_NAMESPACE
|
500
source/engine/thirdparty/imgui/imnodes_internal.h
vendored
Normal file
500
source/engine/thirdparty/imgui/imnodes_internal.h
vendored
Normal file
|
@ -0,0 +1,500 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <imgui_internal.h>
|
||||||
|
|
||||||
|
#include "imnodes.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
// the structure of this file:
|
||||||
|
//
|
||||||
|
// [SECTION] internal enums
|
||||||
|
// [SECTION] internal data structures
|
||||||
|
// [SECTION] global and editor context structs
|
||||||
|
// [SECTION] object pool implementation
|
||||||
|
|
||||||
|
struct ImNodesContext;
|
||||||
|
|
||||||
|
extern ImNodesContext* GImNodes;
|
||||||
|
|
||||||
|
// [SECTION] internal enums
|
||||||
|
|
||||||
|
typedef int ImNodesScope;
|
||||||
|
typedef int ImNodesAttributeType;
|
||||||
|
typedef int ImNodesUIState;
|
||||||
|
typedef int ImNodesClickInteractionType;
|
||||||
|
typedef int ImNodesLinkCreationType;
|
||||||
|
|
||||||
|
enum ImNodesScope_
|
||||||
|
{
|
||||||
|
ImNodesScope_None = 1,
|
||||||
|
ImNodesScope_Editor = 1 << 1,
|
||||||
|
ImNodesScope_Node = 1 << 2,
|
||||||
|
ImNodesScope_Attribute = 1 << 3
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImNodesAttributeType_
|
||||||
|
{
|
||||||
|
ImNodesAttributeType_None,
|
||||||
|
ImNodesAttributeType_Input,
|
||||||
|
ImNodesAttributeType_Output
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImNodesUIState_
|
||||||
|
{
|
||||||
|
ImNodesUIState_None = 0,
|
||||||
|
ImNodesUIState_LinkStarted = 1 << 0,
|
||||||
|
ImNodesUIState_LinkDropped = 1 << 1,
|
||||||
|
ImNodesUIState_LinkCreated = 1 << 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImNodesClickInteractionType_
|
||||||
|
{
|
||||||
|
ImNodesClickInteractionType_Node,
|
||||||
|
ImNodesClickInteractionType_Link,
|
||||||
|
ImNodesClickInteractionType_LinkCreation,
|
||||||
|
ImNodesClickInteractionType_Panning,
|
||||||
|
ImNodesClickInteractionType_BoxSelection,
|
||||||
|
ImNodesClickInteractionType_ImGuiItem,
|
||||||
|
ImNodesClickInteractionType_None
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImNodesLinkCreationType_
|
||||||
|
{
|
||||||
|
ImNodesLinkCreationType_Standard,
|
||||||
|
ImNodesLinkCreationType_FromDetach
|
||||||
|
};
|
||||||
|
|
||||||
|
// [SECTION] internal data structures
|
||||||
|
|
||||||
|
// The object T must have the following interface:
|
||||||
|
//
|
||||||
|
// struct T
|
||||||
|
// {
|
||||||
|
// T();
|
||||||
|
//
|
||||||
|
// int id;
|
||||||
|
// };
|
||||||
|
template<typename T>
|
||||||
|
struct ImObjectPool
|
||||||
|
{
|
||||||
|
ImVector<T> Pool;
|
||||||
|
ImVector<bool> InUse;
|
||||||
|
ImVector<int> FreeList;
|
||||||
|
ImGuiStorage IdMap;
|
||||||
|
|
||||||
|
ImObjectPool() : Pool(), InUse(), FreeList(), IdMap() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Emulates std::optional<int> using the sentinel value `INVALID_INDEX`.
|
||||||
|
struct ImOptionalIndex
|
||||||
|
{
|
||||||
|
ImOptionalIndex() : _Index(INVALID_INDEX) {}
|
||||||
|
ImOptionalIndex(const int value) : _Index(value) {}
|
||||||
|
|
||||||
|
// Observers
|
||||||
|
|
||||||
|
inline bool HasValue() const { return _Index != INVALID_INDEX; }
|
||||||
|
|
||||||
|
inline int Value() const
|
||||||
|
{
|
||||||
|
IM_ASSERT(HasValue());
|
||||||
|
return _Index;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modifiers
|
||||||
|
|
||||||
|
inline ImOptionalIndex& operator=(const int value)
|
||||||
|
{
|
||||||
|
_Index = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Reset() { _Index = INVALID_INDEX; }
|
||||||
|
|
||||||
|
inline bool operator==(const ImOptionalIndex& rhs) const { return _Index == rhs._Index; }
|
||||||
|
|
||||||
|
inline bool operator==(const int rhs) const { return _Index == rhs; }
|
||||||
|
|
||||||
|
inline bool operator!=(const ImOptionalIndex& rhs) const { return _Index != rhs._Index; }
|
||||||
|
|
||||||
|
inline bool operator!=(const int rhs) const { return _Index != rhs; }
|
||||||
|
|
||||||
|
static const int INVALID_INDEX = -1;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _Index;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImNodeData
|
||||||
|
{
|
||||||
|
int Id;
|
||||||
|
ImVec2 Origin; // The node origin is in editor space
|
||||||
|
ImRect TitleBarContentRect;
|
||||||
|
ImRect Rect;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ImU32 Background, BackgroundHovered, BackgroundSelected, Outline, Titlebar, TitlebarHovered,
|
||||||
|
TitlebarSelected;
|
||||||
|
} ColorStyle;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
float CornerRounding;
|
||||||
|
ImVec2 Padding;
|
||||||
|
float BorderThickness;
|
||||||
|
} LayoutStyle;
|
||||||
|
|
||||||
|
ImVector<int> PinIndices;
|
||||||
|
bool Draggable;
|
||||||
|
|
||||||
|
ImNodeData(const int node_id)
|
||||||
|
: Id(node_id), Origin(0.0f, 0.0f), TitleBarContentRect(),
|
||||||
|
Rect(ImVec2(0.0f, 0.0f), ImVec2(0.0f, 0.0f)), ColorStyle(), LayoutStyle(), PinIndices(),
|
||||||
|
Draggable(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~ImNodeData() { Id = INT_MIN; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImPinData
|
||||||
|
{
|
||||||
|
int Id;
|
||||||
|
int ParentNodeIdx;
|
||||||
|
ImRect AttributeRect;
|
||||||
|
ImNodesAttributeType Type;
|
||||||
|
ImNodesPinShape Shape;
|
||||||
|
ImVec2 Pos; // screen-space coordinates
|
||||||
|
int Flags;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ImU32 Background, Hovered;
|
||||||
|
} ColorStyle;
|
||||||
|
|
||||||
|
ImPinData(const int pin_id)
|
||||||
|
: Id(pin_id), ParentNodeIdx(), AttributeRect(), Type(ImNodesAttributeType_None),
|
||||||
|
Shape(ImNodesPinShape_CircleFilled), Pos(), Flags(ImNodesAttributeFlags_None),
|
||||||
|
ColorStyle()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImLinkData
|
||||||
|
{
|
||||||
|
int Id;
|
||||||
|
int StartPinIdx, EndPinIdx;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ImU32 Base, Hovered, Selected;
|
||||||
|
} ColorStyle;
|
||||||
|
|
||||||
|
ImLinkData(const int link_id) : Id(link_id), StartPinIdx(), EndPinIdx(), ColorStyle() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImClickInteractionState
|
||||||
|
{
|
||||||
|
ImNodesClickInteractionType Type;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
int StartPinIdx;
|
||||||
|
ImOptionalIndex EndPinIdx;
|
||||||
|
ImNodesLinkCreationType Type;
|
||||||
|
} LinkCreation;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ImRect Rect; // Coordinates in grid space
|
||||||
|
} BoxSelector;
|
||||||
|
|
||||||
|
ImClickInteractionState() : Type(ImNodesClickInteractionType_None) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImNodesColElement
|
||||||
|
{
|
||||||
|
ImU32 Color;
|
||||||
|
ImNodesCol Item;
|
||||||
|
|
||||||
|
ImNodesColElement(const ImU32 c, const ImNodesCol s) : Color(c), Item(s) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImNodesStyleVarElement
|
||||||
|
{
|
||||||
|
ImNodesStyleVar Item;
|
||||||
|
float FloatValue[2];
|
||||||
|
|
||||||
|
ImNodesStyleVarElement(const ImNodesStyleVar variable, const float value) : Item(variable)
|
||||||
|
{
|
||||||
|
FloatValue[0] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImNodesStyleVarElement(const ImNodesStyleVar variable, const ImVec2 value) : Item(variable)
|
||||||
|
{
|
||||||
|
FloatValue[0] = value.x;
|
||||||
|
FloatValue[1] = value.y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// [SECTION] global and editor context structs
|
||||||
|
|
||||||
|
struct ImNodesEditorContext
|
||||||
|
{
|
||||||
|
ImObjectPool<ImNodeData> Nodes;
|
||||||
|
ImObjectPool<ImPinData> Pins;
|
||||||
|
ImObjectPool<ImLinkData> Links;
|
||||||
|
|
||||||
|
ImVector<int> NodeDepthOrder;
|
||||||
|
|
||||||
|
// ui related fields
|
||||||
|
ImVec2 Panning;
|
||||||
|
ImVec2 AutoPanningDelta;
|
||||||
|
// Minimum and maximum extents of all content in grid space. Valid after final
|
||||||
|
// ImNodes::EndNode() call.
|
||||||
|
ImRect GridContentBounds;
|
||||||
|
|
||||||
|
ImVector<int> SelectedNodeIndices;
|
||||||
|
ImVector<int> SelectedLinkIndices;
|
||||||
|
|
||||||
|
// Relative origins of selected nodes for snapping of dragged nodes
|
||||||
|
ImVector<ImVec2> SelectedNodeOffsets;
|
||||||
|
// Offset of the primary node origin relative to the mouse cursor.
|
||||||
|
ImVec2 PrimaryNodeOffset;
|
||||||
|
|
||||||
|
ImClickInteractionState ClickInteraction;
|
||||||
|
|
||||||
|
// Mini-map state set by MiniMap()
|
||||||
|
|
||||||
|
bool MiniMapEnabled;
|
||||||
|
ImNodesMiniMapLocation MiniMapLocation;
|
||||||
|
float MiniMapSizeFraction;
|
||||||
|
ImNodesMiniMapNodeHoveringCallback MiniMapNodeHoveringCallback;
|
||||||
|
ImNodesMiniMapNodeHoveringCallbackUserData MiniMapNodeHoveringCallbackUserData;
|
||||||
|
|
||||||
|
// Mini-map state set during EndNodeEditor() call
|
||||||
|
|
||||||
|
ImRect MiniMapRectScreenSpace;
|
||||||
|
ImRect MiniMapContentScreenSpace;
|
||||||
|
float MiniMapScaling;
|
||||||
|
|
||||||
|
ImNodesEditorContext()
|
||||||
|
: Nodes(), Pins(), Links(), Panning(0.f, 0.f), SelectedNodeIndices(), SelectedLinkIndices(),
|
||||||
|
SelectedNodeOffsets(), PrimaryNodeOffset(0.f, 0.f), ClickInteraction(),
|
||||||
|
MiniMapEnabled(false), MiniMapSizeFraction(0.0f), MiniMapNodeHoveringCallback(NULL),
|
||||||
|
MiniMapNodeHoveringCallbackUserData(NULL), MiniMapScaling(0.0f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImNodesContext
|
||||||
|
{
|
||||||
|
ImNodesEditorContext* DefaultEditorCtx;
|
||||||
|
ImNodesEditorContext* EditorCtx;
|
||||||
|
|
||||||
|
// Canvas draw list and helper state
|
||||||
|
ImDrawList* CanvasDrawList;
|
||||||
|
ImGuiStorage NodeIdxToSubmissionIdx;
|
||||||
|
ImVector<int> NodeIdxSubmissionOrder;
|
||||||
|
ImVector<int> NodeIndicesOverlappingWithMouse;
|
||||||
|
ImVector<int> OccludedPinIndices;
|
||||||
|
|
||||||
|
// Canvas extents
|
||||||
|
ImVec2 CanvasOriginScreenSpace;
|
||||||
|
ImRect CanvasRectScreenSpace;
|
||||||
|
|
||||||
|
// Debug helpers
|
||||||
|
ImNodesScope CurrentScope;
|
||||||
|
|
||||||
|
// Configuration state
|
||||||
|
ImNodesIO Io;
|
||||||
|
ImNodesStyle Style;
|
||||||
|
ImVector<ImNodesColElement> ColorModifierStack;
|
||||||
|
ImVector<ImNodesStyleVarElement> StyleModifierStack;
|
||||||
|
ImGuiTextBuffer TextBuffer;
|
||||||
|
|
||||||
|
int CurrentAttributeFlags;
|
||||||
|
ImVector<int> AttributeFlagStack;
|
||||||
|
|
||||||
|
// UI element state
|
||||||
|
int CurrentNodeIdx;
|
||||||
|
int CurrentPinIdx;
|
||||||
|
int CurrentAttributeId;
|
||||||
|
|
||||||
|
ImOptionalIndex HoveredNodeIdx;
|
||||||
|
ImOptionalIndex HoveredLinkIdx;
|
||||||
|
ImOptionalIndex HoveredPinIdx;
|
||||||
|
|
||||||
|
ImOptionalIndex DeletedLinkIdx;
|
||||||
|
ImOptionalIndex SnapLinkIdx;
|
||||||
|
|
||||||
|
// Event helper state
|
||||||
|
// TODO: this should be a part of a state machine, and not a member of the global struct.
|
||||||
|
// Unclear what parts of the code this relates to.
|
||||||
|
int ImNodesUIState;
|
||||||
|
|
||||||
|
int ActiveAttributeId;
|
||||||
|
bool ActiveAttribute;
|
||||||
|
|
||||||
|
// ImGui::IO cache
|
||||||
|
|
||||||
|
ImVec2 MousePos;
|
||||||
|
|
||||||
|
bool LeftMouseClicked;
|
||||||
|
bool LeftMouseReleased;
|
||||||
|
bool AltMouseClicked;
|
||||||
|
bool LeftMouseDragging;
|
||||||
|
bool AltMouseDragging;
|
||||||
|
float AltMouseScrollDelta;
|
||||||
|
bool MultipleSelectModifier;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace IMNODES_NAMESPACE
|
||||||
|
{
|
||||||
|
static inline ImNodesEditorContext& EditorContextGet()
|
||||||
|
{
|
||||||
|
// No editor context was set! Did you forget to call ImNodes::CreateContext()?
|
||||||
|
IM_ASSERT(GImNodes->EditorCtx != NULL);
|
||||||
|
return *GImNodes->EditorCtx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SECTION] ObjectPool implementation
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static inline int ObjectPoolFind(const ImObjectPool<T>& objects, const int id)
|
||||||
|
{
|
||||||
|
const int index = objects.IdMap.GetInt(static_cast<ImGuiID>(id), -1);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static inline void ObjectPoolUpdate(ImObjectPool<T>& objects)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < objects.InUse.size(); ++i)
|
||||||
|
{
|
||||||
|
const int id = objects.Pool[i].Id;
|
||||||
|
|
||||||
|
if (!objects.InUse[i] && objects.IdMap.GetInt(id, -1) == i)
|
||||||
|
{
|
||||||
|
objects.IdMap.SetInt(id, -1);
|
||||||
|
objects.FreeList.push_back(i);
|
||||||
|
(objects.Pool.Data + i)->~T();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void ObjectPoolUpdate(ImObjectPool<ImNodeData>& nodes)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < nodes.InUse.size(); ++i)
|
||||||
|
{
|
||||||
|
if (nodes.InUse[i])
|
||||||
|
{
|
||||||
|
nodes.Pool[i].PinIndices.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const int id = nodes.Pool[i].Id;
|
||||||
|
|
||||||
|
if (nodes.IdMap.GetInt(id, -1) == i)
|
||||||
|
{
|
||||||
|
// Remove node idx form depth stack the first time we detect that this idx slot is
|
||||||
|
// unused
|
||||||
|
ImVector<int>& depth_stack = EditorContextGet().NodeDepthOrder;
|
||||||
|
const int* const elem = depth_stack.find(i);
|
||||||
|
IM_ASSERT(elem != depth_stack.end());
|
||||||
|
depth_stack.erase(elem);
|
||||||
|
|
||||||
|
nodes.IdMap.SetInt(id, -1);
|
||||||
|
nodes.FreeList.push_back(i);
|
||||||
|
(nodes.Pool.Data + i)->~ImNodeData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static inline void ObjectPoolReset(ImObjectPool<T>& objects)
|
||||||
|
{
|
||||||
|
if (!objects.InUse.empty())
|
||||||
|
{
|
||||||
|
memset(objects.InUse.Data, 0, objects.InUse.size_in_bytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static inline int ObjectPoolFindOrCreateIndex(ImObjectPool<T>& objects, const int id)
|
||||||
|
{
|
||||||
|
int index = objects.IdMap.GetInt(static_cast<ImGuiID>(id), -1);
|
||||||
|
|
||||||
|
// Construct new object
|
||||||
|
if (index == -1)
|
||||||
|
{
|
||||||
|
if (objects.FreeList.empty())
|
||||||
|
{
|
||||||
|
index = objects.Pool.size();
|
||||||
|
IM_ASSERT(objects.Pool.size() == objects.InUse.size());
|
||||||
|
const int new_size = objects.Pool.size() + 1;
|
||||||
|
objects.Pool.resize(new_size);
|
||||||
|
objects.InUse.resize(new_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index = objects.FreeList.back();
|
||||||
|
objects.FreeList.pop_back();
|
||||||
|
}
|
||||||
|
IM_PLACEMENT_NEW(objects.Pool.Data + index) T(id);
|
||||||
|
objects.IdMap.SetInt(static_cast<ImGuiID>(id), index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flag it as used
|
||||||
|
objects.InUse[index] = true;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline int ObjectPoolFindOrCreateIndex(ImObjectPool<ImNodeData>& nodes, const int node_id)
|
||||||
|
{
|
||||||
|
int node_idx = nodes.IdMap.GetInt(static_cast<ImGuiID>(node_id), -1);
|
||||||
|
|
||||||
|
// Construct new node
|
||||||
|
if (node_idx == -1)
|
||||||
|
{
|
||||||
|
if (nodes.FreeList.empty())
|
||||||
|
{
|
||||||
|
node_idx = nodes.Pool.size();
|
||||||
|
IM_ASSERT(nodes.Pool.size() == nodes.InUse.size());
|
||||||
|
const int new_size = nodes.Pool.size() + 1;
|
||||||
|
nodes.Pool.resize(new_size);
|
||||||
|
nodes.InUse.resize(new_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node_idx = nodes.FreeList.back();
|
||||||
|
nodes.FreeList.pop_back();
|
||||||
|
}
|
||||||
|
IM_PLACEMENT_NEW(nodes.Pool.Data + node_idx) ImNodeData(node_id);
|
||||||
|
nodes.IdMap.SetInt(static_cast<ImGuiID>(node_id), node_idx);
|
||||||
|
|
||||||
|
ImNodesEditorContext& editor = EditorContextGet();
|
||||||
|
editor.NodeDepthOrder.push_back(node_idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flag node as used
|
||||||
|
nodes.InUse[node_idx] = true;
|
||||||
|
|
||||||
|
return node_idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static inline T& ObjectPoolFindOrCreateObject(ImObjectPool<T>& objects, const int id)
|
||||||
|
{
|
||||||
|
const int index = ObjectPoolFindOrCreateIndex(objects, id);
|
||||||
|
return objects.Pool[index];
|
||||||
|
}
|
||||||
|
} // namespace IMNODES_NAMESPACE
|
Loading…
Reference in a new issue