diff --git a/CMakeLists.txt b/CMakeLists.txt index 768d50a..d7d0203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,29 @@ cmake_minimum_required(VERSION 3.18) +### Helper Function to Build Librarys without have always +### These includes and definition defines +function(add_pd_lib TARGET_NAME) +set(opts "") +set(one_val_args "") +set(multi_val_args SRC_FILES DEPENDS) +cmake_parse_arguments(ARG "${opts}" "${one_val_args}" "${multi_val_args}" ${ARGN}) + +add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES}) +target_include_directories(${TARGET_NAME} PUBLIC + include + ${DEVKITPRO}/portlibs/3ds/include) +target_compile_definitions(${TARGET_NAME} PUBLIC + -D_GNU_SOURCE=1 + -DPALLADIUM_VERSION="${PROJECT_VERSION}" + -DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}" + -DBUILD_CTR=1) +### For the libs that depend on another +if(ARG_DEPENDS) +target_link_libraries(${TARGET_NAME} PUBLIC ${ARG_DEPENDS}) +endif() +install(TARGETS ${TARGET_NAME}) +endfunction() + # Setup Toolchain if not specified # Could propably avoided by using arm-none-eabi-cmake if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) @@ -18,7 +42,9 @@ execute_process( ) # Set Project -project(palladium LANGUAGES C CXX VERSION 0.1.9) +project(palladium LANGUAGES C CXX VERSION 0.2.1) + +option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF) # Enable Compile Command Export set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -31,67 +57,103 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions") -set(SRC_FILES - # Core (common) - source/common/app.cpp - source/common/common.cpp - source/common/strings.cpp - source/common/timetrace.cpp - source/common/sys.cpp - source/common/lang.cpp - source/common/error.cpp - source/common/io.cpp - # Controls - source/controls/hid.cpp - # Maths - source/maths/color.cpp - source/maths/bit_util.cpp - source/maths/img_convert.cpp - source/maths/img_blur.cpp - # Graphics - source/graphics/texture.cpp - source/graphics/spritesheet.cpp - source/graphics/li7_shader.cpp - source/graphics/lithium.cpp - # Overlays - source/overlays/message_mgr.cpp - source/overlays/overlay_mgr.cpp - source/overlays/keyboard.cpp - source/overlays/performance.cpp - source/overlays/settings.cpp - # Tools - source/tools/gamepad_icons.cpp - # UI7 - source/ui7/drawlist.cpp - source/ui7/menu.cpp - source/ui7/theme.cpp - source/ui7/ui7.cpp - source/ui7/container/container.cpp - source/ui7/container/button.cpp - source/ui7/container/checkbox.cpp - source/ui7/container/image.cpp - source/ui7/container/label.cpp - # External - source/external/stb.cpp +set(CORE_SRC +source/core/common.cpp +source/core/io.cpp +source/core/strings.cpp +source/core/sys.cpp +source/core/timetrace.cpp) + +add_pd_lib(pd-core SRC_FILES ${CORE_SRC}) + +set(MATHS_SRC +source/maths/bit_util.cpp +source/maths/color.cpp +source/maths/img_blur.cpp +source/maths/img_convert.cpp) +add_pd_lib(pd-maths SRC_FILES ${MATHS_SRC} DEPENDS pd-core) + +set(EXTERNAL_SRC +source/external/stb.cpp) +add_pd_lib(pd-external SRC_FILES ${EXTERNAL_SRC}) + +set(DRVS_SRC +source/drivers/hid.cpp) + +add_pd_lib(pd-drivers SRC_FILES ${DRVS_SRC} DEPENDS pd-maths) + +set(L3DS_SRC +source/lib3ds/gamepad_icons.cpp +source/lib3ds/result_decoder.cpp +source/lib3ds/drv_hid.cpp) + +add_pd_lib(pd-lib3ds SRC_FILES ${L3DS_SRC} DEPENDS pd-drivers) + +set(LI_SRC +source/lithium/li7_shader.cpp +source/lithium/spritesheet.cpp +source/lithium/texture.cpp +source/lithium/font.cpp +source/lithium/objects.cpp +source/lithium/renderer.cpp) + +add_pd_lib(pd-lithium SRC_FILES ${LI_SRC} DEPENDS pd-maths pd-external citro3d) + +set(OVL_SRC +source/overlays/keyboard.cpp +source/overlays/message_mgr.cpp +source/overlays/overlay_mgr.cpp +source/overlays/performance.cpp +source/overlays/settings.cpp) + +add_pd_lib(pd-overlays SRC_FILES ${OVL_SRC} DEPENDS pd-lithium) + +set(APP_SRC +source/app/app.cpp +source/app/lang.cpp +source/app/error.cpp) + +add_pd_lib(pd-app SRC_FILES ${APP_SRC} DEPENDS pd-overlays pd-drivers pd-lib3ds) + +set(UI7_SRC +source/ui7/drawlist.cpp +source/ui7/menu.cpp +source/ui7/theme.cpp +source/ui7/ui7.cpp +source/ui7/container/container.cpp +source/ui7/container/button.cpp +source/ui7/container/checkbox.cpp +source/ui7/container/image.cpp +source/ui7/container/label.cpp) + +add_pd_lib(pd-ui7 SRC_FILES ${UI7_SRC} DEPENDS pd-drivers pd-lithium) + +add_library(palladium INTERFACE) +target_link_libraries(palladium INTERFACE + pd-core + pd-maths + pd-external + pd-drivers + pd-lib3ds + pd-lithium + pd-overlays + pd-app + pd-ui7 ) -set(TARGET_NAME palladium) - -# Set Executable and its sources -add_library(${TARGET_NAME} STATIC ${SRC_FILES}) - -# Set dependencies, include dirs and definitions -target_include_directories(${TARGET_NAME} PUBLIC - include - ${DEVKITPRO}/portlibs/3ds/include -) -target_compile_definitions(${TARGET_NAME} PUBLIC - -D_GNU_SOURCE=1 - -DPALLADIUM_VERSION="${PROJECT_VERSION}" - -DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}" - -DBUILD_CTR=1 +add_dependencies(palladium + pd-core + pd-maths + pd-external + pd-drivers + pd-lib3ds + pd-lithium + pd-overlays + pd-app + pd-ui7 ) +if(PD_BUILD_TESTS) add_executable(test test/app/main.cpp) target_include_directories(test PUBLIC include test/app) target_link_directories(test PUBLIC ${CMAKE_BINARY_DIR}) @@ -121,5 +183,6 @@ ctr_create_3dsx( SMDH "${CMAKE_BINARY_DIR}/test.smdh" ROMFS "${CMAKE_SOURCE_DIR}/test/romfs" ) -install(TARGETS ${TARGET_NAME}) +endif() + install(DIRECTORY include DESTINATION ".") \ No newline at end of file diff --git a/include/pd.hpp b/include/pd.hpp index 5a6c70a..7b1aa30 100644 --- a/include/pd.hpp +++ b/include/pd.hpp @@ -24,22 +24,23 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Common -#include -#include -#include -#include -#include +// Core +#include +#include +#include +#include +#include // Graphics -#include -#include -#include +#include +#include // Maths #include #include #include #include #include +// Drivers +#include // Overlays #include #include @@ -49,6 +50,12 @@ SOFTWARE. // UI7 #include +// App +#include +#include +#include +#include + /// Setup these as non Namespaced access by default #ifndef PD_MATH_NAMESPACED using vec2 = PD::vec2; diff --git a/include/pd/common/app.hpp b/include/pd/app/app.hpp similarity index 90% rename from include/pd/common/app.hpp rename to include/pd/app/app.hpp index 61af3e6..b5c4939 100644 --- a/include/pd/common/app.hpp +++ b/include/pd/app/app.hpp @@ -23,10 +23,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -52,16 +52,20 @@ class App { AppInitFlags_New3dsMode = 1 << 2, AppInitFlags_InitGraphicsNoC3D = 1 << 3, AppInitFlags_InitLithium = 1 << 4, + /// I dont have a name for this one yet + /// It Inits Internal Directory structure + AppInitFlags_UnnamedOption1 = 1 << 5, AppInitFlags_Default = AppInitFlags_MountRomfs | AppInitFlags_InitGraphics | AppInitFlags_New3dsMode | AppInitFlags_InitLithium, }; - App() { + App(const std::string& name = "App") { if (too) { Error("Only one App can be created at the same time!"); } + this->name = name; too++; } - ~App() = default; + ~App() { too--; } /// @brief Templete function where the user can Init his stuff virtual void Init() {} @@ -110,6 +114,8 @@ class App { float app_time; float fps; + std::string name; + /// The Only One static int too; }; diff --git a/include/pd/common/error.hpp b/include/pd/app/error.hpp similarity index 97% rename from include/pd/common/error.hpp rename to include/pd/app/error.hpp index d797fdf..12dede3 100644 --- a/include/pd/common/error.hpp +++ b/include/pd/app/error.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { void Error(const std::string& error); diff --git a/include/pd/common/lang.hpp b/include/pd/app/lang.hpp similarity index 98% rename from include/pd/common/lang.hpp rename to include/pd/app/lang.hpp index 512319c..27ef8e2 100644 --- a/include/pd/common/lang.hpp +++ b/include/pd/app/lang.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { /// @brief Lang System diff --git a/include/pd/common/timer.hpp b/include/pd/app/timer.hpp similarity index 95% rename from include/pd/common/timer.hpp rename to include/pd/app/timer.hpp index 0b14d2b..ff9a36f 100644 --- a/include/pd/common/timer.hpp +++ b/include/pd/app/timer.hpp @@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include namespace PD { class Timer { diff --git a/include/pd/common/common.hpp b/include/pd/core/common.hpp similarity index 100% rename from include/pd/common/common.hpp rename to include/pd/core/common.hpp diff --git a/include/pd/common/io.hpp b/include/pd/core/io.hpp similarity index 97% rename from include/pd/common/io.hpp rename to include/pd/core/io.hpp index d7f576d..d9ca522 100644 --- a/include/pd/common/io.hpp +++ b/include/pd/core/io.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { namespace IO { diff --git a/include/pd/tools/markdown.hpp b/include/pd/core/markdown.hpp similarity index 98% rename from include/pd/tools/markdown.hpp rename to include/pd/core/markdown.hpp index 994c983..5b22bc1 100644 --- a/include/pd/tools/markdown.hpp +++ b/include/pd/core/markdown.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { class Markdown { diff --git a/include/pd/common/strings.hpp b/include/pd/core/strings.hpp similarity index 98% rename from include/pd/common/strings.hpp rename to include/pd/core/strings.hpp index a94c3cd..89515b6 100644 --- a/include/pd/common/strings.hpp +++ b/include/pd/core/strings.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { namespace Strings { diff --git a/include/pd/common/sys.hpp b/include/pd/core/sys.hpp similarity index 95% rename from include/pd/common/sys.hpp rename to include/pd/core/sys.hpp index 122c783..c780d3f 100644 --- a/include/pd/common/sys.hpp +++ b/include/pd/core/sys.hpp @@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include namespace PD { namespace Sys { diff --git a/include/pd/common/timetrace.hpp b/include/pd/core/timetrace.hpp similarity index 99% rename from include/pd/common/timetrace.hpp rename to include/pd/core/timetrace.hpp index 15edcb9..4d85aa6 100644 --- a/include/pd/common/timetrace.hpp +++ b/include/pd/core/timetrace.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { class TimeStats : public SmartCtor { diff --git a/include/pd/controls/hid.hpp b/include/pd/drivers/hid.hpp similarity index 97% rename from include/pd/controls/hid.hpp rename to include/pd/drivers/hid.hpp index ccbb1dc..4d8a27a 100644 --- a/include/pd/controls/hid.hpp +++ b/include/pd/drivers/hid.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include namespace PD { @@ -64,7 +64,7 @@ class Hid : public SmartCtor { Event_Held, Event_Up, }; - Hid(); + Hid() {} ~Hid() {} vec2 TouchPos() const { return touch[0]; } @@ -105,14 +105,14 @@ class Hid : public SmartCtor { /// @brief Get the New Keystates etc /// @note WOW not using the deltatime - void Update(); + virtual void Update() {} - private: + protected: + std::unordered_map binds; void SwappyTable(); /// Using 2 Touch positions for current and last frame vec2 touch[2]; bool locked = false; std::unordered_map key_events[2]; - std::unordered_map binds; }; } // namespace PD \ No newline at end of file diff --git a/include/pd/lib3ds/drv_hid.hpp b/include/pd/lib3ds/drv_hid.hpp new file mode 100644 index 0000000..b5a3ff4 --- /dev/null +++ b/include/pd/lib3ds/drv_hid.hpp @@ -0,0 +1,36 @@ +#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 + +namespace PD { +class CtrHid : public Hid { + public: + CtrHid(); + ~CtrHid() {} + + void Update() override; +}; +} // namespace PD \ No newline at end of file diff --git a/include/pd/tools/gamepad_icons.hpp b/include/pd/lib3ds/gamepad_icons.hpp similarity index 95% rename from include/pd/tools/gamepad_icons.hpp rename to include/pd/lib3ds/gamepad_icons.hpp index 0dc0188..726b2b2 100644 --- a/include/pd/tools/gamepad_icons.hpp +++ b/include/pd/lib3ds/gamepad_icons.hpp @@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include namespace PD { namespace GamePadIcons { diff --git a/include/pd/common/memory.hpp b/include/pd/lib3ds/memory.hpp similarity index 96% rename from include/pd/common/memory.hpp rename to include/pd/lib3ds/memory.hpp index 6a82fb3..4d05526 100644 --- a/include/pd/common/memory.hpp +++ b/include/pd/lib3ds/memory.hpp @@ -26,8 +26,8 @@ SOFTWARE. #include <3ds.h> -#include -#include +#include +#include namespace PD { template diff --git a/include/pd/tools/result_decoder.hpp b/include/pd/lib3ds/result_decoder.hpp similarity index 91% rename from include/pd/tools/result_decoder.hpp rename to include/pd/lib3ds/result_decoder.hpp index e51d8b7..7e250d0 100644 --- a/include/pd/tools/result_decoder.hpp +++ b/include/pd/lib3ds/result_decoder.hpp @@ -25,13 +25,12 @@ SOFTWARE. #include <3ds.h> -#include -#include +#include +#include namespace PD { class ResultDecoder { - public: - ResultDecoder(Result res); - + public: + ResultDecoder(Result res); }; } // namespace PD \ No newline at end of file diff --git a/include/pd/lithium/command.hpp b/include/pd/lithium/command.hpp new file mode 100644 index 0000000..731fc07 --- /dev/null +++ b/include/pd/lithium/command.hpp @@ -0,0 +1,105 @@ +#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 +#include +#include +#include +#include + +namespace PD { +namespace LI { +/// @brief Reform the Drawcommand by generating the Vertexbuffer into it +class Command : public SmartCtor { + public: + Command() {} + ~Command() {} + + Command(Command::Ref v) { + this->index = v->index; + this->index_buf = v->index_buf; + this->layer = v->layer; + this->mode = v->mode; + this->tex = v->tex; + this->vertex_buf = v->vertex_buf; + } + + Command& Layer(int v) { + layer = v; + return *this; + } + + int Layer() const { return layer; } + + Command& Index(int v) { + index = v; + return *this; + } + + int Index() const { return index; } + + Command& Tex(Texture::Ref v) { + tex = v; + return *this; + } + + Texture::Ref Tex() const { return tex; } + + Command& PushVertex(const Vertex& v) { + vertex_buf.push_back(v); + return *this; + } + + const std::vector& IndexList() const { return index_buf; } + const std::vector& VertexList() const { return vertex_buf; } + + /// ADVANCED /// + std::vector& IndexList() { return index_buf; } + std::vector& VertexList() { return vertex_buf; } + + Command& PushIndex(u16 v) { + index_buf.push_back(vertex_buf.size() + v); + return *this; + } + + Command& Rendermode(const RenderMode& v) { + mode = v; + return *this; + } + + RenderMode Rendermode() const { return mode; } + + private: + /// Using Default std::vector here + std::vector vertex_buf; + std::vector index_buf; + int layer; + Texture::Ref tex; + int index; + RenderMode mode = RenderMode_RGBA; +}; +} // namespace LI +} // namespace PD \ No newline at end of file diff --git a/include/pd/lithium/flags.hpp b/include/pd/lithium/flags.hpp new file mode 100644 index 0000000..78a7dce --- /dev/null +++ b/include/pd/lithium/flags.hpp @@ -0,0 +1,60 @@ +#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 + +using LITextFlags = PD::u32; + +enum LITextFlags_ { + LITextFlags_None = 0, + LITextFlags_AlignRight = 1 << 0, + LITextFlags_AlignMid = 1 << 1, + LITextFlags_Shaddow = 1 << 2, // Draws the text twice + LITextFlags_Wrap = 1 << 3, // May be runs better with TMS + LITextFlags_Short = 1 << 4, // May be runs better with TMS + LITextFlags_Scroll = 1 << 5, // Not implemented + LITextFlags_RenderOOS = 1 << 6 // Render Out of Screen +}; + +using LIRenderFlags = PD::u32; +enum LIRenderFlags_ { + LIRenderFlags_None = 0, + LIRenderFlags_TMS = 1 << 0, ///< Text Map System + LIRenderFlags_LRS = 1 << 1, ///< Layer Render System + LIRenderFlags_AST = 1 << 2, ///< Auto Static Text + LIRenderFlags_Default = + LIRenderFlags_TMS | LIRenderFlags_LRS | LIRenderFlags_AST, +}; + +namespace PD { +namespace LI { +/// @brief Required to Set the TexENV +enum RenderMode { + RenderMode_RGBA, + RenderMode_Font, +}; +} // namespace LI +} // namespace PD \ No newline at end of file diff --git a/include/pd/lithium/font.hpp b/include/pd/lithium/font.hpp new file mode 100644 index 0000000..23dbf6a --- /dev/null +++ b/include/pd/lithium/font.hpp @@ -0,0 +1,95 @@ +#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 +#include +#include +#include + +namespace PD { +namespace LI { +class Font : public SmartCtor { + public: + class Codepoint { + public: + Codepoint() {} + ~Codepoint() {} + + u32 cp() const { return m_cp; } + Codepoint& cp(u32 v) { + m_cp = v; + return *this; + } + vec4 uv() const { return m_uv; } + Codepoint& uv(const vec4& v) { + m_uv = v; + return *this; + } + Texture::Ref tex() const { return m_tex; } + Codepoint& tex(Texture::Ref v) { + m_tex = v; + return *this; + } + vec2 size() const { return m_size; } + Codepoint& size(const vec2& v) { + m_size = v; + return *this; + } + float off() const { return m_off; } + Codepoint& off(float v) { + m_off = v; + return *this; + } + bool invalid() const { return m_invalid; } + Codepoint& invalid(bool v) { + m_invalid = v; + return *this; + } + + private: + u32 m_cp = 0; + vec4 m_uv; + Texture::Ref m_tex = nullptr; + vec2 m_size; + float m_off = 0; + bool m_invalid = false; + }; + Font() {} + ~Font() {} + void LoadTTF(const std::string& path, int px_height = 32); + void LoadSystemFont(); + int PixelHeight() const { return pixel_height; } + Codepoint& GetCodepoint(u32 c); + bool SystemFont() const { return sysfont; } + + private: + bool sysfont; + int pixel_height; + std::vector textures; + std::map cpmap; +}; +} // namespace LI +} // namespace PD \ No newline at end of file diff --git a/include/pd/graphics/li7_shader.hpp b/include/pd/lithium/li7_shader.hpp similarity index 100% rename from include/pd/graphics/li7_shader.hpp rename to include/pd/lithium/li7_shader.hpp diff --git a/include/pd/lithium/objects.hpp b/include/pd/lithium/objects.hpp new file mode 100644 index 0000000..4f80cc0 --- /dev/null +++ b/include/pd/lithium/objects.hpp @@ -0,0 +1,166 @@ +#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 +#include +#include +#include +#include +#include +#include + +namespace PD { +namespace LI { +class Renderer; +class StaticObject : public SmartCtor { + public: + StaticObject() {} + ~StaticObject() {} + + void PushCommand(Command::Ref v) { cmds.push_back(v); } + + void ReCopy() { + cpy.clear(); + for (auto it : cmds) { + cpy.push_back(Command::New(it)); + } + } + + void ReColorQuad(int idx, u32 col) { + if (idx > (int)cpy.size()) { + return; + } + for (auto& it : cpy[idx]->VertexList()) { + it.Color(col); + } + } + + void MoveIt(vec2 off) { + for (auto& it : cpy) { + for (auto& jt : it->VertexList()) { + jt.pos += off; + } + } + } + + void ReColor(u32 col) { + for (auto& it : cpy) { + for (auto& jt : it->VertexList()) { + jt.Color(col); + } + } + } + + void ReLayer(int base_layer) { + for (auto& it : cpy) { + it->Layer(it->Layer() + base_layer); + } + } + + void ReIndex(int start) { + for (int i = 0; i < (int)cpy.size(); i++) { + cpy[i]->Index(start + i); + } + } + + std::vector& List() { + if (cpy.size() != 0) { + return cpy; + } + return cmds; + } + + private: + std::vector cpy; + std::vector cmds; +}; + +class TextBox { + public: + TextBox() {} + TextBox(const vec2& s, float time) { + size = s; + time_created = time; + optional = false; + } + ~TextBox() {} + + void TimeCreated(float v) { time_created = v; } + void Size(const vec2& v) { size = v; } + void Optional(bool v) { optional = v; } + void Text(const std::string& v) { text = v; } + + vec2 Size() const { return size; } + float TimeCreated() const { return time_created; } + bool Optional() const { return optional; } + std::string Text() const { return text; } + + private: + vec2 size; + float time_created; + bool optional; + std::string text; // TextWrap +}; + +class StaticText : public SmartCtor { + public: + StaticText() {} + StaticText(Renderer* ren, const vec2& pos, u32 clr, const std::string& text, + LITextFlags flags = 0, const vec2& box = 0) { + Setup(ren, pos, clr, text, flags, box); + } + ~StaticText() {} + + void Setup(Renderer* ren, const vec2& pos, u32 clr, const std::string& text, + LITextFlags flags = 0, const vec2& box = 0); + + vec2 GetDim() const { return tdim; } + vec2 GetPos() const { return pos; } + + void SetColor(u32 col); + void SetPos(const vec2& pos); + void SetLayer(int l); + + void SetUnused() { used = false; } + bool Used() const { return used; } + + bool IsSetup() { return text != nullptr; } + + void Draw(); + + void Font(Font::Ref fnt) { font = fnt; } + Font::Ref Font() { return font; } + + private: + Font::Ref font; + bool used; + Renderer* ren; + vec2 tdim; + vec2 pos; + StaticObject::Ref text; +}; +} // namespace LI +} // namespace PD \ No newline at end of file diff --git a/include/pd/graphics/rect.hpp b/include/pd/lithium/rect.hpp similarity index 98% rename from include/pd/graphics/rect.hpp rename to include/pd/lithium/rect.hpp index e38a5d9..c13a386 100644 --- a/include/pd/graphics/rect.hpp +++ b/include/pd/lithium/rect.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include namespace PD { diff --git a/include/pd/graphics/lithium.hpp b/include/pd/lithium/renderer.hpp similarity index 51% rename from include/pd/graphics/lithium.hpp rename to include/pd/lithium/renderer.hpp index eb5a7e1..7e3e2a0 100644 --- a/include/pd/graphics/lithium.hpp +++ b/include/pd/lithium/renderer.hpp @@ -24,332 +24,24 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include - -using LITextFlags = u32; - -enum LITextFlags_ { - LITextFlags_None = 0, - LITextFlags_AlignRight = 1 << 0, - LITextFlags_AlignMid = 1 << 1, - LITextFlags_Shaddow = 1 << 2, // Draws the text twice - LITextFlags_Wrap = 1 << 3, // May be runs better with TMS - LITextFlags_Short = 1 << 4, // May be runs better with TMS - LITextFlags_Scroll = 1 << 5, // Not implemented - LITextFlags_RenderOOS = 1 << 6 // Render Out of Screen -}; namespace PD { namespace LI { -class Font : public SmartCtor { - public: - class Codepoint { - public: - Codepoint() {} - ~Codepoint() {} - - u32 cp() const { return m_cp; } - Codepoint& cp(u32 v) { - m_cp = v; - return *this; - } - vec4 uv() const { return m_uv; } - Codepoint& uv(const vec4& v) { - m_uv = v; - return *this; - } - Texture::Ref tex() const { return m_tex; } - Codepoint& tex(Texture::Ref v) { - m_tex = v; - return *this; - } - vec2 size() const { return m_size; } - Codepoint& size(const vec2& v) { - m_size = v; - return *this; - } - float off() const { return m_off; } - Codepoint& off(float v) { - m_off = v; - return *this; - } - bool invalid() const { return m_invalid; } - Codepoint& invalid(bool v) { - m_invalid = v; - return *this; - } - - private: - u32 m_cp = 0; - vec4 m_uv; - Texture::Ref m_tex = nullptr; - vec2 m_size; - float m_off = 0; - bool m_invalid = false; - }; - Font() {} - ~Font() {} - void LoadTTF(const std::string& path, int px_height = 32); - void LoadSystemFont(); - int PixelHeight() const { return pixel_height; } - Codepoint& GetCodepoint(u32 c); - bool SystemFont() const { return sysfont; } - - private: - bool sysfont; - int pixel_height; - std::vector textures; - std::map cpmap; -}; -class Vertex { - public: - Vertex() {} - Vertex(const vec2& p, const vec2& u, u32 c) { - pos[0] = p[0]; - pos[1] = p[1]; - uv = u; - color = c; - } - ~Vertex() {} - - Vertex& Pos(const vec2& v) { - pos = v; - return *this; - } - Vertex& Uv(const vec2& v) { - uv = v; - return *this; - } - Vertex& Color(u32 v) { - color = v; - return *this; - } - - // private: - vec2 pos; - vec2 uv; - u32 color; -}; -/// @brief Required to Set the TexENV -enum RenderMode { - RenderMode_RGBA, - RenderMode_Font, -}; -/// @brief Reform the Drawcommand by generating the Vertexbuffer into it -class Command : public SmartCtor { - public: - Command() {} - ~Command() {} - - Command(Command::Ref v) { - this->index = v->index; - this->index_buf = v->index_buf; - this->layer = v->layer; - this->mode = v->mode; - this->tex = v->tex; - this->vertex_buf = v->vertex_buf; - } - - Command& Layer(int v) { - layer = v; - return *this; - } - - int Layer() const { return layer; } - - Command& Index(int v) { - index = v; - return *this; - } - - int Index() const { return index; } - - Command& Tex(Texture::Ref v) { - tex = v; - return *this; - } - - Texture::Ref Tex() const { return tex; } - - Command& PushVertex(const Vertex& v) { - vertex_buf.push_back(v); - return *this; - } - - const std::vector& IndexList() const { return index_buf; } - const std::vector& VertexList() const { return vertex_buf; } - - /// ADVANCED /// - std::vector& IndexList() { return index_buf; } - std::vector& VertexList() { return vertex_buf; } - - Command& PushIndex(u16 v) { - index_buf.push_back(vertex_buf.size() + v); - return *this; - } - - Command& Rendermode(const RenderMode& v) { - mode = v; - return *this; - } - - RenderMode Rendermode() const { return mode; } - - private: - /// Using Default std::vector here - std::vector vertex_buf; - std::vector index_buf; - int layer; - Texture::Ref tex; - int index; - RenderMode mode = RenderMode_RGBA; -}; -class TextBox { - public: - TextBox() {} - TextBox(const vec2& s, float time) { - size = s; - time_created = time; - optional = false; - } - ~TextBox() {} - - void TimeCreated(float v) { time_created = v; } - void Size(const vec2& v) { size = v; } - void Optional(bool v) { optional = v; } - void Text(const std::string& v) { text = v; } - - vec2 Size() const { return size; } - float TimeCreated() const { return time_created; } - bool Optional() const { return optional; } - std::string Text() const { return text; } - - private: - vec2 size; - float time_created; - bool optional; - std::string text; // TextWrap -}; -class StaticObject : public SmartCtor { - public: - StaticObject() {} - ~StaticObject() {} - - void PushCommand(Command::Ref v) { cmds.push_back(v); } - - void ReCopy() { - cpy.clear(); - for (auto it : cmds) { - cpy.push_back(Command::New(it)); - } - } - - void ReColorQuad(int idx, u32 col) { - if (idx > (int)cpy.size()) { - return; - } - for (auto& it : cpy[idx]->VertexList()) { - it.Color(col); - } - } - - void MoveIt(vec2 off) { - for (auto& it : cpy) { - for (auto& jt : it->VertexList()) { - jt.pos += off; - } - } - } - - void ReColor(u32 col) { - for (auto& it : cpy) { - for (auto& jt : it->VertexList()) { - jt.Color(col); - } - } - } - - void ReLayer(int base_layer) { - for (auto& it : cpy) { - it->Layer(it->Layer() + base_layer); - } - } - - void ReIndex(int start) { - for (int i = 0; i < (int)cpy.size(); i++) { - cpy[i]->Index(start + i); - } - } - - std::vector& List() { - if (cpy.size() != 0) { - return cpy; - } - return cmds; - } - - private: - std::vector cpy; - std::vector cmds; -}; - -using RenderFlags = u32; -enum RenderFlags_ { - RenderFlags_None = 0, - RenderFlags_TMS = 1 << 0, ///< Text Map System - RenderFlags_LRS = 1 << 1, ///< Layer Render System - RenderFlags_AST = 1 << 2, ///< Auto Static Text - RenderFlags_Default = RenderFlags_TMS | RenderFlags_LRS | RenderFlags_AST, -}; class Renderer : public SmartCtor { public: - Renderer(RenderFlags flags = RenderFlags_Default); + Renderer(LIRenderFlags flags = LIRenderFlags_Default); ~Renderer(); - class StaticText : public SmartCtor { - public: - StaticText() {} - StaticText(Renderer* ren, const vec2& pos, u32 clr, const std::string& text, - LITextFlags flags = 0, const vec2& box = 0) { - Setup(ren, pos, clr, text, flags, box); - } - ~StaticText() {} - - void Setup(Renderer* ren, const vec2& pos, u32 clr, const std::string& text, - LITextFlags flags = 0, const vec2& box = 0); - - vec2 GetDim() const { return tdim; } - vec2 GetPos() const { return pos; } - - void SetColor(u32 col); - void SetPos(const vec2& pos); - void SetLayer(int l); - - void SetUnused() { used = false; } - bool Used() const { return used; } - - bool IsSetup() { return text != nullptr; } - - void Draw(); - - void Font(Font::Ref fnt) { font = fnt; } - Font::Ref Font() { return font; } - - private: - Font::Ref font; - bool used; - Renderer* ren; - vec2 tdim; - vec2 pos; - StaticObject::Ref text; - }; - void PrepareRender(); void Render(Screen::Ref s); void FinalizeRender(); @@ -377,7 +69,7 @@ class Renderer : public SmartCtor { float TextScale() const { return text_size; } void Layer(int v) { current_layer = v; } int Layer() const { return current_layer; } - RenderFlags& GetFlags() { return flags; } + LIRenderFlags& GetFlags() { return flags; } void Font(Font::Ref v) { font = v; font_update = true; @@ -494,7 +186,7 @@ class Renderer : public SmartCtor { Screen::Ref screens[2]; /// Context Related /// - RenderFlags flags = RenderFlags_Default; + LIRenderFlags flags = LIRenderFlags_Default; vec2 area_size; int current_layer = 0; Texture::Ref current_tex = nullptr; diff --git a/include/pd/graphics/screen.hpp b/include/pd/lithium/screen.hpp similarity index 98% rename from include/pd/graphics/screen.hpp rename to include/pd/lithium/screen.hpp index a6c5bbe..e4469dd 100644 --- a/include/pd/graphics/screen.hpp +++ b/include/pd/lithium/screen.hpp @@ -26,7 +26,7 @@ SOFTWARE. #include <3ds.h> #include -#include +#include #include namespace PD { diff --git a/include/pd/graphics/spritesheet.hpp b/include/pd/lithium/spritesheet.hpp similarity index 93% rename from include/pd/graphics/spritesheet.hpp rename to include/pd/lithium/spritesheet.hpp index 80e7362..202aca5 100644 --- a/include/pd/graphics/spritesheet.hpp +++ b/include/pd/lithium/spritesheet.hpp @@ -26,9 +26,8 @@ SOFTWARE. #include #include -#include -#include -#include +#include +#include namespace PD { class SpriteSheet : public SmartCtor { diff --git a/include/pd/graphics/texture.hpp b/include/pd/lithium/texture.hpp similarity index 98% rename from include/pd/graphics/texture.hpp rename to include/pd/lithium/texture.hpp index 4b94450..0358208 100644 --- a/include/pd/graphics/texture.hpp +++ b/include/pd/lithium/texture.hpp @@ -26,8 +26,8 @@ SOFTWARE. #include -#include -#include +#include +#include #include namespace PD { diff --git a/include/pd/lithium/vertex.hpp b/include/pd/lithium/vertex.hpp new file mode 100644 index 0000000..a68a63c --- /dev/null +++ b/include/pd/lithium/vertex.hpp @@ -0,0 +1,62 @@ +#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 +#include + +namespace PD { +namespace LI { +class Vertex { + public: + Vertex() {} + Vertex(const vec2& p, const vec2& u, u32 c) { + pos[0] = p[0]; + pos[1] = p[1]; + uv = u; + color = c; + } + ~Vertex() {} + + Vertex& Pos(const vec2& v) { + pos = v; + return *this; + } + Vertex& Uv(const vec2& v) { + uv = v; + return *this; + } + Vertex& Color(u32 v) { + color = v; + return *this; + } + + // private: + vec2 pos; + vec2 uv; + u32 color; +}; +} // namespace LI +} // namespace PD \ No newline at end of file diff --git a/include/pd/maths/bit_util.hpp b/include/pd/maths/bit_util.hpp index 84741ce..6e83ce6 100644 --- a/include/pd/maths/bit_util.hpp +++ b/include/pd/maths/bit_util.hpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { namespace BitUtil { diff --git a/include/pd/maths/color.hpp b/include/pd/maths/color.hpp index 12d6125..55c43a6 100644 --- a/include/pd/maths/color.hpp +++ b/include/pd/maths/color.hpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { /// @brief Color class (Supports hex, rgb(a)8, u32 input) diff --git a/include/pd/maths/img.hpp b/include/pd/maths/img.hpp index 88e4d1c..46595d2 100644 --- a/include/pd/maths/img.hpp +++ b/include/pd/maths/img.hpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include namespace PD { diff --git a/include/pd/maths/img_blur.hpp b/include/pd/maths/img_blur.hpp index bbaf46d..0290286 100644 --- a/include/pd/maths/img_blur.hpp +++ b/include/pd/maths/img_blur.hpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include #include diff --git a/include/pd/maths/img_convert.hpp b/include/pd/maths/img_convert.hpp index cc7a3c4..293a1f0 100644 --- a/include/pd/maths/img_convert.hpp +++ b/include/pd/maths/img_convert.hpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { namespace ImgConvert { diff --git a/include/pd/maths/vec.hpp b/include/pd/maths/vec.hpp index 4d1c85d..5ad9b5f 100644 --- a/include/pd/maths/vec.hpp +++ b/include/pd/maths/vec.hpp @@ -29,7 +29,7 @@ SOFTWARE. * and easy to use like in glsl or glm */ -#include +#include namespace PD { struct vec2 { diff --git a/include/pd/overlays/keyboard.hpp b/include/pd/overlays/keyboard.hpp index 7b73847..a84c687 100644 --- a/include/pd/overlays/keyboard.hpp +++ b/include/pd/overlays/keyboard.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include #include diff --git a/include/pd/overlays/message_mgr.hpp b/include/pd/overlays/message_mgr.hpp index fb46a58..207fe23 100644 --- a/include/pd/overlays/message_mgr.hpp +++ b/include/pd/overlays/message_mgr.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include #include diff --git a/include/pd/overlays/overlay.hpp b/include/pd/overlays/overlay.hpp index 56807fa..d54755c 100644 --- a/include/pd/overlays/overlay.hpp +++ b/include/pd/overlays/overlay.hpp @@ -23,9 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include -#include +#include +#include +#include namespace PD { class Overlay : public SmartCtor { diff --git a/include/pd/overlays/overlay_mgr.hpp b/include/pd/overlays/overlay_mgr.hpp index da8c19e..5e9c9f8 100644 --- a/include/pd/overlays/overlay_mgr.hpp +++ b/include/pd/overlays/overlay_mgr.hpp @@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include #include namespace PD { diff --git a/include/pd/overlays/performance.hpp b/include/pd/overlays/performance.hpp index 3c33e2c..638448e 100644 --- a/include/pd/overlays/performance.hpp +++ b/include/pd/overlays/performance.hpp @@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include #include -#include namespace PD { class Performance : public Overlay { diff --git a/include/pd/overlays/settings.hpp b/include/pd/overlays/settings.hpp index 769cf2c..5a0b97e 100644 --- a/include/pd/overlays/settings.hpp +++ b/include/pd/overlays/settings.hpp @@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include #include #include #include @@ -32,14 +31,12 @@ SOFTWARE. namespace PD { class SettingsMenu : public Overlay { public: - SettingsMenu(PD::App* app) { + SettingsMenu() { too++; if (too > 1) { Kill(); return; } - app_ref = app; - app->FeatureDisable(PD::App::AppFLags_UserLoop); flymgr.From(vec2(0, 240)).To(vec2(0, 115)).In(0.3f).As(flymgr.EaseInQuad); } ~SettingsMenu() { too--; } @@ -48,12 +45,10 @@ class SettingsMenu : public Overlay { void Rem() { rem = true; - app_ref->FeatureEnable(App::AppFLags_UserLoop); flymgr.From(vec2(0, 115)).To(vec2(0, 240)).In(0.2f).As(flymgr.EaseOutQuad); } private: - PD::App* app_ref = nullptr; /// Section is used to determinate what /// should be displayed on the top screen int section = 0; diff --git a/include/pd/ui7/container/container.hpp b/include/pd/ui7/container/container.hpp index 9bfa0a8..c31ba34 100644 --- a/include/pd/ui7/container/container.hpp +++ b/include/pd/ui7/container/container.hpp @@ -23,9 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include -#include +#include +#include +#include #include #include diff --git a/include/pd/ui7/drawlist.hpp b/include/pd/ui7/drawlist.hpp index ecc0f52..5877b75 100644 --- a/include/pd/ui7/drawlist.hpp +++ b/include/pd/ui7/drawlist.hpp @@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include #include namespace PD { @@ -61,7 +61,7 @@ class DrawList : public SmartCtor { int layer; int base; LI::Renderer::Ref ren; - std::unordered_map static_text; + std::unordered_map static_text; std::vector> commands; }; } // namespace UI7 diff --git a/include/pd/ui7/id.hpp b/include/pd/ui7/id.hpp index b31c50b..bcac181 100644 --- a/include/pd/ui7/id.hpp +++ b/include/pd/ui7/id.hpp @@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include namespace PD { namespace UI7 { diff --git a/include/pd/ui7/menu.hpp b/include/pd/ui7/menu.hpp index 809f67c..3a4e09e 100644 --- a/include/pd/ui7/menu.hpp +++ b/include/pd/ui7/menu.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include #include #include diff --git a/include/pd/ui7/theme.hpp b/include/pd/ui7/theme.hpp index 88b7c7c..15dd42a 100644 --- a/include/pd/ui7/theme.hpp +++ b/include/pd/ui7/theme.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include using UI7Color = PD::u32; diff --git a/include/pd/ui7/ui7.hpp b/include/pd/ui7/ui7.hpp index f747283..946bf98 100644 --- a/include/pd/ui7/ui7.hpp +++ b/include/pd/ui7/ui7.hpp @@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include //// WOW A NON UI/ Header +#include //// WOW A NON UI/ Header #include #include #include diff --git a/source/common/app.cpp b/source/app/app.cpp similarity index 94% rename from source/common/app.cpp rename to source/app/app.cpp index d1a2e2a..9a4bc08 100644 --- a/source/common/app.cpp +++ b/source/app/app.cpp @@ -24,8 +24,8 @@ SOFTWARE. #include <3ds.h> -#include -#include +#include +#include namespace PD { int App::too; @@ -87,7 +87,10 @@ void App::PreInit() { if (InitFlags & AppInitFlags_MountRomfs) { romfsInit(); } - input_mgr = Hid::New(); + if (InitFlags & AppInitFlags_UnnamedOption1) { + std::filesystem::create_directories("sdmc:/palladium/apps/" + name); + } + input_mgr = PD::New(); if (InitFlags & AppInitFlags_InitLithium) { Assert(!(InitFlags & AppInitFlags_InitGraphicsNoC3D), "InitGraphicsNoC3D is not compatible with InitLithium!"); diff --git a/source/common/error.cpp b/source/app/error.cpp similarity index 98% rename from source/common/error.cpp rename to source/app/error.cpp index c69a495..d0d29a6 100644 --- a/source/common/error.cpp +++ b/source/app/error.cpp @@ -23,7 +23,7 @@ SOFTWARE. #include <3ds.h> -#include +#include namespace PD { void Error(const std::string& msg) { diff --git a/source/common/lang.cpp b/source/app/lang.cpp similarity index 98% rename from source/common/lang.cpp rename to source/app/lang.cpp index 01f1346..04afa0a 100644 --- a/source/common/lang.cpp +++ b/source/app/lang.cpp @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include namespace PD { diff --git a/source/common/common.cpp b/source/core/common.cpp similarity index 96% rename from source/common/common.cpp rename to source/core/common.cpp index a849977..c37eece 100644 --- a/source/common/common.cpp +++ b/source/core/common.cpp @@ -22,8 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include #ifndef PALLADIUM_VERSION #define PALLADIUM_VERSION "unknown" diff --git a/source/common/io.cpp b/source/core/io.cpp similarity index 98% rename from source/common/io.cpp rename to source/core/io.cpp index b523860..f81729b 100644 --- a/source/common/io.cpp +++ b/source/core/io.cpp @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { namespace IO { diff --git a/source/common/strings.cpp b/source/core/strings.cpp similarity index 99% rename from source/common/strings.cpp rename to source/core/strings.cpp index 5b607b5..deb9f88 100644 --- a/source/common/strings.cpp +++ b/source/core/strings.cpp @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD::Strings { bool StringEndsWith(const std::string& str, diff --git a/source/common/sys.cpp b/source/core/sys.cpp similarity index 98% rename from source/common/sys.cpp rename to source/core/sys.cpp index f39525b..265f3b5 100644 --- a/source/common/sys.cpp +++ b/source/core/sys.cpp @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD::Sys { TraceMap pd_sys_tm; diff --git a/source/common/timetrace.cpp b/source/core/timetrace.cpp similarity index 95% rename from source/common/timetrace.cpp rename to source/core/timetrace.cpp index 91bea17..a99c73d 100644 --- a/source/common/timetrace.cpp +++ b/source/core/timetrace.cpp @@ -21,8 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include namespace PD::TT { void Beg(const std::string& id) { diff --git a/source/drivers/hid.cpp b/source/drivers/hid.cpp new file mode 100644 index 0000000..ed878b3 --- /dev/null +++ b/source/drivers/hid.cpp @@ -0,0 +1,44 @@ +/* +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 + +/// Reform of the RenderD7 095 Hid Api +/// Using Custom Keybindings for future +/// Porting of the library + +namespace PD { +bool Hid::IsEvent(Event e, Key keys) { return key_events[0][e] & keys; } + +void Hid::SwappyTable() { + auto tkd = key_events[1][Event_Down]; + auto tkh = key_events[1][Event_Held]; + auto tku = key_events[1][Event_Up]; + key_events[1][Event_Down] = key_events[0][Event_Down]; + key_events[1][Event_Held] = key_events[0][Event_Held]; + key_events[1][Event_Up] = key_events[0][Event_Up]; + key_events[0][Event_Down] = tkd; + key_events[0][Event_Held] = tkh; + key_events[0][Event_Up] = tku; +} +} // namespace PD \ No newline at end of file diff --git a/source/controls/hid.cpp b/source/lib3ds/drv_hid.cpp similarity index 81% rename from source/controls/hid.cpp rename to source/lib3ds/drv_hid.cpp index 6fb858f..c67407f 100644 --- a/source/controls/hid.cpp +++ b/source/lib3ds/drv_hid.cpp @@ -23,14 +23,14 @@ SOFTWARE. #include <3ds.h> -#include +#include /// Reform of the RenderD7 095 Hid Api /// Using Custom Keybindings for future /// Porting of the library namespace PD { -Hid::Hid() { +CtrHid::CtrHid() { binds[KEY_A] = A; binds[KEY_B] = B; binds[KEY_X] = X; @@ -55,7 +55,7 @@ Hid::Hid() { binds[KEY_ZR] = ZR; binds[KEY_TOUCH] = Touch; } -void Hid::Update() { +void CtrHid::Update() { hidScanInput(); for (int i = 0; i < 2; i++) { key_events[i][Event_Down] = 0; @@ -84,18 +84,4 @@ void Hid::Update() { touch[1] = touch[0]; // Cycle touch pos touch[0] = vec2(t.px, t.py); } - -bool Hid::IsEvent(Event e, Key keys) { return key_events[0][e] & keys; } - -void Hid::SwappyTable() { - auto tkd = key_events[1][Event_Down]; - auto tkh = key_events[1][Event_Held]; - auto tku = key_events[1][Event_Up]; - key_events[1][Event_Down] = key_events[0][Event_Down]; - key_events[1][Event_Held] = key_events[0][Event_Held]; - key_events[1][Event_Up] = key_events[0][Event_Up]; - key_events[0][Event_Down] = tkd; - key_events[0][Event_Held] = tkh; - key_events[0][Event_Up] = tku; -} } // namespace PD \ No newline at end of file diff --git a/source/tools/gamepad_icons.cpp b/source/lib3ds/gamepad_icons.cpp similarity index 98% rename from source/tools/gamepad_icons.cpp rename to source/lib3ds/gamepad_icons.cpp index fd13f5f..4f140b7 100644 --- a/source/tools/gamepad_icons.cpp +++ b/source/lib3ds/gamepad_icons.cpp @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include namespace PD { namespace GamePadIcons { diff --git a/source/tools/result_decoder.cpp b/source/lib3ds/result_decoder.cpp similarity index 99% rename from source/tools/result_decoder.cpp rename to source/lib3ds/result_decoder.cpp index 46895c7..5a488a6 100644 --- a/source/tools/result_decoder.cpp +++ b/source/lib3ds/result_decoder.cpp @@ -22,7 +22,7 @@ SOFTWARE. */ #ifdef PD_EXTENDED_DEBUG -#include +#include static const std::map modules = { {0, "common"}, diff --git a/source/lithium/font.cpp b/source/lithium/font.cpp new file mode 100644 index 0000000..8cb08a3 --- /dev/null +++ b/source/lithium/font.cpp @@ -0,0 +1,222 @@ +/* +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 <3ds.h> +#include + +#include +#include +#include +#include + +namespace PD { +namespace LI { +void Font::LoadTTF(const std::string& path, int height) { + sysfont = false; + TT::Scope st("LI_LoadTTF_" + path); + pixel_height = height; + int quad = height * 16; + stbtt_fontinfo inf; + std::ifstream loader(path, std::ios::binary); + if (!loader.is_open()) return; + loader.seekg(0, std::ios::end); + size_t len = loader.tellg(); + loader.seekg(0, std::ios::beg); + unsigned char* buffer = new unsigned char[len]; + loader.read(reinterpret_cast(buffer), len); + loader.close(); + stbtt_InitFont(&inf, buffer, 0); + std::vector font_tex(quad * quad); + float scale = stbtt_ScaleForPixelHeight(&inf, pixel_height); + + int ascent, descent, lineGap; + stbtt_GetFontVMetrics(&inf, &ascent, &descent, &lineGap); + int baseline = static_cast(ascent * scale); + + std::map buf_cache; + + auto tex = Texture::New(); + vec2 off; + for (u32 ii = 0x0000; ii < 0xFFFF; ii++) { + int i = stbtt_FindGlyphIndex(&inf, ii); + if (i == 0) { + continue; + } + if (stbtt_IsGlyphEmpty(&inf, i)) { + continue; + } + + Codepoint c; + int w = 0, h = 0, xo = 0, yo = 0; + unsigned char* bitmap = + stbtt_GetCodepointBitmap(&inf, scale, scale, i, &w, &h, &xo, &yo); + int x0, y0, x1, y1; + stbtt_GetCodepointBitmapBox(&inf, i, scale, scale, &x0, &y0, &x1, &y1); + + u32 hashed_map = IO::HashMemory(std::vector(bitmap, bitmap + (w * h))); + if (buf_cache.find(hashed_map) != buf_cache.end()) { + c = GetCodepoint(buf_cache[hashed_map]); + c.cp(i); + cpmap[i] = c; + free(bitmap); + continue; + } else { + buf_cache[hashed_map] = i; + } + + if (off[0] + w > quad) { + off[1] += pixel_height; + off[0] = 0; + } + + vec4 uvs; + uvs[0] = static_cast(off.x() / (float)quad); + uvs[1] = static_cast(1.f - (off.y() / (float)quad)); + uvs[2] = static_cast((float)(off.x() + w) / (float)quad); + uvs[3] = static_cast(1.f - (float)(off.y() + h) / (float)quad); + c.uv(uvs); + + c.tex(tex); + c.size(vec2(w, h)); + c.off(baseline + yo); + + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + int map_pos = ((off[1] + y) * quad + (off[0] + x)); + font_tex[map_pos] = bitmap[x + y * w]; + } + } + + free(bitmap); + cpmap[i] = c; + + // Small Patch to avoid some possible artifacts + off[0] += w + 1; + if (off[0] + w > quad) { + off[1] += pixel_height; + if (off[1] + pixel_height > quad) { + break; + } + off[0] = 0; + } + } + tex->LoadPixels(font_tex, quad, quad, Texture::A8, Texture::LINEAR); + textures.push_back(tex); +} + +Font::Codepoint& Font::GetCodepoint(u32 cp) { + auto res = cpmap.find(cp); + if (res == cpmap.end()) { + static Codepoint invalid; + return invalid.invalid(true); + } + return res->second; +} + +void Font::LoadSystemFont() { + TT::Scope st("LI_SystemFont"); + sysfont = true; + fontEnsureMapped(); + const auto fnt = fontGetSystemFont(); + const auto fnt_info = fontGetInfo(fnt); + const auto glyph_info = fontGetGlyphInfo(fnt); + this->textures.resize(glyph_info->nSheets + 1); + /// Modify the Pixel Height by 1.1f to fit the + /// Size og ttf font Rendering + pixel_height = glyph_info->cellHeight * 1.1f; + for (size_t i = 0; i < glyph_info->nSheets; i++) { + auto stex = 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->LoadExternal(tx, vec2(tx->width, tx->height), vec4(0, 1, 1, 0)); + stex->AutoUnLoad(false); + textures[i] = stex; + } + std::vector charSet; + 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; + } + } + + std::sort(charSet.begin(), charSet.end()); + charSet.erase(std::unique(charSet.begin(), charSet.end())); + + for (auto cp : charSet) { + int gidx = fontGlyphIndexFromCodePoint(fnt, cp); + if (gidx >= 0xFFFF) continue; + Codepoint codepoint; + fontGlyphPos_s dat; + fontCalcGlyphPos(&dat, fnt, gidx, GLYPH_POS_CALC_VTXCOORD, 1.f, 1.f); + + codepoint.cp(cp); + codepoint.uv(vec4(dat.texcoord.left, dat.texcoord.top, dat.texcoord.right, + dat.texcoord.bottom)); + + if (dat.sheetIndex < (int)textures.size()) { + codepoint.tex(textures[dat.sheetIndex]); + } else { + codepoint.invalid(true); + } + codepoint.size(vec2(dat.vtxcoord.right, dat.vtxcoord.bottom)); + codepoint.off(0); + cpmap[cp] = codepoint; + } +} +} // namespace LI +} // namespace PD \ No newline at end of file diff --git a/source/graphics/li7_shader.cpp b/source/lithium/li7_shader.cpp similarity index 98% rename from source/graphics/li7_shader.cpp rename to source/lithium/li7_shader.cpp index 86f07b5..d2164a8 100644 --- a/source/graphics/li7_shader.cpp +++ b/source/lithium/li7_shader.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include // clang-format off unsigned char li7_shader[] = { diff --git a/source/graphics/lithium.cpp b/source/lithium/lithium.cpp similarity index 100% rename from source/graphics/lithium.cpp rename to source/lithium/lithium.cpp diff --git a/source/lithium/objects.cpp b/source/lithium/objects.cpp new file mode 100644 index 0000000..c790e2d --- /dev/null +++ b/source/lithium/objects.cpp @@ -0,0 +1,60 @@ +/* +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 + +#include +#include +#include +#include +#include + +namespace PD { +namespace LI { +void StaticText::Setup(Renderer* ren, const vec2& pos, u32 clr, + const std::string& text, LITextFlags flags, + const vec2& box) { + this->tdim = ren->GetTextDimensions(text); + this->pos = pos; + this->ren = ren; + this->text = StaticObject::New(); + /// Ensure that it also renders Out of Screen i guess + ren->TextCommand(this->text->List(), pos, clr, text, + flags | LITextFlags_RenderOOS, box); + Renderer::OptiCommandList(this->text->List()); +} + +void StaticText::Draw() { + used = true; + for (auto& it : text->List()) { + ren->PushCommand(it); + } + text->ReCopy(); +} + +void StaticText::SetColor(u32 col) { text->ReColor(col); } +void StaticText::SetPos(const vec2& pos) { text->MoveIt(pos - this->pos); } + +void StaticText::SetLayer(int layer) { text->ReLayer(layer); } +} // namespace LI +} // namespace PD \ No newline at end of file diff --git a/source/lithium/renderer.cpp b/source/lithium/renderer.cpp new file mode 100644 index 0000000..df34408 --- /dev/null +++ b/source/lithium/renderer.cpp @@ -0,0 +1,596 @@ +/* +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 <3ds.h> +#include + +#include +#include +#include +#include +#include +#include + +namespace PD { +namespace LI { +Renderer::Renderer(LIRenderFlags flags) { + vertex_buf.resize(4 * 4096, Vertex()); + index_buf.resize(6 * 4096, 0); + + /// Use 3ds u32 here + dvlb = DVLB_ParseFile((uint32_t*)li7_shader, li7_shader_size); + shaderProgramInit(&shader); + shaderProgramSetVsh(&shader, &dvlb->DVLE[0]); + uLoc_projection = + shaderInstanceGetUniformLocation(shader.vertexShader, "projection"); + + AttrInfo_Init(&attr); + AttrInfo_AddLoader(&attr, 0, GPU_FLOAT, 2); + AttrInfo_AddLoader(&attr, 1, GPU_FLOAT, 2); + AttrInfo_AddLoader(&attr, 2, GPU_UNSIGNED_BYTE, 4); + + // Precalculate Projection (Never changes) + Mtx_OrthoTilt(&top_proj, 0.f, 400.f, 240.f, 0.f, 1.f, -1.f, false); + Mtx_OrthoTilt(&bot_proj, 0.f, 320.f, 240.f, 0.f, 1.f, -1.f, false); + + std::vector pixels(16 * 16 * 4, 255); + white = Texture::New(pixels, 16, 16); + UseTex(white); + + // Not Loading as Systemfont is freezing + // font = Font::New(); + // font->LoadSystemFont(); +} +Renderer::~Renderer() { + shaderProgramFree(&shader); + DVLB_Free(dvlb); +} + +bool Renderer::InBox(const vec2& pos, const vec2& szs, const vec4& rect) { + return (pos[0] + szs[0] >= rect[0] && pos[1] + szs[1] >= rect[1] && + pos[0] <= rect[2] && pos[1] <= rect[3]); +} + +bool Renderer::InBox(const vec2& pos, const vec4& rect) { + return (pos.x() > rect.x() && pos.x() < rect.x() + rect.z() && + pos.y() > rect.y() && pos.y() < rect.y() + rect.w()); +} + +bool Renderer::InBox(const vec2& alpha, const vec2& bravo, const vec2& charlie, + const vec4& rect) { + return ((alpha[0] < rect[2] && bravo[0] < rect[2] && charlie[0] < rect[2]) || + (alpha[1] < rect[3] && bravo[1] < rect[3] && charlie[1] < rect[3]) || + (alpha[0] > 0 && bravo[0] > 0 && charlie[0] > 0) || + (alpha[1] > 0 && bravo[1] > 0 && charlie[1] > 0)); +} + +void Renderer::RotateCorner(vec2& v, float s, float c) { + float x = v[0] * c - v[1] * s; + float y = v[1] * c + v[0] * s; + v = vec2(x, y); +} + +Rect Renderer::CreateRect(const vec2& pos, const vec2& size, float angle) { + vec2 c = size * 0.5f; // Center + vec2 corner[4] = { + vec2(-c[0], -c[1]), + vec2(-c[0] + size[0], -c[1]), + vec2(-c[0], -c[1] + size[1]), + vec2(-c[0] + size[0], -c[1] + size[1]), + }; + + // Only rotate if required + if (angle != 0.f) { + float s = std::sin(angle); + float co = std::cos(angle); + for (int i = 0; i < 4; i++) { + RotateCorner(corner[i], s, co); + } + } + + // Return Result + return Rect(corner[0] + pos + c, corner[1] + pos + c, corner[2] + pos + c, + corner[3] + pos + c); +} + +Rect Renderer::CreateLine(const vec2& a, const vec2& b, int t) { + // Usin g th evec maths api makes the code as short as it is + vec2 dir = a - b; + float len = dir.len(); + vec2 unit_dir = dir / len; + vec2 perpendicular(-unit_dir.y(), unit_dir.x()); + vec2 off = perpendicular * ((float)t * 0.5f); + + return Rect(a + off, b + off, a - off, b - off); +} + +void Renderer::OptiCommandList(std::vector& list) { + std::sort(list.begin(), list.end(), [](Command::Ref a, Command::Ref b) { + if (a->Layer() == b->Layer()) { + if (a->Tex() == b->Tex()) { + return a->Index() < b->Index(); + } + return a->Tex() < b->Tex(); // else + } + return a->Layer() < b->Layer(); // else + }); +} + +void Renderer::SetupCommand(Command::Ref cmd) { + cmd->Index(cmd_idx++).Layer(current_layer).Tex(current_tex); +} + +void Renderer::QuadCommand(Command::Ref cmd, const Rect& quad, const Rect& uv, + u32 col) { + cmd->PushIndex(0).PushIndex(1).PushIndex(2); + cmd->PushIndex(0).PushIndex(2).PushIndex(3); + cmd->PushVertex(Vertex(quad.BotRight(), uv.BotRight(), col)); + cmd->PushVertex(Vertex(quad.TopRight(), uv.TopRight(), col)); + cmd->PushVertex(Vertex(quad.TopLeft(), uv.TopLeft(), col)); + cmd->PushVertex(Vertex(quad.BotLeft(), uv.BotLeft(), col)); +} + +void Renderer::TriangleCommand(Command::Ref cmd, const vec2& a, const vec2& b, + const vec2& c, u32 col) { + cmd->Index(cmd_idx++).Layer(current_layer).Tex(current_tex); + cmd->PushIndex(2).PushIndex(1).PushIndex(0); + cmd->PushVertex(Vertex(a, vec2(0.f, 1.f), col)); + cmd->PushVertex(Vertex(b, vec2(1.f, 1.f), col)); + cmd->PushVertex(Vertex(c, vec2(1.f, 0.f), col)); +} + +void Renderer::TextCommand(std::vector& cmds, const vec2& pos, + u32 color, const std::string& text, + LITextFlags flags, const vec2& box) { + if (!font) { + return; + } + vec2 off; + float cfs = (default_font_h * text_size) / (float)font->PixelHeight(); + float lh = (float)font->PixelHeight() * cfs; + vec2 td; + vec2 rpos = pos; + vec2 rbox = box; + if (flags & (LITextFlags_AlignMid | LITextFlags_AlignRight)) { + td = GetTextDimensions(text); + if (rbox[0] == 0.f) { + rbox[0] = area_size.x(); + } + if (rbox[1] == 0.f) { + rbox[1] = area_size.y(); + } + } + if (flags & LITextFlags_AlignMid) { + rpos = rbox * 0.5 - td * 0.5 + pos; + } + if (flags & LITextFlags_AlignRight) { + rpos[0] = rpos[0] - td[0]; + } + + std::vector lines; + std::istringstream iss(text); + std::string tmp; + while (std::getline(iss, tmp)) { + lines.push_back(tmp); + } + + for (auto& it : lines) { + if (flags & LITextFlags_Short) { + vec2 tmp_dim; + it = ShortText(it, box.x() - pos.x(), tmp_dim); + } + /// Well support OOS Rendering here as well + /// Fixes UI7 Scroll back up bug + if (rpos[1] + off[1] + lh < 0 && !(flags & LITextFlags_RenderOOS)) { + off[1] += lh; + continue; + } else if (rpos[1] + off[1] > GetViewport().w() && + !(flags & LITextFlags_RenderOOS)) { + // Break cause next lines would be out of screen + break; + } + auto wline = Strings::MakeWstring(it); + auto cmd = Command::New(); + current_tex = font->GetCodepoint(wline[0]).tex(); + SetupCommand(cmd); + cmd->Rendermode(RenderMode_Font); + for (auto& jt : wline) { + auto cp = font->GetCodepoint(jt); + if (cp.invalid() && jt != '\n' && jt != '\t') { + continue; + } + if (current_tex != cp.tex()) { + cmds.push_back(cmd); + cmd = Command::New(); + current_tex = cp.tex(); + SetupCommand(cmd); + cmd->Rendermode(RenderMode_Font); + } + if (jt == '\t') { + off[0] += 16 * cfs; + } else { + if (jt != ' ') { + int lr = current_layer; + if (flags & LITextFlags_Shaddow) { + // Draw + Rect rec = CreateRect( + rpos + vec2(off[0] + 1, off[1] + (cp.off() * cfs)) + 1, + cp.size() * cfs, 0.f); + QuadCommand(cmd, rec, cp.uv(), 0xff111111); + current_layer++; + } + // Draw + Rect rec = CreateRect(rpos + off + vec2(0, (cp.off() * cfs)), + cp.size() * cfs, 0.f); + QuadCommand(cmd, rec, cp.uv(), color); + current_layer = lr; + } else { + if (!font->SystemFont()) { + off[0] += 2 * cfs; + } + } + off[0] += cp.size().x() * cfs + 2 * cfs; + } + } + cmds.push_back(cmd); + off[1] += lh; + off[0] = 0; + } +} + +vec4 Renderer::GetViewport() { return vec4(vec2(), screen->GetSize()); } + +std::string Renderer::ShortText(const std::string& text, int maxlen, + vec2& newsize) { + vec2 cdim; + if (flags & LIRenderFlags_TMS) { + auto e = tms.find(text); + if (e != tms.end()) { + e->second.TimeCreated(Sys::GetTime()); + if (e->second.Optional()) { + return e->second.Text(); + } + cdim = e->second.Size(); + } + } + cdim = this->GetTextDimensions(text); + if (cdim[0] < (float)maxlen) { + return text; + } + std::string ext; + /// Forgot why i called this var ending cause + /// Its more a placeholder for removed content + std::string ending = "..."; + std::string cpy = text; + std::string res; + size_t extension = text.find_last_of('.'); + if (extension != text.npos) { + ext = text.substr(extension); + cpy = text.substr(0, extension); + maxlen -= GetTextDimensions(ext).x(); + } + maxlen -= GetTextDimensions(ending).x(); + for (auto& it : cpy) { + if (GetTextDimensions(res).x() > (float)maxlen) { + res += ending; + res += ext; + newsize = GetTextDimensions(res); + if (flags & LIRenderFlags_TMS) { + auto& tmp = tms[text]; + tmp.Text(res); + tmp.Size(newsize); + tmp.TimeCreated(Sys::GetTime()); + tmp.Optional(true); + } + break; + } + res += it; + } + return res; +} + +std::string Renderer::WrapText(const std::string& text, int maxlen, + vec2& newsize) {} + +vec2 Renderer::GetTextDimensions(const std::string& text) { + if (!font) { + // No font no size (oder so) + return vec2(); + } + // Handle TextMapSystem + if (flags & LIRenderFlags_TMS) { + auto ref = tms.find(text); + if (ref != tms.end()) { + ref->second.TimeCreated(Sys::GetTime()); + return ref->second.Size(); + } + } + // Use wstring for exemple for german äöü + auto wtext = Strings::MakeWstring(text); + // Create a temp position and offset as [0, 0] + vec2 res; + float x = 0; + // Curent Font Scale + float cfs = (default_font_h * text_size) / (float)font->PixelHeight(); + float lh = (float)font->PixelHeight() * cfs; + size_t index = 0; + for (auto& it : wtext) { + if (it == '\0') { + break; + } + index++; + auto cp = font->GetCodepoint(it); + if (cp.invalid() && it != '\n' && it != '\t' && it != ' ') { + continue; + } + switch (it) { + case '\n': + res[1] += lh; + res[0] = std::max(res[0], x); + x = 0.f; + break; + case '\t': + x += 16 * cfs; + break; + case ' ': + if (!font->SystemFont()) { + x += 2 * cfs; + } + // Fall trough here to get the same result as in + // TextCommand if/else Section + default: + x += cp.size().x() * cfs; + if (index != wtext.size()) { + x += 2 * cfs; + } + break; + } + } + res[0] = std::max(res[0], x); + res[1] += lh; + if (flags & LIRenderFlags_TMS) { + tms[text] = TextBox(res, Sys::GetTime()); + } + return res; +} + +void Renderer::UpdateRenderMode(const RenderMode& mode) { + C3D_TexEnv* env = C3D_GetTexEnv(0); + switch (mode) { + case RenderMode_Font: + /// Sets Only Alpha Using the Color and Replase RGB with vertex color + C3D_TexEnvInit(env); + C3D_TexEnvSrc(env, C3D_RGB, GPU_PRIMARY_COLOR); + C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE); + C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0); + C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE); + break; + // Fall trough instead of defining twice + case RenderMode_RGBA: + default: + /// Use Texture for RGBA and vertexcolor for visibility + C3D_TexEnvInit(env); + C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0); + C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE); + break; + } +} + +void Renderer::PrepareRender() { + if (font_update) { + tms.clear(); + font_update = false; + } + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + TT::Beg("LI_RenderAll"); + vertex_idx = 0; + index_idx = 0; + vertices = 0; + indices = 0; + commands = 0; + drawcalls = 0; + C3D_BindProgram(&shader); + C3D_SetAttrInfo(&attr); +} + +void Renderer::FinalizeRender() { + C3D_FrameEnd(0); + TT::End("LI_RenderAll"); + current_layer = 0; + cmd_idx = 0; + rot = 0.f; + UseTex(); + if (flags & LIRenderFlags_TMS) { + std::vector rem; + for (auto& it : tms) { + if (Sys::GetTime() - it.second.TimeCreated() > 5) rem.push_back(it.first); + } + for (auto it : rem) tms.erase(it); + } else { + tms.clear(); + } + if (flags & LIRenderFlags_AST) { + std::vector rem; + for (auto it : ast) { + if (!it.second->Used()) { + rem.push_back(it.first); + } + it.second->SetUnused(); + } + for (auto& it : rem) { + ast.erase(it); + } + } else { + ast.clear(); + } +} + +void Renderer::Render(Screen::Ref s) { + Assert(s.get(), "Expected Screen Address but got nullptr!"); + s->Clear(); + s->Use(); + bool bot = s->ScreenType() == Screen::Bottom; + C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, + (bot ? &bot_proj : &top_proj)); + C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL); + UpdateRenderMode(RenderMode_RGBA); + int total_vertices = 0; + int total_indices = 0; + auto& cmds = draw_list[Screen32(s)]; + commands += cmds.size(); + size_t index = 0; + if (flags & LIRenderFlags_LRS) { + OptiCommandList(cmds); + } + while (index < cmds.size()) { + C3D_Tex* tex = cmds[index]->Tex()->GetTex(); + auto mode = cmds[index]->Rendermode(); + UpdateRenderMode(mode); + u32 start_vtx = vertex_idx; + u32 start_idx = index_idx; + while (index < cmds.size() && cmds[index]->Tex()->GetTex() == tex && + cmds[index]->Rendermode() == mode) { + auto c = cmds[index]; + // Indices + for (size_t i = 0; i < c->IndexList().size(); i++) { + index_buf[index_idx++] = vertex_idx + c->IndexList().at(i); + } + // Vertices + for (size_t i = 0; i < c->VertexList().size(); i++) { + vertex_buf[vertex_idx++] = c->VertexList().at(i); + } + index++; + } + + C3D_TexBind(0, tex); + + auto bufInfo = C3D_GetBufInfo(); + BufInfo_Init(bufInfo); + BufInfo_Add(bufInfo, vertex_buf.data(), sizeof(Vertex), 3, 0x210); + + C3D_DrawElements(GPU_TRIANGLES, index_idx - start_idx, C3D_UNSIGNED_SHORT, + index_buf.data() + start_idx); + + drawcalls++; + total_vertices += vertex_idx - start_vtx; + total_indices += index_idx - start_idx; + } + cmds.clear(); + C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL); + vertices += total_vertices; + indices += total_indices; +} + +void Renderer::DrawRect(const vec2& pos, const vec2& size, u32 color, + const Rect& uv) { + if (!InBox(pos, size, GetViewport())) { + // Instand abort as it is out of screen + return; + } + Rect rec = CreateRect(pos, size, rot); + auto cmd = Command::New(); + SetupCommand(cmd); + QuadCommand(cmd, rec, uv, color); + draw_list[Screen32(screen)].push_back(cmd); +} + +void Renderer::DrawRectSolid(const vec2& pos, const vec2& size, u32 color) { + UseTex(); + DrawRect(pos, size, color, vec4(0.f, 1.f, 1.f, 0.f)); +} + +void Renderer::DrawTriangle(const vec2& a, const vec2& b, const vec2& c, + u32 color) { + if (!InBox(a, b, c, GetViewport())) { + return; + } + UseTex(); + auto cmd = Command::New(); + SetupCommand(cmd); + TriangleCommand(cmd, a, b, c, color); + draw_list[Screen32(screen)].push_back(cmd); +} + +void Renderer::DrawCircle(const vec2& center_pos, float r, u32 color, + int segments) { + if (segments < 3) { + return; + } + auto cmd = Command::New(); + cmd->Index(cmd_idx++).Layer(current_layer).Tex(current_tex); + for (int i = 1; i < segments - 1; i++) { + cmd->PushIndex(0); + cmd->PushIndex(i + 1).PushIndex(i); + } + float as = 2.f * M_PI / segments; + for (int i = 0; i < segments; i++) { + float a = i * as; + float x = center_pos.x() + r * std::cos(a); + float y = center_pos.y() + r * std::sin(a); + cmd->PushVertex(Vertex( + vec2(x, y), vec2((std::cos(a) + 1.f) / 2.f, (std::sin(a) + 1.f) / 2.f), + color)); + } + draw_list[Screen32(screen)].push_back(cmd); +} + +void Renderer::DrawLine(const vec2& a, const vec2& b, u32 color, int t) { + UseTex(); + Rect line = CreateLine(a, b, t); + + auto cmd = Command::New(); + SetupCommand(cmd); + QuadCommand(cmd, line, vec4(0.f, 1.f, 1.f, 0.f), color); + draw_list[Screen32(screen)].push_back(cmd); +} + +void Renderer::DrawImage(const vec2& pos, Texture::Ref tex, const vec2& scale) { + UseTex(tex); + DrawRect(pos, tex->GetSize() * scale, 0xffffffff, tex->GetUV()); +} + +void Renderer::DrawText(const vec2& pos, u32 color, const std::string& text, + u32 flags, const vec2& ap) { + if (!font) { + return; + } + if (this->flags & LIRenderFlags_AST) { + u32 id = Strings::FastHash(text); + auto e = ast.find(id); + if (e == ast.end()) { + ast[id] = StaticText::New(); + e = ast.find(id); + } + if (!e->second->IsSetup() || e->second->Font() != font) { + e->second->Setup(this, pos, color, text, flags, ap); + e->second->Font(font); + } + e->second->SetPos(pos); + e->second->SetColor(color); + e->second->Draw(); + return; + } + TextCommand(draw_list[Screen32(screen)], pos, color, text, flags, ap); +} +} // namespace LI +} // namespace PD \ No newline at end of file diff --git a/source/graphics/spritesheet.cpp b/source/lithium/spritesheet.cpp similarity index 96% rename from source/graphics/spritesheet.cpp rename to source/lithium/spritesheet.cpp index a11223d..3c98025 100644 --- a/source/graphics/spritesheet.cpp +++ b/source/lithium/spritesheet.cpp @@ -21,8 +21,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include +#include namespace PD { SpriteSheet::~SpriteSheet() { textures.clear(); } diff --git a/source/graphics/texture.cpp b/source/lithium/texture.cpp similarity index 97% rename from source/graphics/texture.cpp rename to source/lithium/texture.cpp index a1755ab..a7bb01d 100644 --- a/source/graphics/texture.cpp +++ b/source/lithium/texture.cpp @@ -26,10 +26,10 @@ SOFTWARE. #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/source/overlays/keyboard.cpp b/source/overlays/keyboard.cpp index 6453d42..5d3f8db 100644 --- a/source/overlays/keyboard.cpp +++ b/source/overlays/keyboard.cpp @@ -24,7 +24,7 @@ SOFTWARE. #include #include #include -#include +#include namespace PD { struct Key { diff --git a/source/overlays/performance.cpp b/source/overlays/performance.cpp index c5c404f..e154a47 100644 --- a/source/overlays/performance.cpp +++ b/source/overlays/performance.cpp @@ -21,8 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include #include namespace PD { diff --git a/source/ui7/container/container.cpp b/source/ui7/container/container.cpp index 930f4c3..5791149 100644 --- a/source/ui7/container/container.cpp +++ b/source/ui7/container/container.cpp @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include namespace PD { diff --git a/source/ui7/drawlist.cpp b/source/ui7/drawlist.cpp index 5f9599d..0ec0f1d 100644 --- a/source/ui7/drawlist.cpp +++ b/source/ui7/drawlist.cpp @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include namespace PD { @@ -62,7 +62,7 @@ void DrawList::AddText(vec2 pos, const std::string& text, const UI7Color& clr, u32 id = Strings::FastHash(text); auto e = static_text.find(id); if (e == static_text.end()) { - static_text[id] = LI::Renderer::StaticText::New(); + static_text[id] = LI::StaticText::New(); e = static_text.find(id); } if (!e->second->IsSetup() || e->second->Font() != ren->Font()) { diff --git a/source/ui7/menu.cpp b/source/ui7/menu.cpp index 86d755f..34ae6fe 100644 --- a/source/ui7/menu.cpp +++ b/source/ui7/menu.cpp @@ -21,8 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include +#include +#include #include namespace PD { diff --git a/source/ui7/ui7.cpp b/source/ui7/ui7.cpp index e23d1bd..e107265 100644 --- a/source/ui7/ui7.cpp +++ b/source/ui7/ui7.cpp @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include namespace PD { diff --git a/test/app/main.cpp b/test/app/main.cpp index 21a54ab..2fa6285 100644 --- a/test/app/main.cpp +++ b/test/app/main.cpp @@ -84,7 +84,7 @@ class Test : public PD::App { m->SameLine(); if (m->Button("Palladium")) { this->FeatureDisable(AppFLags_UserLoop); - Overlays()->Push(PD::New(this)); + Overlays()->Push(PD::New()); } m->SeparatorText("SeparatorText"); m->Checkbox("Test", cbtest); diff --git a/tools/build_shaders.py b/tools/build_shaders.py index a6d7963..d904862 100644 --- a/tools/build_shaders.py +++ b/tools/build_shaders.py @@ -86,9 +86,9 @@ for object in shaders: name = Path(Path(object).stem).stem bp = os.path.dirname(object) build_shader(object) - file2array(bp + '/' + name + '.shbin', 'pd/graphics/') - install_code(name + '.cpp', 'source/graphics/') - install_code(name + '.hpp', 'include/pd/graphics/') + file2array(bp + '/' + name + '.shbin', 'pd/lithium/') + install_code(name + '.cpp', 'source/lithium/') + install_code(name + '.hpp', 'include/pd/lithium/') cleanup() print("Done") \ No newline at end of file