Skip to content

Commit

Permalink
std::string for encoded node input
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Aug 4, 2021
1 parent 344732d commit 20a7acd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions NoiseTool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ add_executable(NoiseTool
"MeshNoisePreview.cpp"
"NoiseTexture.cpp"
"${imnodes_SOURCE_DIR}/imnodes.cpp"
"${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp"
${NoiseTool_RESOURCES}
)

Expand Down
12 changes: 6 additions & 6 deletions NoiseTool/FastNoiseNodeEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include <imgui_internal.h>
#include <misc/cpp/imgui_stdlib.h>
#include <imnodes.h>

#include "FastNoiseNodeEditor.h"
Expand Down Expand Up @@ -785,13 +786,13 @@ void FastNoiseNodeEditor::DoContextMenu()
if( openImportModal )
{
mImportNodeModal = true;
memset( mImportNodeString, 0, sizeof( mImportNodeString ) );
mImportNodeString.clear();
ImGui::OpenPopup( "New From Encoded Node Tree" );
}

ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, { 5,5 } );
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, { 5,5 } );
ImGui::SetNextWindowSize( { 400, 90 }, ImGuiCond_Always );
ImGui::SetNextWindowSize( { 400, 92 }, ImGuiCond_Always );
ImGui::SetNextWindowPos( ImGui::GetIO().DisplaySize / 2, ImGuiCond_Always, { 0.5f,0.5f } );

if( ImGui::BeginPopupModal( "New From Encoded Node Tree", &mImportNodeModal, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings ) )
Expand All @@ -801,18 +802,17 @@ void FastNoiseNodeEditor::DoContextMenu()
ImGui::SetKeyboardFocusHere();
}

bool txtEnter = ImGui::InputText( "Base64 String", mImportNodeString, sizeof( mImportNodeString ), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CharsNoBlank );
bool txtEnter = ImGui::InputText( "Base64 String", &mImportNodeString, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CharsNoBlank );

if( txtEnter | ImGui::Button( "Create", { 100, 30 } ) )
{
if( AddNodeFromEncodedString( mImportNodeString, mContextStartPos ) )
if( AddNodeFromEncodedString( mImportNodeString.c_str(), mContextStartPos ) )
{
mImportNodeModal = false;
}
else
{
const char* error = "DESERIALISATION FAILED";
memcpy( mImportNodeString, error, strlen( error ) + 1 );
mImportNodeString = "DESERIALISATION FAILED";
}
}
ImGui::EndPopup();
Expand Down
3 changes: 2 additions & 1 deletion NoiseTool/FastNoiseNodeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <unordered_map>
#include <vector>
#include <memory>
#include <string>
#include <climits>

#include <Magnum/Magnum.h>
Expand Down Expand Up @@ -116,7 +117,7 @@ namespace Magnum

ImVec2 mContextStartPos;
std::vector<std::unique_ptr<MetadataMenu>> mContextMetadata;
char mImportNodeString[4096];
std::string mImportNodeString;
bool mImportNodeModal = false;

MeshNoisePreview mMeshNoisePreview;
Expand Down

0 comments on commit 20a7acd

Please sign in to comment.