Skip to content

Commit

Permalink
Merge pull request #1 from thedmd/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
Lumengine authored Oct 12, 2023
2 parents 33e5923 + af7fa51 commit 8a21bbb
Show file tree
Hide file tree
Showing 17 changed files with 414 additions and 260 deletions.
4 changes: 2 additions & 2 deletions crude_json.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Crude implementation of JSON value object and parser.
// Crude implementation of JSON value object and parser.
//
// VERSION 0.1
//
Expand Down Expand Up @@ -561,7 +561,7 @@ struct value::parser
if (end != hex.c_str() + hex.size())
return false;

c = v;
c = static_cast<int>(v);
return true;
}

Expand Down
59 changes: 58 additions & 1 deletion docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
v0.9.1 (WIP):
v0.9.3 (WIP):

CHANGE: Canvas: Use ImDrawCallback_ImCanvas macro as draw callback sentinel (#256), thanks @nspitko

BUGFIX: Canvas: Ensure SentinelDrawCallback cleanup (#255)

BUGFIX: Editor: Don't call Reasume/Suspend on invisible canvas (#255)


v0.9.2 (2023-09-01):

NEW: Editor: Add offset of hover/select to style (thanks @MultiPain)

NEW: Editor: Add IMGUI_NODE_EDITOR_API to support building editor as a shared library (#189)

NEW: Canvas: Add IMGUIEX_CANVAS_API to support building canvas as a shared library (#189)

CHANGE: Editor: Support ImGui r18836 after SetItemUsingMouseWheel removal (#218), thanks @ocornut

CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before <imgui.h> (#209), thanks @ocornut

CHANGE: Examples: Define IMGUI_DEFINE_MATH_OPERATORS before <imgui.h> (#209), thanks @ocornut

CHANGE: Canvas: Don't use deprecated SetItemAllowOverlap (#250)

CHANGE: Examples: Don't use deprecated SetItemAllowOverlap (#250)

CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before <imgui.h> (#209), thanks @ocornut

CHANGE: Editor: Unary operator- for ImVec2 is defined by ImGui since r18955 (#248)

BUGFIX: Editor: Correctly initialize 'width' for view resize code (thx @gnif)

BUGFIX: Examples: Handle node deletion before links (#182)
Deleting node queue connected links for deletion.

BUGFIX: Examples: Simplify and fix drawing of node header line (#180)

BUGFIX: Editor: Cleanup tabs.

BUGFIX: Editor: Use ImGuiKey directly with ImGui r18822 (#183)

BUGFIX: Examples: Use ImGuiKey directly with ImGui r18822 (#183)

BUGFIX: Examples: Use ImGuiKey_KeypadEnter with ImGui r18604 (#183)

BUGFIX: Examples: Add missing <cstdint> include for std::intptr_t (#199)

BUGFIX: Examples: Don't use empty string as identifier

BUGFIX: Editor: Clean long to int implicit cast warning in crude_json

BUGFIX: Canvas: Ensure canvas draw commands are separated from other ImGui draw commands (#205, #250)

BUGFIX: Editor: Don't call Canvas.End() when Canvas.Begin() failed (#186), thanks @pthom, @TheZoc


v0.9.1 (2022-08-27):

CHANGE: Remove unwanted extra frame height from node bottom

Expand Down
17 changes: 17 additions & 0 deletions examples/application/source/imgui_extra_keys.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pragma once
# include <imgui.h>

# if !defined(IMGUI_VERSION_NUM) || (IMGUI_VERSION_NUM < 18822)

# include <type_traits>

// https://stackoverflow.com/a/8597498
Expand Down Expand Up @@ -46,3 +49,17 @@ static inline int GetEnumValueForD()
{
return KeyTester_ImGuiKey_D::Get<ImGuiKey_>(nullptr);
}

# else

static inline ImGuiKey GetEnumValueForF()
{
return ImGuiKey_F;
}

static inline ImGuiKey GetEnumValueForD()
{
return ImGuiKey_D;
}

# endif
4 changes: 4 additions & 0 deletions examples/application/source/imgui_impl_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ bool ImGui_ImplWin32_Init(void* hwnd)
io.KeyMap[ImGuiKey_Space] = VK_SPACE;
io.KeyMap[ImGuiKey_Enter] = VK_RETURN;
io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE;
# if defined(IMGUI_VERSION_NUM) && (IMGUI_VERSION_NUM >= 18604)
io.KeyMap[ImGuiKey_KeypadEnter] = VK_RETURN;
# else
io.KeyMap[ImGuiKey_KeyPadEnter] = VK_RETURN;
# endif
io.KeyMap[ImGuiKey_A] = 'A';
io.KeyMap[ImGuiKey_C] = 'C';
io.KeyMap[ImGuiKey_V] = 'V';
Expand Down
1 change: 1 addition & 0 deletions examples/application/source/renderer_ogl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# include "platform.h"
# include <algorithm>
# include <cstdint> // std::intptr_t

# if PLATFORM(WINDOWS)
# define NOMINMAX
Expand Down
40 changes: 27 additions & 13 deletions examples/blueprints-example/blueprints-example.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include <application.h>
#include "utilities/builders.h"
#include "utilities/widgets.h"

#include <imgui_node_editor.h>

#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>

#include <string>
Expand Down Expand Up @@ -648,7 +647,9 @@ struct Example:
ImGui::DragFloat("Node Rounding", &editorStyle.NodeRounding, 0.1f, 0.0f, 40.0f);
ImGui::DragFloat("Node Border Width", &editorStyle.NodeBorderWidth, 0.1f, 0.0f, 15.0f);
ImGui::DragFloat("Hovered Node Border Width", &editorStyle.HoveredNodeBorderWidth, 0.1f, 0.0f, 15.0f);
ImGui::DragFloat("Hovered Node Border Offset", &editorStyle.HoverNodeBorderOffset, 0.1f, -40.0f, 40.0f);
ImGui::DragFloat("Selected Node Border Width", &editorStyle.SelectedNodeBorderWidth, 0.1f, 0.0f, 15.0f);
ImGui::DragFloat("Selected Node Border Offset", &editorStyle.SelectedNodeBorderOffset, 0.1f, -40.0f, 40.0f);
ImGui::DragFloat("Pin Rounding", &editorStyle.PinRounding, 0.1f, 0.0f, 40.0f);
ImGui::DragFloat("Pin Border Width", &editorStyle.PinBorderWidth, 0.1f, 0.0f, 15.0f);
ImGui::DragFloat("Link Strength", &editorStyle.LinkStrength, 1.0f, 0.0f, 500.0f);
Expand Down Expand Up @@ -682,7 +683,7 @@ struct Example:
ImGui::EndHorizontal();

static ImGuiTextFilter filter;
filter.Draw("", paneWidth);
filter.Draw("##filter", paneWidth);

ImGui::Spacing();

Expand Down Expand Up @@ -765,6 +766,9 @@ struct Example:
}

bool isSelected = std::find(selectedNodes.begin(), selectedNodes.end(), node.ID) != selectedNodes.end();
# if IMGUI_VERSION_NUM >= 18967
ImGui::SetNextItemAllowOverlap();
# endif
if (ImGui::Selectable((node.Name + "##" + std::to_string(reinterpret_cast<uintptr_t>(node.ID.AsPointer()))).c_str(), &isSelected))
{
if (io.KeyCtrl)
Expand Down Expand Up @@ -793,7 +797,11 @@ struct Example:

auto drawList = ImGui::GetWindowDrawList();
ImGui::SetCursorScreenPos(iconPanelPos);
# if IMGUI_VERSION_NUM < 18967
ImGui::SetItemAllowOverlap();
# else
ImGui::SetNextItemAllowOverlap();
# endif
if (node.SavedState.empty())
{
if (ImGui::InvisibleButton("save", ImVec2((float)saveIconWidth, (float)saveIconHeight)))
Expand All @@ -813,7 +821,11 @@ struct Example:
}

ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x);
# if IMGUI_VERSION_NUM < 18967
ImGui::SetItemAllowOverlap();
# else
ImGui::SetNextItemAllowOverlap();
# endif
if (!node.SavedState.empty())
{
if (ImGui::InvisibleButton("restore", ImVec2((float)restoreIconWidth, (float)restoreIconHeight)))
Expand All @@ -837,7 +849,9 @@ struct Example:
}

ImGui::SameLine(0, 0);
# if IMGUI_VERSION_NUM < 18967
ImGui::SetItemAllowOverlap();
# endif
ImGui::Dummy(ImVec2(0, (float)restoreIconHeight));

ImGui::PopID();
Expand Down Expand Up @@ -1537,25 +1551,25 @@ struct Example:

if (ed::BeginDelete())
{
ed::LinkId linkId = 0;
while (ed::QueryDeletedLink(&linkId))
ed::NodeId nodeId = 0;
while (ed::QueryDeletedNode(&nodeId))
{
if (ed::AcceptDeletedItem())
{
auto id = std::find_if(m_Links.begin(), m_Links.end(), [linkId](auto& link) { return link.ID == linkId; });
if (id != m_Links.end())
m_Links.erase(id);
auto id = std::find_if(m_Nodes.begin(), m_Nodes.end(), [nodeId](auto& node) { return node.ID == nodeId; });
if (id != m_Nodes.end())
m_Nodes.erase(id);
}
}

ed::NodeId nodeId = 0;
while (ed::QueryDeletedNode(&nodeId))
ed::LinkId linkId = 0;
while (ed::QueryDeletedLink(&linkId))
{
if (ed::AcceptDeletedItem())
{
auto id = std::find_if(m_Nodes.begin(), m_Nodes.end(), [nodeId](auto& node) { return node.ID == nodeId; });
if (id != m_Nodes.end())
m_Nodes.erase(id);
auto id = std::find_if(m_Links.begin(), m_Links.end(), [linkId](auto& link) { return link.ID == linkId; });
if (id != m_Links.end())
m_Links.erase(id);
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions examples/blueprints-example/utilities/builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// CREDITS
// Written by Michal Cichon
//------------------------------------------------------------------------------
# include "builders.h"
# define IMGUI_DEFINE_MATH_OPERATORS
# include "builders.h"
# include <imgui_internal.h>


Expand Down Expand Up @@ -72,15 +72,11 @@ void util::BlueprintNodeBuilder::End()
headerColor, GetStyle().NodeRounding, 1 | 2);
#endif


auto headerSeparatorMin = ImVec2(HeaderMin.x, HeaderMax.y);
auto headerSeparatorMax = ImVec2(HeaderMax.x, HeaderMin.y);

if ((headerSeparatorMax.x > headerSeparatorMin.x) && (headerSeparatorMax.y > headerSeparatorMin.y))
if (ContentMin.y > HeaderMax.y)
{
drawList->AddLine(
headerSeparatorMin + ImVec2(-(8 - halfBorderWidth), -0.5f),
headerSeparatorMax + ImVec2( (8 - halfBorderWidth), -0.5f),
ImVec2(HeaderMin.x - (8 - halfBorderWidth), HeaderMax.y - 0.5f),
ImVec2(HeaderMax.x + (8 - halfBorderWidth), HeaderMax.y - 0.5f),
ImColor(255, 255, 255, 96 * alpha / (3 * 255)), 1.0f);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/blueprints-example/utilities/drawing.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# include "drawing.h"
# define IMGUI_DEFINE_MATH_OPERATORS
# include "drawing.h"
# include <imgui_internal.h>

void ax::Drawing::DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, IconType type, bool filled, ImU32 color, ImU32 innerColor)
Expand Down
2 changes: 1 addition & 1 deletion examples/blueprints-example/utilities/widgets.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# include "widgets.h"
# define IMGUI_DEFINE_MATH_OPERATORS
# include "widgets.h"
# include <imgui_internal.h>

void ax::Widgets::Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& color/* = ImVec4(1, 1, 1, 1)*/, const ImVec4& innerColor/* = ImVec4(0, 0, 0, 0)*/)
Expand Down
2 changes: 1 addition & 1 deletion examples/canvas-example/canvas-example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# include <imgui.h>
# define IMGUI_DEFINE_MATH_OPERATORS
# include <imgui.h>
# include <imgui_internal.h>
# include <imgui_canvas.h>
# include <application.h>
Expand Down
44 changes: 33 additions & 11 deletions imgui_canvas.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# define IMGUI_DEFINE_MATH_OPERATORS
# ifndef IMGUI_DEFINE_MATH_OPERATORS
# define IMGUI_DEFINE_MATH_OPERATORS
# endif
# include "imgui_canvas.h"
# include <type_traits>

Expand All @@ -25,6 +27,11 @@
static constexpr bool value = (sizeof(yes_type) == sizeof(test<mixin>(0))); \
}

// Special sentinel value. This needs to be unique, so allow it to be overridden in the user's ImGui config
# ifndef ImDrawCallback_ImCanvas
# define ImDrawCallback_ImCanvas (ImDrawCallback)(-2)
# endif

namespace ImCanvasDetails {

DECLARE_HAS_MEMBER(HasFringeScale, _FringeScale);
Expand Down Expand Up @@ -131,6 +138,10 @@ bool ImGuiEx::Canvas::Begin(ImGuiID id, const ImVec2& size)

EnterLocalSpace();

# if IMGUI_VERSION_NUM >= 18967
ImGui::SetNextItemAllowOverlap();
# endif

// Emit dummy widget matching bounds of the canvas.
ImGui::SetCursorScreenPos(m_ViewRect.Min);
ImGui::Dummy(m_ViewRect.GetSize());
Expand Down Expand Up @@ -162,7 +173,9 @@ void ImGuiEx::Canvas::End()

ImGui::GetCurrentWindow()->DC.CursorMaxPos = m_WindowCursorMaxBackup;

# if IMGUI_VERSION_NUM < 18967
ImGui::SetItemAllowOverlap();
# endif

// Emit dummy widget matching bounds of the canvas.
ImGui::SetCursorScreenPos(m_WidgetPosition);
Expand Down Expand Up @@ -407,6 +420,15 @@ void ImGuiEx::Canvas::EnterLocalSpace()
auto clipped_clip_rect = m_DrawList->_ClipRectStack.back();
ImGui::PopClipRect();

# if IMGUI_EX_CANVAS_DEFERED()
m_Ranges.resize(m_Ranges.Size + 1);
m_CurrentRange = &m_Ranges.back();
m_CurrentRange->BeginComandIndex = ImMax(m_DrawList->CmdBuffer.Size, 0);
m_CurrentRange->BeginVertexIndex = m_DrawList->_VtxCurrentIdx + ImVtxOffsetRef(m_DrawList);
# endif
m_DrawListCommadBufferSize = ImMax(m_DrawList->CmdBuffer.Size, 0);
m_DrawListStartVertexIndex = m_DrawList->_VtxCurrentIdx + ImVtxOffsetRef(m_DrawList);

// Make sure we do not share draw command with anyone. We don't want to mess
// with someones clip rectangle.

Expand All @@ -421,16 +443,7 @@ void ImGuiEx::Canvas::EnterLocalSpace()
//
// More investigation is needed. To get to the bottom of this.
if ((!m_DrawList->CmdBuffer.empty() && m_DrawList->CmdBuffer.back().ElemCount > 0) || m_DrawList->_Splitter._Count > 1)
m_DrawList->AddDrawCmd();

# if IMGUI_EX_CANVAS_DEFERED()
m_Ranges.resize(m_Ranges.Size + 1);
m_CurrentRange = &m_Ranges.back();
m_CurrentRange->BeginComandIndex = ImMax(m_DrawList->CmdBuffer.Size - 1, 0);
m_CurrentRange->BeginVertexIndex = m_DrawList->_VtxCurrentIdx + ImVtxOffsetRef(m_DrawList);
# endif
m_DrawListCommadBufferSize = ImMax(m_DrawList->CmdBuffer.Size - 1, 0);
m_DrawListStartVertexIndex = m_DrawList->_VtxCurrentIdx + ImVtxOffsetRef(m_DrawList);
m_DrawList->AddCallback(ImDrawCallback_ImCanvas, nullptr);

# if defined(IMGUI_HAS_VIEWPORT)
auto window = ImGui::GetCurrentWindow();
Expand Down Expand Up @@ -539,6 +552,15 @@ void ImGuiEx::Canvas::LeaveLocalSpace()
}
}

// Remove sentinel draw command if present
if (m_DrawListCommadBufferSize > 0)
{
if (m_DrawList->CmdBuffer.size() > m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize].UserCallback == ImDrawCallback_ImCanvas)
m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize);
else if (m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == ImDrawCallback_ImCanvas)
m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize - 1);
}

auto& fringeScale = ImFringeScaleRef(m_DrawList);
fringeScale = m_LastFringeScale;

Expand Down
Loading

0 comments on commit 8a21bbb

Please sign in to comment.