Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
488 changes: 289 additions & 199 deletions 3rdparty/imnodes/imnodes.cpp

Large diffs are not rendered by default.

34 changes: 28 additions & 6 deletions 3rdparty/imnodes/imnodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum ImNodesCol_
ImNodesCol_BoxSelectorOutline,
ImNodesCol_GridBackground,
ImNodesCol_GridLine,
ImNodesCol_GridLinePrimary,
ImNodesCol_MiniMapBackground,
ImNodesCol_MiniMapBackgroundHovered,
ImNodesCol_MiniMapOutline,
Expand Down Expand Up @@ -75,7 +76,9 @@ enum ImNodesStyleFlags_
{
ImNodesStyleFlags_None = 0,
ImNodesStyleFlags_NodeOutline = 1 << 0,
ImNodesStyleFlags_GridLines = 1 << 2
ImNodesStyleFlags_GridLines = 1 << 2,
ImNodesStyleFlags_GridLinesPrimary = 1 << 3,
ImNodesStyleFlags_GridSnapping = 1 << 4
};

enum ImNodesPinShape_
Expand Down Expand Up @@ -134,6 +137,21 @@ struct ImNodesIO
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;
Expand Down Expand Up @@ -241,10 +259,11 @@ 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.
void StyleColorsDark(); // on by default
void StyleColorsClassic();
void StyleColorsLight();
// 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.
Expand Down Expand Up @@ -328,6 +347,9 @@ 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();
Expand Down Expand Up @@ -413,4 +435,4 @@ void SaveEditorStateToIniFile(const ImNodesEditorContext* editor, const char* fi

void LoadCurrentEditorStateFromIniFile(const char* file_name);
void LoadEditorStateFromIniFile(ImNodesEditorContext* editor, const char* file_name);
} // namespace IMNODES_NAMESPACE
} // namespace IMNODES_NAMESPACE
29 changes: 17 additions & 12 deletions 3rdparty/imnodes/imnodes_internal.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once

#include "imnodes.h"

#include <imgui.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include <imgui_internal.h>

#include <assert.h>
#include "imnodes.h"

#include <limits.h>

// the structure of this file:
Expand Down Expand Up @@ -101,7 +100,7 @@ struct ImOptionalIndex

inline int Value() const
{
assert(HasValue());
IM_ASSERT(HasValue());
return _Index;
}

Expand Down Expand Up @@ -153,7 +152,7 @@ struct ImNodeData
bool Draggable;

ImNodeData(const int node_id)
: Id(node_id), Origin(100.0f, 100.0f), TitleBarContentRect(),
: 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)
{
Expand Down Expand Up @@ -262,6 +261,11 @@ struct ImNodesEditorContext
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()
Expand All @@ -280,9 +284,9 @@ struct ImNodesEditorContext

ImNodesEditorContext()
: Nodes(), Pins(), Links(), Panning(0.f, 0.f), SelectedNodeIndices(), SelectedLinkIndices(),
ClickInteraction(), MiniMapEnabled(false), MiniMapSizeFraction(0.0f),
MiniMapNodeHoveringCallback(NULL), MiniMapNodeHoveringCallbackUserData(NULL),
MiniMapScaling(0.0f)
SelectedNodeOffsets(), PrimaryNodeOffset(0.f, 0.f), ClickInteraction(),
MiniMapEnabled(false), MiniMapSizeFraction(0.0f), MiniMapNodeHoveringCallback(NULL),
MiniMapNodeHoveringCallbackUserData(NULL), MiniMapScaling(0.0f)
{
}
};
Expand Down Expand Up @@ -346,14 +350,15 @@ struct ImNodesContext
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()?
assert(GImNodes->EditorCtx != NULL);
IM_ASSERT(GImNodes->EditorCtx != NULL);
return *GImNodes->EditorCtx;
}

Expand Down Expand Up @@ -401,7 +406,7 @@ inline void ObjectPoolUpdate(ImObjectPool<ImNodeData>& nodes)
// unused
ImVector<int>& depth_stack = EditorContextGet().NodeDepthOrder;
const int* const elem = depth_stack.find(i);
assert(elem != depth_stack.end());
IM_ASSERT(elem != depth_stack.end());
depth_stack.erase(elem);

nodes.IdMap.SetInt(id, -1);
Expand Down Expand Up @@ -492,4 +497,4 @@ static inline T& ObjectPoolFindOrCreateObject(ImObjectPool<T>& objects, const in
const int index = ObjectPoolFindOrCreateIndex(objects, id);
return objects.Pool[index];
}
} // namespace IMNODES_NAMESPACE
} // namespace IMNODES_NAMESPACE
30 changes: 22 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
cmake_minimum_required(VERSION 3.11.0)
project(implot_demos VERSION 0.1.0)

# Workaround for the cmake generation stage:
# https://github.com/libsdl-org/SDL/issues/6454

enable_language(OBJC)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

