35 Commits
Author SHA1 Message Date
tobid7 68cc809555 Fix Drawlist::Clear / Add HashID / FNV Type traits 2026-03-09 20:46:41 +01:00
tobid7 8ee7006d2c Export OS correctly 2026-01-30 20:19:13 +01:00
tobid7 683c226ce0 Fix MSVC dll building 2026-01-29 20:17:04 +01:00
tobid7 1ec06a26cc Fix GL Scissor in Desktop Backend 2026-01-28 07:40:34 +01:00
tobid7 21b45f5855 WIP: Add CLipRects to UI7 Layouts
- Added Scissor Support to Font Rendering
2026-01-28 07:11:56 +01:00
tobid7 090656b30c Fix close sym input logic 2026-01-27 08:06:52 +01:00
tobid7 e8072a064c WIP Backend System Redesign Step 1
- Created 1 Context for Backend Management and Sharing
- Made every class that used a static Backend require the Context or specific Backend
- Bring Back 3ds support
2026-01-26 20:46:27 +01:00
tobid7 892f8ce0c4 Update License Header Text 2026-01-25 21:12:16 +01:00
tobid7 c373b15bab remove drivers pd_p_api header 2026-01-25 21:00:50 +01:00
tobid7 fb46f4d36a Let's just use 1 PD_API header 2026-01-25 20:57:14 +01:00
tobid7 337c016824 Unfiy all sub projects back into 1 libpalladium 2026-01-25 20:44:52 +01:00
tobid7 d2806b2061 Add Nee Backend Structure
Use TexAddress instead of Texture::Ref in Cmds
Add a .clang-format??
2026-01-25 00:04:40 +01:00
tobid7 da79db223f Add MacOS support as well as OpenGL 3.3 support 2026-01-24 23:08:03 +01:00
tobid7 b2c7c1fdbf UI7 Add Containers to Layout
- Hotfix in CommandPool
- Add UI7 ItemRowHeight (Universal Item Size/Height)
- Add Containers to Layout
- Add ColorEdit to Menu
- Switch Back to COlorEdit in UI7::StyleEditor
- Add DrawList Layer Sorting to UI7 (Not working as expected)
- STart Work at ColorEdit container
2026-01-24 11:58:41 +01:00
tobid7 4a73e8c8da UI7 hotfix
- Fix Image has No Size
- Fix DragData PathRect Positioning
2026-01-24 09:27:21 +01:00
tobid7 641fc27e55 Auto Menu Sizing 2026-01-23 16:11:09 +01:00
tobid7 b8c25d6901 Add a Drag Slider to UI7 2026-01-23 15:45:25 +01:00
tobid7 931e02aefb Move CmdPool code to a source file 2026-01-22 19:25:01 +01:00
tobid7 0db4953125 Reimplement list sorting and Fix UI7 Layers 2026-01-22 16:34:46 +01:00
tobid7 2b7d25cf06 Update
- Added DestroyTex to 3ds backend
- Added Size() -> ivec2 to PD::Image
- Added CmdPool Copy as well as DrawList Copy (Static rendering)
- Added == ooperator for Rect
- Added UI7 Frame Rounding
- Fix UI7 Image usage withour size or uv
- Added New way to use BeginMenu
2026-01-18 19:25:50 +01:00
tobid7 0ef6d34435 Refactor the Command / DrawList System
Use Command Pool instead of always allocating.
This gives us e big performance diffrence on the 3ds
Fixed IDS of ui7 for now
2026-01-16 12:13:48 +01:00
tobid7 eb5d5f9974 backend updates
pd-3ds:
Add support for RGB565 textures
pd-desktop:
Add support for A8 textures
Add glfw callback chain to not break other libs using the same callback
2026-01-05 14:37:57 +01:00
tobid7 3575a6787d hotfix 2025-12-28 21:38:41 +01:00
tobid7 7fc7a2ecb9 QoL Changes
fix timetrace last diff
2025-12-27 23:35:23 +01:00
tobid7 03f65e069f Add TextMapSystem WIP 2025-12-24 18:17:58 +01:00
tobid7 c618c616fe Fix UI7 Crash by safe deleting the elements 2025-12-24 15:05:05 +01:00
tobid7 ac281dc7a9 Update
- Add data getter to DrawList
- Add NoOOS (Out Of screen Rendering) flag to text renderer (requires a textbox)
- UI7 Label Wrapping (optinal and beta)
2025-12-23 19:20:31 +01:00
tobid7 0cb5de882f Fixes and function additions
- Fixed Text pos at NoCollapse flag
- Fix Button Input Api (HandleScrolling after layout Update)
- Add getter for IO and Current Menu
- Add AdObject func wrappers to Menu
2025-12-20 19:25:20 +01:00
tobid7 b3d621a847 Add LayerOptimisation / QoL change 2025-12-19 21:08:32 +01:00
tobid7 4ad00cd2be pd-3ds: Add sysfont loader
- add support for Alpha only textures in rendering
2025-12-19 21:07:57 +01:00
tobid7 1e35dbd743 ReAdd text shorting 2025-12-18 21:51:48 +01:00
tobid7 803fa5cdb5 Remove custom standard lib
Why?? cause it was russian roulette with pointer access stuff etc
2025-12-17 10:02:05 +01:00
tobid7 66d3825481 bknd-3ds: implement libpicasso to load shader 2025-12-17 09:25:36 +01:00
tobid7 6c38aa6f21 Adding and fixing stuff
- Fix HexChar2Int
- Remove some devisions in tween engine
- Add PathAdd function for x, y seperated instead of fvec2
- Readd text wrapping (rd7-palladium maybe)
2025-12-15 22:16:19 +01:00
tobid7 f19c947fc3 Road to 0.6.0
- readd the c++ linear allocator for 3ds
- start switching from PD::Vec to std::vector
- Add Color::Hex as constexpr for compiletime color converts
- Add FNV Hasing functions
- Make UI7 ids be able to be generated at compile time
- Added a Throw Function (for whatever)
- Added HexCHar2Int (replaces the lookup table)
- Made u128 fully constexpr
2025-12-10 19:02:54 +01:00
149 changed files with 6480 additions and 5346 deletions
+334
View File
@@ -0,0 +1,334 @@
---
Language: Cpp
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: true
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveShortCaseStatements:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCaseArrows: false
AlignCaseColons: false
AlignConsecutiveTableGenBreakingDAGArgColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenCondOperatorColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenDefinitionColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AllowShortNamespacesOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AttributeMacros:
- __capability
- absl_nonnull
- absl_nullable
- absl_nullability_unknown
BinPackArguments: true
BinPackLongBracedList: true
BinPackParameters: BinPack
BitFieldColonSpacing: Both
BracedInitializerIndentWidth: -1
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakAfterReturnType: None
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTemplateCloser: false
BreakBeforeTernaryOperators: true
BreakBinaryOperations: Never
BreakConstructorInitializers: BeforeColon
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakTemplateDeclarations: Yes
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
EnumTrailingComma: Leave
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExportBlock: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfFile: true
KeepFormFeed: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
OneLineFormatOffRegex: ''
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakBeforeMemberAccess: 150
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakScopeResolution: 500
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: Always
RemoveBracesLLVM: false
RemoveEmptyLinesInUnwrappedLines: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes:
Enabled: true
IgnoreCase: false
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterOperatorKeyword: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterNot: false
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
ExceptDoubleParentheses: false
InCStyleCasts: false
InConditionalStatements: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TableGenBreakInsideDAGArg: DontBreak
TabWidth: 8
UseTab: Never
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
WrapNamespaceBodyWithEmptyLines: Leave
...
+3
View File
@@ -1,3 +1,6 @@
[submodule "backends/desktop/glfw"]
path = backends/desktop/glfw
url = https://github.com/glfw/glfw
[submodule "backends/3ds/libpicasso"]
path = backends/3ds/libpicasso
url = https://github.com/npid7/libpicasso
+90 -13
View File
@@ -1,14 +1,14 @@
cmake_minimum_required(VERSION 3.22)
# Set Project
project(palladium LANGUAGES C CXX VERSION 0.5.1)
project(palladium LANGUAGES C CXX VERSION 0.6.0)
# Required to add this Variable
set(PD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
include(cmake/palladium.cmake)
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
option(PD_BUILD_SHARED "Build Shared Libraries" OFF)
option(PD_BUILD_SHARED "Build Shared Library" OFF)
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
if(${PD_BUILD_TOOLS})
@@ -16,21 +16,98 @@ if(${PD_BUILD_TOOLS})
endif()
# # Include Library Source
set(PD_SOURCES
add_subdirectory(pd/drivers)
add_subdirectory(pd/core)
add_subdirectory(pd/image)
add_subdirectory(pd/external)
add_subdirectory(pd/lithium)
add_subdirectory(pd/ui7)
# Core
source/core/bit_util.cpp
source/core/color.cpp
source/core/io.cpp
source/core/mat.cpp
source/core/strings.cpp
source/core/timer.cpp
source/core/timetrace.cpp
add_library(palladium INTERFACE)
target_link_libraries(palladium INTERFACE
pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net
# Drivers
source/drivers/context.cpp
source/drivers/gfx.cpp
source/drivers/hid.cpp
source/drivers/os.cpp
# External
source/external/stb.cpp
# Image
source/image/image.cpp
source/image/img_blur.cpp
source/image/img_convert.cpp
# Lithium
source/lithium/command.cpp
source/lithium/drawlist.cpp
source/lithium/font.cpp
source/lithium/fonts.cpp
source/lithium/renderer.cpp
# UI7
source/ui7/container/button.cpp
source/ui7/container/checkbox.cpp
source/ui7/container/coloredit.cpp
source/ui7/container/container.cpp
source/ui7/container/dragdata.cpp
source/ui7/container/dynobj.cpp
source/ui7/container/image.cpp
source/ui7/container/label.cpp
source/ui7/container/slider.cpp
source/ui7/io.cpp
source/ui7/layout.cpp
source/ui7/menu.cpp
source/ui7/theme.cpp
source/ui7/ui7.cpp
)
add_dependencies(palladium
pd-drivers pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net
if(${PD_BUILD_SHARED})
add_library(palladium SHARED ${PD_SOURCES})
target_compile_definitions(palladium PRIVATE -DPD_BUILD_SHARED)
else()
add_library(palladium STATIC ${PD_SOURCES})
target_compile_definitions(palladium PUBLIC -DPD_BUILD_STATIC)
endif()
target_include_directories(palladium PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
target_compile_options(palladium PRIVATE
$<$<COMPILE_LANGUAGE:C>:-Wall>
$<$<COMPILE_LANGUAGE:C>:-Wno-psabi>
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
)
endif()
target_compile_options(palladium PRIVATE
$<$<CONFIG:Debug>:-O0 -g>
$<$<CONFIG:Release>:-O3>
)
install(DIRECTORY include DESTINATION ".")
install(TARGETS palladium)
find_program(CLANG_FORMAT clang-format)
file(GLOB_RECURSE PD_FMTFILES CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/pd/core/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/pd/drivers/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/pd/image/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/pd/lithium/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/pd/ui7/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/desktop/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/3ds/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/desktop/include/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/3ds/include/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/source*.cpp
)
add_custom_target(pd-clang-format
COMMAND ${CLANG_FORMAT} --style=file -i ${PD_FMTFILES}
COMMENT "Formatting Project Sources"
)
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+3 -3
View File
@@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.22)
project(pd-3ds LANGUAGES CXX VERSION 0.5.0)
project(pd-3ds LANGUAGES CXX VERSION 0.6.0)
set(SRC
source/bknd-gfx.cpp
source/bknd-hid.cpp
source/pd-3ds.cpp
)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libpicasso)
pd_add_lib(pd-3ds SRC_FILES ${SRC})
target_include_directories(pd-3ds PUBLIC include)
target_link_libraries(pd-3ds PUBLIC m palladium ctru citro3d)
target_link_libraries(pd-3ds PUBLIC m palladium ctru citro3d pica::pica)
+3 -3
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -28,5 +27,6 @@ SOFTWARE.
#include <pd-3ds/bknd-hid.hpp>
namespace PD {
PD::Li::Font::Ref LoadSystemFont(Context& ctx);
void Init(void* data = nullptr);
}
} // namespace PD
+8 -17
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -27,22 +26,13 @@ SOFTWARE.
#include <3ds.h>
#include <citro3d.h>
#include <pd-3ds/linearAllocator.hpp>
#include <pd/lithium/lithium.hpp>
namespace PD {
template <typename T>
class LinearAlloc : public Allocator<T> {
public:
LinearAlloc() = default;
~LinearAlloc() = default;
/** Never forget the sizeof(T) again (most painful bug i created) */
T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); }
void Deallocate(T* ptr) { linearFree(ptr); }
};
class GfxC3D : public GfxDriver {
public:
GfxC3D() : GfxDriver("Citro3D") {}
GfxC3D(PDDriverData data = nullptr) : GfxDriver("Citro3D") {}
~GfxC3D() = default;
PD_SHARED(GfxC3D);
@@ -51,19 +41,20 @@ class GfxC3D : public GfxDriver {
void Deinit() override;
void NewFrame() override;
void BindTex(PD::Li::TexAddress addr) override;
void RenderDrawData(
const std::vector<PD::Li::Command::Ref>& Commands) override;
void RenderDrawData(const PD::Li::CmdPool& Commands) override;
PD::Li::Texture::Ref LoadTex(
const std::vector<PD::u8>& pixels, int w, int h,
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
PD::Li::Texture::Filter filter =
PD::Li::Texture::Filter::LINEAR) override;
void DestroyTex(PD::Li::Texture::Ref tex) override;
Vec<Li::Vertex, LinearAlloc<Li::Vertex>> VertexBuffer;
Vec<u16, LinearAlloc<u16>> IndexBuffer;
std::vector<Li::Vertex, LinearAllocator<Li::Vertex>> VertexBuffer;
std::vector<u16, LinearAllocator<u16>> IndexBuffer;
int pLocProjection = 0;
DVLB_s* ShaderCode;
shaderProgram_s Shader;
C3D_AttrInfo ShaderInfo;
std::vector<u8> pRawShader;
};
} // namespace PD
+2 -3
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +28,7 @@ SOFTWARE.
namespace PD {
class Hid3DS : public HidDriver {
public:
Hid3DS();
Hid3DS(PDDriverData data = nullptr);
~Hid3DS() = default;
PD_SHARED(Hid3DS);
@@ -0,0 +1,72 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
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 <3ds.h>
#include <pd/core/common.hpp>
// Custom C++ Allocator class to interface with libctru linear heap memory
// based on this guide:
// https://johnfarrier.com/custom-allocators-in-c-high-performance-memory-management/
namespace PD {
template <typename T>
class LinearAllocator {
public:
using value_type = T;
LinearAllocator() noexcept = default;
template <typename U>
constexpr LinearAllocator(const LinearAllocator<U>&) noexcept {}
T* allocate(std::size_t n) {
if (n > max_size()) {
PD::Throw("[PD] LinearAllocator: Bad alloc!");
}
return static_cast<T*>(linearAlloc(n * sizeof(T)));
}
void deallocate(T* p, std::size_t) noexcept { linearFree(p); }
template <class U, class... Args>
void construct(U* p, Args&&... args) {
::new ((void*)p) U(std::forward<Args>(args)...);
}
template <class U>
void destroy(U* p) {
p->~U();
}
friend bool operator==(const LinearAllocator, const LinearAllocator) {
return true;
}
friend bool operator!=(const LinearAllocator, const LinearAllocator) {
return false;
}
// Use linearSpace free as max_size to not allocate out of bounds
// or to b eable to see a crash report screen.
size_t max_size() const noexcept { return linearSpaceFree(); }
};
} // namespace PD
+56 -38
View File
@@ -1,7 +1,6 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,11 +22,8 @@ SOFTWARE.
*/
#include <pd-3ds/bknd-gfx.hpp>
#include <pica.hpp>
/// @brief Shader Code (Unused as i dont want to use libpicasso here (yet))
/// Update: Picasso breaks the linearRam or ram for somereason
/// as far as i found out loading anything into linear ram after
/// using libpicasso to compile a shader leads into a system freeze
const char* LIShaderCTR = R"(
; LI7 Shader
; Constants
@@ -65,13 +61,6 @@ const char* LIShaderCTR = R"(
.end
)";
// clang-format off
unsigned char li_shader[] = {
0x44, 0x56, 0x4c, 0x42, 0x1, 0x0, 0x0, 0x0, 0xa4, 0x0, 0x0, 0x0, 0x44, 0x56, 0x4c, 0x50, 0x0, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0x98, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x1, 0xf0, 0x7, 0x4e, 0x2, 0x8, 0x2, 0x8, 0x3, 0x18, 0x2, 0x8, 0x4, 0x28, 0x2, 0x8, 0x5, 0x38, 0x2, 0x8, 0x6, 0x10, 0x40, 0x4c, 0x7, 0xf1, 0x27, 0x22, 0x8, 0x10, 0x21, 0x4c, 0x0, 0x0, 0x0, 0x88, 0xac, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa1, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x64, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x62, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x61, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0xaf, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4f, 0xd5, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6f, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x56, 0x4c, 0x45, 0x2, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x54, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x54, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x6c, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x74, 0x0, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x2, 0x0, 0x5f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x1, 0x1, 0x37, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0, 0xf, 0x0, 0x0, 0x0, 0x3, 0x0, 0x2, 0x0, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x13, 0x0, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0, 0x0,
};
// clang-format on
size_t li_shader_size = 0x124;
namespace PD {
GPU_TEXCOLOR GetTexFmt(Li::Texture::Type type) {
if (type == Li::Texture::RGBA32)
@@ -92,13 +81,40 @@ int GetBPP(Li::Texture::Type type) {
return 0; // Error
}
void FragCfg(GPU_TEXCOLOR clr) {
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
switch (clr) {
case GPU_A4:
case GPU_A8:
case GPU_L4:
case GPU_L8:
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE);
break;
case GPU_RGB565:
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_MODULATE);
C3D_TexEnvFunc(env, C3D_Alpha, GPU_REPLACE);
break;
default:
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
break;
}
}
void GfxC3D::Init() {
VertexBuffer.Resize(4 * 8192);
IndexBuffer.Resize(6 * 8192);
VertexBuffer.resize(4 * 8192);
IndexBuffer.resize(6 * 8192);
Flags |= LiBackendFlags_FlipUV_Y;
ShaderCode = DVLB_ParseFile((uint32_t*)li_shader, li_shader_size);
pRawShader = Pica::AssembleCode(LIShaderCTR);
ShaderCode = DVLB_ParseFile((uint32_t*)&pRawShader[0], pRawShader.size());
shaderProgramInit(&Shader);
shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]);
pLocProjection =
@@ -130,8 +146,7 @@ void GfxC3D::BindTex(PD::Li::TexAddress addr) {
C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr));
}
void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
// C3D_BindProgram(&Shader);
void GfxC3D::RenderDrawData(const PD::Li::CmdPool& Commands) {
shaderProgramUse(&Shader);
C3D_SetAttrInfo(&ShaderInfo);
C3D_Mtx proj;
@@ -139,31 +154,26 @@ void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, &proj);
// Mat4 proj = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f);
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, (C3D_Mtx*)&proj);
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
size_t index = 0;
while (index < Commands.size()) {
PD::Li::Texture::Ref Tex = Commands[index]->Tex;
while (index < Commands.Size()) {
PD::Li::TexAddress Tex = Commands.GetCmd(index)->Tex;
if (!Tex) {
index++;
continue;
}
bool ScissorEnabled = Commands[index]->ScissorOn;
ivec4 ScissorRect = Commands[index]->ScissorRect;
bool ScissorEnabled = Commands.GetCmd(index)->ScissorOn;
ivec4 ScissorRect = Commands.GetCmd(index)->ScissorRect;
size_t StartIndex = CurrentIndex;
while (index < Commands.size() && Commands[index]->Tex == Tex &&
Commands[index]->ScissorOn == ScissorEnabled &&
Commands[index]->ScissorRect == ScissorRect) {
auto c = Commands[index].get();
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
while (index < Commands.Size() && Commands.GetCmd(index)->Tex == Tex &&
Commands.GetCmd(index)->ScissorOn == ScissorEnabled &&
Commands.GetCmd(index)->ScissorRect == ScissorRect) {
auto c = Commands.GetCmd(index);
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
}
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
}
index++;
}
@@ -176,13 +186,14 @@ void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
} else {
C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0);
}
BindTex(Tex->Address);
FragCfg(((C3D_Tex*)Tex)->fmt);
BindTex(Tex);
auto bufInfo = C3D_GetBufInfo();
BufInfo_Init(bufInfo);
BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Li::Vertex), 3, 0x210);
BufInfo_Add(bufInfo, VertexBuffer.data(), sizeof(Li::Vertex), 3, 0x210);
C3D_DrawElements(GPU_TRIANGLES, CurrentIndex - StartIndex,
C3D_UNSIGNED_SHORT, IndexBuffer.Data() + StartIndex);
C3D_UNSIGNED_SHORT, IndexBuffer.data() + StartIndex);
}
C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
}
@@ -248,4 +259,11 @@ PD::Li::Texture::Ref GfxC3D::LoadTex(const std::vector<PD::u8>& pixels, int w,
<< std::endl;
return res;
}
void GfxC3D::DestroyTex(PD::Li::Texture::Ref tex) {
C3D_Tex* t = reinterpret_cast<C3D_Tex*>(tex->Address);
C3D_TexDelete(t);
delete t;
tex->Address = 0;
}
} // namespace PD
+2 -3
View File
@@ -1,7 +1,6 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -27,7 +26,7 @@ SOFTWARE.
#include <pd-3ds/bknd-hid.hpp>
namespace PD {
Hid3DS::Hid3DS() : HidDriver("Hid3DS") {
Hid3DS::Hid3DS(PDDriverData data) : HidDriver("Hid3DS") {
this->Flags |= Flags_HasTouch;
this->Flags |= FLags_HasGamepad;
pBinds[KEY_A] = A;
+100 -5
View File
@@ -1,7 +1,6 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -22,15 +21,111 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <3ds.h>
#include <palladium>
#include <pd-3ds.hpp>
namespace PD {
PD::Li::Font::Ref LoadSystemFont(Context& ctx) {
TT::Scope st(*ctx.Os(), "LI_SystemFont"); // Trace loading time
Li::Font::Ref ret = Li::Font::New(ctx);
fontEnsureMapped(); // Call this to be sure the font is mapped
// Get some const references for system font loading
const auto fnt = fontGetSystemFont();
const auto fnt_info = fontGetInfo(fnt);
const auto glyph_info = fontGetGlyphInfo(fnt);
// Resize the Texture list by the num of sysfont textures
ret->Textures.resize(glyph_info->nSheets + 1);
/// Modify the Pixel Height by 1.1f to fit the
/// Size og ttf font Rendering
ret->PixelHeight = glyph_info->cellHeight;
// Load the Textures and make sure they don't auto unload
for (size_t i = 0; i < glyph_info->nSheets; i++) {
auto stex = Li::Texture::New();
auto tx = new C3D_Tex;
tx->data = fontGetGlyphSheetTex(fnt, i);
tx->fmt = (GPU_TEXCOLOR)glyph_info->sheetFmt;
tx->size = glyph_info->sheetSize;
tx->width = glyph_info->sheetWidth;
tx->height = glyph_info->sheetHeight;
tx->param = GPU_TEXTURE_MAG_FILTER(GPU_LINEAR) |
GPU_TEXTURE_MIN_FILTER(GPU_LINEAR) |
GPU_TEXTURE_WRAP_S(GPU_REPEAT) | GPU_TEXTURE_WRAP_T(GPU_REPEAT);
tx->border = 0xffffffff;
tx->lodParam = 0;
stex->Address = (Li::TexAddress)tx;
stex->Size = fvec2(tx->width, tx->height);
stex->UV = fvec4(0, 1, 1, 0);
ret->Textures[i] = stex;
}
std::vector<unsigned int> charSet;
// Write the Charset into a vector
for (auto cmap = fnt_info->cmap; cmap; cmap = cmap->next) {
if (cmap->mappingMethod == CMAP_TYPE_DIRECT) {
if (cmap->codeEnd >= cmap->codeBegin) {
charSet.reserve(charSet.size() + cmap->codeEnd - cmap->codeBegin + 1);
for (auto i = cmap->codeBegin; i <= cmap->codeEnd; ++i) {
if (cmap->indexOffset + (i - cmap->codeBegin) == 0xFFFF) break;
charSet.emplace_back(i);
}
}
} else if (cmap->mappingMethod == CMAP_TYPE_TABLE) {
if (cmap->codeEnd >= cmap->codeBegin) {
charSet.reserve(charSet.size() + cmap->codeEnd - cmap->codeBegin + 1);
for (auto i = cmap->codeBegin; i <= cmap->codeEnd; ++i) {
if (cmap->indexTable[i - cmap->codeBegin] == 0xFFFF) continue;
charSet.emplace_back(i);
}
}
} else if (cmap->mappingMethod == CMAP_TYPE_SCAN) {
charSet.reserve(charSet.size() + cmap->nScanEntries);
for (unsigned i = 0; i < cmap->nScanEntries; ++i) {
if (cmap->scanEntries[i].code >= cmap->codeBegin &&
cmap->scanEntries[i].code <= cmap->codeEnd) {
if (cmap->scanEntries[i].glyphIndex != 0xFFFF) {
charSet.emplace_back(cmap->scanEntries[i].code);
}
}
}
} else {
continue;
}
}
// Sort the charset and make sure all values are unique
std::sort(charSet.begin(), charSet.end());
charSet.erase(std::unique(charSet.begin(), charSet.end()));
// Setup the Codepoint map by the charset
for (auto cp : charSet) {
int gidx = fontGlyphIndexFromCodePoint(fnt, cp);
if (gidx >= 0xFFFF) continue;
Li::Font::Codepoint codepoint;
fontGlyphPos_s dat;
fontCalcGlyphPos(&dat, fnt, gidx, GLYPH_POS_CALC_VTXCOORD, 1.f, 1.f);
codepoint.pCodepoint = cp;
codepoint.SimpleUV = fvec4(dat.texcoord.left, dat.texcoord.top,
dat.texcoord.right, dat.texcoord.bottom);
if (dat.sheetIndex < (int)ret->Textures.size()) {
codepoint.Tex = ret->Textures[dat.sheetIndex];
} else {
codepoint.pInvalid = true;
}
codepoint.Size = fvec2(dat.vtxcoord.right, dat.vtxcoord.bottom);
codepoint.Offset = 0;
ret->CodeMap[cp] = codepoint;
}
return ret;
}
void Init(void* data) {
// Dekstop Init Stage
// First use default OS Driver
PD::OS::Init();
PD::Gfx::Init(PD::GfxC3D::New());
PD::Hid::Init(PD::Hid3DS::New());
// PD::OS::Init();
// PD::Gfx::Init(PD::GfxC3D::New());
// PD::Hid::Init(PD::Hid3DS::New());
}
} // namespace PD
+12
View File
@@ -2,6 +2,14 @@ cmake_minimum_required(VERSION 3.22)
project(pd-desktop LANGUAGES CXX VERSION 0.5.0)
set(PD_GL_VERSION 21 CACHE STRING "OpenGL Version (2.1 -> 21, 3.3 -> 33)")
if(APPLE)
set(PD_GL_VERSION 33 CACHE STRING "33" FORCE)
endif()
message("Using OpenGL: " ${PD_GL_VERSION})
add_subdirectory(glad)
add_subdirectory(glfw)
@@ -14,3 +22,7 @@ set(SRC
pd_add_lib(pd-desktop SRC_FILES ${SRC})
target_include_directories(pd-desktop PUBLIC include)
target_link_libraries(pd-desktop PUBLIC palladium glad glfw)
target_compile_definitions(pd-desktop
PRIVATE PD_OPENGL=${PD_GL_VERSION}
)
+1 -2
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -35,7 +34,7 @@ SOFTWARE.
namespace PD {
class GfxGL2 : public GfxDriver {
public:
GfxGL2() : GfxDriver("OpenGL2") {}
GfxGL2(PDDriverData data = nullptr) : GfxDriver("OpenGL2") {}
~GfxGL2() = default;
PD_SHARED(GfxGL2);
@@ -44,19 +43,47 @@ class GfxGL2 : public GfxDriver {
void Deinit() override;
void NewFrame() override;
void BindTex(PD::Li::TexAddress addr) override;
void RenderDrawData(
const std::vector<PD::Li::Command::Ref>& Commands) override;
void RenderDrawData(const Li::CmdPool& Commands) override;
PD::Li::Texture::Ref LoadTex(
const std::vector<PD::u8>& pixels, int w, int h,
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
PD::Li::Texture::Filter filter =
PD::Li::Texture::Filter::LINEAR) override;
PD::Vec<Li::Vertex> VertexBuffer;
PD::Vec<PD::u16> IndexBuffer;
std::vector<Li::Vertex> VertexBuffer;
std::vector<PD::u16> IndexBuffer;
GLuint Shader;
GLuint pLocProjection;
GLuint pLocTex;
GLuint VBO, IBO;
GLuint pLocAlfa;
GLuint VBO, IBO, VAO; // vao is only used in > 3.3
};
class GfxGL3 : public GfxDriver2 {
public:
GfxGL3() : GfxDriver2("OpenGL3") {}
~GfxGL3() = default;
PD_SHARED(GfxGL3);
void Init() override;
void Deinit() override;
// void NewFrame() override;
void TexBind(PD::Li::TexAddress addr) override;
void Draw(const Li::CmdPool& pool) override;
PD::Li::TexAddress TexLoad(
const std::vector<PD::u8>& pixels, int w, int h,
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
PD::Li::Texture::Filter filter =
PD::Li::Texture::Filter::LINEAR) override;
void TexDelete(PD::Li::TexAddress tex) override;
std::vector<Li::Vertex> VertexBuffer;
std::vector<PD::u16> IndexBuffer;
GLuint Shader;
GLuint pLocProjection;
GLuint pLocTex;
GLuint pLocAlfa;
GLuint VBO, IBO, VAO; // vao is only used in > 3.3
};
} // namespace PD
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -31,7 +30,7 @@ SOFTWARE.
namespace PD {
class HidGLFW : public HidDriver {
public:
HidGLFW(GLFWwindow* win);
HidGLFW(PDDriverData data);
~HidGLFW() = default;
PD_SHARED(HidGLFW);
@@ -45,7 +44,7 @@ class HidGLFW : public HidDriver {
pTimings.erase(k);
return false;
}
return (PD::OS::GetTime() - pTimings[k]) > 50;
return 0; //(PD::OS::GetTime() - pTimings[k]) > 50;
}
if (!IsEvent(Event_Held, k)) {
if (pTimings.count(k)) {
@@ -54,7 +53,7 @@ class HidGLFW : public HidDriver {
}
}
if (IsEvent(Event_Held, k)) {
pTimings[k] = PD::OS::GetTime();
pTimings[k] = 0; // PD::OS::GetTime();
return true;
}
return false;
@@ -64,6 +63,7 @@ class HidGLFW : public HidDriver {
GLFWwindow* Window;
int PrevState;
std::unordered_map<int, int> PrevStates;
static GLFWcharfun pOldTextCB;
static std::string* pText;
bool pInTextMode = false;
PD::u64 pLastUpdate = 0;
+267 -21
View File
@@ -1,7 +1,6 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,6 +24,7 @@ SOFTWARE.
#include <pd-desktop/bknd-gfx.hpp>
namespace PD {
#if PD_OPENGL >= 21 && PD_OPENGL < 33
const char* vertex_shader = R"(
#version 120
@@ -53,12 +53,62 @@ const char* frag_shader = R"(
varying vec4 oColor;
uniform sampler2D tex;
uniform bool alfa;
void main() {
vec4 tc = texture2D(tex, oUV);
if (alfa) {
gl_FragColor = vec4(oColor.rgb, tc.a * oColor.a);
} else {
gl_FragColor = tc * oColor;
}
}
)";
#elif PD_OPENGL >= 33
const char* vertex_shader = R"(
#version 330 core
layout(location = 0) in vec2 pos;
layout(location = 1) in vec2 uv;
layout(location = 2) in vec4 color;
out vec2 oUV;
out vec4 oColor;
// Probably forgot about this matrix and
// searched hours for why the rendering isn't working :/
uniform mat4 projection;
void main() {
gl_Position = projection*vec4(pos, 0.0, 1.0);
oUV = uv;
oColor = color;
}
)";
const char* frag_shader = R"(
#version 330 core
in vec2 oUV;
in vec4 oColor;
uniform sampler2D tex;
uniform bool alfa;
out vec4 FragColor;
void main() {
vec4 tc = texture(tex, oUV);
if (alfa) {
FragColor = vec4(oColor.rgb, tc.a * oColor.a);
} else {
FragColor = tc * oColor;
}
}
)";
#else
// Need to show error
#endif
GLuint compileShader(const std::string& source, GLenum type) {
GLuint shader = glCreateShader(type);
@@ -123,30 +173,52 @@ void SetupShaderAttribs(GLuint Shader) {
/** Actual Backend */
void GfxGL2::Init() {
VertexBuffer.Resize(4 * 8192);
IndexBuffer.Resize(6 * 8192);
VertexBuffer.resize(4 * 8192);
IndexBuffer.resize(6 * 8192);
Shader = createShaderProgram(vertex_shader, frag_shader);
glUseProgram(Shader);
#if PD_OPENGL >= 33
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
#endif
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
// Attribs Setup
SetupShaderAttribs(Shader);
#if PD_OPENGL < 33
SetupShaderAttribs(Shader); // GL 2.1
#else
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, Pos));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, UV));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, Color));
#endif
glGenBuffers(1, &IBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
pLocTex = glGetUniformLocation(Shader, "tex");
pLocAlfa = glGetUniformLocation(Shader, "alfa");
pLocProjection = glGetUniformLocation(Shader, "projection");
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#if PD_OPENGL >= 33
glBindVertexArray(0);
#endif
}
void GfxGL2::Deinit() {
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &IBO);
#if PD_OPENGL >= 33
glDeleteBuffers(1, &VAO);
#endif
}
void GfxGL2::NewFrame() {
@@ -172,29 +244,32 @@ void GfxGL2::BindTex(PD::Li::TexAddress addr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
glUniform1i(pLocTex, 0);
GLint fmt = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
}
void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
void GfxGL2::RenderDrawData(const Li::CmdPool& Commands) {
size_t index = 0;
while (index < Commands.size()) {
PD::Li::Texture::Ref Tex = Commands[index]->Tex;
while (index < Commands.Size()) {
PD::Li::TexAddress Tex = Commands.GetCmd(index)->Tex;
if (!Tex) {
index++;
continue;
}
size_t StartIndex = CurrentIndex;
bool ScissorOn = Commands[index]->ScissorOn;
ivec4 ScissorRect = Commands[index]->ScissorRect;
bool ScissorOn = Commands.GetCmd(index)->ScissorOn;
ivec4 ScissorRect = Commands.GetCmd(index)->ScissorRect;
while (index < Commands.size() && Commands[index]->Tex == Tex &&
Commands[index]->ScissorOn == ScissorOn &&
Commands[index]->ScissorRect == ScissorRect) {
auto c = Commands[index].get();
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
while (index < Commands.Size() && Commands.GetCmd(index)->Tex == Tex &&
Commands.GetCmd(index)->ScissorOn == ScissorOn &&
Commands.GetCmd(index)->ScissorRect == ScissorRect) {
auto c = Commands.GetCmd(index);
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
}
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
}
index++;
}
@@ -205,13 +280,21 @@ void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
} else {
glDisable(GL_SCISSOR_TEST);
}
BindTex(Tex->Address);
BindTex(Tex);
#if PD_OPENGL >= 33
glBindVertexArray(VAO);
#endif
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
&VertexBuffer[0], GL_DYNAMIC_DRAW);
#if PD_OPENGL < 33
// For some reason we need to set these every frame for every buffer
// Found that out when creating My 3d Engine
SetupShaderAttribs(Shader);
#endif
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
@@ -223,6 +306,10 @@ void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
BindTex(0);
#if PD_OPENGL >= 33
glBindVertexArray(0);
#endif
glDisable(GL_SCISSOR_TEST);
}
}
@@ -251,6 +338,165 @@ PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w,
}
glBindTexture(GL_TEXTURE_2D, 0);
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
std::cout << std::format("Texture loaded: {} {}", texID, PD::ivec2(w, h))
<< std::endl;
return res;
}
void GfxGL3::Init() {
VertexBuffer.resize(4 * 8192);
IndexBuffer.resize(6 * 8192);
Shader = createShaderProgram(vertex_shader, frag_shader);
glUseProgram(Shader);
#if PD_OPENGL >= 33
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
#endif
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
#if PD_OPENGL < 33
SetupShaderAttribs(Shader); // GL 2.1
#else
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, Pos));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, UV));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, Color));
#endif
glGenBuffers(1, &IBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
pLocTex = glGetUniformLocation(Shader, "tex");
pLocAlfa = glGetUniformLocation(Shader, "alfa");
pLocProjection = glGetUniformLocation(Shader, "projection");
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#if PD_OPENGL >= 33
glBindVertexArray(0);
#endif
}
void GfxGL3::Deinit() {
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &IBO);
#if PD_OPENGL >= 33
glDeleteBuffers(1, &VAO);
#endif
}
// void NewFrame() {
//}
void GfxGL3::TexBind(PD::Li::TexAddress addr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
glUniform1i(pLocTex, 0);
GLint fmt = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
}
void GfxGL3::Draw(const Li::CmdPool& pool) {
size_t index = 0;
while (index < pool.Size()) {
PD::Li::TexAddress Tex = pool.GetCmd(index)->Tex;
if (Tex == 0) {
index++;
continue;
}
size_t StartIndex = CurrentIndex;
bool ScissorOn = pool.GetCmd(index)->ScissorOn;
ivec4 ScissorRect = pool.GetCmd(index)->ScissorRect;
while (index < pool.Size() && pool.GetCmd(index)->Tex == Tex &&
pool.GetCmd(index)->ScissorOn == ScissorOn &&
pool.GetCmd(index)->ScissorRect == ScissorRect) {
auto c = pool.GetCmd(index);
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
}
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
}
index++;
}
if (ScissorOn) {
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
ScissorRect.z, ScissorRect.w);
glEnable(GL_SCISSOR_TEST);
} else {
glDisable(GL_SCISSOR_TEST);
}
TexBind(Tex);
#if PD_OPENGL >= 33
glBindVertexArray(VAO);
#endif
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
&VertexBuffer[0], GL_DYNAMIC_DRAW);
#if PD_OPENGL < 33
// For some reason we need to set these every frame for every buffer
// Found that out when creating My 3d Engine
SetupShaderAttribs(Shader);
#endif
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
&IndexBuffer[0], GL_DYNAMIC_DRAW);
glDrawElements(GL_TRIANGLES, CurrentIndex - StartIndex, GL_UNSIGNED_SHORT,
(void*)(StartIndex * sizeof(PD::u16)));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
TexBind(0);
#if PD_OPENGL >= 33
glBindVertexArray(0);
#endif
}
}
PD::Li::TexAddress GfxGL3::TexLoad(const std::vector<PD::u8>& pixels, int w,
int h, PD::Li::Texture::Type type,
PD::Li::Texture::Filter filter) {
GLuint texID;
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
// Set base format (Always using RGBA as base)
GLenum fmt = GL_RGBA;
if (type == PD::Li::Texture::Type::RGB24) {
fmt = GL_RGB;
} else if (type == PD::Li::Texture::Type::A8) {
fmt = GL_ALPHA;
}
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
pixels.data());
if (filter == PD::Li::Texture::Filter::LINEAR) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else if (filter == PD::Li::Texture::Filter::NEAREST) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
glBindTexture(GL_TEXTURE_2D, 0);
return texID;
}
void GfxGL3::TexDelete(PD::Li::TexAddress tex) {
GLuint tex_ = tex;
glDeleteTextures(1, &tex_);
}
} // namespace PD
+21 -9
View File
@@ -1,7 +1,6 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,19 +23,32 @@ SOFTWARE.
#include <pd-desktop/bknd-hid.hpp>
namespace PD {
std::string* HidGLFW::pText;
std::string* HidGLFW::pText = nullptr;
GLFWcharfun HidGLFW::pOldTextCB = nullptr;
// Default Call back (If no Text input is requsted)
void NullTextCB(GLFWwindow* win, unsigned int c) {}
void NullTextCB(GLFWwindow* win, unsigned int c) {
// Chain
if (HidGLFW::pOldTextCB) {
HidGLFW::pOldTextCB(win, c);
}
}
// Text callback if requested
void TextCB(GLFWwindow* win, unsigned int c) {
// Chain
if (HidGLFW::pOldTextCB) {
HidGLFW::pOldTextCB(win, c);
}
if (!HidGLFW::pText) {
return;
}
*HidGLFW::pText += (char)c;
}
HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") {
Window = win;
glfwSetCharCallback(Window, NullTextCB);
HidGLFW::HidGLFW(PDDriverData data) : HidDriver("HidGLFW") {
if (!data) {
std::cout << "[HidGLFW] Error: Data pointer was null" << std::endl;
}
Window = reinterpret_cast<GLFWwindow*>(data);
HidGLFW::pOldTextCB = glfwSetCharCallback(Window, NullTextCB);
Flags |= Flags_HasKeyboard;
Flags |= Flags_HasMouse;
pBinds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
@@ -139,10 +151,10 @@ void HidGLFW::Update() {
glfwGetCursorPos(Window, &x, &y);
pMouse[1] = pMouse[0]; // Cycle pMouse pos
pMouse[0] = fvec2(x, y);
if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) {
/*if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) {
pLastUpdate = PD::OS::GetTime();
HandleTextOps();
}
}*/
}
void HidGLFW::GetInputStr(std::string& str) {
+3 -4
View File
@@ -1,7 +1,6 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -27,7 +26,7 @@ SOFTWARE.
namespace PD {
void Init(void* data) {
if (!data) {
/*if (!data) {
std::cout << "[PD-DRIVERS] Error: pd-desktop requires GLFWwindow* "
"reference as data "
"input!"
@@ -38,6 +37,6 @@ void Init(void* data) {
// First use default OS Driver
PD::OS::Init();
PD::Gfx::Init(PD::GfxGL2::New());
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));*/
}
} // namespace PD
+23
View File
@@ -1,5 +1,28 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
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 <pd/core/core.hpp>
#include <pd/drivers/drivers.hpp>
#include <pd/external/json.hpp>
+3 -4
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -36,12 +35,12 @@ namespace BitUtil {
* @param v 32 bit unsigned int
* @return true if its a single bit number
*/
PD_CORE_API bool IsSingleBit(u32 v);
PD_API bool IsSingleBit(u32 v);
/**
* Get the Next Power of two Number
* @param v Current Number
* @return Next Number thats a Pow of 2
*/
PD_CORE_API u32 GetPow2(u32 v);
PD_API u32 GetPow2(u32 v);
} // namespace BitUtil
} // namespace PD
+29 -11
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,9 +24,10 @@ SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/strings.hpp>
namespace PD {
class PD_CORE_API Color {
class PD_API Color {
public:
/**
* Default Constructor (all variables are set to 0)
@@ -65,17 +66,34 @@ class PD_CORE_API Color {
b(static_cast<u8>(255.f * b)),
a(static_cast<u8>(255.f * a)) {}
/**
* Constructor for Hex Input
* Constructor for Hex Input (is abel to run at compile time xD)
* @param hex Hex String in `#ffffff` or `#ffffffff` format
*/
Color(const std::string& hex) { Hex(hex); }
constexpr Color(const std::string_view& hex) { Hex(hex); }
/**
* Create Color Object by Hex String
* Create Color Object by Hex String (at compile time btw)
* @param hex Hex String in `#ffffff` or `#ffffffff` format
* @return Color class itself
*/
Color& Hex(const std::string& hex);
constexpr Color& Hex(const std::string_view& hex) {
if (!(hex.length() == 7 || hex.length() == 9)) {
PD::Throw("[PD] Color: hex string is not rgb or rgba!");
}
r = PD::Strings::HexChar2Int(hex[1]) * 16 +
PD::Strings::HexChar2Int(hex[2]);
g = PD::Strings::HexChar2Int(hex[3]) * 16 +
PD::Strings::HexChar2Int(hex[4]);
b = PD::Strings::HexChar2Int(hex[5]) * 16 +
PD::Strings::HexChar2Int(hex[6]);
if (hex.length() == 9) {
a = PD::Strings::HexChar2Int(hex[7]) * 16 +
PD::Strings::HexChar2Int(hex[8]);
} else {
a = 255;
}
return *this;
}
/**
* Convert this Color Object to Hex string
* @param rgba [default false] sets if 8 or 6 digit color should be returned
@@ -89,7 +107,7 @@ class PD_CORE_API Color {
* @param p Amount (supports -1.0 to 1.0 for use of sine)
* @return Class Reference
*/
Color& Fade(const Color& color, float p) {
constexpr Color& Fade(const Color& color, float p) {
a = static_cast<u8>((color.a - a) * ((p + 1.f) / 2));
b = static_cast<u8>((color.b - b) * ((p + 1.f) / 2));
g = static_cast<u8>((color.g - g) * ((p + 1.f) / 2));
@@ -101,12 +119,12 @@ class PD_CORE_API Color {
* Get 32Bit Color Value
* @return 32Bit Color Value (ABGR iirc)
*/
u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; }
constexpr u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; }
/**
* Get The Luminance of the Color
* @return luminance (from 0.0 to 1.0)
*/
float Luminance() const {
constexpr float Luminance() const {
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
return (0.3 * (r / 255.f) + 0.59 * (g / 255.f) + 0.11 * (b / 255.f));
}
@@ -114,13 +132,13 @@ class PD_CORE_API Color {
* Check if the Color is Light or Dark
* @return true if light
*/
bool IsLight() const { return (Luminance() >= 0.5); }
constexpr bool IsLight() const { return (Luminance() >= 0.5); }
/**
* Operator to cast Color to 32Bit Value
* @return 32Bit Color Value
*/
operator u32() const { return Get(); }
constexpr operator u32() const { return Get(); }
/** Public Access Data section */
u8 r;
+21 -2
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -32,6 +32,7 @@ SOFTWARE.
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numbers>
@@ -41,7 +42,7 @@ SOFTWARE.
#include <vector>
/** Dynamic Lib loading */
#include <pd/core/pd_p_api.hpp>
#include <pd/pd_p_api.hpp>
/** Memory Management */
@@ -52,6 +53,16 @@ SOFTWARE.
return std::make_shared<x>(std::forward<Args>(args)...); \
}
#define PD_RAW(x) \
using Ref = x*; \
template <typename... Args> \
static Ref New(Args&&... args) { \
x* v = new x; \
new (v) x(std::forward<Args>(args)...); \
return v; \
} \
static void Delete(Ref ref) { delete ref; }
#define PD_UNIQUE(x) \
using Ref = std::unique_ptr<x>; \
template <typename... Args> \
@@ -62,6 +73,14 @@ SOFTWARE.
#define PD_BIT(x) (1 << x)
namespace PD {
[[noreturn]] inline void Throw(const std::string& str) {
#ifdef _EXCEPTIONS
throw std::runtime_error("PD Error " + str);
#else
std::cout << "PD Error " << str << std::endl;
std::abort();
#endif
}
/** Types */
using u8 = unsigned char;
using u16 = unsigned short;
+4 -2
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,11 +25,13 @@ SOFTWARE.
#include <pd/core/bit_util.hpp>
#include <pd/core/color.hpp>
#include <pd/core/fnv.hpp>
#include <pd/core/hashid.hpp>
#include <pd/core/io.hpp>
#include <pd/core/mat.hpp>
#include <pd/core/sl/sl.hpp>
#include <pd/core/strings.hpp>
#include <pd/core/timer.hpp>
#include <pd/core/timetrace.hpp>
#include <pd/core/tween.hpp>
#include <pd/core/u128.hpp>
#include <pd/core/vec.hpp>
+38 -19
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -28,24 +27,44 @@ SOFTWARE.
namespace PD {
/**
* Custom Allocator for Custom Vec and probably other stuff in future
* FNV-1a 32Bit hasing function
* https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
*/
template <typename T>
class Allocator {
public:
Allocator() = default;
~Allocator() = default;
constexpr u32 FNV1A32(std::string_view str) {
u32 ret = 0x811c9dc5; // Offset basis
for (auto& it : str) {
ret ^= it;
ret *= 0x01000193; // Prime
}
return ret;
}
/**
* FNV-1a 64Bit hasing function
* https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
*/
constexpr u64 FNV1A64(std::string_view str) {
u64 ret = 0xcbf29ce484222325; // Offset basis
for (auto& it : str) {
ret ^= it;
ret *= 0x00000100000001b3; // Prime
}
return ret;
}
virtual T* Allocate(size_t n) { return new T[n]; }
virtual T* AllocateRaw(size_t n) {
return reinterpret_cast<T*>(::operator new(sizeof(T) * n));
}
virtual void DeallocateRaw(T* ptr) { operator delete(ptr); }
virtual void Deallocate(T* ptr) { delete[] ptr; }
template <typename... Args>
void Construct(T* ptr, Args&&... args) {
new (ptr) T(std::forward<Args>(args)...);
}
void Destroy(T* ptr) { ptr->~T(); }
namespace Detail {
template <typename T>
struct FNV1A {};
template <>
struct FNV1A<u32> {
static constexpr u32 Hash(std::string_view str) { return FNV1A32(str); }
static constexpr u32 Hash(const std::string& str) { return FNV1A32(str); }
};
template <>
struct FNV1A<u64> {
static constexpr u64 Hash(std::string_view str) { return FNV1A64(str); }
static constexpr u64 Hash(const std::string& str) { return FNV1A64(str); }
};
} // namespace Detail
} // namespace PD
+1 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+50
View File
@@ -0,0 +1,50 @@
#pragma once
#include <pd/core/fnv.hpp>
#include <pd/core/strings.hpp>
namespace PD {
template <typename T>
class HashID {
public:
using __Type = T;
constexpr HashID() {};
constexpr HashID(T id) { pID = id; }
HashID(const std::string& name) {
pID = Detail::FNV1A<T>::Hash(name);
#ifdef PD_HASHID_KEEP_STR
pName = name;
#endif
}
constexpr HashID(const char* name) {
pID = Detail::FNV1A<T>::Hash(std::string_view(name));
#ifdef PD_HASHID_KEEP_STR
pName = name;
#endif
}
~HashID() {}
constexpr T Get() { return pID; }
std::string GetName() const {
#ifdef PD_HASHID_KEEP_STR
return pName;
#else
return std::format("hash({:#08x})", pID);
#endif
}
operator T() const { return pID; }
// operator std::string() const { return GetName(); }
private:
T pID;
#ifdef PD_HASHID_KEEP_STR
str pName;
#endif
};
using HashID32 = HashID<u32>;
using HashID64 = HashID<u64>;
} // namespace PD
+6 -6
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -35,28 +35,28 @@ namespace IO {
* @param path Path to the File
* @return 8Bit FileBuffer
*/
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
PD_API std::vector<u8> LoadFile2Mem(const std::string& path);
/**
* Load a File into a std::string
* @param path Path to the File
* @return std::string file content
*/
PD_CORE_API std::string LoadFile2Str(const std::string& path);
PD_API std::string LoadFile2Str(const std::string& path);
/**
* Hash a 8Bit Memory Buffer
* @param data 8Bit input Buffer
* @return 32Bit Hash
*/
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
PD_API u32 HashMemory(const std::vector<u8>& data);
/**
* Function to decrompress RLE buffer
* @param data Data buffer to decompress
*/
PD_CORE_API void DecompressRLE(std::vector<u8>& data);
PD_API void DecompressRLE(std::vector<u8>& data);
/**
* Function to compress data with RLE Algorithm
* @param data Data buf
*/
PD_CORE_API void CompressRLE(std::vector<u8>& data);
PD_API void CompressRLE(std::vector<u8>& data);
} // namespace IO
} // namespace PD
+2 -3
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +40,7 @@ constexpr float Radians(float v) { return v * (Numbers::Tau / 360.0f); }
* @note That this is not a full Matrix Library
*/
struct PD_CORE_API Mat4 {
struct PD_API Mat4 {
std::array<float, 16> m;
constexpr Mat4() : m{} {}
constexpr static Mat4 Diagonal(float x, float y, float z, float w) {
-51
View File
@@ -1,51 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
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.
*/
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_CORE_BUILD_SHARED
#define PD_CORE_API __declspec(dllexport)
#else
#define PD_CORE_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_CORE_BUILD_SHARED
#define PD_CORE_API __attribute__((visibility("default")))
#else
#define PD_CORE_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_CORE_BUILD_SHARED
#define PD_CORE_API __attribute__((visibility("default")))
#else
#define PD_CORE_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_CORE_API
#else
#define PD_CORE_API
#endif
-71
View File
@@ -1,71 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
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 <pd/core/common.hpp>
#include <pd/core/sl/list.hpp>
#include <pd/core/sl/pair.hpp>
namespace PD {
template <typename K, typename V, size_t bucket_count = 10>
class HashMap {
public:
HashMap() {}
~HashMap() {}
void Insert(const K& k, const V& v) {
size_t idx = Hash(k);
auto& bukket = pBuckets[idx];
for (auto& it : bukket) {
if (it.First == k) {
it.Second = v;
return;
}
}
bukket.PushBack(Pair(k, v));
}
bool Contains(const K& k) const {
size_t idx = Hash(k);
auto& bukket = pBuckets[idx];
for (auto& it : bukket) {
if (it.First == k) {
return true;
}
}
return false;
}
void Clear() {
for (size_t i = 0; i < bucket_count; i++) {
pBuckets[i].Clear();
}
}
size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; }
PD::List<PD::Pair<K, V>> pBuckets[bucket_count];
};
} // namespace PD
-210
View File
@@ -1,210 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
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 <pd/core/common.hpp>
namespace PD {
template <typename T>
class List {
public:
List() {}
~List() {}
struct Node {
Node(const T& v) : Data(v) {}
T Data;
Node* Prev = nullptr;
Node* Next = nullptr;
};
class Iterator {
public:
Iterator(Node* n) : pNode(n) {}
T& operator*() { return pNode->Data; }
Iterator& operator++() {
pNode = pNode->Next;
return *this;
}
bool operator!=(const Iterator& o) const { return pNode != o.pNode; }
Node* pNode = nullptr;
};
void PushFront(const T& val) {
Node* node = new Node(val);
// node->Data = val;
node->Prev = nullptr;
node->Next = pHead;
if (pHead) {
pHead->Prev = node;
}
pHead = node;
if (!pTail) {
pTail = node;
}
pSize++;
}
void PushBack(const T& val) {
Node* node = new Node(val);
// node->Data = val;
node->Prev = pTail;
node->Next = nullptr;
if (pTail) {
pTail->Next = node;
}
pTail = node;
if (!pHead) {
pHead = node;
}
pSize++;
}
void PopFront() {
if (!pHead) {
return;
}
Node* t = pHead;
pHead = pHead->Next;
if (pHead) {
pHead->Prev = nullptr;
} else {
pTail = nullptr;
}
delete t;
pSize--;
}
void PopBack() {
if (!pTail) {
return;
}
Node* t = pTail;
pTail = pTail->Prev;
if (pTail) {
pTail->Next = nullptr;
} else {
pHead = nullptr;
}
delete t;
pSize--;
}
void Clear() {
while (pHead) {
PopFront();
}
}
void Remove(const T& v) {
Node* s = pHead;
while (s) {
if (s->Data == v) {
if (s->Prev) {
s->Prev->Next = s->Next;
} else {
pHead = s->Next;
}
if (s->Next) {
s->Next->Prev = s->Prev;
} else {
pTail = s->Prev;
}
delete s;
pSize--;
return;
}
s = s->Next;
}
}
void Reverse() {
Node* cur = pHead;
while (cur) {
Node* temp = cur->Prev;
cur->Prev = cur->Next;
cur->Next = temp;
cur = cur->Prev;
}
Node* temp = pHead;
pHead = pTail;
pTail = temp;
}
T& Front() {
if (pHead) {
return pHead->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
const T& Front() const {
if (pHead) {
return pHead->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
T& Back() {
if (pTail) {
return pTail->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
const T& Back() const {
if (pTail) {
return pTail->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
size_t Size() const { return pSize; }
Iterator begin() { return Iterator(pHead); }
Iterator end() { return Iterator(nullptr); }
private:
Node* Find(const T& v) const {
Node* t = pHead;
while (t) {
if (t->Data == v) {
return t;
}
t = t->Next;
}
return nullptr;
}
Node* pHead = nullptr;
Node* pTail = nullptr;
size_t pSize = 0;
};
} // namespace PD
-43
View File
@@ -1,43 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
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 <pd/core/common.hpp>
namespace PD {
/**
* Function to get Arraysize for any type using modern c++ to
* get the size at compiletime instead of runtime
* @note this function only works for Arrays declared as
* type arr[size] and not for pointer references.
* This function will precalculate the size at compile time
* while keeping the code clean to not hardcode arraysizes
* into functions like std::fill_n
*/
template <typename T, size_t N>
constexpr size_t ArraySize(T (&)[N]) noexcept {
return N;
}
} // namespace PD
-165
View File
@@ -1,165 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
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 <pd/core/common.hpp>
#include <pd/core/sl/allocator.hpp>
namespace PD {
/**
* Open Access Vector class (Alternative to std::vector)
*/
template <typename T, typename Alloc = Allocator<T>>
class Vec {
public:
Vec() {
pData = pAllocator.Allocate(2);
pCap = 2;
Clear();
pPos = 0;
};
Vec(const size_t& Size) {
pData = pAllocator.Allocate(Size + 2);
pCap = Size + 2;
Clear();
pPos = Size;
}
Vec(const size_t& Size, const T& v) {
pData = pAllocator.Allocate(Size + 2);
pCap = Size + 2;
Clear();
pPos = Size;
std::fill_n(pData, Size, v);
}
Vec(const T* s, const T* e) {
pData = pAllocator.Allocate(2);
pCap = 2;
Clear();
pPos = 0;
Resize(e - s);
std::copy_n(s, e - s, pData);
}
Vec(const Vec& v) {
pCap = v.pCap;
pPos = v.pPos;
pData = pAllocator.Allocate(pCap);
for (size_t i = 0; i < pPos; i++) {
pData[i] = v.pData[i];
}
}
~Vec() { pAllocator.Deallocate(pData); }
void Add(const T& v) {
if (pPos >= pCap) {
Reserve(pCap * 2);
}
pData[pPos++] = v;
}
void PopBack() {
if (pPos == 0) return;
pPos--;
}
T Pop() {
if (pPos == 0) {
// Todo: LOG
exit(1);
}
return pData[pPos--];
}
T& At(const size_t& Idx) {
if (Idx >= pPos) {
// Log
exit(1);
}
return pData[Idx];
}
const T& At(const size_t& Idx) const {
if (Idx >= pPos) {
// Log
exit(1);
}
return pData[Idx];
}
T& operator[](const size_t& Idx) { return At(Idx); }
const T& operator[](const size_t& Idx) const { return At(Idx); }
void operator+=(T v) { Add(v); }
T* Begin() { return pData; }
const T* Begin() const { return pData; }
T* End() { return pData + pPos; }
const T* End() const { return pData + pPos; }
// Support: `for(auto& it : Vec)` //
T* begin() { return pData; }
const T* begin() const { return pData; }
T* end() { return pData + pPos; }
const T* end() const { return pData + pPos; }
T* Data() { return pData; }
T* Data() const { return pData; }
size_t Size() const { return pPos; }
size_t Capacity() const { return pCap; }
void Clear() {
// Avoid memset to support std::string for now
// probably revert this decision based if it lacks performance
// or make it a setting
std::fill(pData, pData + pCap, T());
pPos = 0;
}
void Reserve(const size_t& Size) {
if (Size <= pCap) return;
T* tmp = pAllocator.Allocate(Size);
std::fill(tmp, tmp + Size, T());
std::copy(pData, pData + pCap, tmp);
pAllocator.Deallocate(pData);
pData = tmp;
pCap = Size;
}
void Resize(size_t Size) {
if (Size < pPos) {
pPos = Size;
} else if (Size > pCap) {
Reserve(Size);
}
std::fill(pData + pPos, pData + Size, T());
pPos = Size;
}
// Allocator
Alloc pAllocator;
// Data Reference Pointer
T* pData;
// Capacity
size_t pCap;
// Current Position (Size)
size_t pPos;
};
} // namespace PD
Executable → Regular
+17 -10
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -30,13 +30,20 @@ namespace PD {
* Set of String Utillity Functions
*/
namespace Strings {
constexpr int HexChar2Int(char c) {
/** Imagine man hat ne lookup table dafür verwendet :/ */
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
if (c >= 'A' && c <= 'F') return 10 + (c - 'A');
return -1; // Error
}
/**
* Check if a String ends with a specific extension
* @param str Input string
* @param exts List of Extensions to check for
* @return true if one of the extensions is found in the String
*/
PD_CORE_API bool StringEndsWith(const std::string& str,
PD_API bool StringEndsWith(const std::string& str,
const std::vector<std::string>& exts);
/**
* Function to Create a wstring of a string
@@ -44,39 +51,39 @@ PD_CORE_API bool StringEndsWith(const std::string& str,
* @return Result wstring
* @note Returns Empty if it has an error
*/
PD_CORE_API std::wstring MakeWstring(const std::string& s);
PD_API std::wstring MakeWstring(const std::string& s);
/**
* Generate a Formatted String by an Nanoseconds Input
* @param nanos Nanoseconds Input
* @return Result String
*/
PD_CORE_API const std::string FormatNanos(unsigned long long nanos);
PD_API const std::string FormatNanos(unsigned long long nanos);
/**
* Generate a Formatted String by an Milliseconds Input
* @param millis Milliseconds Input
* @return Result String
*/
PD_CORE_API const std::string FormatMillis(unsigned long long millis);
PD_API const std::string FormatMillis(unsigned long long millis);
/**
* Create a formatted String by an input bytes value
* @param bytes value in bytes
* @result Formatted String for example `2.5MB`
*/
PD_CORE_API const std::string FormatBytes(unsigned long long bytes);
PD_API const std::string FormatBytes(unsigned long long bytes);
/**
* Extract the Filename out of a Path
* @param path Path to extract from
* @param saperators Path Split Chars
* @return extracted filename
*/
PD_CORE_API const std::string GetFileName(
const std::string& path, const std::string& saperators = "/\\");
PD_API const std::string GetFileName(const std::string& path,
const std::string& saperators = "/\\");
/**
* Remove Extension from a Path / Filename
* @param path Input Path
* @return Path without Extension
*/
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
PD_API const std::string PathRemoveExtension(const std::string& path);
/**
* Function to Convert a Type to a hex value
* @tparam T Type
@@ -94,7 +101,7 @@ inline const std::string ToHex(const T& v) {
* @param s String to hash
* @return 32Bit Hash
*/
PD_CORE_API u32 FastHash(const std::string& s);
PD_API u32 FastHash(const std::string& s);
/**
* Function to Generate a Compiler Name and Version String
* Based on their Macros
+6 -3
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,16 +26,17 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
class OsDriver;
/**
* Timer class
*/
class PD_CORE_API Timer {
class PD_API Timer {
public:
/**
* Constructor
* @param auto_start [default true] sets if timer should start after creation
*/
Timer(bool auto_start = true);
Timer(OsDriver& os, bool auto_start = true);
/**
* Unused Deconstructor
*/
@@ -81,5 +82,7 @@ class PD_CORE_API Timer {
u64 pNow;
/** Is Running */
bool pIsRunning = false;
/** Os Driver reference */
OsDriver& pOs;
};
} // namespace PD
Executable → Regular
+13 -7
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
class OsDriver;
/**
* Class to calculate Maximum/Minimum and Average Timings
*/
@@ -182,6 +183,7 @@ class Res {
*/
void SetEnd(u64 v) {
end = v;
diff = end - start;
protocol->Add(GetLastDiff());
}
/**
@@ -194,7 +196,7 @@ class Res {
* Get Last Diffrence between end and start
* @return end - start
*/
u64 GetLastDiff() { return end - start; }
u64 GetLastDiff() { return diff; }
/**
* Get Protcol Reference
* @return Protocol Ref
@@ -208,6 +210,8 @@ class Res {
u64 start;
/** End Time */
u64 end;
/** Last Diff */
u64 diff;
/** Protocol */
TimeStats::Ref protocol;
};
@@ -215,12 +219,12 @@ class Res {
* Begin a Trace
* @param id Name of the Trace
*/
PD_CORE_API void Beg(const std::string &id);
PD_API void Beg(OsDriver& os, const std::string& id);
/**
* End a Trace
* @param id Name of the Trace
*/
PD_CORE_API void End(const std::string &id);
PD_API void End(OsDriver& os, const std::string& id);
/**
* Collect Start end end of the trace by tracking
* when the Scope object goes out of scope
@@ -242,18 +246,20 @@ class Scope {
* Constructor requiring a Name for the Trace
* @param id Name of the Trace
*/
Scope(const std::string &id) {
Scope(OsDriver& os, const std::string& id) : pOs(os) {
this->ID = id;
Beg(id);
Beg(pOs, id);
}
/**
* Deconstructor getting the end time when going out of scope
*/
~Scope() { End(ID); }
~Scope() { End(pOs, ID); }
private:
/** Trace Name/ID */
std::string ID;
/** Os Driver Reference */
OsDriver& pOs;
};
} // namespace TT
} // namespace PD
+12 -12
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -60,7 +60,7 @@ class Tween {
* @param delta deltatime
*/
void Update(float delta) {
time += delta / 1000.f;
time += delta * 0.001f;
if (time > tend) {
finished = true;
time = tend;
@@ -162,10 +162,10 @@ class Tween {
return -(end - start) * t * (t - 2) + start;
break;
case EaseInOutQuad:
t = time / (tend / 2);
if (t < 1) return (end - start) / 2 * t * t + start;
t = time / (tend * 0.5f);
if (t < 1) return (end - start) * 0.5f * t * t + start;
t--;
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
return -(end - start) * 0.5f * (t * (t - 2) - 1) + start;
break;
case EaseInCubic:
t = time / tend;
@@ -177,20 +177,20 @@ class Tween {
return (end - start) * (t * t * t + 1) + start;
break;
// case EaseInOutCubic:
// t = time / (tend / 2);
// if (t < 1) return (end - start) / 2 * t * t * t + start;
// t = time / (tend *0.5f);
// if (t < 1) return (end - start) *0.5f * t * t * t + start;
// t--;
// return (end - start) / 2 * (t * t * t * 2) + start;
// return (end - start) *0.5f * (t * t * t * 2) + start;
// break;
case EaseInSine:
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
start;
return -(end - start) * cos(time / tend * (M_PI * 0.5f)) +
(end - start) + start;
break;
case EaseOutSine:
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
return (end - start) * sin(time / tend * (M_PI * 0.5f)) + start;
break;
case EaseInOutSine:
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
return -(end - start) * 0.5f * (cos(M_PI * time / tend) - 1) + start;
break;
default: // Linear
@@ -28,18 +28,18 @@ class u128 {
return u128();
}
u128 operator+(const u128& v) const {
constexpr u128 operator+(const u128& v) const {
u128 ret;
ret.pLow = pLow + v.pLow;
ret.pHigh = pHigh + v.pHigh + (ret.pLow < pLow);
return ret;
}
u128 operator&(const u128& v) const {
constexpr u128 operator&(const u128& v) const {
return u128(pLow & v.pLow, pHigh & v.pHigh);
}
u128 operator<<(u32 s) const {
constexpr u128 operator<<(u32 s) const {
if (s == 0) {
return *this;
}
@@ -52,7 +52,7 @@ class u128 {
return u128(pLow << s, (pHigh << s) | (pLow >> (64 - s)));
}
u128 operator>>(u32 s) const {
constexpr u128 operator>>(u32 s) const {
if (s == 0) {
return *this;
}
@@ -65,23 +65,23 @@ class u128 {
return u128((pLow >> s) | (pHigh << (64 - s)), pHigh >> s);
}
u128& operator|=(const u128& v) {
constexpr u128& operator|=(const u128& v) {
pLow |= v.pLow;
pHigh |= v.pHigh;
return *this;
}
u128 operator|(const u128& v) const {
constexpr u128 operator|(const u128& v) const {
return u128(pLow | v.pLow, pHigh | v.pHigh);
}
u128& operator&=(const u128& v) {
constexpr u128& operator&=(const u128& v) {
pLow &= v.pLow;
pHigh &= v.pHigh;
return *this;
}
u128 operator~() const { return u128(~pLow, ~pHigh); }
constexpr u128 operator~() const { return u128(~pLow, ~pHigh); }
/**
* Old why to make if checks possible
@@ -92,7 +92,7 @@ class u128 {
// return pLow & v.pLow || pHigh & v.pHigh;
// }
bool operator==(const u128& v) const {
constexpr bool operator==(const u128& v) const {
return pLow == v.pLow && pHigh == v.pHigh;
}
@@ -100,12 +100,14 @@ class u128 {
* Use explicit here to make sure it is only for checking and not for
* some error leading implicit bool assignments...
*/
explicit operator bool() const { return pLow != 0 || pHigh != 0; }
constexpr explicit operator bool() const { return pLow != 0 || pHigh != 0; }
/** Deprecated way to handle `flag & SomeFlag` */
bool Has(const u128& v) const { return pLow & v.pLow || pHigh & v.pHigh; }
constexpr bool Has(const u128& v) const {
return pLow & v.pLow || pHigh & v.pHigh;
}
bool operator!=(const u128& v) const { return !(*this == v); }
constexpr bool operator!=(const u128& v) const { return !(*this == v); }
};
} // namespace PD
+1 -2
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+79
View File
@@ -0,0 +1,79 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
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 <pd/core/core.hpp>
#include <pd/drivers/gfx.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/drivers/os.hpp>
namespace PD {
class PD_API Context {
public:
Context()
: pOs(OsDriver::New()), pGfx(GfxDriver::New()), pHid(HidDriver::New()) {}
~Context() {}
PD_RAW(Context);
static Context::Ref Create();
template <typename Driver>
void UseGfxDriver(PDDriverData data) {
static_assert(std::is_base_of<GfxDriver, Driver>::value,
"Driver must extend GfxDriver");
pGfx.reset();
pGfx = Driver::New(data);
}
template <typename Driver>
void UseHidDriver(PDDriverData data) {
static_assert(std::is_base_of<HidDriver, Driver>::value,
"Driver must extend HidDriver");
pHid.reset();
pHid = Driver::New(data);
}
template <typename Driver>
void UseOsDriver(PDDriverData data) {
static_assert(std::is_base_of<OsDriver, Driver>::value,
"Driver must extend OsDriver");
pOs.reset();
pOs = Driver::New(data);
}
PD::Li::Texture::Ref GetSolidTex();
OsDriver::Ref Os() { return pOs; }
GfxDriver::Ref Gfx() { return pGfx; }
HidDriver::Ref Hid() { return pHid; }
private:
OsDriver::Ref pOs = nullptr;
GfxDriver::Ref pGfx = nullptr;
HidDriver::Ref pHid = nullptr;
PD::Li::Texture::Ref pSolidTex = nullptr;
};
} // namespace PD
+2 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/drivers/context.hpp>
#include <pd/drivers/gfx.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/drivers/os.hpp>
+35 -34
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,6 +24,7 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/drivers/types.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/texture.hpp>
@@ -34,9 +35,35 @@ enum LiBackendFlags_ {
};
namespace PD {
// The backend api nobody asked for
class GfxDriver2 {
public:
GfxDriver2(const std::string& name = "NullGfx") : pName(name) {};
~GfxDriver2() = default;
virtual void Init() {}
virtual void Deinit() {}
virtual void Draw(const PD::Li::CmdPool& pool) {}
virtual void TexBind(PD::Li::TexAddress addr) {}
virtual PD::Li::TexAddress TexLoad(
const std::vector<PD::u8>& pixels, int w, int h,
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
PD::Li::Texture::Filter filter = PD::Li::Texture::Filter::LINEAR) {
return 0;
}
virtual void TexDelete(PD::Li::TexAddress tex) {}
protected:
const std::string pName;
LiBackendFlags pFlags = 0;
size_t CurrentIndex = 0;
size_t CurrentVertex = 0;
ivec2 ViewPort;
};
class GfxDriver {
public:
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};
GfxDriver(const std::string& name = "NullGfx") : pName(name) {}
GfxDriver(PDDriverData data) : pName("NullGfx") {}
~GfxDriver() = default;
PD_SHARED(GfxDriver);
@@ -49,9 +76,10 @@ class GfxDriver {
virtual void BindTex(Li::TexAddress addr) {}
virtual void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {}
virtual void RenderDrawData(const Li::CmdPool& Commands) {}
void SetViewPort(const ivec2& vp) { ViewPort = vp; }
void SetViewPort(int w, int h) { ViewPort = PD::ivec2(w, h); }
virtual Li::Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
@@ -61,8 +89,12 @@ class GfxDriver {
return nullptr;
}
virtual void DestroyTex(PD::Li::Texture::Ref tex) {}
Li::Texture::Ref GetSolidTex() { return pSolid; }
const std::string& GetName() const { return pName; }
const std::string pName = "NullGfx";
LiBackendFlags Flags = 0;
ivec2 ViewPort;
@@ -80,35 +112,4 @@ class GfxDriver {
// Optional Frame Counter
u64 FrameCounter;
};
/** Static Gfx Controller */
class Gfx {
public:
Gfx() = default;
~Gfx() = default;
static void Init(GfxDriver::Ref d);
static void Deinit() { pGfx->Deinit(); }
static void NewFrame() { pGfx->NewFrame(); }
static void BindTex(Li::TexAddress addr) { pGfx->BindTex(addr); }
static void SetViewPort(const ivec2& vp) { pGfx->SetViewPort(vp); }
static void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {
pGfx->RenderDrawData(Commands);
}
static LiBackendFlags Flags() { return pGfx->Flags; }
static Li::Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
Li::Texture::Type type = Li::Texture::Type::RGBA32,
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
return pGfx->LoadTex(pixels, w, h, type, filter);
}
static Li::Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
static GfxDriver::Ref pGfx;
};
} // namespace PD
+11 -40
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,6 +24,7 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/drivers/types.hpp>
namespace PD {
/** Did not found a better solution yet sadly */
@@ -82,7 +83,8 @@ constexpr static KbKey Kb_F11 = KbKey::Flag(47);
constexpr static KbKey Kb_F12 = KbKey::Flag(48);
constexpr static KbKey Kb_MouseLeft = KbKey::Flag(120);
} // namespace HidKb
class HidDriver {
class PD_API HidDriver {
public:
enum Flags : u32 {
Flags_None = 0,
@@ -134,7 +136,8 @@ class HidDriver {
Event_Up, ///< Key released
};
HidDriver(const std::string& name = "NullHid") : pName(name) {};
HidDriver(const std::string& name = "NullHid") : pName(name) {}
HidDriver(PDDriverData data) : pName("NullHid") {}
virtual ~HidDriver() = default;
PD_SHARED(HidDriver);
@@ -233,6 +236,8 @@ class HidDriver {
*/
virtual void GetInputStr(std::string& str) {}
const std::string& GetName() const { return pName; }
/** Data Section */
/** Backend Identification Name */
@@ -255,42 +260,8 @@ class HidDriver {
/** Keyboard Key Event Table Setup */
std::unordered_map<Event, u128> KbKeyEvents[2];
};
/** Static Hid Controller */
class Hid {
public:
Hid() = default;
~Hid() = default;
/** Referenec to Drivers enums */
using Key = HidDriver::Key;
using KbKey = HidKb::KbKey;
namespace Hid {
using Event = HidDriver::Event;
static void Init(HidDriver::Ref v = nullptr) {
if (v) {
pHid = v;
} else {
pHid = HidDriver::New();
}
}
static bool IsEvent(Event e, Key keys) { return pHid->IsEvent(e, keys); }
static bool IsEvent(Event e, KbKey key) { return pHid->IsEvent(e, key); }
static bool IsDown(Key keys) { return pHid->IsDown(keys); }
static bool IsUp(Key keys) { return pHid->IsUp(keys); }
static bool IsHeld(Key keys) { return pHid->IsHeld(keys); }
static fvec2 MousePos() { return pHid->MousePos(); }
static fvec2 MousePosLast() { return pHid->MousePosLast(); }
static void Clear() { pHid->Clear(); }
static void Lock() { pHid->Lock(); }
static void Lock(bool v) { pHid->Lock(v); }
static void Unlock() { pHid->Unlock(); }
static bool Locked() { return pHid->Locked(); }
static void Update() { pHid->Update(); }
static u32 GetFlags() { return pHid->Flags; }
static void GetStrInput(std::string& str) { pHid->GetInputStr(str); }
static HidDriver::Ref pHid;
};
using Key = HidDriver::Key;
} // namespace Hid
} // namespace PD
+9 -27
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,13 +25,16 @@ SOFTWARE.
#include <pd/core/common.hpp>
#include <pd/core/timetrace.hpp>
#include <pd/drivers/types.hpp>
#include <pd/pd_p_api.hpp>
namespace PD {
using TraceMap = std::map<std::string, TT::Res::Ref>;
class OsDriver {
class PD_API OsDriver {
public:
OsDriver() = default;
OsDriver(const std::string& name = "StdPd") : pName(name) {}
OsDriver(PDDriverData data) : pName("StdPd") {}
virtual ~OsDriver() = default;
PD_SHARED(OsDriver);
@@ -40,32 +43,11 @@ class OsDriver {
TraceMap& GetTraceMap();
TT::Res::Ref& GetTraceRef(const std::string& id);
bool TraceExist(const std::string& id);
const std::string& GetName() const { return pName; }
TraceMap pTraces;
};
/** Static Os Controller */
class OS {
public:
OS() = default;
~OS() = default;
static void Init(OsDriver::Ref v = nullptr) {
if (v) {
pOs = v;
} else {
pOs = OsDriver::New();
}
}
static u64 GetTime() { return pOs->GetTime(); }
static u64 GetNanoTime() { return pOs->GetNanoTime(); }
static TraceMap& GetTraceMap() { return pOs->GetTraceMap(); }
static TT::Res::Ref& GetTraceRef(const std::string& id) {
return pOs->GetTraceRef(id);
}
static bool TraceExist(const std::string& id) { return pOs->TraceExist(id); }
static OsDriver::Ref pOs;
private:
const std::string pName = "StdPd";
};
} // namespace PD
+15 -11
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,18 +23,23 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/core.hpp>
namespace PD {
template <typename T1, typename T2>
class Pair {
class Snd {
public:
Pair() = default;
Pair(const T1& f, const T2& s) : First(f), Second(s) {}
Pair(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {}
~Pair() = default;
Snd(const std::string& name = "NullSnd") : pName(name) {};
~Snd() = default;
T1 First;
T2 Second;
PD_SHARED(Snd);
virtual void Init() {}
virtual void Deinit() {}
virtual bool Done(int buf_idx) {}
virtual void Update(int buf_idx, void* data) {}
virtual bool IsChannelPlaying(int chn) {}
virtual bool IsChannelPaused(int chn) {}
const std::string pName = "NullSnd";
};
} // namespace PD
+3
View File
@@ -0,0 +1,3 @@
#pragma once
using PDDriverData = void*;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,10 +24,10 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/image/pd_p_api.hpp>
#include <pd/pd_p_api.hpp>
namespace PD {
class PD_IMAGE_API Image {
class PD_API Image {
public:
enum Format {
RGBA, // bpp == 4
@@ -57,6 +56,7 @@ class PD_IMAGE_API Image {
int Width() const { return pWidth; }
int Height() const { return pHeight; }
ivec2 Size() const { return ivec2(pWidth, pHeight); }
Format Fmt() const { return pFmt; }
void FlipVertical();
Executable → Regular
+5 -6
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,7 +24,7 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/image/pd_p_api.hpp>
#include <pd/pd_p_api.hpp>
namespace PD {
/**
@@ -38,7 +37,7 @@ namespace ImgBlur {
* @param si sigma value to use
* @return list of kernel values
*/
PD_IMAGE_API std::vector<float> GaussianKernel(int radius, float si);
PD_API std::vector<float> GaussianKernel(int radius, float si);
/**
* Gaussian Blur for basic Image Buffer
* @param buf Image Buffer (unsigned char)
@@ -48,7 +47,7 @@ PD_IMAGE_API std::vector<float> GaussianKernel(int radius, float si);
* @param si Blur sigma
* @param idxfn Indexing function
*/
PD_IMAGE_API void GaussianBlur(
PD_API void GaussianBlur(
std::vector<u8>& buf, int w, int h, float radius, float si,
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
return y * w + x;
@@ -63,7 +62,7 @@ PD_IMAGE_API void GaussianBlur(
* @param si Blur sigma
* @param idxfn Indexing function
*/
PD_IMAGE_API void GaussianBlur(
PD_API void GaussianBlur(
void* buf, int w, int h, int bpp, float radius, float si,
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
return y * w + x;
Executable → Regular
+6 -30
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +25,7 @@ SOFTWARE.
#include <pd/core/core.hpp>
#include <pd/image/image.hpp>
#include <pd/image/pd_p_api.hpp>
#include <pd/pd_p_api.hpp>
namespace PD {
/**
@@ -41,10 +40,10 @@ namespace ImgConvert {
* @param w width of the image
* @param h height of the image
*/
PD_IMAGE_API
PD_API
void RGB24toRGBA32(std::vector<PD::u8>& out, const std::vector<u8>& in,
const int& w, const int& h);
PD_IMAGE_API
PD_API
void RGB32toRGBA24(std::vector<u8>& out, const std::vector<u8>& in,
const int& w, const int& h);
/**
@@ -53,30 +52,7 @@ void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in,
* @param w width
* @param h height
*/
PD_IMAGE_API void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
PD_IMAGE_API void ReverseBuf(std::vector<u8> &buf, size_t bpp, int w, int h);
/**
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
* to every pixel
* @param out Result List
* @param in Input Buffer List (rgb24)
* @param w width of the image
* @param h height of the image
*/
PD_IMAGE_API
void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
const int &h);
PD_IMAGE_API
void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
const int &h);
/**
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
* @param buf Buffer to convert
* @param w width
* @param h height
*/
PD_IMAGE_API void Reverse32(PD::Vec<u8> &buf, const int &w, const int &h);
PD_IMAGE_API void ReverseBuf(PD::Vec<u8> &buf, size_t bpp, int w, int h);
PD_API void Reverse32(std::vector<u8>& buf, const int& w, const int& h);
PD_API void ReverseBuf(std::vector<u8>& buf, size_t bpp, int w, int h);
} // namespace ImgConvert
} // namespace PD
-51
View File
@@ -1,51 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
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.
*/
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_IMAGE_BUILD_SHARED
#define PD_IMAGE_API __declspec(dllexport)
#else
#define PD_IMAGE_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_IMAGE_BUILD_SHARED
#define PD_IMAGE_API __attribute__((visibility("default")))
#else
#define PD_IMAGE_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_IMAGE_BUILD_SHARED
#define PD_IMAGE_API __attribute__((visibility("default")))
#else
#define PD_IMAGE_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_IMAGE_API
#else
#define PD_IMAGE_API
#endif
Executable → Regular
+54 -9
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@ SOFTWARE.
#include <pd/core/core.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
#include <pd/pd_p_api.hpp>
namespace PD {
namespace Li {
@@ -34,25 +35,69 @@ class Command {
Command() = default;
~Command() = default;
PD_UNIQUE(Command);
PD_RAW(Command);
Command& AddIdx(const u16& idx) {
IndexBuffer.Add(VertexBuffer.Size() + idx);
IndexBuffer.push_back(VertexBuffer.size() + idx);
return *this;
}
Command& AddIdxs(const u16& a, const u16& b, const u16& c) {
IndexBuffer.push_back(VertexBuffer.size() + a);
IndexBuffer.push_back(VertexBuffer.size() + b);
IndexBuffer.push_back(VertexBuffer.size() + c);
return *this;
}
Command& AddVtx(const Vertex& v) {
VertexBuffer.Add(std::move(v));
VertexBuffer.push_back(std::move(v));
return *this;
}
PD::Vec<Vertex> VertexBuffer;
PD::Vec<u16> IndexBuffer;
void Clear() {
VertexBuffer.clear();
IndexBuffer.clear();
Index = 0;
Layer = 0;
Tex = 0;
ScissorOn = false;
ScissorRect = ivec4();
}
std::vector<Vertex> VertexBuffer;
std::vector<u16> IndexBuffer;
ivec4 ScissorRect;
bool ScissorOn = false;
int Layer;
int Index;
Texture::Ref Tex;
int Layer = 0;
int Index = 0;
TexAddress Tex;
};
class PD_API CmdPool {
public:
CmdPool() {}
~CmdPool() {}
Command::Ref NewCmd();
void Init(size_t initial_size);
void Deinit();
void Resize(size_t nulen);
void Reset();
Command::Ref GetCmd(size_t idx) const;
Command::Ref GetCmd(size_t idx);
size_t Size() const;
size_t Cap() const;
void Merge(CmdPool& p);
void Copy(CmdPool& p);
void Sort();
private:
static bool pTheOrder(const Command::Ref& a, const Command::Ref& b);
friend class DrawList;
Command::Ref* begin() { return &pPool[0]; }
Command::Ref* end() { return &pPool[pPoolIdx - 1]; }
std::vector<Command::Ref> pPool;
u32 pPoolIdx = 0;
int Layer = 0;
};
} // namespace Li
} // namespace PD
+48 -25
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +25,7 @@ SOFTWARE.
#include <pd/lithium/command.hpp>
#include <pd/lithium/font.hpp>
#include <pd/lithium/pd_p_api.hpp>
#include <pd/pd_p_api.hpp>
/** Path Rect Flags */
using LiPathRectFlags = PD::u32;
@@ -46,10 +45,10 @@ enum LiPathRectFlags_ : PD::u32 {
namespace PD {
namespace Li {
class PD_LITHIUM_API DrawList {
class PD_API DrawList {
public:
DrawList() { DrawSolid(); }
~DrawList() { pDrawList.clear(); }
DrawList(Context& ctx, int initial_size = 64);
~DrawList();
/** Require Copy and Move Constructors */
@@ -64,20 +63,35 @@ class PD_LITHIUM_API DrawList {
/**
* Append an input drawlist on top of this one
* This Function will clear the Input list to make sure
* THat the moved memory blocks don't get used
* That the moved memory blocks don't get used
* @param list DrawList to move into current
*/
void Merge(DrawList::Ref list);
/**
* Copy another drawlist to this drawist.
* This is important for static prerendered Drawlists
* @param list DrawList Reference to copy from
*/
void Copy(DrawList::Ref list);
/**
* Optimize a Drawlist to a more or less perfect order
* to reduce drawcall overhead... This function also uses
* the Layersystem to keep specific stuff in the correct order
*/
void Optimize();
Command::Ref PreGenerateCmd();
void AddCommand(Command::Ref v);
Command::Ref GetNewCmd();
void Clear();
void Layer(int l) { this->pPool.Layer = l; }
int Layer() { return this->pPool.Layer; }
void LayerUp() { this->pPool.Layer++; }
void LayerDown() { this->pPool.Layer--; }
void SetFont(Font::Ref font) { pCurrentFont = font; }
void SetFontScale(float scale) { pFontScale = scale; }
void DrawSolid();
void DrawTexture(Texture::Ref tex) { CurrentTex = tex; }
void DrawTexture(Texture::Ref tex);
// SECTION: Draw API //
@@ -97,7 +111,7 @@ class PD_LITHIUM_API DrawList {
* Extended Draw Text Function
*/
void DrawTextEx(const fvec2& p, const std::string& text, u32 color,
LiTextFlags flags, fvec2 box = fvec2(0.f));
LiTextFlags flags, const fvec2& box = fvec2(0.f));
void DrawLine(const fvec2& a, const fvec2& b, u32 color, int t = 1);
/**
* Take list of points and display it as a line on screen
@@ -106,7 +120,7 @@ class PD_LITHIUM_API DrawList {
* @param flags Additional Flags (Close for go back to starting point)
* @param thickness Thickness of the Line
*/
void DrawPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
void DrawPolyLine(const std::vector<fvec2>& points, u32 clr, u32 flags = 0,
int thickness = 1);
/**
* Take a List ofpoints and display it as Filled Shape
@@ -114,7 +128,7 @@ class PD_LITHIUM_API DrawList {
* @param points List of Points
* @param clr Color of the shape
*/
void DrawConvexPolyFilled(const Vec<fvec2>& points, u32 clr);
void DrawConvexPolyFilled(const std::vector<fvec2>& points, u32 clr);
// SECTION: PATH API //
@@ -124,20 +138,28 @@ class PD_LITHIUM_API DrawList {
* @param num_points Number of Positions you want to add
*/
void PathReserve(size_t num_points) {
pPath.Reserve(pPath.Size() + num_points);
pPath.reserve(pPath.size() + num_points);
}
/**
* Clear current Path
* @note PathStroke and PathFill will automatically clear
*/
void PathClear() { pPath.Clear(); }
void PathClear() { pPath.clear(); }
/**
* Add a Point to the Path
* @note Keep in mind that this function is used for
* setting the starting point
* @param v Position to add
*/
void PathAdd(const fvec2& v) { pPath.Add(v); }
void PathAdd(const fvec2& v) { pPath.push_back(v); }
/**
* Add a Point to the Path
* @note Keep in mind that this function is used for
* setting the starting point
* @param x X Position to add
* @param y Y Position to add
*/
void PathAdd(float x, float y) { pPath.push_back(fvec2(x, y)); }
/**
* Path Stroke Create Line from point to point
* @note For Primitives like Rect or Triangle mak sure to use
@@ -148,7 +170,7 @@ class PD_LITHIUM_API DrawList {
*/
void PathStroke(u32 clr, int thickness = 1, u32 flags = 0) {
DrawPolyLine(pPath, clr, flags, thickness);
pPath.Clear();
pPath.clear();
}
/**
* Fill a Path with a Color
@@ -158,7 +180,7 @@ class PD_LITHIUM_API DrawList {
*/
void PathFill(u32 clr) {
DrawConvexPolyFilled(pPath, clr);
pPath.Clear();
pPath.clear();
}
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
int segments);
@@ -175,27 +197,28 @@ class PD_LITHIUM_API DrawList {
/// @param flags DrawFlags (for special rounding rules)
void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
void PushClipRect(const fvec4& cr) { pClipRects.Push(cr); }
void PushClipRect(const fvec4& cr) { pClipRects.push(cr); }
void PopClipRect() {
if (pClipRects.IsEmpty()) {
if (pClipRects.empty()) {
return;
}
pClipRects.Pop();
pClipRects.pop();
}
const CmdPool& Data() const { return pPool; }
/** One linear Clip rect Setup */
void pClipCmd(Command* cmd);
/** Data Section */
Stack<fvec4> pClipRects;
int Layer;
std::stack<fvec4> pClipRects;
float pFontScale = 0.7f;
Font::Ref pCurrentFont;
Texture::Ref CurrentTex;
std::vector<Command::Ref> pDrawList;
PD::Vec<fvec2> pPath;
CmdPool pPool;
std::vector<fvec2> pPath;
u32 pNumIndices = 0;
u32 pNumVertices = 0;
Context* pCtx = nullptr;
};
} // namespace Li
} // namespace PD
Executable → Regular
+27 -7
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,9 +25,9 @@ SOFTWARE.
#include <pd/core/core.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/pd_p_api.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/pd_p_api.hpp>
using LiTextFlags = PD::u32;
enum LiTextFlags_ {
@@ -39,11 +38,14 @@ enum LiTextFlags_ {
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
LiTextFlags_NoOOS = 1 << 6, ///< No Out of Screen Rendering
};
namespace PD {
class Context;
namespace Li {
class PD_LITHIUM_API Font {
class DrawList;
class PD_API Font {
public:
/** Codepoint Data holder */
struct Codepoint {
@@ -56,7 +58,7 @@ class PD_LITHIUM_API Font {
};
/** Constructore doesnt need Backand anymore */
Font() = default;
Font(Context& ctx) : pCtx(ctx) {}
~Font() = default;
PD_SHARED(Font);
@@ -92,15 +94,24 @@ class PD_LITHIUM_API Font {
/**
* Extended Draw Text Function that vreates a Command List
*/
void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text, LiTextFlags flags = 0,
void CmdTextEx(DrawList& dl, const fvec2& pos, u32 color, float scale,
const std::string& text, LiTextFlags flags = 0,
const fvec2& box = 0);
/**
* Garbage collection for TextMapSystem
*/
void CleanupTMS();
/**
* Utility function to create a font atlas
* During TTF loading (Internal and should not be called)
*/
void pMakeAtlas(bool final, std::vector<u8>& font_tex, int texszs,
PD::Li::Texture::Ref tex);
std::string pWrapText(const std::string& txt, float scale,
const PD::fvec2& max, PD::fvec2& dim);
std::string pShortText(const std::string& txt, float scale,
const PD::fvec2& max, PD::fvec2& dim);
/** Data Section */
int PixelHeight;
@@ -111,6 +122,15 @@ class PD_LITHIUM_API Font {
* **Now using unordered map**
*/
std::unordered_map<u32, Codepoint> CodeMap;
/** TMS */
struct TMELEM {
PD::u32 ID;
PD::fvec2 Size;
std::string Text;
u64 TimeStamp;
};
std::unordered_map<u32, TMELEM> pTMS;
Context& pCtx;
};
} // namespace Li
} // namespace PD
+1 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+1 -2
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
-51
View File
@@ -1,51 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
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.
*/
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_LITHIUM_BUILD_SHARED
#define PD_LITHIUM_API __declspec(dllexport)
#else
#define PD_LITHIUM_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_LITHIUM_BUILD_SHARED
#define PD_LITHIUM_API __attribute__((visibility("default")))
#else
#define PD_LITHIUM_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_LITHIUM_BUILD_SHARED
#define PD_LITHIUM_API __attribute__((visibility("default")))
#else
#define PD_LITHIUM_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_LITHIUM_API
#else
#define PD_LITHIUM_API
#endif
+3 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -131,6 +131,8 @@ class Rect {
return *this;
}
bool operator==(const Rect& r) const { return Top == r.Top && Bot == r.Bot; }
void SwapVec2XY() {
Top.SwapXY();
Top.SwapZW();
Executable → Regular
+8 -8
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,15 +24,15 @@ SOFTWARE.
*/
#include <pd/drivers/drivers.hpp>
#include <pd/lithium/pd_p_api.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/pd_p_api.hpp>
namespace PD {
namespace Li {
/**
* Static Class Render Setup Functions
*/
class PD_LITHIUM_API Renderer {
class PD_API Renderer {
public:
Renderer() = default;
~Renderer() = default;
@@ -46,10 +45,11 @@ class PD_LITHIUM_API Renderer {
u32 color);
static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b,
const fvec2 c, u32 clr);
static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
int thickness = 1);
static void CmdConvexPolyFilled(Command* cmd, const Vec<fvec2>& points,
u32 clr, Texture::Ref tex);
static void CmdPolyLine(const std::vector<fvec2>& points, u32 clr,
u32 flags = 0, int thickness = 1);
static void CmdConvexPolyFilled(Command* cmd,
const std::vector<fvec2>& points, u32 clr,
Texture::Ref tex);
// SECTION: InBounds Checks
+1 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+3 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -38,6 +38,8 @@ class Vertex {
}
~Vertex() {}
PD_RAW(Vertex);
// private:
/** Open Access Data Section */
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,28 +24,31 @@ SOFTWARE.
*/
/** Generated with ppam */
#ifndef PD_BUILD_STATIC
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_UI7_BUILD_SHARED
#define PD_UI7_API __declspec(dllexport)
#ifdef PD_BUILD_SHARED
#define PD_API __declspec(dllexport)
#else
#define PD_UI7_API __declspec(dllimport)
#define PD_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_UI7_BUILD_SHARED
#define PD_UI7_API __attribute__((visibility("default")))
#ifdef PD_BUILD_SHARED
#define PD_API __attribute__((visibility("default")))
#else
#define PD_UI7_API
#define PD_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_UI7_BUILD_SHARED
#define PD_UI7_API __attribute__((visibility("default")))
#ifdef PD_BUILD_SHARED
#define PD_API __attribute__((visibility("default")))
#else
#define PD_UI7_API
#define PD_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_UI7_API
#define PD_API
#else
#define PD_UI7_API
#define PD_API
#endif
#else
#define PD_API
#endif
+2 -2
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -35,7 +35,7 @@ namespace UI7 {
* This only means that InPressed is responding the info in
* the next frame
*/
class PD_UI7_API Button : public Container {
class PD_API Button : public Container {
public:
/**
* Button Object constructor
+2 -2
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +33,7 @@ namespace UI7 {
* Context::Update while the visual update is done
* during the Update
*/
class PD_UI7_API Checkbox : public Container {
class PD_API Checkbox : public Container {
public:
/**
* Constructor for Checkbox Object
+2 -2
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -32,7 +32,7 @@ namespace UI7 {
/**
* Color Editor (Creating a PopUP when clicking)
*/
class PD_UI7_API ColorEdit : public Container {
class PD_API ColorEdit : public Container {
public:
/**
* Constructor
+8 -3
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,8 +24,8 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/pd_p_api.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/pd_p_api.hpp>
namespace PD {
namespace UI7 {
@@ -33,7 +33,7 @@ namespace UI7 {
* Container base class all Objects are based on
* @note this class can be used to create custom Objects as well
*/
class PD_UI7_API Container {
class PD_API Container {
public:
Container() = default;
/**
@@ -113,6 +113,11 @@ class PD_UI7_API Container {
/** Template function to update internal data (if needed) */
virtual void Update() {}
/** Internal function */
void PreDraw();
/** Internal function */
void PostDraw();
/** Internal Input Handler */
void HandleInternalInput();
+2 -2
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +33,7 @@ namespace UI7 {
* and modifys these by moving left or right when dragging
*/
template <typename T>
class PD_UI7_API DragData : public Container {
class PD_API DragData : public Container {
public:
/**
* Constructor
+2 -3
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -36,7 +35,7 @@ namespace UI7 {
* This only means that InPressed is responding the info in
* the next frame
*/
class PD_UI7_API DynObj : public Container {
class PD_API DynObj : public Container {
public:
/**
* Button Object constructor
+10 -8
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -30,7 +30,7 @@ namespace UI7 {
/**
* Image Object
*/
class PD_UI7_API Image : public Container {
class PD_API Image : public Container {
public:
/**
* Constructor for the Image Object
@@ -39,13 +39,15 @@ class PD_UI7_API Image : public Container {
*/
Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0.f)) {
this->img = img;
this->newsize = size;
this->cuv = uv;
if (size.x != 0 || size.y != 0) {
this->SetSize(size);
} else {
this->SetSize(fvec2(img->GetSize().x, img->GetSize().y));
if (size == fvec2(0.f)) {
size = img->GetSize();
}
if (uv == Li::Rect(fvec4(0.f))) {
uv = img->GetUV();
}
this->cuv = uv;
this->newsize = size;
SetSize(size);
}
~Image() = default;
+6 -2
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -30,7 +30,7 @@ namespace UI7 {
/**
* Label [Text] Object
*/
class PD_UI7_API Label : public Container {
class PD_API Label : public Container {
public:
/**
* Constructor for Label Object
@@ -51,6 +51,10 @@ class PD_UI7_API Label : public Container {
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/**
* Override Update func to support Text modifications
*/
void Update() override;
private:
fvec2 tdim; ///< Text Size
+91
View File
@@ -0,0 +1,91 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
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 <pd/ui7/container/container.hpp>
#include <pd/ui7/io.hpp>
namespace PD {
namespace UI7 {
/**
* Slider Object can take a datatype or a list
* and modifys these by moving left or right when dragging
*/
template <typename T>
class PD_API Slider : public Container {
public:
/**
* Constructor
* @param label Label of the Button
* @param data Data reference (Supported types can be seen in Slider.cpp)
* @param num_elms Number of Array elements (for exaple with use ofvec4)
* @param io IO Reference
* @param min minimum number using Minimum limit
* @param max Maximum number set by max limit by default
* @param step To set the modifier for drag movement
* @param precision for float and double to set precision
*/
Slider(const std::string& label, T* data, UI7::IO::Ref io,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), int precision = 1) {
// PD::Assert(data != nullptr, "Input Data Address is null!");
this->label = label;
this->data = data;
this->min = min;
this->max = max;
this->precision = precision;
this->width = io->CurrentViewPort.z * 0.3f;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Slider() = default;
/** Als ob das funktioniert... */
PD_SHARED(Slider<T>);
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Function to Update Size if framepadding changes */
void Update() override;
private:
fvec2 tdim; ///< Text size
float width; ///< Size
std::string label; ///< Label of the Button
T* data;
T min;
T max;
int precision = 1;
float slw = 0.f; // silider drag width (calculated in update)
float slp = 0.f; // silider drag pos (calculated in update)
};
} // namespace UI7
} // namespace PD
+2 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -30,3 +30,4 @@ SOFTWARE.
#include <pd/ui7/container/dynobj.hpp>
#include <pd/ui7/container/image.hpp>
#include <pd/ui7/container/label.hpp>
#include <pd/ui7/container/slider.hpp>
+2 -1
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -49,6 +49,7 @@ enum UI7MenuFlags_ {
// POC
UI7MenuFlags_Maximize = 1 << 11, ///< Add a Maximize Button
UI7MenuFlags_Minimize = 1 << 12, ///< Add a Minimize Button
UI7MenuFlags_AlwaysAutoSize = 1 << 13, ///< Always Auto Resize Menu
// Enable Horizontal and Vertical Scrolling
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
};
+9 -6
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -38,6 +38,7 @@ class ID {
*/
ID(const std::string& text) {
pID = PD::Strings::FastHash(text);
// pStrName = text;
pName = text;
}
/**
@@ -45,8 +46,8 @@ class ID {
* used when directly placing a string istead of using ID("")
* @param text Input String
*/
ID(const char* text) {
pID = PD::Strings::FastHash(text);
constexpr ID(const char* text) {
pID = PD::FNV1A32(text);
pName = text;
}
/**
@@ -56,16 +57,18 @@ class ID {
~ID() = default;
/** Get The ID Initial Name */
const std::string& GetName() const { return pName; }
// constexpr const std::string_view& GetNameView() const { return pName; }
const std::string GetName() const { return std::string(pName); }
/** Getter for the raw 32bit int id */
const u32& RawID() const { return pID; }
constexpr const u32& RawID() const { return pID; }
/** Return the ID when casting to u32 */
operator u32() const { return pID; }
constexpr operator u32() const { return pID; }
u32 pID; ///< Hash of the name
std::string pName; ///< Name
// std::string pStrName; ///< Keep this stringview alive
};
} // namespace UI7
} // namespace PD
Executable → Regular
+16 -13
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,14 +25,16 @@ SOFTWARE.
#include <pd/core/core.hpp>
#include <pd/lithium/lithium.hpp>
#include <pd/pd_p_api.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/pd_p_api.hpp>
namespace PD {
namespace UI7 {
class InputHandler {
public:
InputHandler() { DragTime = Timer::New(false); }
InputHandler(PD::Context& ctx) : pCtx(ctx) {
DragTime = Timer::New(*pCtx.Os().get(), false);
}
~InputHandler() = default;
PD_SHARED(InputHandler);
@@ -56,10 +57,10 @@ class InputHandler {
}
}
// Get a Short define for touch pos
fvec2 p = Hid::MousePos();
fvec2 p = pCtx.Hid()->MousePos();
// Check if Drag starts in the area position
if ((Hid::IsDown(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Down, HidKb::Kb_MouseLeft)) &&
if ((pCtx.Hid()->IsDown(pCtx.Hid()->Key::Touch) ||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Down, HidKb::Kb_MouseLeft)) &&
Li::Renderer::InBox(p, area)) {
// Set ID and iniatial Positions
DraggedObject = id;
@@ -71,15 +72,16 @@ class InputHandler {
DragTime->Reset();
DragTime->Rseume();
return false; // To make sure the Object is "Dragged"
} else if ((Hid::IsHeld(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Held,
} else if ((pCtx.Hid()->IsHeld(pCtx.Hid()->Key::Touch) ||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Held,
HidKb::Kb_MouseLeft)) &&
IsObjectDragged()) {
// Update DragLast and DragPoisition
DragLastPosition = DragPosition;
DragPosition = p;
} else if ((Hid::IsUp(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Up, HidKb::Kb_MouseLeft)) &&
} else if ((pCtx.Hid()->IsUp(pCtx.Hid()->Key::Touch) ||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Up,
HidKb::Kb_MouseLeft)) &&
IsObjectDragged()) {
// Released... Everything gets reset
DraggedObject = 0;
@@ -89,9 +91,9 @@ class InputHandler {
DragDestination = fvec4(0);
// Set Drag released to true (only one frame)
// and Only if still in Box
DragReleased = Li::Renderer::InBox(Hid::MousePosLast(), area);
DragReleased = Li::Renderer::InBox(pCtx.Hid()->MousePosLast(), area);
DragReleasedAW = true; // Advanced
u64 d_rel = PD::OS::GetTime();
u64 d_rel = pCtx.Os()->GetTime();
if (d_rel - DragLastReleased < DoubleClickTime) {
DragDoubleRelease = true;
DragLastReleased = 0; // Set 0 to prevent double exec
@@ -130,6 +132,7 @@ class InputHandler {
bool DragReleased = false; ///< Drag Releaded in Box
bool DragReleasedAW = false; ///< Drag Released Anywhere
bool DragDoubleRelease = false; ///< Double Click
PD::Context& pCtx;
/** Check if an object is Dragged already */
bool IsObjectDragged() const { return DraggedObject != 0; }
};
Executable → Regular
+21 -17
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,26 +24,27 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/pd_p_api.hpp>
#include <pd/ui7/input_api.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/ui7/theme.hpp>
#include <pd/ui7/viewport.hpp>
namespace PD {
class Context;
namespace UI7 {
class PD_UI7_API IO {
class PD_API IO {
public:
IO() {
Time = Timer::New();
InputHandler = InputHandler::New();
IO(PD::Context& ctx) : pCtx(ctx) {
Time = Timer::New(*pCtx.Os().get());
InputHandler = InputHandler::New(pCtx);
Theme = UI7::Theme::New();
Back = Li::DrawList::New();
Front = Li::DrawList::New();
FDL = Li::DrawList::New();
Back = Li::DrawList::New(pCtx);
Front = Li::DrawList::New(pCtx);
FDL = Li::DrawList::New(pCtx);
DeltaStats = TimeStats::New(60);
/** Probably not the best solution i guess */
CurrentViewPort.z = PD::Gfx::pGfx->ViewPort.x;
CurrentViewPort.w = PD::Gfx::pGfx->ViewPort.y;
CurrentViewPort.z = pCtx.Gfx()->ViewPort.x;
CurrentViewPort.w = pCtx.Gfx()->ViewPort.y;
}
~IO() {}
@@ -73,25 +73,29 @@ class PD_UI7_API IO {
UI7::Theme::Ref Theme;
fvec2 MenuPadding = 5.f;
fvec2 FramePadding = 5.f;
float ItemRowHeight = 0.f;
float FrameRounding = 0.f;
fvec2 ItemSpace = vec2(5.f, 2.f);
fvec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)
bool ShowMenuBorder = true;
bool ShowFrameBorder = false; // not implemented yet
bool WrapLabels = false; // Beta state
float OverScrollMod = 0.15f;
u64 DoubleClickTime = 500; // Milliseconds
PD::List<Pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
std::list<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
// Short define for DrawKistRegestryLast
PD::List<Pair<UI7::ID, Li::DrawList::Ref>> pDLRL;
// std::vector<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
std::list<std::pair<UI7::ID, Li::DrawList::Ref>> pDLRL;
Li::DrawList::Ref Back;
Li::DrawList::Ref Front;
u32 NumVertices = 0; ///< Debug Vertices Num
u32 NumIndices = 0; ///< Debug Indices Num
Vec<u32> MenuOrder;
std::vector<u32> MenuOrder;
PD::Context& pCtx; // Palladium base context
// DrawListApi
void RegisterDrawList(const UI7::ID& id, Li::DrawList::Ref v) {
DrawListRegestry.PushBack(Pair(id, v));
DrawListRegestry.push_back(std::make_pair(id, v));
}
void AddViewPort(const ID& id, const ivec4& size) {
Executable → Regular
+79 -10
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,34 +24,101 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/pd_p_api.hpp>
#include <pd/ui7/container/container.hpp>
#include <pd/ui7/container/dragdata.hpp>
#include <pd/ui7/container/slider.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/input_api.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/ui7/theme.hpp>
namespace PD {
namespace UI7 {
class PD_UI7_API Layout {
class Context;
class PD_API Layout {
public:
Layout(const ID& id, IO::Ref io) : ID(id) {
this->IO = io;
DrawList = Li::DrawList::New();
DrawList = Li::DrawList::New(io->pCtx);
DrawList->SetFont(IO->Font);
DrawList->SetFontScale(io->FontScale);
Scrolling[0] = false;
Scrolling[1] = false;
CursorInit();
Pos = fvec2(io->CurrentViewPort.x, io->CurrentViewPort.y);
Size = fvec2(io->CurrentViewPort.z - io->CurrentViewPort.x,
io->CurrentViewPort.w - io->CurrentViewPort.y);
Size = 0;
WorkRect = fvec4(IO->MenuPadding, Size - (fvec2(2) * IO->MenuPadding));
}
~Layout() = default;
PD_SHARED(Layout);
const std::string& GetName() const { return ID.GetName(); }
/** SECTION CONTAINERS */
/**
* Render a Simple Label
* @param label The text to draw
*/
void Label(const std::string& label);
template <typename... Args>
void Label(std::format_string<Args...> s, Args&&... args) {
Label(std::format(s, std::forward<Args>(args)...));
}
/**
* Render a Button
* @param label The buttons text
* @return if the button was pressed
*/
bool Button(const std::string& label);
/**
* Render a Checkbox
* @param label Label of the Checkbox
* @param v A value to update
*/
void Checkbox(const std::string& label, bool& v);
/**
* Render an Image
* @param img Texture reference of the image
* @param size a Custom Size if needed
*/
void Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0));
/**
* Render a Drag Object witth any supported type:
* [`int`, `float`, `double`, `u8`, `u16`, `u32`]
* @param label Name of the Drag
* @param data Reference to Data Object (can be multiple as well)
* @param num_elements Defien the number of Elements in the Data addr
* @param precission Difine the Format string len for float/double
*/
template <typename T>
void DragData(const std::string& label, T* data, size_t num_elms = 1,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), T step = 1,
int precision = 1) {
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
Container::Ref r = FindObject(id);
if (!r) {
r = UI7::DragData<T>::New(label, data, num_elms, this->IO, min, max, step,
precision);
r->SetID(id);
}
AddObject(r);
}
template <typename T>
void Slider(const std::string& label, T* data,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), int precision = 1) {
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
Container::Ref r = FindObject(id);
if (!r) {
r = UI7::Slider<T>::New(label, data, this->IO, min, max, precision);
r->SetID(id);
}
AddObject(r);
}
/** SECTION OTHERSTUFF */
const std::string GetName() const { return ID.GetName(); }
const UI7::ID& GetID() const { return this->ID; }
const fvec2& GetPosition() const { return Pos; }
@@ -103,14 +169,17 @@ class PD_UI7_API Layout {
void Update();
fvec2 DbgScrollOffset() { return ScrollOffset; }
private:
friend class Menu;
friend class Context;
friend class PD::UI7::Context;
friend class ReMenu;
// Base Components
UI7::ID ID;
UI7::IO::Ref IO;
Li::DrawList::Ref DrawList;
UI7LayoutFlags Flags;
// Positioning
fvec2 Pos;
@@ -135,7 +204,7 @@ class PD_UI7_API Layout {
bool Scrolling[2];
// Objects
PD::List<Container::Ref> Objects;
std::list<Container::Ref> Objects;
std::vector<Container::Ref> IDObjects;
};
} // namespace UI7
Executable → Regular
+23 -4
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,15 +24,16 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/pd_p_api.hpp>
#include <pd/ui7/containers.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/layout.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include "pd/ui7/container/dragdata.hpp"
namespace PD {
namespace UI7 {
class PD_UI7_API Menu {
class PD_API Menu {
public:
Menu(const UI7::ID& id, UI7::IO::Ref pIO);
~Menu() {}
@@ -92,6 +92,19 @@ class PD_UI7_API Menu {
}
pLayout->AddObject(r);
}
template <typename T>
void Slider(const std::string& label, T* data,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), int precision = 1) {
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
Container::Ref r = pLayout->FindObject(id);
if (!r) {
r = UI7::Slider<T>::New(label, data, pIO, min, max, precision);
r->SetID(id);
}
pLayout->AddObject(r);
}
void ColorEdit(const std::string& label, u32& clr);
void SameLine() { pLayout->SameLine(); }
void Separator();
void SeparatorText(const std::string& label);
@@ -103,6 +116,12 @@ class PD_UI7_API Menu {
void HandleTitlebarActions();
void DrawBaseLayout();
void AddObject(PD::UI7::Container::Ref obj) { pLayout->AddObject(obj); }
void AddObjectEx(PD::UI7::Container::Ref obj, PD::u32 flags) {
pLayout->AddObjectEx(obj, flags);
}
Container::Ref FindObject(u32 id) { return pLayout->FindObject(id); }
void Update();
/** Data Section */
+3 -3
View File
@@ -2,7 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,7 +24,7 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/pd_p_api.hpp>
/**
* Using this to support 32bit color values as well as
@@ -55,7 +55,7 @@ enum UI7Color_ {
namespace PD {
namespace UI7 {
class PD_UI7_API Theme {
class PD_API Theme {
public:
/**
* Default Constructor Setting up the Default theme
Executable → Regular
+10 -8
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,9 +24,9 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/pd_p_api.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/menu.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include "pd/ui7/flags.hpp"
@@ -37,7 +36,7 @@ SOFTWARE.
* Major Minor Patch Build
* 0x01010000 -> 1.1.0-0
*/
#define UI7_VERSION 0x00050100
#define UI7_VERSION 0x00060000
namespace PD {
namespace UI7 {
@@ -46,19 +45,22 @@ namespace UI7 {
* @param show_build Show build num (mostly unused)
* @return Version String (1.0.0-1 for example)
*/
PD_UI7_API std::string GetVersion(bool show_build = false);
PD_API std::string GetVersion(bool show_build = false);
/** Base Context for UI7 */
class PD_UI7_API Context {
class PD_API Context {
public:
Context() { pIO = IO::New(); }
Context(PD::Context& ctx) { pIO = IO::New(ctx); }
~Context() = default;
PD_SHARED(Context);
IO::Ref GetIO() { return pIO; }
void AddViewPort(const ID& id, const ivec4& vp);
void UseViewPort(const ID& id);
void Update();
bool BeginMenu(const ID &id, UI7MenuFlags flags = 0, bool *pShow = nullptr);
Menu::Ref BeginMenu(const ID& id, UI7MenuFlags flags = 0,
bool* pShow = nullptr);
Menu::Ref CurrentMenu() { return pCurrent; }
void EndMenu();
void AboutMenu(bool* show = nullptr);
void MetricsMenu(bool* show = nullptr);
+1 -2
View File
@@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
-21
View File
@@ -1,21 +0,0 @@
cmake_minimum_required(VERSION 3.22)
project(pd-core LANGUAGES CXX VERSION 0.5.1)
set(SRC
source/bit_util.cpp
source/color.cpp
source/io.cpp
source/mat.cpp
source/strings.cpp
source/timer.cpp
source/timetrace.cpp
)
if(PD_BUILD_SHARED)
pd_add_lib(pd-core BUILD_SHARED TRUE SRC_FILES ${SRC})
else()
pd_add_lib(pd-core SRC_FILES ${SRC})
endif()
target_link_libraries(pd-core PUBLIC pd-drivers)
-73
View File
@@ -1,73 +0,0 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
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 <pd/core/color.hpp>
namespace PD {
// The Solution of the biggest performance issue
// A Simple Lookup table
static const std::map<char, int> HEX_DEC = {
{'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5},
{'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'a', 10}, {'b', 11},
{'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}, {'A', 10}, {'B', 11},
{'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}};
PD_CORE_API Color& Color::Hex(const std::string& hex) {
#ifdef PD_NO_SAFE_CODE
/// Safetey check (not required if you programm well xd)
if (hex.length() != 7 || hex.length() != 9 || hex.length() != 6 ||
hex.length() != 8 || std::find_if(hex.begin(), hex.end(), [](char c) {
return !std::isxdigit(c);
}) != hex.end()) {
return *this;
}
#endif
int offset = ((hex.length() == 7 || hex.length() == 9) ? 1 : 0);
r = HEX_DEC.at(hex[offset]) * 16 + HEX_DEC.at(hex[offset + 1]);
offset += 2;
g = HEX_DEC.at(hex[offset]) * 16 + HEX_DEC.at(hex[offset + 1]);
offset += 2;
b = HEX_DEC.at(hex[offset]) * 16 + HEX_DEC.at(hex[offset + 1]);
offset += 2;
if (hex.length() == 9) {
a = HEX_DEC.at(hex[offset]) * 16 + HEX_DEC.at(hex[offset + 1]);
} else {
a = 255;
}
return *this;
}
PD_CORE_API std::string Color::Hex(bool rgba) const {
/** Need to int cast (so it is used as num and not char...) */
std::stringstream s;
s << "#";
s << std::hex << std::setw(2) << std::setfill('0') << (int)r;
s << std::hex << std::setw(2) << std::setfill('0') << (int)g;
s << std::hex << std::setw(2) << std::setfill('0') << (int)b;
if (rgba) {
s << std::hex << std::setw(2) << std::setfill('0') << (int)a;
}
return s.str();
}
} // namespace PD
-13
View File
@@ -1,13 +0,0 @@
cmake_minimum_required(VERSION 3.22)
## The Core Core Library
project(pd-drivers LANGUAGES CXX VERSION 0.5.1)
set(SRC
source/hid.cpp
source/os.cpp
source/gfx.cpp
)
# Only Static Supported
pd_add_lib(pd-drivers SRC_FILES ${SRC})
-39
View File
@@ -1,39 +0,0 @@
#include <pd/drivers/hid.hpp>
#include <pd/drivers/pd_p_api.hpp>
namespace PD {
PD_DEF_EXP(HidDriver::Ref, Hid::pHid);
bool HidDriver::IsEvent(Event e, Key keys) { return KeyEvents[0][e] & keys; }
bool HidDriver::IsEvent(Event e, KbKey keys) {
return KbKeyEvents[0][e].Has(keys);
}
void HidDriver::SwapTab() {
auto tkd = KeyEvents[1][Event_Down];
auto tkh = KeyEvents[1][Event_Held];
auto tku = KeyEvents[1][Event_Up];
KeyEvents[1][Event_Down] = KeyEvents[0][Event_Down];
KeyEvents[1][Event_Held] = KeyEvents[0][Event_Held];
KeyEvents[1][Event_Up] = KeyEvents[0][Event_Up];
KeyEvents[0][Event_Down] = tkd;
KeyEvents[0][Event_Held] = tkh;
KeyEvents[0][Event_Up] = tku;
}
/**
* If this func has no verride, still clear the stats
* cause if they are empty this leads to a crash
*/
void HidDriver::Update() {
// Clear States
for (int i = 0; i < 2; i++) {
KeyEvents[i][Event_Down] = 0;
KeyEvents[i][Event_Held] = 0;
KeyEvents[i][Event_Up] = 0;
for (auto& it : KbKeyEvents[i]) {
it.second = Event_Null;
}
}
}
} // namespace PD
-9
View File
@@ -1,9 +0,0 @@
cmake_minimum_required(VERSION 3.22)
project(pd-external LANGUAGES CXX VERSION 0.5.0)
set(SRC
source/stb.cpp
)
pd_add_lib(pd-external SRC_FILES ${SRC})
-4
View File
@@ -1,4 +0,0 @@
#define STB_IMAGE_IMPLEMENTATION
#include <pd/external/stb_image.h>
#define STB_TRUETYPE_IMPLEMENTATION
#include <pd/external/stb_truetype.h>
-15
View File
@@ -1,15 +0,0 @@
cmake_minimum_required(VERSION 3.22)
project(pd-image LANGUAGES CXX VERSION 0.5.0)
set(SRC
source/image.cpp
source/img_blur.cpp
source/img_convert.cpp
)
if(PD_BUILD_SHARED)
pd_add_lib(pd-image BUILD_SHARED TRUE SRC_FILES ${SRC})
else()
pd_add_lib(pd-image SRC_FILES ${SRC})
endif()
-26
View File
@@ -1,26 +0,0 @@
cmake_minimum_required(VERSION 3.22)
project(pd-lithium LANGUAGES CXX VERSION 0.5.1)
option(PD_LI_INCLUDE_FONTS "Include Fonts" OFF)
set(SRC
source/drawlist.cpp
source/font.cpp
source/fonts.cpp
source/renderer.cpp
)
if(PD_BUILD_SHARED)
pd_add_lib(pd-lithium BUILD_SHARED TRUE SRC_FILES ${SRC})
else()
pd_add_lib(pd-lithium SRC_FILES ${SRC})
endif()
if(${PD_LI_INCLUDE_FONTS})
target_compile_definitions(pd-lithium PUBLIC
-DPD_LI_INCLUDE_FONTS=1
)
endif()
target_link_libraries(pd-lithium PUBLIC pd-core)

Some files were not shown because too many files have changed in this diff Show More