diff --git a/.github/workflows/RunTestsGNU-Linux.yml b/.github/workflows/RunTestsGNU-Linux.yml deleted file mode 100644 index f8e3c86..0000000 --- a/.github/workflows/RunTestsGNU-Linux.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: CMake Build for GNU/Linux - -on: - push: - branches: - - main - -jobs: - build-and-test: - runs-on: ubuntu-latest - strategy: - fail-fast: false - steps: - - uses: actions/checkout@v4 - - - name: Cache CMake builds - uses: actions/cache@v2 - with: - path: ${{ github.workspace }}/build - key: ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt', '**/*.cpp', '**/*.h') }} - restore-keys: | - ${{ runner.os }}-build- - - - name: Install dependencies - run: sudo apt-get update && sudo apt-get install -y wayland-protocols - - - name: Configure CMake - run: cmake -B build -DCMAKE_CXX_COMPILER=gcc -DCMAKE_C_COMPILER=gcc -DCMAKE_BUILD_TYPE=Release -DRN_ENABLE_SANITIZER=OFF -DRN_BUILD_TESTS=ON -S . - working-directory: ${{ github.workspace }} - - - name: Build - run: cmake --build build --config Release - working-directory: ${{ github.workspace }} - - - name: Run Tests - run: ctest -C Release --output-on-failure - working-directory: ${{ github.workspace }}/build - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v2 - with: - name: Test Results - path: ${{ github.workspace }}/build/Testing/**/*.xml \ No newline at end of file diff --git a/.github/workflows/RunTestsWindows.yml b/.github/workflows/RunTestsWindows.yml deleted file mode 100644 index df5658a..0000000 --- a/.github/workflows/RunTestsWindows.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: CMake Build for Windows - -on: - push: - branches: - - main - -jobs: - build-and-test: - runs-on: windows-latest - strategy: - fail-fast: false - steps: - - uses: actions/checkout@v4 - - - name: Cache CMake builds - uses: actions/cache@v2 - with: - path: ${{ github.workspace }}/build - key: ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt', '**/*.cpp', '**/*.h') }} - restore-keys: | - ${{ runner.os }}-build- - - - name: Configure CMake - run: cmake -B build -DCMAKE_CXX_COMPILER=cl -DCMAKE_C_COMPILER=cl -DCMAKE_BUILD_TYPE=Release -DRN_ENABLE_SANITIZER=OFF -DRN_BUILD_TESTS=ON -S . - working-directory: ${{ github.workspace }} - shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'" - - - name: Build - run: cmake --build build --config Release - working-directory: ${{ github.workspace }} - - - name: Run Tests - run: ctest -C Release --output-on-failure - working-directory: ${{ github.workspace }}/build - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v2 - with: - name: Test Results - path: ${{ github.workspace }}/build/Testing/**/*.xml \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 13e8075..451ee6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,9 @@ set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) # Build as shared lib option(RN_ENABLE_SANITIZER "Set to compile with adress sanitizer (MSVC)") # set(RN_ENABLE_SANITIZER ON) option(RN_BUILD_TESTS "Set to compile the test executable") # set(RN_BUILD_TESTS ON) +option(RN_BUILD_RELEASES "Set to build the release archives") # set(RN_BUILD_RELEASES ON) +#set(RN_BUILD_TESTS ON) # Compiler options for MSVC and GCC include(cmake/CompilerOptions.cmake) @@ -30,7 +32,8 @@ add_subdirectory(src/plugins) add_subdirectory(src/import) # Add all built targets here -add_dependencies(raynodes MQQS BuiltIns) +add_dependencies(raynodes QuestScript BuiltIns) + if (RN_BUILD_TESTS) enable_testing() diff --git a/src/external/catch2/LICENSE.txt.txt b/src/external/catch2/LICENSE.txt similarity index 100% rename from src/external/catch2/LICENSE.txt.txt rename to src/external/catch2/LICENSE.txt diff --git a/src/external/cxstructs/include/cxutil/cxstring.h b/src/external/cxstructs/include/cxutil/cxstring.h index e914e38..201b83b 100644 --- a/src/external/cxstructs/include/cxutil/cxstring.h +++ b/src/external/cxstructs/include/cxutil/cxstring.h @@ -27,8 +27,8 @@ namespace cxstructs { // Pads the given string "arg" inside "buff" with the "padSymbol" - optional prefix and suffix -inline void str_pad(char* buff, const int size, const char* arg, const char padSymbol, - const char* prefix = nullptr, const char* suffix = nullptr) { +inline void str_pad(char* buff, const int size, const char* arg, const char padSymbol, const char* prefix = nullptr, + const char* suffix = nullptr) { int currPos = 0; std::memset(buff, 0, size); @@ -40,14 +40,10 @@ inline void str_pad(char* buff, const int size, const char* arg, const char padS currPos += snprintf(buff + currPos, size - currPos, "%s", arg); currPos = currPos > size ? size : currPos; } - if (suffix && currPos < size) { - snprintf(buff + currPos, size - currPos, "%s", suffix); - } + if (suffix && currPos < size) { snprintf(buff + currPos, size - currPos, "%s", suffix); } for (int i = currPos; i < size - 1; i++) { - if (buff[i] == '\0') { - buff[i] = padSymbol; - } + if (buff[i] == '\0') { buff[i] = padSymbol; } } buff[size - 1] = '\0'; } diff --git a/src/external/raylib/CONTRIBUTING.md b/src/external/raylib/CONTRIBUTING.md deleted file mode 100644 index 644a89b..0000000 --- a/src/external/raylib/CONTRIBUTING.md +++ /dev/null @@ -1,76 +0,0 @@ -## Contributing to raylib - -Hello contributors! Welcome to raylib! - -Do you enjoy raylib and want to contribute? Nice! You can help with the following points: - -- `C programming` - Can you write/review/test/improve the code? -- `Documentation/Tutorials/Example` - Can you write some tutorial/example? -- `Porting to other platforms` - Can you port/adapt/compile raylib on other systems? -- `Web Development` - Can you help [with the website](https://github.com/raysan5/raylib.com)? -- `Testing` - Can you find some bugs in raylib? - -This document contains a set of guidelines to contribute to the project. These are mostly guidelines, not rules. -Use your best judgement, and feel free to propose changes to this document in a pull request. - -### raylib philosophy - - - raylib is a tool to **ENJOY** videogames programming, every function in raylib is designed as a mini-tutorial on itself. - - raylib is **SIMPLE** and **EASY-TO-USE**, I tried to keep it compact with a small set of functions, if a function is too complex, better not including it. - - raylib is open source and free; educators and institutions can use this tool to **TEACH** videogames programming completely for free. - - raylib is collaborative; contribution of tutorials / code examples / bug fixes / code comments are highly appreciated. - - raylib's license (and its external libs respective licenses) allow using raylib on commercial projects. - -### Some interesting reads to start with - - - [raylib history](HISTORY.md) - - [raylib architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture) - - [raylib license](LICENSE) - - [raylib roadmap](ROADMAP.md) - -[raylib Wiki](https://github.com/raysan5/raylib/wiki) contains some information about the library and is open to anyone for edit. -Feel free to review it if required, just take care not to break something. - -### raylib C coding conventions - -Despite being written in C, raylib does not follow the standard Hungarian notation for C, -it [follows Pascal-case/camel-case notation](https://github.com/raysan5/raylib/wiki/raylib-coding-conventions), -more common on C# language. All code formatting decisions have been carefully taken -to make it easier for students/users to read, write and understand code. - -Source code is extensively commented for that purpose, raylib primary learning method is: - - > `Learn by reading code and examples` - -For detailed information on building raylib and examples, please check [raylib Wiki](https://github.com/raysan5/raylib/wiki). - -### Opening new Issues - -To open new issue for raylib (bug, enhancement, discussion...), just try to follow these rules: - - - Make sure the issue has not already been reported before by searching on GitHub under Issues. - - If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a - title and clear description, as much relevant information as possible, and a code sample demonstrating the unexpected behavior. - - If applies, attach some screenshot of the issue and a .zip file with the code sample and required resources. - - On issue description, add a brackets tag about the raylib module that relates to this issue. - If don't know which module, just report the issue, I will review it. - - You can check other issues to see how is being done! - -### Sending a Pull-Request - - - Make sure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. - - Don't send big pull requests (lots of changelists), they are difficult to review. It's better to send small pull requests, one at a time. - - Verify that changes don't break the build (at least on Windows platform). As many platforms where you can test it, the better, but don't worry - if you cannot test all the platforms. - -### Contact information - -If you have any doubt, don't hesitate to [contact me](mailto:ray@raylib.com)!. -You can write me a direct mail but you can also contact me on the following networks: - - - [raylib Discord](https://discord.gg/raylib) - A direct communication channel for project discussions. - - [raylib twitter](https://twitter.com/raysan5) - My personal twitter account, I usually post about raylib, you can send me PMs. - - [raylib reddit](https://www.reddit.com/r/raylib/) - A good place for discussions or to ask for help. - - [raylib web](http://www.raylib.com/) - On top-right corner there is a bunch of networks where you can find me. - -Thank you very much for your time! :) diff --git a/src/plugins/BuiltIns/BuiltIns.cpp b/src/plugins/BuiltIns/BuiltIns.cpp index 1e9759b..7ade3d8 100644 --- a/src/plugins/BuiltIns/BuiltIns.cpp +++ b/src/plugins/BuiltIns/BuiltIns.cpp @@ -22,30 +22,58 @@ #include "components/MathC.h" #include "components/DisplayC.h" -#include "components/NumberOutputC.h" +#include "components/NumberFieldC.h" +#include "components/SeparateXYC.h" #include "components/SeparateXYZC.h" #include "components/StringToNumberC.h" -#include "components/TextInputC.h" -#include "components/TextOutC.h" -#include "components/Vec3OutC.h" +#include "components/TextFieldC.h" +#include "components/Vec2C.h" +#include "components/Vec3C.h" void BuiltIns::registerComponents(ComponentRegister& cr) { cr.registerComponent("BI_MathOp"); cr.registerComponent("BI_Display"); cr.registerComponent("BI_StrToNum"); - cr.registerComponent("BI_TextOut"); - cr.registerComponent("BI_TextIn"); - cr.registerComponent("BI_NumberOut"); cr.registerComponent("BI_SeparateXYZ"); - cr.registerComponent("BI_Vec3Out"); + cr.registerComponent("BI_SeparateXY"); + + // NumberField - different flavours + cr.registerComponent>("BI_Number"); + cr.registerComponent>("BI_Number_In"); + cr.registerComponent>("BI_Number_Out"); + + // Textfield - different flavours + cr.registerComponent>("BI_Text"); + cr.registerComponent>("BI_Text_In"); + cr.registerComponent>("BI_Text_Out"); + + // Vector 3 - different flavours + cr.registerComponent>("BI_Vec3"); + cr.registerComponent>("BI_Vec3_In"); + cr.registerComponent>("BI_Vec3_Out"); + + // Vector 2 - different flavours + cr.registerComponent>("BI_Vec2"); + cr.registerComponent>("BI_Vec2_In"); + cr.registerComponent>("BI_Vec2_Out"); } +// IMPORTANT :: DONT CHANGE ORDER -> Will invalidate all saves made +// TODO properly manage that -> maybe register with a number region? void BuiltIns::registerNodes(NodeRegister& nr) { + // Misc nr.registerNode("MathOp", {{"Operation", "BI_MathOp"}}); - nr.registerNode("TextField", {{"TextField", "BI_TextOut"}}); - nr.registerNode("StringToNum", {{"Converter", "BI_StrToNum"}}); nr.registerNode("Display", {{"Display", "BI_Display"}}); - nr.registerNode("NumberField", {{"Number", "BI_NumberOut"}}); - nr.registerNode("SeparateXYZ", {{"Vector", "BI_SeparateXYZ"}}); - nr.registerNode("Vector 3", {{"Vector3", "BI_Vec3Out"}}); + + // Conversion + nr.registerNode("StringToNum", {{"Converter", "BI_StrToNum"}}); + nr.registerNode("SeparateXYZ", {{"Separator", "BI_SeparateXYZ"}}); + nr.registerNode("SeparateXY", {{"Separator", "BI_SeparateXY"}}); + + // Data Input + nr.registerNode("TextField", {{"Text", "BI_Text_Out"}}); + nr.registerNode("NumberField", {{"Number", "BI_Number_Out"}}); + nr.registerNode("Vector3", {{"Vec3", "BI_Vec3_Out"}}); + nr.registerNode("Vector2", {{"Vec2", "BI_Vec2_Out"}}); + } \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/DisplayC.cpp b/src/plugins/BuiltIns/components/DisplayC.cpp index 4886e51..5aaa681 100644 --- a/src/plugins/BuiltIns/components/DisplayC.cpp +++ b/src/plugins/BuiltIns/components/DisplayC.cpp @@ -54,12 +54,4 @@ void DisplayC::onCreate(EditorContext& ec, Node& /**/) { addPinOutput(STRING); addPinOutput(FLOAT); addPinOutput(INTEGER); -} - -void DisplayC::save(FILE* /**/) { - /*No state*/ -} - -void DisplayC::load(FILE* /**/) { - /*No state*/ } \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/DisplayC.h b/src/plugins/BuiltIns/components/DisplayC.h index f504bb9..e2ee39e 100644 --- a/src/plugins/BuiltIns/components/DisplayC.h +++ b/src/plugins/BuiltIns/components/DisplayC.h @@ -28,8 +28,6 @@ struct DisplayC final : Component { Component* clone() override { return new DisplayC(*this); }; void draw(EditorContext& ec, Node& parent) override; void update(EditorContext& ec, Node& parent) override; - void save(FILE* file) override; - void load(FILE* file) override; void onCreate(EditorContext& ec, Node& parent) override; }; #endif //RAYNODES_SRC_COMPONENT_COMPONENTS_DISPLAYC_H_ \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/NumberFieldC.h b/src/plugins/BuiltIns/components/NumberFieldC.h new file mode 100644 index 0000000..4eafd56 --- /dev/null +++ b/src/plugins/BuiltIns/components/NumberFieldC.h @@ -0,0 +1,118 @@ +// Copyright (c) 2024 gk646 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef NUMBERINPUT_H +#define NUMBERINPUT_H + +#include +#include +#include + +#include "application/EditorContext.h" +#include "application/elements/Action.h" +#include "ui/TextField.h" + +template +class NumberFieldC final : public Component { + TextInputField textField; + TextAction* currentAction = nullptr; + + public: + explicit NumberFieldC(const ComponentTemplate ct) : Component(ct, 200, 20), textField(200, 20, NUMERIC) {} + Component* clone() override { return new NumberFieldC(*this); } + + void draw(EditorContext& ec, Node& /**/) override { + auto bounds = getBounds(); + textField.bounds.x = bounds.x; + textField.bounds.y = bounds.y; + textField.draw(); + } + + void update(EditorContext& ec, Node& parent) override { + textField.update(ec.logic.worldMouse); + + if constexpr (style == IN_AND_OUT || style == INPUT_ONLY) { + auto* input = inputs[0].getData(); + if (input) textField.buffer = input; + } + + if constexpr (style == IN_AND_OUT || style == OUTPUT_ONLY) { + const auto* text = textField.buffer.c_str(); + outputs[0].setData(cxstructs::str_parse_long(text)); + outputs[1].setData(cxstructs::str_parse_float(text)); + } + + height = static_cast(textField.bounds.height); + width = static_cast(textField.bounds.width); + } + + void onFocusGain(EditorContext& ec) override { + textField.onFocusGain(ec.logic.worldMouse); + + delete currentAction; + currentAction = new TextAction(textField.buffer, textField.buffer); + } + + void onFocusLoss(EditorContext& ec) override { + textField.onFocusLoss(); + + if (currentAction) { + // Discard if nothing changed + if (currentAction->beforeState == textField.buffer) { + delete currentAction; + currentAction = nullptr; + return; + } + //TRANSFER OWNERSHIP + currentAction->setAfter(textField.buffer); + ec.core.addEditorAction(ec, currentAction); + currentAction = nullptr; + } + } + + void onCreate(EditorContext& ec, Node& /**/) override { + internalLabel = false; //We don't want to draw our label + textField.font = &ec.display.editorFont; + textField.fs = ec.display.fontSize; + + if constexpr (style == IN_AND_OUT || style == INPUT_ONLY) { + addPinInput(STRING); + } + if constexpr (style == IN_AND_OUT || style == OUTPUT_ONLY) { + addPinOutput(INTEGER); + addPinOutput(FLOAT); + } + } + + double getFloat() override { return cxstructs::str_parse_float(textField.buffer.c_str()); } + + int64_t getInt() override { return cxstructs::str_parse_long(textField.buffer.c_str()); } + + void save(FILE* file) override { cxstructs::io_save(file, textField.buffer.c_str()); } + + void load(FILE* file) override { + cxstructs::io_load(file, textField.buffer); + textField.updateDimensions(); + } + + const char* getString() override { return textField.buffer.c_str(); } +}; + +#endif //NUMBERINPUT_H \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/NumberOutputC.cpp b/src/plugins/BuiltIns/components/NumberOutputC.cpp deleted file mode 100644 index f566f72..0000000 --- a/src/plugins/BuiltIns/components/NumberOutputC.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#include "NumberOutputC.h" - -#include - -#include "application/EditorContext.h" -#include "application/elements/Action.h" - -void NumberOutputC::draw(EditorContext& ec, Node& /**/) { - auto bounds = getBounds(); - textField.bounds.x = bounds.x; - textField.bounds.y = bounds.y; - textField.draw(); -} - -void NumberOutputC::update(EditorContext& ec, Node& parent) { - const auto* text = textField.buffer.c_str(); - outputs[0].setData(cxstructs::str_parse_long(text)); - outputs[1].setData(cxstructs::str_parse_float(text)); - - textField.update(ec.logic.worldMouse); - - height = static_cast(textField.bounds.height); - width = static_cast(textField.bounds.width); -} - -void NumberOutputC::onFocusGain(EditorContext& ec) { - textField.onFocusGain(ec.logic.worldMouse); - - delete currentAction; - currentAction = new TextAction(textField.buffer, textField.buffer); -} - -void NumberOutputC::onFocusLoss(EditorContext& ec) { - textField.onFocusLoss(); - - if (currentAction) { - // Discard if nothing changed - if (currentAction->beforeState == textField.buffer) { - delete currentAction; - currentAction = nullptr; - return; - } - //TRANSFER OWNERSHIP - currentAction->setAfter(textField.buffer); - ec.core.addEditorAction(ec, currentAction); - currentAction = nullptr; - } -} - -void NumberOutputC::onCreate(EditorContext& ec, Node& /**/) { - internalLabel = false; //We don't want to draw our label - textField.font = &ec.display.editorFont; - textField.fs = ec.display.fontSize; - - addPinOutput(INTEGER); - addPinOutput(FLOAT); -} -double NumberOutputC::getFloat() { - return cxstructs::str_parse_float(textField.buffer.c_str()); -} - -int64_t NumberOutputC::getInt() { - return cxstructs::str_parse_long(textField.buffer.c_str()); -} - -void NumberOutputC::save(FILE* file) { - cxstructs::io_save(file, textField.buffer.c_str()); -} - -void NumberOutputC::load(FILE* file) { - cxstructs::io_load(file, textField.buffer); - textField.updateDimensions(); -} \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/NumberOutputC.h b/src/plugins/BuiltIns/components/NumberOutputC.h deleted file mode 100644 index bdd2ac2..0000000 --- a/src/plugins/BuiltIns/components/NumberOutputC.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#ifndef NUMBERINPUT_H -#define NUMBERINPUT_H - -#include "component/Component.h" -#include "ui/TextField.h" - -class NumberOutputC final : public Component { - TextInputField textField; - TextAction* currentAction = nullptr; - - public: - explicit NumberOutputC(const ComponentTemplate ct) : Component(ct, 200, 20), textField(200, 20, NUMERIC) {} - Component* clone() override { return new NumberOutputC(*this); } - void draw(EditorContext& ec, Node& parent) override; - void update(EditorContext&, Node& parent) override; - void load(FILE* file) override; - void save(FILE* file) override; - void onFocusGain(EditorContext&) override; - void onFocusLoss(EditorContext&) override; - void onCreate(EditorContext& ec, Node& parent) override; - const char* getString() override { return textField.buffer.c_str(); } - int64_t getInt() override; - double getFloat() override; -}; - -#endif //NUMBERINPUT_H \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/StringToNumberC.cpp b/src/plugins/BuiltIns/components/SeparateXYC.h similarity index 62% rename from src/plugins/BuiltIns/components/StringToNumberC.cpp rename to src/plugins/BuiltIns/components/SeparateXYC.h index 9549e3f..8e2af21 100644 --- a/src/plugins/BuiltIns/components/StringToNumberC.cpp +++ b/src/plugins/BuiltIns/components/SeparateXYC.h @@ -18,20 +18,29 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "StringToNumberC.h" +#ifndef SEPARATEXY_H +#define SEPARATEXY_H +#include "application/EditorContext.h" +struct SeparateXYC final : Component { + explicit SeparateXYC(const ComponentTemplate ct) : Component(ct, 100, 20) {} + Component* clone() override { return new SeparateXYC(*this); } -void StringToNumberC::update(EditorContext& /**/, Node& /**/) { - const auto inData = inputs[0].getData(); + void draw(EditorContext& /**/, Node& /**/) override {} + void update(EditorContext& ec, Node& parent) override { + Vec2 outVec = inputs[0].getData(); - outputs[0].setData(inData ? std::atof(inData) : 0.0); - outputs[1].setData(inData ? std::atoi(inData) : 0L); -} + outputs[0].setData(outVec.x); + outputs[1].setData(outVec.y); + } -void StringToNumberC::onCreate(EditorContext& /**/, Node& /**/) { - addPinInput(STRING); + void onCreate(EditorContext& ec, Node& parent) override { + addPinInput(VECTOR_2); - addPinOutput(FLOAT); - addPinOutput(INTEGER); -} \ No newline at end of file + addPinOutput(FLOAT); + addPinOutput(FLOAT); + } +}; + +#endif //SEPARATEXY_H \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/SeparateXYZC.cpp b/src/plugins/BuiltIns/components/SeparateXYZC.cpp deleted file mode 100644 index df52cd3..0000000 --- a/src/plugins/BuiltIns/components/SeparateXYZC.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#include "SeparateXYZC.h" - -void SeparateXYZC::update(EditorContext& ec, Node& parent) { - Vec3 outVec = inputs[0].getData(); - - outputs[0].setData(outVec.x); - outputs[1].setData(outVec.y); - outputs[2].setData(outVec.z); -} - -void SeparateXYZC::onCreate(EditorContext& ec, Node& parent) { - addPinInput(VECTOR_3); - - addPinOutput(FLOAT); - addPinOutput(FLOAT); - addPinOutput(FLOAT); -} \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/SeparateXYZC.h b/src/plugins/BuiltIns/components/SeparateXYZC.h index 730fd0b..56948f9 100644 --- a/src/plugins/BuiltIns/components/SeparateXYZC.h +++ b/src/plugins/BuiltIns/components/SeparateXYZC.h @@ -27,9 +27,22 @@ struct SeparateXYZC final : Component { explicit SeparateXYZC(const ComponentTemplate ct) : Component(ct, 100, 20) {} Component* clone() override { return new SeparateXYZC(*this); } - void draw(EditorContext& /**/, Node& /**/) override{} - void update(EditorContext& ec, Node& parent) override; - void onCreate(EditorContext& ec, Node& parent) override; + void draw(EditorContext& /**/, Node& /**/) override {} + void update(EditorContext& ec, Node& parent) override { + Vec3 outVec = inputs[0].getData(); + + outputs[0].setData(outVec.x); + outputs[1].setData(outVec.y); + outputs[2].setData(outVec.z); + } + + void onCreate(EditorContext& ec, Node& parent) override { + addPinInput(VECTOR_3); + + addPinOutput(FLOAT); + addPinOutput(FLOAT); + addPinOutput(FLOAT); + } }; #endif //SEPARATEXYZ_H \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/StringToNumberC.h b/src/plugins/BuiltIns/components/StringToNumberC.h index 04219d1..f520f73 100644 --- a/src/plugins/BuiltIns/components/StringToNumberC.h +++ b/src/plugins/BuiltIns/components/StringToNumberC.h @@ -26,9 +26,20 @@ struct StringToNumberC final : Component { explicit StringToNumberC(const ComponentTemplate ct) : Component(ct, 50, 20) {} Component* clone() override { return new StringToNumberC(*this); }; - void draw(EditorContext& ec, Node& parent) override{} - void update(EditorContext& ec, Node& parent) override; - void onCreate(EditorContext &ec, Node &parent) override; + void draw(EditorContext& ec, Node& parent) override {} + void update(EditorContext& /**/, Node& /**/) override { + const auto inData = inputs[0].getData(); + + outputs[0].setData(inData ? cxstructs::str_parse_float(inData) : 0.0); + outputs[1].setData(inData ? cxstructs::str_parse_long(inData) : 0L); + } + + void onCreate(EditorContext& /**/, Node& /**/) override { + addPinInput(STRING); + + addPinOutput(FLOAT); + addPinOutput(INTEGER); + } }; #endif //RAYNODES_SRC_COMPONENT_COMPONENTS_STRINGTONUMBERC_H_ \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/TextFieldC.h b/src/plugins/BuiltIns/components/TextFieldC.h new file mode 100644 index 0000000..d3ee807 --- /dev/null +++ b/src/plugins/BuiltIns/components/TextFieldC.h @@ -0,0 +1,105 @@ +// Copyright (c) 2024 gk646 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef TEXTINPUTC_H +#define TEXTINPUTC_H + +#include + +#include "application/EditorContext.h" +#include "component/Component.h" +#include "application/elements/Action.h" +#include "ui/TextField.h" + +template +class TextFieldC final : public Component { + TextInputField textField; + TextAction* currentAction = nullptr; + + public: + explicit TextFieldC(const ComponentTemplate ct) : Component(ct, 200, 20), textField(200, 20, NONE) {} + Component* clone() override { return new TextFieldC(*this); } + void draw(EditorContext& ec, Node& /**/) override { + auto bounds = getBounds(); + textField.bounds.x = bounds.x; + textField.bounds.y = bounds.y; + textField.draw(); + } + + void update(EditorContext& ec, Node& parent) override { + textField.update(ec.logic.worldMouse); + + if constexpr (style == IN_AND_OUT || style == INPUT_ONLY) { + auto* input = inputs[0].getData(); + if (input) textField.buffer = input; + } + + if constexpr (style == IN_AND_OUT || style == OUTPUT_ONLY) { + outputs[0].setData(textField.buffer.c_str()); + } + + height = static_cast(textField.bounds.height); + width = static_cast(textField.bounds.width); + } + + void onFocusGain(EditorContext& ec) override { + textField.onFocusGain(ec.logic.worldMouse); + + delete currentAction; + currentAction = new TextAction(textField.buffer, textField.buffer); + } + + void onFocusLoss(EditorContext& ec) override { + textField.onFocusLoss(); + + if (currentAction) { + // Discard if nothing changed + if (currentAction->beforeState == textField.buffer) { + delete currentAction; + currentAction = nullptr; + return; + } + //TRANSFER OWNERSHIP + currentAction->setAfter(textField.buffer); + ec.core.addEditorAction(ec, currentAction); + currentAction = nullptr; + } + } + + void onCreate(EditorContext& ec, Node& /**/) override { + internalLabel = false; //We don't want to draw our label + textField.font = &ec.display.editorFont; + textField.fs = ec.display.fontSize; + + if constexpr (style == IN_AND_OUT || style == INPUT_ONLY) { addPinInput(STRING); } + if constexpr (style == IN_AND_OUT || style == OUTPUT_ONLY) { addPinOutput(STRING); } + } + + void save(FILE* file) override { cxstructs::io_save(file, textField.buffer.c_str()); } + + void load(FILE* file) override { + cxstructs::io_load(file, textField.buffer); + textField.updateDimensions(); + } + + const char* getString() override { return textField.buffer.c_str(); } +}; + +#endif //TEXTINPUTC_H \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/TextInputC.cpp b/src/plugins/BuiltIns/components/TextInputC.cpp deleted file mode 100644 index bb8add8..0000000 --- a/src/plugins/BuiltIns/components/TextInputC.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#include "TextInputC.h" - -#include - -#include "application/EditorContext.h" -#include "application/elements/Action.h" - -void TextInputC::draw(EditorContext& ec, Node& /**/) { - auto bounds = getBounds(); - textField.bounds.x = bounds.x; - textField.bounds.y = bounds.y; - textField.draw(); -} - -void TextInputC::update(EditorContext& ec, Node& parent) { - auto* input = inputs[0].getData(); - if (input) textField.buffer = input; - - textField.update(ec.logic.worldMouse); - - height = static_cast(textField.bounds.height); - width = static_cast(textField.bounds.width); -} - -void TextInputC::onFocusGain(EditorContext& ec) { - textField.onFocusGain(ec.logic.worldMouse); - - delete currentAction; - currentAction = new TextAction(textField.buffer, textField.buffer); -} - -void TextInputC::onFocusLoss(EditorContext& ec) { - textField.onFocusLoss(); - - if (currentAction) { - // Discard if nothing changed - if (currentAction->beforeState == textField.buffer) { - delete currentAction; - currentAction = nullptr; - return; - } - //TRANSFER OWNERSHIP - currentAction->setAfter(textField.buffer); - ec.core.addEditorAction(ec, currentAction); - currentAction = nullptr; - } -} - -void TextInputC::onCreate(EditorContext& ec, Node& /**/) { - internalLabel = false; //We don't want to draw our label - textField.font = &ec.display.editorFont; - textField.fs = ec.display.fontSize; - - addPinInput(STRING); -} - -void TextInputC::save(FILE* file) { - cxstructs::io_save(file, textField.buffer.c_str()); -} - -void TextInputC::load(FILE* file) { - cxstructs::io_load(file, textField.buffer); - textField.updateDimensions(); -} \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/TextInputC.h b/src/plugins/BuiltIns/components/TextInputC.h deleted file mode 100644 index bf2f33d..0000000 --- a/src/plugins/BuiltIns/components/TextInputC.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#ifndef TEXTINPUTC_H -#define TEXTINPUTC_H - -#include "component/Component.h" -#include "ui/TextField.h" - -class TextInputC final : public Component { - TextInputField textField; - TextAction* currentAction = nullptr; - - public: - explicit TextInputC(const ComponentTemplate ct) : Component(ct, 200, 20), textField(200, 20, NONE) {} - Component* clone() override { return new TextInputC(*this); } - void draw(EditorContext& ec, Node& parent) override; - void update(EditorContext&, Node& parent) override; - void load(FILE* file) override; - void save(FILE* file) override; - void onFocusGain(EditorContext&) override; - void onFocusLoss(EditorContext&) override; - void onCreate(EditorContext& ec, Node& parent) override; - const char* getString() override { return textField.buffer.c_str(); } -}; - -#endif //TEXTINPUTC_H \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/TextOutC.cpp b/src/plugins/BuiltIns/components/TextOutC.cpp deleted file mode 100644 index 509dcb3..0000000 --- a/src/plugins/BuiltIns/components/TextOutC.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#include "TextOutC.h" - - -#include - -#include "application/EditorContext.h" -#include "application/elements/Action.h" - -void TextOutputC::draw(EditorContext& ec, Node& /**/) { - auto bounds = getBounds(); - textField.bounds.x = bounds.x; - textField.bounds.y = bounds.y; - textField.draw(); -} - -void TextOutputC::update(EditorContext& ec, Node& parent) { - outputs[0].setData(textField.buffer.c_str()); - - textField.update(ec.logic.worldMouse); - - height = static_cast(textField.bounds.height); - width = static_cast(textField.bounds.width); -} - -void TextOutputC::onFocusGain(EditorContext& ec) { - textField.onFocusGain(ec.logic.worldMouse); - - delete currentAction; - currentAction = new TextAction(textField.buffer, textField.buffer); -} - -void TextOutputC::onFocusLoss(EditorContext& ec) { - textField.onFocusLoss(); - - if (currentAction) { - // Discard if nothing changed - if (currentAction->beforeState == textField.buffer) { - delete currentAction; - currentAction = nullptr; - return; - } - //TRANSFER OWNERSHIP - currentAction->setAfter(textField.buffer); - ec.core.addEditorAction(ec, currentAction); - currentAction = nullptr; - } -} - -void TextOutputC::onCreate(EditorContext& ec, Node& /**/) { - internalLabel = true; - textField.font = &ec.display.editorFont; - textField.fs = ec.display.fontSize; - - addPinOutput(STRING); -} - -void TextOutputC::save(FILE* file) { - cxstructs::io_save(file, textField.buffer.c_str()); -} - -void TextOutputC::load(FILE* file) { - cxstructs::io_load(file, textField.buffer); - textField.updateDimensions(); -} \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/TextOutC.h b/src/plugins/BuiltIns/components/TextOutC.h deleted file mode 100644 index c081530..0000000 --- a/src/plugins/BuiltIns/components/TextOutC.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#ifndef RAYNODES_SRC_NODES_ELEMENTS_TEXTINPUTFIELD_H_ -#define RAYNODES_SRC_NODES_ELEMENTS_TEXTINPUTFIELD_H_ - -#include "component/Component.h" -#include "ui/TextField.h" - -class TextOutputC final : public Component { - TextInputField textField; - TextAction* currentAction = nullptr; - - public: - explicit TextOutputC(const ComponentTemplate ct) : Component(ct, 200, 20), textField(200, 20, NONE) {} - Component* clone() override { return new TextOutputC(*this); } - void draw(EditorContext& ec, Node& parent) override; - void update(EditorContext&, Node& parent) override; - void load(FILE* file) override; - void save(FILE* file) override; - void onFocusGain(EditorContext&) override; - void onFocusLoss(EditorContext&) override; - void onCreate(EditorContext& ec, Node& parent) override; - const char* getString() override { return textField.buffer.c_str(); } -}; - -#endif //RAYNODES_SRC_NODES_ELEMENTS_TEXTINPUTFIELD_H_ \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/Vec2C.h b/src/plugins/BuiltIns/components/Vec2C.h new file mode 100644 index 0000000..723c946 --- /dev/null +++ b/src/plugins/BuiltIns/components/Vec2C.h @@ -0,0 +1,125 @@ +// Copyright (c) 2024 gk646 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef VEC2C_H +#define VEC2C_H + +#include +#include + +#include "application/EditorContext.h" +#include "ui/TextField.h" + +template +class Vec2C final : public Component { + static constexpr int FLOAT_FIELDS = 2; + TextInputField textFields[FLOAT_FIELDS]{}; + + public: + explicit Vec2C(const ComponentTemplate ct) : Component(ct, 200, 20) {} + Component* clone() override { return new Vec2C(*this); } + + void draw(EditorContext& ec, Node& /**/) override { + auto bounds = getBounds(); + + constexpr std::array labels = {"X:", "Y:"}; + const auto& font = ec.display.editorFont; + const auto fs = ec.display.fontSize; + float startX = bounds.x; + + for (int i = 0; i < FLOAT_FIELDS; ++i) { + DrawTextEx(font, labels[i], {startX, bounds.y}, fs, 0.0F, UI::COLORS[UI_LIGHT]); + startX += 12; + auto& f = textFields[i]; + f.bounds.x = startX; + f.bounds.y = bounds.y; + f.draw(); + startX += f.bounds.width + 1; + } + + width = startX - bounds.x; + } + + void update(EditorContext& ec, Node& parent) override { + for (auto& f : textFields) { + f.update(ec.logic.worldMouse); + } + + Vec2 out{0.0F, 0.0F}; + + out.x = cxstructs::str_parse_float(textFields[0].buffer.c_str()); + out.y = cxstructs::str_parse_float(textFields[1].buffer.c_str()); + + outputs[0].setData(out); + + if (ec.input.isMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + for (auto& f : textFields) { + f.onFocusGain(ec.logic.worldMouse); + } + } + } + + void onFocusGain(EditorContext& ec) override { + for (auto& f : textFields) { + f.onFocusGain(ec.logic.worldMouse); + } + } + + void onFocusLoss(EditorContext& ec) override { + for (auto& f : textFields) { + f.onFocusLoss(); + } + } + + void onCreate(EditorContext& ec, Node& /**/) override { + internalLabel = false; //We don't want to draw our label + for (auto& f : textFields) { + f.font = &ec.display.editorFont; + f.fs = ec.display.fontSize; + f.minWidth = 60; + f.bounds.width = 60; + f.bounds.height = 20; + } + + // Correctly apply style + if (style == IN_AND_OUT) { + addPinOutput(VECTOR_2); + addPinInput(VECTOR_2); + } else if (style == INPUT_ONLY) { + addPinInput(VECTOR_2); + } else if (style == OUTPUT_ONLY) { + addPinOutput(VECTOR_2); + } + } + + void save(FILE* file) override { + for (auto& f : textFields) { + cxstructs::io_save(file, f.buffer.c_str()); + } + } + + void load(FILE* file) override { + for (auto& f : textFields) { + cxstructs::io_load(file, f.buffer); + } + } +}; + +#endif //VEC2C_H \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/Vec3C.h b/src/plugins/BuiltIns/components/Vec3C.h new file mode 100644 index 0000000..6a4f9c4 --- /dev/null +++ b/src/plugins/BuiltIns/components/Vec3C.h @@ -0,0 +1,126 @@ +// Copyright (c) 2024 gk646 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef VEC3_H +#define VEC3_H + +#include +#include + +#include "application/EditorContext.h" +#include "ui/TextField.h" + +template +class Vec3C final : public Component { + static constexpr int FLOAT_FIELDS = 3; + TextInputField textFields[FLOAT_FIELDS]{}; + + public: + explicit Vec3C(const ComponentTemplate ct) : Component(ct, 200, 20) {} + Component* clone() override { return new Vec3C(*this); } + + void draw(EditorContext& ec, Node& /**/) override { + auto bounds = getBounds(); + + constexpr std::array labels = {"X:", "Y:", "Z:"}; + const auto& font = ec.display.editorFont; + const auto fs = ec.display.fontSize; + float startX = bounds.x; + + for (int i = 0; i < FLOAT_FIELDS; ++i) { + DrawTextEx(font, labels[i], {startX, bounds.y}, fs, 0.0F, UI::COLORS[UI_LIGHT]); + startX += 12; + auto& f = textFields[i]; + f.bounds.x = startX; + f.bounds.y = bounds.y; + f.draw(); + startX += f.bounds.width + 1; + } + + width = startX - bounds.x; + } + + void update(EditorContext& ec, Node& parent) override { + for (auto& f : textFields) { + f.update(ec.logic.worldMouse); + } + + Vec3 out{0.0F, 0.0F, 0.0F}; + + out.x = cxstructs::str_parse_float(textFields[0].buffer.c_str()); + out.y = cxstructs::str_parse_float(textFields[1].buffer.c_str()); + out.z = cxstructs::str_parse_float(textFields[2].buffer.c_str()); + + outputs[0].setData(out); + + if (ec.input.isMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + for (auto& f : textFields) { + f.onFocusGain(ec.logic.worldMouse); + } + } + } + + void onFocusGain(EditorContext& ec) override { + for (auto& f : textFields) { + f.onFocusGain(ec.logic.worldMouse); + } + } + + void onFocusLoss(EditorContext& ec) override { + for (auto& f : textFields) { + f.onFocusLoss(); + } + } + + void onCreate(EditorContext& ec, Node& /**/) override { + internalLabel = false; //We don't want to draw our label + for (auto& f : textFields) { + f.font = &ec.display.editorFont; + f.fs = ec.display.fontSize; + f.minWidth = 60; + f.bounds.width = 60; + f.bounds.height = 20; + } + + // Correctly apply style + if (style == IN_AND_OUT) { + addPinOutput(VECTOR_3); + addPinInput(VECTOR_3); + } else if (style == INPUT_ONLY) { + addPinInput(VECTOR_3); + } else if (style == OUTPUT_ONLY) { + addPinOutput(VECTOR_3); + } + } + + void save(FILE* file) override { + for (auto& f : textFields) { + cxstructs::io_save(file, f.buffer.c_str()); + } + } + + void load(FILE* file) override { + for (auto& f : textFields) { + cxstructs::io_load(file, f.buffer); + } + } +}; + +#endif \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/Vec3OutC.cpp b/src/plugins/BuiltIns/components/Vec3OutC.cpp deleted file mode 100644 index 75a527d..0000000 --- a/src/plugins/BuiltIns/components/Vec3OutC.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#include "Vec3OutC.h" - -#include - -#include "application/EditorContext.h" - -void Vec3OutC::draw(EditorContext& ec, Node& /**/) { - auto bounds = getBounds(); - - float startX = bounds.x; - for (auto& f : textFields) { - f.bounds.x = startX; - f.bounds.y = bounds.y; - f.draw(); - startX += 65.0F; - } -} - -void Vec3OutC::update(EditorContext& ec, Node& parent) { - for (auto& f : textFields) { - f.update(ec.logic.worldMouse); - } - - Vec3 out{0.0F, 0.0F, 0.0F}; - - out.x = cxstructs::str_parse_float(textFields[0].buffer.c_str()); - out.y = cxstructs::str_parse_float(textFields[1].buffer.c_str()); - out.z = cxstructs::str_parse_float(textFields[2].buffer.c_str()); - outputs[0].setData(out); -} - -void Vec3OutC::onFocusGain(EditorContext& ec) { - for (auto& f : textFields) { - f.onFocusGain(ec.logic.worldMouse); - } -} - -void Vec3OutC::onFocusLoss(EditorContext& ec) { - for (auto& f : textFields) { - f.onFocusLoss(); - } -} - -void Vec3OutC::onCreate(EditorContext& ec, Node& /**/) { - internalLabel = false; //We don't want to draw our label - for (auto& f : textFields) { - f.font = &ec.display.editorFont; - f.fs = ec.display.fontSize; - f.minWidth = 60; - f.bounds.width = 60; - f.bounds.height = 20; - } - - addPinOutput(VECTOR_3); -} - -void Vec3OutC::save(FILE* file) { - for (auto& f : textFields) { - cxstructs::io_save(file, f.buffer.c_str()); - } -} - -void Vec3OutC::load(FILE* file) { - for (auto& f : textFields) { - cxstructs::io_load(file, f.buffer); - } -} \ No newline at end of file diff --git a/src/plugins/BuiltIns/components/Vec3OutC.h b/src/plugins/BuiltIns/components/Vec3OutC.h deleted file mode 100644 index 1f685a1..0000000 --- a/src/plugins/BuiltIns/components/Vec3OutC.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2024 gk646 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#ifndef VECTOR3OUTPUTC_H -#define VECTOR3OUTPUTC_H - -#include "component/Component.h" -#include "ui/TextField.h" - -class Vec3OutC final : public Component { - TextInputField textFields[3]{}; - - public: - explicit Vec3OutC(const ComponentTemplate ct) : Component(ct, 200, 20) {} - Component* clone() override { return new Vec3OutC(*this); } - void draw(EditorContext& ec, Node& parent) override; - void update(EditorContext&, Node& parent) override; - void load(FILE* file) override; - void save(FILE* file) override; - void onFocusGain(EditorContext&) override; - void onFocusLoss(EditorContext&) override; - void onCreate(EditorContext& ec, Node& parent) override; -}; - -#endif //VECTOR3OUTPUTC_H \ No newline at end of file diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 80f27d4..78492ad 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -16,4 +16,4 @@ #target_link_libraries(MyPlugin PRIVATE editor) # Link against the editor (static) or possibly raylib (shared) add_subdirectory(BuiltIns) # Built in Types (raynodes STL...) -add_subdirectory(MQQS) # MageQuest Quest Script \ No newline at end of file +add_subdirectory(QuestScript) # MageQuest Quest Script \ No newline at end of file diff --git a/src/plugins/MQQS/CMakeLists.txt b/src/plugins/QuestScript/CMakeLists.txt similarity index 55% rename from src/plugins/MQQS/CMakeLists.txt rename to src/plugins/QuestScript/CMakeLists.txt index 433bdca..3eb6415 100644 --- a/src/plugins/MQQS/CMakeLists.txt +++ b/src/plugins/QuestScript/CMakeLists.txt @@ -1,14 +1,13 @@ file(GLOB_RECURSE PLUGIN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") -add_library(MQQS SHARED ${PLUGIN_FILES}) +add_library(QuestScript SHARED ${PLUGIN_FILES}) -set_target_properties(MQQS PROPERTIES +set_target_properties(QuestScript PROPERTIES PREFIX "" # Sets the output directory for the actual library files RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins" ) - -target_include_directories(MQQS PRIVATE ${CMAKE_SOURCE_DIR}/src/raynodes) -target_link_libraries(MQQS PRIVATE raylib editor) \ No newline at end of file +target_include_directories(QuestScript PRIVATE ${CMAKE_SOURCE_DIR}/src/raynodes) +target_link_libraries(QuestScript PRIVATE raylib editor) \ No newline at end of file diff --git a/src/plugins/MQQS/MQQS.cpp b/src/plugins/QuestScript/QuestScrip.cpp similarity index 74% rename from src/plugins/MQQS/MQQS.cpp rename to src/plugins/QuestScript/QuestScrip.cpp index c547bf0..d6f3327 100644 --- a/src/plugins/MQQS/MQQS.cpp +++ b/src/plugins/QuestScript/QuestScrip.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "MQQS.h" +#include "QuestScript.h" #include "components/DialogChoiceC.h" @@ -27,16 +27,19 @@ void MQQS::registerComponents(ComponentRegister& cr) { } void MQQS::registerNodes(NodeRegister& nr) { - nr.registerNode("Dialog Choice", {{"NPCType", "BI_TextIn"}, - {"DisplayText", "BI_TextIn"}, + nr.registerNode("Dialog Choice", {{"NPCType", "BI_Text_In"}, + {"DisplayText", "BI_Text_In"}, {"Choice1", "QST_DialogChoice"}, {"Choice2", "QST_DialogChoice"}, {"Choice3", "QST_DialogChoice"}, {"Choice4", "QST_DialogChoice"}}); - nr.registerNode("Dialog", {{"NPCType", "BI_TextIn"}, {"DisplayText", "BI_TextIn"}}); + nr.registerNode("Dialog", {{"NPCType", "BI_Text_In"}, {"DisplayText", "BI_Text_In"}}); nr.registerNode( "QuestHeader", - {{"Name", "BI_TextIn"}, {"Description", "BI_TextIn"}, {"Zone", "BI_TextIn"}, {"Level", "BI_NumberOut"}}); + {{"Name", "BI_Text_In"}, {"Description", "BI_Text_In"}, {"Zone", "BI_Text_In"}, {"Level", "BI_Number_In"}}); + + nr.registerNode("GOTO Player", {{"Zone", "BI_Text_In"}, {"Target", "BI_Vec2_In"}}); + nr.registerNode("GOTO Player Proximity", {{"Zone", "BI_Text_In"}, {"Target", "BI_Vec2_In"},{"Distance","BI_Number_In"}}); } \ No newline at end of file diff --git a/src/plugins/MQQS/MQQS.h b/src/plugins/QuestScript/QuestScript.h similarity index 100% rename from src/plugins/MQQS/MQQS.h rename to src/plugins/QuestScript/QuestScript.h diff --git a/src/plugins/MQQS/components/DialogChoiceC.cpp b/src/plugins/QuestScript/components/DialogChoiceC.cpp similarity index 100% rename from src/plugins/MQQS/components/DialogChoiceC.cpp rename to src/plugins/QuestScript/components/DialogChoiceC.cpp diff --git a/src/plugins/MQQS/components/DialogChoiceC.h b/src/plugins/QuestScript/components/DialogChoiceC.h similarity index 100% rename from src/plugins/MQQS/components/DialogChoiceC.h rename to src/plugins/QuestScript/components/DialogChoiceC.h diff --git a/src/raynodes/application/context/ContextInfo.h b/src/raynodes/application/context/ContextInfo.h index d141dc9..007abd6 100644 --- a/src/raynodes/application/context/ContextInfo.h +++ b/src/raynodes/application/context/ContextInfo.h @@ -31,7 +31,7 @@ struct Info { static constexpr auto about = "Copyright #226# 2024 gk646. MIT License"; static constexpr int majorVersion = 1; static constexpr int minorVersion = 0; - static constexpr int patch = 0; + static constexpr int patch = 1; static const char* getVersion(EditorContext& ec); }; diff --git a/src/raynodes/application/context/ContextUI.h b/src/raynodes/application/context/ContextUI.h index 2f7b968..93251a9 100644 --- a/src/raynodes/application/context/ContextUI.h +++ b/src/raynodes/application/context/ContextUI.h @@ -42,6 +42,7 @@ struct ContextMenu { } }; + // All the ui is made to be normed to 1920x1080 so FullHD // The methods allow you to always us absolute coordinates and then transferthem to real screen space // Use display.smartScaling for elements that have a minimum height -> scaling will only be apl @@ -107,6 +108,9 @@ struct UI final { bool showSettingsMenu = false; bool showHelpMenu = false; + // Tools + bool nodeCreatorEnabled = true; + // UI wrappers static int DrawListMenu(EditorContext& ec, bool& open, const char* title, const char* listText, int& active); static int DrawButton(EditorContext& ec, Rectangle& r, const char* txt); diff --git a/src/raynodes/application/editor/EditorControls.h b/src/raynodes/application/editor/EditorControls.h index 3337fd1..b7cd611 100644 --- a/src/raynodes/application/editor/EditorControls.h +++ b/src/raynodes/application/editor/EditorControls.h @@ -91,11 +91,11 @@ inline void PollControls(EditorContext& ec) { //Selecting if (ec.input.isMouseButtonPressed(MOUSE_BUTTON_RIGHT) && !ec.logic.isAnyNodeHovered && !ec.logic.showContextMenu) { - selectedNodes.clear(); ec.logic.isSelecting = true; ec.logic.selectPoint = worldMouse; selectRect.width = 0; selectRect.height = 0; + selectedNodes.clear(); } if (ec.input.isMouseButtonReleased(MOUSE_BUTTON_RIGHT)) { diff --git a/src/raynodes/application/editor/EditorUI.h b/src/raynodes/application/editor/EditorUI.h index d943c30..a9d63f0 100644 --- a/src/raynodes/application/editor/EditorUI.h +++ b/src/raynodes/application/editor/EditorUI.h @@ -236,6 +236,10 @@ inline void DrawTopBar(EditorContext& ec) { if (UI::DrawButton(ec, buttonBounds, "#141#")) ec.ui.showSettingsMenu = !ec.ui.showSettingsMenu; if (UI::DrawButton(ec, buttonBounds, "#193#")) ec.ui.showHelpMenu = !ec.ui.showHelpMenu; + + // Draw tool toggle buttons + + } inline void DrawStatusBar(EditorContext& ec) { constexpr float height = 20.0F; diff --git a/src/raynodes/blocks/Pin.cpp b/src/raynodes/blocks/Pin.cpp index 16c043b..af76952 100644 --- a/src/raynodes/blocks/Pin.cpp +++ b/src/raynodes/blocks/Pin.cpp @@ -34,13 +34,17 @@ Color Pin::getColor() const { case FLOAT: return SKYBLUE; case DATA: - return PURPLE; + return DARKGRAY; + case VECTOR_4: + return {25, 60, 62, 255}; // Dark Green case VECTOR_3: - break; + return {38, 92, 66, 255}; // Green case VECTOR_2: - break; + return {62, 137, 72, 255}; // Light Green case NODE: return VIOLET; + case IMAGE: + return {184, 111, 80, 255}; // Light Brown } return RED; } diff --git a/src/raynodes/blocks/Pin.h b/src/raynodes/blocks/Pin.h index c96ad78..9d29f6b 100644 --- a/src/raynodes/blocks/Pin.h +++ b/src/raynodes/blocks/Pin.h @@ -30,8 +30,10 @@ enum PinType : uint8_t { INTEGER, // A 64bit integer DATA, // A arbitrary data pointer FLOAT, // A single Float values - VECTOR_3, // 3 Float values - VECTOR_2, // 2 Float values + VECTOR_4, // 4 Float values (Color) + VECTOR_3, // 3 Float values (3D Position) + VECTOR_2, // 2 Float values (2D Position) + IMAGE, // Image data NODE, // Signals a connection between nodes }; @@ -48,6 +50,7 @@ struct OutputData { bool boolean; double floating; Pointer pointer; + ImageData image; Node* node; Vec2 vec2; Vec3 vec3; @@ -72,6 +75,8 @@ struct OutputData { return vec2; } else if constexpr (pt == VECTOR_3) { return vec3; + } else if constexpr (pt == IMAGE) { + return image; } else { static_assert(pt == STRING, "Unsupported PinType"); } @@ -94,6 +99,8 @@ struct OutputData { vec2 = val; } else if constexpr (pt == VECTOR_3) { vec3 = val; + } else if constexpr (pt == IMAGE) { + image = val; } else { static_assert(pt == STRING, "Unsupported PinType"); } @@ -126,6 +133,8 @@ struct Pin { return "Vec3"; case NODE: return "Node"; + case IMAGE: + return "Image"; default: return "Unknown Type"; } diff --git a/src/raynodes/shared/types.h b/src/raynodes/shared/types.h index 25b005f..b6141ef 100644 --- a/src/raynodes/shared/types.h +++ b/src/raynodes/shared/types.h @@ -33,8 +33,15 @@ struct Pointer { uint32_t size; }; -// Dont wanna include raylib everywhere +// Potentially use bit encoding to save more information - size doesnt need 32 bit +struct ImageData { + void* data; + uint32_t size; + uint16_t x; + uint16_t y; +}; +// Dont wanna include raylib everywhere struct Vec2 { float x; float y; @@ -67,16 +74,12 @@ struct NodeTemplate { // E = Editor // N = Node // C = Component -enum ColorIndex : uint8_t { - E_BACK_GROUND = 0, - E_GRID, - N_BACK_GROUND, - UI_LIGHT, - UI_MEDIUM, - UI_DARK, - INDEX_END -}; +enum ColorIndex : uint8_t { E_BACK_GROUND = 0, E_GRID, N_BACK_GROUND, UI_LIGHT, UI_MEDIUM, UI_DARK, INDEX_END }; enum ScaleDirection : uint8_t { HORIZONTAL, VERTICAL }; +// Flavour of components with only 1 datatype - specifies if it has both input and output or only either one +// This is mostly cosmetic - for example if you have a complex node and only wanna output node level, you can make the components have no outputs +enum ComponentStyle : uint8_t { INPUT_ONLY, OUTPUT_ONLY, IN_AND_OUT }; + #endif //TYPES_H \ No newline at end of file diff --git a/src/raynodes/ui/TextField.cpp b/src/raynodes/ui/TextField.cpp index 1dec974..1779bfa 100644 --- a/src/raynodes/ui/TextField.cpp +++ b/src/raynodes/ui/TextField.cpp @@ -44,8 +44,7 @@ void DrawTextSelection(const Font& f, char* buffer, int bufferLength, int select : 0; float lineEndX = MeasureTextUpTo(buffer + lineStartIndex, std::min(selectionEnd, i) - lineStartIndex, f, fs, 0.5F); - DrawRectangleRec({currentX + lineStartX, currentY, lineEndX - lineStartX, fs}, - ColorAlpha(WHITE, 0.5F)); + DrawRectangleRec({currentX + lineStartX, currentY, lineEndX - lineStartX, fs}, ColorAlpha(WHITE, 0.5F)); } lineStartIndex = i + 1; currentX = x; @@ -68,17 +67,13 @@ void DrawCursor(const Font& f, char* buffer, int bufferLength, int cursorPos, fl float offset = MeasureTextUpTo(buffer + startIndex, cursorPos - startIndex, f, fs, 0.5F); DrawTextEx(f, "|", {x + offset, y + lineCount * fs}, fs, 0.5F, WHITE); } - bool IsInputAllowed(const int key, InputConstraint constraint) { - if (constraint == NUMERIC) { - return (key >= 48 && key <= 57) || key == 46 /* dot*/; - } + if (constraint == NUMERIC) { return (key >= 48 && key <= 57) || key == 46 /* dot*/; } - if (constraint == NONE) { - return key >= 32 && key <= 125; - } + if (constraint == NONE) { return key >= 32 && key <= 125; } return false; } + } // namespace void TextInputField::draw() { @@ -118,9 +113,7 @@ void TextInputField::update(Vector2 mouse) { selectionEnd = selectionStart; } - if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { - isDragging = false; - } + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { isDragging = false; } if (IsKeyPressed(KEY_V) && IsKeyDown(KEY_LEFT_CONTROL) && buffer.length() < 1024) { if (selectionStart != selectionEnd) { @@ -149,6 +142,7 @@ void TextInputField::update(Vector2 mouse) { 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())); + //TODO replace selection when you type with active selection buffer.insert(buffer.begin() + cursorPos, static_cast(key)); cursorPos++; updateDimensions(); @@ -198,13 +192,9 @@ void TextInputField::update(Vector2 mouse) { updateDimensions(); } - if (cursorPos < buffer.length() && (IsKeyPressed(KEY_RIGHT) || IsKeyPressedRepeat(KEY_RIGHT))) { - cursorPos++; - } + if (cursorPos < buffer.length() && (IsKeyPressed(KEY_RIGHT) || IsKeyPressedRepeat(KEY_RIGHT))) { cursorPos++; } - if (cursorPos > 0 && (IsKeyPressed(KEY_LEFT) || IsKeyPressedRepeat(KEY_LEFT))) { - cursorPos--; - } + if (cursorPos > 0 && (IsKeyPressed(KEY_LEFT) || IsKeyPressedRepeat(KEY_LEFT))) { cursorPos--; } // Handle blinking cursor blinkCounter++; @@ -216,7 +206,7 @@ void TextInputField::update(Vector2 mouse) { void TextInputField::onFocusGain(const Vector2 mouse) { //Position the cursor correct inside the text - if (!CheckCollisionPointRec(mouse, bounds)) return; + if (!CheckCollisionPointRec(mouse, bounds)) return onFocusLoss() ; cursorPos = getIndexFromPos(mouse); selectionEnd = selectionStart; blinkCounter = 0; @@ -276,9 +266,7 @@ uint16_t TextInputField::getIndexFromPos(const Vector2 mouse) { for (uint16_t j = currentLineStartIndex; j < i; ++j) { const auto currentWidth = MeasureTextUpTo(text + currentLineStartIndex, j - currentLineStartIndex + 1, *font, fs, 0.5F); - if (currentWidth > relX) { - return j; - } + if (currentWidth > relX) { return j; } } return i; } @@ -291,6 +279,5 @@ uint16_t TextInputField::getIndexFromPos(const Vector2 mouse) { } Ints TextInputField::getSelection() const { - return selectionStart < selectionEnd ? Ints{selectionStart, selectionEnd} - : Ints{selectionEnd, selectionStart}; + return selectionStart < selectionEnd ? Ints{selectionStart, selectionEnd} : Ints{selectionEnd, selectionStart}; } \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4dd9352..9860391 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,10 +1,10 @@ # Add catch 2 - the easy way -add_library(catch2 STATIC "${DEPENDENCIES_PATH}/catch2v3/catch_amalgamated.cpp") +add_library(catch2 STATIC "${DEPENDENCIES_PATH}/catch2/catch_amalgamated.cpp") # Collect all ".cpp" files file(GLOB_RECURSE TEST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") add_executable(raynodes_test ${TEST_FILES} "${CMAKE_SOURCE_DIR}/src/plugins/BuiltIns/components/TextOutC.cpp") -target_include_directories(raynodes_test PRIVATE "${CMAKE_SOURCE_DIR}/src/import" "${CMAKE_SOURCE_DIR}/src/raynodes" "${DEPENDENCIES_PATH}/catch2v3") # We use the new version +target_include_directories(raynodes_test PRIVATE "${CMAKE_SOURCE_DIR}/src/import" "${CMAKE_SOURCE_DIR}/src/raynodes" "${DEPENDENCIES_PATH}/catch2") # We use the new version target_link_libraries(raynodes_test PRIVATE catch2 raylib editor) # Register the test with CMake - run from binary dir diff --git a/test/res/Test1.rn b/test/res/Test1.rn index 24a1b8f..37287e4 100644 --- a/test/res/Test1.rn +++ b/test/res/Test1.rn @@ -1,24 +1,28 @@ --EditorData-- -6|6|-72.000|-157.000|1.000|1| +6|6|-75.000|-180.000|1.000|1| --Templates-- -10| -0|Dialog Choice|NPCType|DisplayText|Choice1|Choice2|Choice3|Choice4|255| +14| +0|Vector2|Vec2||||||255| 1|MathOp|Operation||||||255| -2|TextField|TextField||||||255| -3|Vector 3|Vector3||||||255| -4|StringToNum|Converter||||||255| -5|Display|Display||||||255| -6|NumberField|Number||||||255| -7|SeparateXYZ|Vector||||||255| -8|Dialog|NPCType|DisplayText|||||255| -9|QuestHeader|Name|Description|Zone|Level|||255| +2|Display|Display||||||255| +3|StringToNum|Converter||||||255| +4|Vector3|Vec3||||||255| +5|SeparateXY|Separator||||||255| +6|SeparateXYZ|Separator||||||255| +7|TextField|Text||||||255| +8|NumberField|Number||||||255| +9|Dialog Choice|NPCType|DisplayText|Choice1|Choice2|Choice3|Choice4|255| +10|Dialog|NPCType|DisplayText|||||255| +11|QuestHeader|Name|Description|Zone|Level|||255| +12|GOTO Player|Zone|Target|||||255| +13|GOTO Player Proximity|Zone|Target|Distance||||255| --Nodes-- -2|0|Test1|$-684|-192| -2|1|Test2|$-327|-539| -6|2|2.33|$-290|-118| -3|3|1.1|1.22|1.333|$-527|42| +7|0|Test1|$-694|-201| +7|1|Test2|$-327|-539| +8|2|2.33|$-290|-118| +4|3|1.1|1.22|1.333|$-527|42| 1|4|1|$75|15| -0|5||$Display|$C1|$C2|$C3|$C4|$313|-524| +9|5||$Display|$C1|$C2|$C3|$C4|$313|-524| --Connections-- 0|-1|0|1|-1|0| 3|-1|0|4|-1|0|