###############################################################################
# 3RD PARTY LIBS
###############################################################################
Expand Down Expand Up @@ -82,7 +90,10 @@ add_library(imgui ${IMGUI_HEADERS} ${IMGUI_SRC})
if(MSVC)
target_compile_options(imgui PRIVATE /W4 /WX /arch:AVX2 /fp:fast)
endif()
target_link_libraries(imgui PUBLIC glfw glad OpenGL::GL imm32)
target_link_libraries(imgui PUBLIC glfw glad OpenGL::GL)
if(MSVC)
target_link_libraries(imgui PUBLIC imm32)
endif()
target_compile_definitions(imgui PRIVATE IMGUI_DLL_EXPORT)

include_directories(../imgui/ ../imgui/examples ../imgui/examples/libs/gl3w ../imgui/backends ../imgui/misc/cpp)
Expand Down Expand Up @@ -110,10 +121,13 @@ target_compile_definitions(implot PUBLIC IMPLOT_DEBUG IMPLOT_DLL_EXPORT IMPLOT_B
set_property(TARGET implot PROPERTY CXX_STANDARD 11)
if(MSVC)
target_compile_options(implot PRIVATE /W4 /WX /arch:AVX2 /fp:fast /permissive-)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_compile_options(implot PRIVATE -Wall -Wextra -pedantic -Werror -O3)
else()
target_compile_options(implot PRIVATE -Wall -Wextra -pedantic -Werror -mavx2 -Ofast)
endif()


include_directories(../implot/)

###############################################################################
Expand Down Expand Up @@ -158,13 +172,13 @@ add_executable(perlin "demos/perlin.cpp")
target_link_libraries(perlin app)
target_include_directories(perlin PRIVATE "3rdparty")

# mandel demo
add_executable(mandel "demos/mandel.cpp")
target_link_libraries(mandel app)
target_include_directories(mandel PRIVATE "3rdparty")
if (MSVC)
target_compile_options(mandel PRIVATE /arch:AVX2 /fp:fast /openmp)
endif()
# # mandel demo
# add_executable(mandel "demos/mandel.cpp")
# target_link_libraries(mandel app)
# target_include_directories(mandel PRIVATE "3rdparty")
# if (MSVC)
# target_compile_options(mandel PRIVATE /arch:AVX2 /fp:fast /openmp)
# endif()

# graph demo
add_executable(graph "demos/graph.cpp")
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ git clone https://github.com/ocornut/imgui
2. Build with CMake, e.g.:
```shell
cd implot_demos
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake -G"Unix Makefiles" -B build -S .
cmake --build build --config Release --parallel 8
```

## Demos
Expand Down
2 changes: 2 additions & 0 deletions common/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ App::App(std::string title, int w, int h, int argc, char const *argv[])
const bool no_vsync = result["vsync"].as<bool>();
const bool use_msaa = result["msaa"].as<bool>();
const bool im_style = result["imgui"].as<bool>();
#if defined(_WIN32)
NvOptimusEnablement = AmdPowerXpressRequestHighPerformance = result["gpu"].as<bool>();
UsingDGPU = result["gpu"].as<bool>();
#endif

#ifdef _DEBUG
title += " - OpenGL - Debug";
Expand Down
2 changes: 1 addition & 1 deletion demos/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct ImFilter : public App {
ImGui::SetNextWindowPos(ImVec2(0,0), ImGuiCond_Always);
ImGui::SetNextWindowSize(GetWindowSize(), ImGuiCond_Always);
ImGui::Begin("Filter",nullptr, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoTitleBar);
ImGui::BeginChild("ChildL", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.5f, -1));
ImGui::BeginChild("ChildL", ImVec2(ImGui::GetWindowWidth() * 0.5f, -1));
ImGui::Text("Input: x(t) = A1*sin(2*pi*F1*t) + A2*sin(2*pi*F1*t) + noise");
ImGui::Separator();

Expand Down
4 changes: 2 additions & 2 deletions demos/maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ struct ImMaps : public App {
void Update() override {
static int renders = 0;
static bool debug = false;
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_A)))
if (ImGui::IsKeyPressed(ImGuiKey_A))
debug = !debug;

ImGui::SetNextWindowPos({0,0});
Expand Down Expand Up @@ -355,7 +355,7 @@ struct ImMaps : public App {
auto [bmin,bmax] = coord.bounds();
if (tile != nullptr) {
auto col = debug ? ((coord.x % 2 == 0 && coord.y % 2 != 0) || (coord.x % 2 != 0 && coord.y % 2 == 0))? ImVec4(1,0,1,1) : ImVec4(1,1,0,1) : ImVec4(1,1,1,1);
ImPlot::PlotImage("##Tiles",(void*)(intptr_t)tile->image.ID,bmin,bmax,{0,0},{1,1},col);
ImPlot::PlotImage("##Tiles",tile->image.ID,bmin,bmax,{0,0},{1,1},col);
}
if (debug)
ImPlot::PlotText(coord.label().c_str(),(bmin.x+bmax.x)/2,(bmin.y+bmax.y)/2);
Expand Down