From 8c7eedbddb65e1d351be82c57a2d2be8f8b3b17c Mon Sep 17 00:00:00 2001 From: Annwan Date: Fri, 27 Sep 2024 07:05:43 +0200 Subject: [PATCH] did stuff --- .clang-format | 110 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 5 ++ CMakeLists.txt | 46 +++++++++++++++++ src/Application.cppm | 116 +++++++++++++++++++++++++++++++++++++++++++ src/Base.cppm | 27 ++++++++++ src/Node.cppm | 53 ++++++++++++++++++++ src/Port.cppm | 87 ++++++++++++++++++++++++++++++++ src/main.cpp | 9 ++++ 8 files changed, 453 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 src/Application.cppm create mode 100644 src/Base.cppm create mode 100644 src/Node.cppm create mode 100644 src/Port.cppm create mode 100644 src/main.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..e37a2bd --- /dev/null +++ b/.clang-format @@ -0,0 +1,110 @@ +--- +AlignConsecutiveMacros: + Enabled: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +BitFieldColonSpacing: Both +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +AllowShortCompoundRequirementOnASingleLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowAllArgumentsOnNextLine: false +AlignTrailingComments: + Kind: Always +AlignAfterOpenBracket: BlockIndent +AccessModifierOffset: -4 +IndentWidth: 4 +UseTab: Never +TabWidth: 4 +Standard: Latest +SpacesInSquareBrackets: false +SpacesInParensOptions: {} +SpacesInParens: Never +SpacesInContainerLiterals: false +SpacesInAngles: Never +SpacesBeforeTrailingComments: 4 +SpaceInEmptyBlock: false +SpaceBeforeSquareBrackets: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDeclarationName: false + AfterFunctionDefinitionName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: true + AfterRequiresInExpression: true + BeforeNonEmptyParentheses: false +SpaceBeforeJsonColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCaseColon: false +SpaceBeforeAssignmentOperators: true +PointerAlignment: Middle +SpaceAfterTemplateKeyword: true +SpaceAfterLogicalNot: false +SpaceAfterCStyleCast: false +SortUsingDeclarations: LexicographicNumeric +SortJavaStaticImport: After +SortIncludes: CaseInsensitive +ShortNamespaceLines: 20 +SeparateDefinitionBlocks: Leave +RequiresExpressionIndentation: OuterScope +RequiresClausePosition: OwnLine +RemoveSemicolon: true +RemoveParentheses: Leave +RemoveBracesLLVM: false +ReflowComments: true +ReferenceAlignment: Middle +QualifierAlignment: Right +PackConstructorInitializers: NextLine +PPIndentWidth: -1 +NamespaceIndentation: None +MaxEmptyLinesToKeep: 1 +LineEnding: LF +Language: Cpp +LambdaBodyIndentation: OuterScope +KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: true +IntegerLiteralSeparator: + Binary: 4 + BinaryMinDigits: 9 + Decimal: 3 + DecimalMinDigits: 5 + Hex: 4 + HexMinDigits: 6 +InsertTrailingCommas: None +InsertNewlineAtEOF: true +InsertBraces: false +IndentWrappedFunctionNames: false +IndentRequiresClause: false +IndentPPDirectives: AfterHash +IndentGotoLabels: false +IndentExternBlock: NoIndent +IndentCaseLabels: true +IndentCaseBlocks: false +IndentAccessModifiers: false +IncludeBlocks: Regroup +FixNamespaceComments: true +EmptyLineBeforeAccessModifier: Leave +EmptyLineAfterAccessModifier: Leave +DisableFormat: false +DerivePointerAlignment: true +Cpp11BracedListStyle: true +ContinuationIndentWidth: 4 +ConstructorInitializerIndentWidth: 4 +CompactNamespaces: false +ColumnLimit: 80 +BreakStringLiterals: true +BreakInheritanceList: BeforeComma +AlignArrayOfStructures: Left diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ff11aeb --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +build/* +/ffmpegraph +/.idea +/cmake-build-debug +/cmake-build-release \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2fe66d4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,46 @@ +# Needs CMake 3.28 for module +cmake_minimum_required(VERSION 3.28) +project(ffmpegraph CXX) +set(CMAKE_CXX_STANDARD 26) + +# color shit out +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_options(-fdiagnostics-color=always) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options(-fcolor-diagnostics) +endif() + +# Use mold as the default linker, if it exists. +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + find_program(MOLD_LINKER "mold") + if (MOLD_LINKER) + add_link_options(-fuse-ld=mold) + endif() +endif() + +# Find all the modules +file(GLOB_RECURSE modules src/*.cppm) +# Create the executable target +add_executable(ffmpegraph) +# Main file +target_sources(ffmpegraph + PUBLIC + src/main.cpp +) +# The modules +target_sources(ffmpegraph + PUBLIC + FILE_SET CXX_MODULES FILES + ${modules} +) +#Compile flags +target_compile_options(ffmpegraph PRIVATE + -Wall -Wextra # Standard screaming + -Wconversion -Wsign-conversion # Scream about accidentally converting stuff + -Werror=return-type # Scream extra hard at not returning when you should. + # Target detection black magic + $<$:-O0 -g3 -glldb> + $<$:-O3 -march=native> +) +# Link against exernal libraries +target_link_libraries(ffmpegraph PRIVATE raylib m) diff --git a/src/Application.cppm b/src/Application.cppm new file mode 100644 index 0000000..b3c5538 --- /dev/null +++ b/src/Application.cppm @@ -0,0 +1,116 @@ +module; +#include +#include +#include +#include +#include +export module Application; +import Node; +import Base; +import Port; +namespace ffmpegraph { +export class Application { + +public: + explicit Application(std::string _title = "FFmpeGraph"); + ~Application(); + void Run(); +protected: + void ProcessEvents(); + void Render() const; + std::string title; + bool should_close; + std::vector> nodes; + Node* selected_node = nullptr; + OutputPort* selected_port = nullptr; +}; +} +module : private; +namespace ffmpegraph { + +Application::Application(std::string _title): title(std::move(_title)), should_close(false) { + SetConfigFlags(FLAG_WINDOW_RESIZABLE); + InitWindow(800, 600, this->title.c_str()); + SetTargetFPS(60); + + nodes.push_back(std::make_unique()); + nodes.push_back(std::make_unique()); + nodes[0]->pos_x = 10; + nodes[0]->pos_y = 10; + nodes[1]->pos_x = 200; + nodes[1]->pos_y = 100; +} + + + +void Application::ProcessEvents() { + + auto GetPort = [&] -> Port * { + for(auto& node : nodes) { + for (auto* port: node->ports) { + auto distx = double(GetMouseX() - port->pos_x); + auto disty = double(GetMouseY() - port->pos_y); + if (std::sqrt(distx * distx + disty * disty) < 10) { + return port; + } + } + } + return nullptr; + }; + + if (selected_node) { + selected_node->pos_x = GetMouseX(); + selected_node->pos_y = GetMouseY(); + } + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + if (selected_node) { + selected_node = nullptr; + } else if (selected_port) { + auto port = GetPort(); + auto iport = dynamic_cast(port); + if (iport) { + selected_port->Connect(*iport); + } + selected_port = nullptr; + } + else { + i32 x = GetMouseX(); + i32 y = GetMouseY(); + auto port = GetPort(); + auto oport = dynamic_cast(port); + if (oport) { + selected_port = oport; + } else { + for (auto& node : nodes) { + if (node->pos_x < x and x < node->pos_x + node->Width() + and node->pos_y < y and y < node->pos_y + node->Height()) { + selected_node = node.get(); + break; + } + } + } + } + } +} + +void Application::Render() const { + BeginDrawing(); + ClearBackground(RAYWHITE); + if (selected_port) { + DrawLine(selected_port->pos_x, selected_port->pos_y, GetMouseX(), GetMouseY(), BLACK); + } + for (auto &node : nodes) { + node->Render(); + } + EndDrawing(); +} +void Application::Run() { + while(not WindowShouldClose()) { + this->ProcessEvents(); + this->Render(); + } +} +Application::~Application(){ + CloseWindow(); +} +} diff --git a/src/Base.cppm b/src/Base.cppm new file mode 100644 index 0000000..7907ab5 --- /dev/null +++ b/src/Base.cppm @@ -0,0 +1,27 @@ +module; +#include +#include +#include +export module Base; + +export namespace rgs = std::ranges; +export namespace vws = std::views; + +export using u8 = std::uint8_t; +export using u16 = std::uint16_t; +export using u32 = std::uint32_t; +export using u64 = std::uint64_t; +export using usz = std::size_t; +export using uptr = std::uintptr_t; + +export using i8 = std::int8_t; +export using i16 = std::int16_t; +export using i32 = std::int32_t; +export using i64 = std::int64_t; +export using isz = std::make_signed_t; +export using iptr = std::intptr_t; + +export using f32 = float; +export using f64 = double; + + diff --git a/src/Node.cppm b/src/Node.cppm new file mode 100644 index 0000000..fa01d04 --- /dev/null +++ b/src/Node.cppm @@ -0,0 +1,53 @@ +module; +#include +#include +#include +export module Node; +import Base; +import Port; + +export namespace ffmpegraph { + +struct Node { + virtual ~Node() = default; + void Render(); + i32 Width() const; + i32 Height()const; + i32 pos_x{}, pos_y{}; + std::vector ports; +}; +struct InputNode : Node { + InputNode(); + Label label; + InputPort filename_port; + OutputPort output_port; +}; + + +} + +module : private; + +namespace ffmpegraph { + +i32 Node::Width() const {return 100;} +i32 Node::Height() const {return 20 * i32(ports.size());} + +InputNode::InputNode(): + label("Input"), + filename_port("filename"), + output_port("output") { + ports.emplace_back(&label); + ports.emplace_back(&filename_port); + ports.emplace_back(&output_port); +} +void Node::Render() { + i32 port_y = pos_y; + DrawRectangle(pos_x, pos_y, Width(), Height(), WHITE); + for (auto* port: ports) { + port->Render(pos_x, port_y); + port_y += 20; + }; +} +} + diff --git a/src/Port.cppm b/src/Port.cppm new file mode 100644 index 0000000..cc233fd --- /dev/null +++ b/src/Port.cppm @@ -0,0 +1,87 @@ +module; +#include +#include +#include +export module Port; +import Base; + +export namespace ffmpegraph { + +struct Port { +protected: + std::string name; + explicit Port(std::string name): name(std::move(name)) {} + virtual ~Port() = default; +public: + i32 pos_x{}, pos_y{}; + virtual void Render(i32 x, i32 y) = 0; +}; + +struct OutputPort; + +struct InputPort : Port { +protected: + std::optional value = std::nullopt; +public: + explicit InputPort(std::string name): Port(std::move(name)) {} + std::optional GetValue(); + void Render(i32 x, i32 y) override; + + friend OutputPort; +}; +struct OutputPort : Port { +protected: + InputPort* connected = nullptr; +public: + explicit OutputPort(std::string name): Port(std::move(name)) {} + void SetValue(std::optional); + void Connect(InputPort& ip); + void Disconnect(); + void Render(i32 x, i32 y) override; +}; + +struct Label : Port { + void Render(i32 x, i32 y) override; + explicit Label(std::string name): Port(std::move(name)) { + pos_x = -1; + pos_y = -1; + } +}; + +std::optional InputPort::GetValue(){ + return value; +} +void OutputPort::SetValue(std::optional val){ + if (connected) { + connected->value = val; + } +} +void OutputPort::Connect(InputPort& ip){ + connected = &ip; +} + +void OutputPort::Disconnect(){ + connected = nullptr; +} + +void OutputPort::Render(i32 x, i32 y) { + pos_x = x+100; pos_y = y+10; + DrawRectangleLines(x, y, 100, 20, BLACK); + DrawText(name.c_str(), x + 5, y + 5, 10, RED); + DrawCircle(x+100, y+10, 2.5f, BLACK); + if (connected) { + DrawLine(pos_x, pos_y, connected->pos_x, connected->pos_y, BLUE); + } +} +void InputPort::Render(i32 x, i32 y) { + pos_x = x; pos_y = y+10; + DrawRectangleLines(x, y, 100, 20, BLACK); + DrawText(name.c_str(), x + 5, y + 5, 10, BLUE); + DrawCircle(x, y+10, 2.5f, BLACK); +} +void Label::Render(i32 x, i32 y){ + DrawRectangleLines(x, y, 100, 20, BLACK); + DrawText(name.c_str(), x + 5, y + 5, 10, BLACK); +} + +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..7e8624a --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,9 @@ +import Base; +import Application; +using namespace ffmpegraph; + +int main() { + Application app("FFMpeGraph"); + app.Run(); + return 0; +}