Annwan
3 months ago
commit
8c7eedbddb
8 changed files with 453 additions and 0 deletions
-
110.clang-format
-
5.gitignore
-
46CMakeLists.txt
-
116src/Application.cppm
-
27src/Base.cppm
-
53src/Node.cppm
-
87src/Port.cppm
-
9src/main.cpp
@ -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 |
@ -0,0 +1,5 @@ |
|||||
|
build/* |
||||
|
/ffmpegraph |
||||
|
/.idea |
||||
|
/cmake-build-debug |
||||
|
/cmake-build-release |
@ -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 |
||||
|
$<$<CONFIG:DEBUG>:-O0 -g3 -glldb> |
||||
|
$<$<CONFIG:RELEASE>:-O3 -march=native> |
||||
|
) |
||||
|
# Link against exernal libraries |
||||
|
target_link_libraries(ffmpegraph PRIVATE raylib m) |
@ -0,0 +1,116 @@ |
|||||
|
module; |
||||
|
#include <raylib.h> |
||||
|
#include <string> |
||||
|
#include <vector> |
||||
|
#include <memory> |
||||
|
#include <cmath> |
||||
|
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<std::unique_ptr<Node>> 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<InputNode>()); |
||||
|
nodes.push_back(std::make_unique<InputNode>()); |
||||
|
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<InputPort*>(port); |
||||
|
if (iport) { |
||||
|
selected_port->Connect(*iport); |
||||
|
} |
||||
|
selected_port = nullptr; |
||||
|
} |
||||
|
else { |
||||
|
i32 x = GetMouseX(); |
||||
|
i32 y = GetMouseY(); |
||||
|
auto port = GetPort(); |
||||
|
auto oport = dynamic_cast<OutputPort*>(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(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
module; |
||||
|
#include <cstdint> |
||||
|
#include <type_traits> |
||||
|
#include <ranges> |
||||
|
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<std::size_t>; |
||||
|
export using iptr = std::intptr_t; |
||||
|
|
||||
|
export using f32 = float; |
||||
|
export using f64 = double; |
||||
|
|
||||
|
|
@ -0,0 +1,53 @@ |
|||||
|
module; |
||||
|
#include <raylib.h> |
||||
|
#include <vector> |
||||
|
#include <string> |
||||
|
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<Port*> 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; |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,87 @@ |
|||||
|
module; |
||||
|
#include <optional> |
||||
|
#include <string> |
||||
|
#include <raylib.h> |
||||
|
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<int> value = std::nullopt; |
||||
|
public: |
||||
|
explicit InputPort(std::string name): Port(std::move(name)) {} |
||||
|
std::optional<int> 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<int>); |
||||
|
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<int> InputPort::GetValue(){ |
||||
|
return value; |
||||
|
} |
||||
|
void OutputPort::SetValue(std::optional<int> 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); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
import Base; |
||||
|
import Application; |
||||
|
using namespace ffmpegraph; |
||||
|
|
||||
|
int main() { |
||||
|
Application app("FFMpeGraph"); |
||||
|
app.Run(); |
||||
|
return 0; |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue