From cd0b8c5db368332ee68bd9b6c048d958f88508fc Mon Sep 17 00:00:00 2001 From: gk646 Date: Fri, 10 May 2024 23:47:12 +0200 Subject: [PATCH] Release 1.0.0 update misc fixes to ui actions fixed some bugs regarding loading empty files added icon properly for windows added lowspecs release with lower open gl version --- CMakeLists.txt | 8 +++---- cmake/LoadLocalLibs.cmake | 11 +++++---- src/raynodes/CMakeLists.txt | 8 ++++--- .../application/context/ContextCore.h | 2 +- .../application/context/ContextInfo.h | 6 ++--- src/raynodes/application/context/ContextUI.h | 2 +- .../application/context/impl/ContextInfo.cpp | 2 +- .../context/impl/ContextPersist.cpp | 7 ++++-- src/raynodes/application/editor/EditorUI.h | 9 ++++---- src/raynodes/application/elements/Action.cpp | 23 +++++++++++++------ src/raynodes/application/elements/Action.h | 1 + src/raynodes/shared/app.rc | 2 ++ src/raynodes/ui/TextField.cpp | 7 ++++++ 13 files changed, 57 insertions(+), 31 deletions(-) create mode 100644 src/raynodes/shared/app.rc diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bc7cef..dfb3b88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,20 +4,20 @@ set(CMAKE_CXX_STANDARD 23) set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(BUILD_GAMES OFF CACHE BOOL "" FORCE) -set(OPENGL_VERSION "4.3" CACHE STRING "OpenGL Version to build raylib with") +set(OPENGL_VERSION "2.1" CACHE STRING "OpenGL Version to build raylib with") set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) # Build as shared lib set(ENABLE_SANITIZER OFF) -set(RUN_TESTS ON) +set(RUN_TESTS ON) # If it should build the test executable -# Compiler options for MSVC and unix +# Compiler options for MSVC and GCC include(cmake/CompilerOptions.cmake) # Choose how the STL is linked include(cmake/LinkSTL.cmake) -# Choose either one - currently only local libs supported +# Choose how to supply dependencies - currently only local libs supported # include(cmake/FetchLibs.cmake) include(cmake/LoadLocalLibs.cmake) diff --git a/cmake/LoadLocalLibs.cmake b/cmake/LoadLocalLibs.cmake index cce32cb..ed518cd 100644 --- a/cmake/LoadLocalLibs.cmake +++ b/cmake/LoadLocalLibs.cmake @@ -1,10 +1,11 @@ -set(DEPENDENCIES_PATH "C:/Users/gk646/Documents/Libraries") + +set(DEPENDENCIES_PATH "C:/Users/gk646/Documents/Libraries") # Set to where your libraries are stored include_directories( - "${DEPENDENCIES_PATH}/raylib-master/src" - "${DEPENDENCIES_PATH}/raygui-master/src" - "${DEPENDENCIES_PATH}/tinyfiledialogs" - "${CMAKE_SOURCE_DIR}/../cxstructs/src" #Just supply a clone of cxstructs/include here + "${DEPENDENCIES_PATH}/raylib-master/src" # Supply a clone of raylib.git + "${DEPENDENCIES_PATH}/raygui-master/src" # Supply a clone of raygui.git + "${DEPENDENCIES_PATH}/tinyfiledialogs" # Download from here https://sourceforge.net/projects/tinyfiledialogs/ + "${DEPENDENCIES_PATH}/cxstructs-master/include" # Supply a clone of cxstructs.git ) add_subdirectory("${DEPENDENCIES_PATH}/raylib-master" raylib) diff --git a/src/raynodes/CMakeLists.txt b/src/raynodes/CMakeLists.txt index 0febcc3..12f5971 100644 --- a/src/raynodes/CMakeLists.txt +++ b/src/raynodes/CMakeLists.txt @@ -12,22 +12,24 @@ add_executable(raynodes main.cpp) target_include_directories(raynodes PRIVATE ${CMAKE_SOURCE_DIR}/src/raynodes) # This places the executable in the root of the build directory set_target_properties(raynodes PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -# Link against user32 on windows +# Link raylib and the core editor target_link_libraries(raynodes PUBLIC raylib editor) if (MSVC) - target_link_libraries(raynodes PRIVATE user32) + target_sources(raynodes PRIVATE shared/app.rc) # Add the icon resource file + target_link_libraries(raynodes PRIVATE user32) # Need to link to avoid duplicate symbols add_custom_command(TARGET raynodes POST_BUILD COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_BINARY_DIR}/raylib/raylib/raylib.dll" "${CMAKE_BINARY_DIR}/raylib.dll" COMMENT "Moving raylib.dll to project binary directory" ) + else () add_custom_command(TARGET raynodes POST_BUILD COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_BINARY_DIR}/raylib/raylib/libraylib.so" "${CMAKE_BINARY_DIR}/libraylib.so" - COMMENT "Moving raylib.dll to project binary directory" + COMMENT "Moving raylib.so to project binary directory" ) endif () \ No newline at end of file diff --git a/src/raynodes/application/context/ContextCore.h b/src/raynodes/application/context/ContextCore.h index efdb351..7981c4c 100644 --- a/src/raynodes/application/context/ContextCore.h +++ b/src/raynodes/application/context/ContextCore.h @@ -23,7 +23,7 @@ struct Core { static constexpr int TARGET_FPS = 100; - static constexpr int MAX_ACTIONS = 25; + static constexpr int MAX_ACTIONS = 5; std::unordered_map selectedNodes; std::unordered_map nodeMap; diff --git a/src/raynodes/application/context/ContextInfo.h b/src/raynodes/application/context/ContextInfo.h index f189cb7..5820638 100644 --- a/src/raynodes/application/context/ContextInfo.h +++ b/src/raynodes/application/context/ContextInfo.h @@ -29,9 +29,9 @@ struct Info { static constexpr auto wikiLink = "https://github.com/gk646/raynodes"; static constexpr auto github = "https://github.com/gk646/raynodes"; static constexpr auto about = "Copyright #226# 2024 gk646. MIT License"; - static constexpr int majorVersion = 0; - static constexpr int middleVersion = 9; - static constexpr int minorVersion = 9; + static constexpr int majorVersion = 1; + static constexpr int minorVersion = 0; + static constexpr int patch = 0; static const char* getVersion(EditorContext& ec); }; diff --git a/src/raynodes/application/context/ContextUI.h b/src/raynodes/application/context/ContextUI.h index 3d7093d..2f7b968 100644 --- a/src/raynodes/application/context/ContextUI.h +++ b/src/raynodes/application/context/ContextUI.h @@ -53,7 +53,7 @@ struct UI final { {63, 63, 63, 255}, // N_BACK_GROUND {207, 207, 207, 255}, // UI_LIGHT {88, 88, 88, 255}, // UI_MEDIUM - {56, 56, 56, 255} // UI_DARK + {60, 60, 60, 255} // UI_DARK }; static constexpr auto* fileMenuText = "#001#File;" diff --git a/src/raynodes/application/context/impl/ContextInfo.cpp b/src/raynodes/application/context/impl/ContextInfo.cpp index 4c3cbba..0acc076 100644 --- a/src/raynodes/application/context/impl/ContextInfo.cpp +++ b/src/raynodes/application/context/impl/ContextInfo.cpp @@ -21,5 +21,5 @@ #include "application/EditorContext.h" const char* Info::getVersion(EditorContext& ec) { - return ec.string.formatText2("%d.%d.%d", majorVersion, middleVersion, minorVersion); + return ec.string.formatText2("%d.%d.%d", majorVersion, minorVersion, patch); } \ No newline at end of file diff --git a/src/raynodes/application/context/impl/ContextPersist.cpp b/src/raynodes/application/context/impl/ContextPersist.cpp index fb39961..f1f481d 100644 --- a/src/raynodes/application/context/impl/ContextPersist.cpp +++ b/src/raynodes/application/context/impl/ContextPersist.cpp @@ -187,9 +187,12 @@ void LoadTemplates(FILE* file, EditorContext& ec) { int LoadNodes(FILE* file, EditorContext& ec) { int count = 0; while (io_load_inside_section(file, "Nodes")) { - printf("%d\n",(int)ftell(file)); - int index = 0; + int index = -1; io_load(file, index); + if(index == -1) { + io_load_newline(file, true); + continue; + } int id; io_load(file, id); auto* nodeName = compIndices.getName(index); diff --git a/src/raynodes/application/editor/EditorUI.h b/src/raynodes/application/editor/EditorUI.h index 412a831..85664cd 100644 --- a/src/raynodes/application/editor/EditorUI.h +++ b/src/raynodes/application/editor/EditorUI.h @@ -79,7 +79,7 @@ inline void DrawContextMenu(EditorContext& ec) { Vector2 drawPos{pos.x, pos.y}; // Draw main menu background - DrawRectangleRounded(menuRect, 0.1F, 10, ColorAlpha(UI::COLORS[UI_DARK], 0.8)); + DrawRectangleRounded(menuRect, 0.1F, 10, ColorAlpha(UI::COLORS[UI_DARK], 0.9)); const ContextMenuCategory* hoveredCategory = nullptr; bool closeToMenu = false; @@ -113,12 +113,13 @@ inline void DrawContextMenu(EditorContext& ec) { // Highlight the category if it's open if (category.isOpen) { DrawRectangleRounded(textRect, 0.1F, 10, hightLightColor); } - DrawTextEx(font, category.name, {drawPos.x + padding, drawPos.y + padding}, fs, 0.6F, UI::COLORS[UI_LIGHT]); + DrawTextEx(font, category.name, {drawPos.x + padding, drawPos.y + padding / 2.0F}, fs, 0.6F, + UI::COLORS[UI_LIGHT]); // Draw the category's nodes if it's open if (category.isOpen && !category.nodes.empty()) { Vector2 drawPosC = {drawPos.x + menuWidth, drawPos.y}; - DrawRectangleRounded(categoryRect, 0.1F, 10, ColorAlpha(UI::COLORS[UI_DARK], 0.8)); + DrawRectangleRounded(categoryRect, 0.1F, 10, ColorAlpha(UI::COLORS[UI_DARK], 0.9)); for (const auto& name : category.nodes) { const Rectangle nodeTextRect = {drawPosC.x, drawPosC.y, menuWidth, fs + padding}; if (CheckCollisionPointRec(mouse, nodeTextRect)) { @@ -129,7 +130,7 @@ inline void DrawContextMenu(EditorContext& ec) { break; } } - DrawTextEx(font, name, {drawPosC.x + padding, drawPosC.y + padding}, fs, 0.7F, UI::COLORS[UI_LIGHT]); + DrawTextEx(font, name, {drawPosC.x + padding, drawPosC.y + padding / 2.0F}, fs, 0.7F, UI::COLORS[UI_LIGHT]); drawPosC.y += fs + padding; } } diff --git a/src/raynodes/application/elements/Action.cpp b/src/raynodes/application/elements/Action.cpp index caef836..980e3f1 100644 --- a/src/raynodes/application/elements/Action.cpp +++ b/src/raynodes/application/elements/Action.cpp @@ -62,27 +62,31 @@ void NodeDeleteAction::undo(EditorContext& ec) { for (const auto conn : deletedConnections) { ec.core.addConnection(conn); } + deletedConnections.clear(); } void NodeDeleteAction::redo(EditorContext& ec) { removeNodes = true; for (const auto n : deletedNodes) { ec.core.removeNode(ec, n->uID); - } - for (const auto conn : deletedConnections) { - ec.core.removeConnection(conn); + ec.core.removeConnectionsFromNode(*n, deletedConnections); } } //-----------NODE_CREATE-----------// NodeCreateAction::NodeCreateAction(const int size) : Action(CREATE_NODE) { - createdNodes.reserve(size); + createdNodes.reserve(size+1); + deletedConnections.reserve(5); } NodeCreateAction::~NodeCreateAction() noexcept { - if (!removeNodes) return; - for (const auto n : createdNodes) { - delete n; + if (removeNodes) { + for (const auto n : createdNodes) { + delete n; + } + for (const auto conn : deletedConnections) { + delete conn; + } } } @@ -90,6 +94,7 @@ void NodeCreateAction::undo(EditorContext& ec) { removeNodes = true; for (const auto n : createdNodes) { ec.core.removeNode(ec, n->uID); + ec.core.removeConnectionsFromNode(*n, deletedConnections); } } @@ -98,6 +103,10 @@ void NodeCreateAction::redo(EditorContext& ec) { for (const auto n : createdNodes) { ec.core.insertNode(ec, *n); } + for (const auto conn : deletedConnections) { + ec.core.addConnection(conn); + } + deletedConnections.clear(); } //-----------NODE_MOVE-----------// diff --git a/src/raynodes/application/elements/Action.h b/src/raynodes/application/elements/Action.h index b24bb47..3f6f438 100644 --- a/src/raynodes/application/elements/Action.h +++ b/src/raynodes/application/elements/Action.h @@ -99,6 +99,7 @@ struct NodeDeleteAction final : Action { struct NodeCreateAction final : Action { std::vector createdNodes; + std::vector deletedConnections; explicit NodeCreateAction(int size); ~NodeCreateAction() noexcept override; void undo(EditorContext& ec) override; diff --git a/src/raynodes/shared/app.rc b/src/raynodes/shared/app.rc new file mode 100644 index 0000000..6c0a5e4 --- /dev/null +++ b/src/raynodes/shared/app.rc @@ -0,0 +1,2 @@ +#include "winuser.h" +IDI_ICON1 ICON DISCARDABLE "../../../res/icon.ico" \ No newline at end of file diff --git a/src/raynodes/ui/TextField.cpp b/src/raynodes/ui/TextField.cpp index 89ac30d..1dec974 100644 --- a/src/raynodes/ui/TextField.cpp +++ b/src/raynodes/ui/TextField.cpp @@ -101,6 +101,7 @@ void TextInputField::draw() { } } +//TODO reoder operations to avoid creating rare crashes of same tick inputs void TextInputField::update(Vector2 mouse) { if (!isFocused) return; @@ -146,6 +147,8 @@ void TextInputField::update(Vector2 mouse) { while (key > 0) { selectionStart = selectionEnd; if (IsInputAllowed(key, constraint) && buffer.length() < 1024) { + // Safety measure - i could produce some crashes here + cursorPos = cxstructs::clamp(static_cast(cursorPos), 0, static_cast(buffer.size())); buffer.insert(buffer.begin() + cursorPos, static_cast(key)); cursorPos++; updateDimensions(); @@ -161,6 +164,8 @@ void TextInputField::update(Vector2 mouse) { } if (IsKeyPressed(KEY_ENTER) && buffer.length() < 1024) { + // Safety measure - i could produce some crashes here + cursorPos = cxstructs::clamp(static_cast(cursorPos), 0, static_cast(buffer.size())); buffer.insert(buffer.begin() + cursorPos, '\n'); cursorPos++; updateDimensions(); @@ -172,6 +177,8 @@ void TextInputField::update(Vector2 mouse) { buffer.erase(start, end - start); cursorPos -= end - start - 1; } else { + // Safety measure - i could produce some crashes here + cursorPos = cxstructs::clamp(static_cast(cursorPos), 1, static_cast(buffer.size())); buffer.erase(buffer.begin() + cursorPos - 1); } selectionStart = selectionEnd;