Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
ea76a304d4 | |||
f75f7067ff | |||
13c2869ba8 | |||
dbffb7f316 | |||
6738fda55c | |||
35272687f6 |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "backends/desktop/glfw"]
|
||||
path = backends/desktop/glfw
|
||||
url = https://github.com/glfw/glfw.git
|
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@ -10,7 +10,8 @@
|
||||
"C:/devkitpro/portlibs/3ds/include/**"
|
||||
],
|
||||
"defines": [
|
||||
"BUILD_CTR"
|
||||
"BUILD_CTR",
|
||||
"__3DS__"
|
||||
],
|
||||
"compilerPath": "C:/devkitPro/devkitARM/bin/arm-none-eabi-g++.exe",
|
||||
"intelliSenseMode": "gcc-arm",
|
||||
|
156
CMakeLists.txt
156
CMakeLists.txt
@ -3,15 +3,27 @@ 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(opts "BUILD_SHARED")
|
||||
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})
|
||||
string(REPLACE "-" "_" FLAG_NAME_T ${TARGET_NAME})
|
||||
string(TOUPPER ${FLAG_NAME_T} FLAG_NAME_F)
|
||||
|
||||
if(ARG_BUILD_SHARED)
|
||||
add_library(${TARGET_NAME} SHARED ${ARG_SRC_FILES})
|
||||
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=1)
|
||||
message("Building SHARED library: ${FLAG_NAME_F}_BUILD_SHARED=1")
|
||||
else()
|
||||
add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES})
|
||||
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=0)
|
||||
message("Building STATIC library: ${FLAG_NAME_F}_BUILD_SHARED=0")
|
||||
endif()
|
||||
target_include_directories(${TARGET_NAME} PUBLIC
|
||||
include
|
||||
${DEVKITPRO}/portlibs/3ds/include)
|
||||
${DEVKITPRO}/portlibs/3ds/include
|
||||
backends)
|
||||
target_compile_definitions(${TARGET_NAME} PUBLIC
|
||||
-D_GNU_SOURCE=1
|
||||
-DPALLADIUM_VERSION="${PROJECT_VERSION}"
|
||||
@ -25,16 +37,6 @@ 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)
|
||||
if(DEFINED ENV{DEVKITPRO})
|
||||
set(CMAKE_TOOLCHAIN_FILE "$ENV{DEVKITPRO}/cmake/3DS.cmake" CACHE PATH "toolchain file")
|
||||
else()
|
||||
message(FATAL_ERROR "Please define DEVKITPRO to point to your SDK path!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
## Get Current Git Commit Value
|
||||
execute_process(
|
||||
COMMAND git rev-parse --short HEAD
|
||||
@ -52,9 +54,12 @@ execute_process(
|
||||
)
|
||||
|
||||
# Set Project
|
||||
project(palladium LANGUAGES C CXX VERSION 0.3.0)
|
||||
project(palladium LANGUAGES C CXX VERSION 0.4.0)
|
||||
|
||||
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
|
||||
option(PD_BUILD_SHARED "Build Shared Libraries" OFF)
|
||||
|
||||
message("Var: ${PD_BUILD_SHARED}")
|
||||
|
||||
# Enable Compile Command Export
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
@ -63,9 +68,15 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
|
||||
# Set Special C and CXX flags
|
||||
# Set Special C and CXX flags for 3ds
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
if(${PD_BUILD_SHARED})
|
||||
message(ERROR "3DS Only supports Static libraries")
|
||||
endif()
|
||||
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")
|
||||
endif()
|
||||
#include_directories(include)
|
||||
|
||||
## Core Source Code
|
||||
set(CORE_SRC
|
||||
@ -73,6 +84,8 @@ source/core/common.cpp
|
||||
source/core/bit_util.cpp
|
||||
source/core/color.cpp
|
||||
source/core/io.cpp
|
||||
source/core/hid_driver.cpp
|
||||
source/core/mat.cpp
|
||||
source/core/strings.cpp
|
||||
source/core/sys.cpp
|
||||
source/core/timer.cpp
|
||||
@ -88,123 +101,58 @@ source/image/img_convert.cpp)
|
||||
set(EXTERNAL_SRC
|
||||
source/external/stb.cpp)
|
||||
|
||||
## Drivers Source Code
|
||||
set(DRVS_SRC
|
||||
source/drivers/hid.cpp)
|
||||
|
||||
## Lib3ds Source Code
|
||||
set(L3DS_SRC
|
||||
source/lib3ds/gamepad_icons.cpp
|
||||
source/lib3ds/result_decoder.cpp
|
||||
source/lib3ds/drv_hid.cpp
|
||||
source/lib3ds/hwinfo.cpp
|
||||
source/lib3ds/os.cpp)
|
||||
|
||||
## Lithium Source Code
|
||||
## Lithiu, Source Code
|
||||
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/drawlist.cpp
|
||||
source/lithium/renderer.cpp)
|
||||
|
||||
## Sounbd Source Code
|
||||
set(SOUND_SRC
|
||||
source/sound/mp3.cpp)
|
||||
|
||||
## Overlay source Code
|
||||
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)
|
||||
|
||||
## App Source Code
|
||||
set(APP_SRC
|
||||
source/app/app.cpp
|
||||
source/app/lang.cpp
|
||||
source/app/error.cpp)
|
||||
## Net Source Code
|
||||
set(NET_SRC
|
||||
source/net/socket.cpp)
|
||||
|
||||
## UI7 Source Code
|
||||
set(UI7_SRC
|
||||
source/ui7/drawlist.cpp
|
||||
source/ui7/io.cpp
|
||||
source/ui7/layout.cpp
|
||||
source/ui7/menu.cpp
|
||||
source/ui7/remenu.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/coloredit.cpp
|
||||
source/ui7/container/dragdata.cpp
|
||||
source/ui7/container/dynobj.cpp
|
||||
source/ui7/container/image.cpp
|
||||
source/ui7/container/label.cpp)
|
||||
|
||||
#### Creating the Libraries (if activated) ####
|
||||
#### Creating the Libraries ####
|
||||
if(PD_BUILD_SHARED)
|
||||
add_pd_lib(pd-core BUILD_SHARED TRUE SRC_FILES ${CORE_SRC})
|
||||
add_pd_lib(pd-image BUILD_SHARED TRUE SRC_FILES ${IMAGE_SRC} DEPENDS pd-core)
|
||||
add_pd_lib(pd-external SRC_FILES ${EXTERNAL_SRC})
|
||||
add_pd_lib(pd-lithium BUILD_SHARED TRUE SRC_FILES ${LI_SRC} DEPENDS pd-core)
|
||||
add_pd_lib(pd-net BUILD_SHARED TRUE SRC_FILES ${NET_SRC} DEPENDS pd-core)
|
||||
add_pd_lib(pd-ui7 BUILD_SHARED TRUE SRC_FILES ${UI7_SRC} DEPENDS pd-core pd-lithium)
|
||||
else()
|
||||
add_pd_lib(pd-core SRC_FILES ${CORE_SRC})
|
||||
add_pd_lib(pd-image SRC_FILES ${IMAGE_SRC} DEPENDS pd-core)
|
||||
add_pd_lib(pd-external SRC_FILES ${EXTERNAL_SRC})
|
||||
add_pd_lib(pd-drivers SRC_FILES ${DRVS_SRC} DEPENDS pd-core)
|
||||
add_pd_lib(pd-lib3ds SRC_FILES ${L3DS_SRC} DEPENDS pd-drivers)
|
||||
add_pd_lib(pd-lithium SRC_FILES ${LI_SRC} DEPENDS pd-core pd-image pd-external citro3d)
|
||||
add_pd_lib(pd-sound SRC_FILES ${SOUND_SRC} DEPENDS pd-core mpg123)
|
||||
add_pd_lib(pd-overlays SRC_FILES ${OVL_SRC} DEPENDS pd-lithium)
|
||||
add_pd_lib(pd-app SRC_FILES ${APP_SRC} DEPENDS pd-overlays pd-drivers pd-lib3ds)
|
||||
add_pd_lib(pd-ui7 SRC_FILES ${UI7_SRC} DEPENDS pd-drivers pd-lithium)
|
||||
add_pd_lib(pd-lithium SRC_FILES ${LI_SRC} DEPENDS pd-core)
|
||||
add_pd_lib(pd-net SRC_FILES ${NET_SRC} DEPENDS pd-core)
|
||||
add_pd_lib(pd-ui7 SRC_FILES ${UI7_SRC} DEPENDS pd-core pd-lithium)
|
||||
endif()
|
||||
|
||||
add_library(palladium INTERFACE)
|
||||
target_link_libraries(palladium INTERFACE
|
||||
pd-core pd-image pd-external pd-drivers pd-lib3ds
|
||||
pd-lithium pd-overlays pd-app pd-ui7
|
||||
pd-core pd-image pd-external pd-lithium pd-net pd-ui7
|
||||
)
|
||||
|
||||
add_dependencies(palladium
|
||||
pd-core pd-image pd-external pd-drivers
|
||||
pd-lib3ds pd-lithium pd-overlays pd-app pd-ui7
|
||||
pd-core pd-image pd-external pd-lithium pd-net pd-ui7
|
||||
)
|
||||
|
||||
add_library(palladium-lite INTERFACE)
|
||||
target_link_libraries(palladium-lite INTERFACE
|
||||
pd-core pd-image pd-external pd-drivers pd-lib3ds
|
||||
pd-lithium
|
||||
)
|
||||
|
||||
add_dependencies(palladium-lite
|
||||
pd-core pd-image pd-external pd-drivers
|
||||
pd-lib3ds pd-lithium
|
||||
)
|
||||
|
||||
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})
|
||||
target_link_libraries(test PUBLIC palladium citro3d ctru m)
|
||||
|
||||
add_executable(testbench test/bench/main.cpp)
|
||||
target_include_directories(testbench PUBLIC include test/bench)
|
||||
target_link_directories(testbench PUBLIC ${CMAKE_BINARY_DIR})
|
||||
target_link_libraries(testbench PUBLIC palladium citro3d ctru m)
|
||||
# Generate 3DSX
|
||||
ctr_generate_smdh(
|
||||
${CMAKE_BINARY_DIR}/test.smdh
|
||||
NAME "${APP_NAME}"
|
||||
DESCRIPTION "Palladium test app"
|
||||
AUTHOR "tobid7"
|
||||
ICON "test/romfs/icon.png"
|
||||
)
|
||||
ctr_create_3dsx(
|
||||
test
|
||||
OUTPUT "${CMAKE_BINARY_DIR}/test.3dsx"
|
||||
SMDH "${CMAKE_BINARY_DIR}/test.smdh"
|
||||
ROMFS "${CMAKE_SOURCE_DIR}/test/romfs"
|
||||
)
|
||||
ctr_create_3dsx(
|
||||
testbench
|
||||
OUTPUT "${CMAKE_BINARY_DIR}/testbench.3dsx"
|
||||
SMDH "${CMAKE_BINARY_DIR}/test.smdh"
|
||||
ROMFS "${CMAKE_SOURCE_DIR}/test/romfs"
|
||||
)
|
||||
endif()
|
||||
|
||||
install(DIRECTORY include DESTINATION ".")
|
@ -27,16 +27,15 @@ make install
|
||||
|
||||
| Name | Last Updated | Platform | Depends |
|
||||
|---|---|---|---|
|
||||
| pd-core | 0.2.6 | multi | none |
|
||||
| pd-core | 0.3.3 | multi | none |
|
||||
| pd-external | 0.1.0 | multi | none |
|
||||
| pd-image | 0.2.6 | multi | pd-core |
|
||||
| pd-drivers | 0.2.4 | multi | pd-core |
|
||||
| pd-image | 0.3.3 | multi | pd-core |
|
||||
| pd-lib3ds | 0.2.4 | 3ds | pd-core, pd-drivers |
|
||||
| pd-net | 0.2.4 | 3ds | pd-core, pd-lib3ds |
|
||||
| pd-lithium | 0.2.9 | 3ds | pd-core, pd-image pd-lib3ds, citro3d |
|
||||
| pd-lithium | 0.3.3 | multi | pd-core |
|
||||
| pd-sound | 0.2.4 | 3ds | pd-core, mpg123 |
|
||||
| pd-overlays | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium, pd-ui7 |
|
||||
| pd-ui7 | 0.2.9 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium |
|
||||
| pd-ui7 | 0.3.3 | multi | pd-core, pd-lithium |
|
||||
| pd-app | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium |
|
||||
|
||||
## Credits
|
||||
|
18
backends/3ds/CMakeLists.txt
Normal file
18
backends/3ds/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
# Make sure to use 3ds toolschain for 3ds build :)
|
||||
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
if(DEFINED ENV{DEVKITPRO})
|
||||
set(CMAKE_TOOLCHAIN_FILE "$ENV{DEVKITPRO}/cmake/3DS.cmake" CACHE PATH "toolchain file")
|
||||
else()
|
||||
message(FATAL_ERROR "Please define DEVKITPRO to point to your SDK path!")
|
||||
endif()
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions")
|
||||
|
||||
add_library(pd-backend-3ds STATIC
|
||||
source/li_backend_c3d.cpp
|
||||
source/pd_hid_3ds.cpp)
|
||||
target_include_directories(pd-backend-3ds PUBLIC include)
|
||||
target_link_libraries(pd-backend-3ds PUBLIC palladium)
|
84
backends/3ds/include/li_backend_c3d.hpp
Normal file
84
backends/3ds/include/li_backend_c3d.hpp
Normal file
@ -0,0 +1,84 @@
|
||||
#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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/backend.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); }
|
||||
};
|
||||
namespace LI {
|
||||
class Backend_C3D : public PD::LI::Backend {
|
||||
public:
|
||||
Backend_C3D() : LI::Backend("Citro3D") {}
|
||||
~Backend_C3D() {}
|
||||
PD_SMART_CTOR(Backend_C3D)
|
||||
|
||||
void Init() override;
|
||||
|
||||
void Deinit() override;
|
||||
|
||||
void NewFrame() override;
|
||||
|
||||
void BindTexture(PD::LI::TexAddress addr) override;
|
||||
|
||||
void RenderDrawData(const PD::Vec<PD::LI::Command::Ref>& Commands) override;
|
||||
|
||||
PD::LI::Texture::Ref LoadTexture(
|
||||
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;
|
||||
|
||||
private:
|
||||
Vec<Vertex, LinearAlloc<Vertex>> VertexBuffer;
|
||||
Vec<u16, LinearAlloc<u16>> IndexBuffer;
|
||||
size_t CurrentVertex = 0;
|
||||
size_t CurrentIndex = 0;
|
||||
Mat4 Projection;
|
||||
int pLocProjection = 0;
|
||||
DVLB_s* ShaderCode;
|
||||
shaderProgram_s Shader;
|
||||
C3D_AttrInfo ShaderInfo;
|
||||
// For Stats
|
||||
PD::u32 num_vtx = 0;
|
||||
PD::u32 num_idx = 0;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -23,19 +23,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/hid_driver.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Nintendo 3DS Input Driver
|
||||
*/
|
||||
class CtrHid : public Hid {
|
||||
class Hid3DS : public Hid {
|
||||
public:
|
||||
/**
|
||||
* Constructor to setup Key binds
|
||||
*/
|
||||
CtrHid();
|
||||
~CtrHid() = default;
|
||||
Hid3DS();
|
||||
~Hid3DS() = default;
|
||||
PD_SMART_CTOR(Hid3DS)
|
||||
|
||||
/**
|
||||
* Overrideing the Update Function for Input Checking etc
|
117
backends/3ds/include/pd_net_3ds.hpp
Normal file
117
backends/3ds/include/pd_net_3ds.hpp
Normal file
@ -0,0 +1,117 @@
|
||||
#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 <3ds.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <malloc.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <pd/net/backend.hpp>
|
||||
|
||||
namespace PD {
|
||||
class NetBackend3DS : public Net::Backend {
|
||||
public:
|
||||
NetBackend3DS() : Net::Backend("3DS") {}
|
||||
~NetBackend3DS() = default;
|
||||
PD_SMART_CTOR(NetBackend3DS)
|
||||
|
||||
bool Init() override {
|
||||
pSocBuffer = (uint32_t*)memalign(pSocAlign, pSocBufferSize);
|
||||
Result ret = 0;
|
||||
if (pSocBuffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((ret = socInit(pSocBuffer, pSocBufferSize)) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Deinit() override { socExit(); }
|
||||
int NewSocket() override { return socket(AF_INET, SOCK_STREAM, 0); }
|
||||
void Close(int sock_id) override { close(sock_id); }
|
||||
int GetInvalidRef() const override { return -1; }
|
||||
|
||||
bool Bind(int sock_id, u16 port) {
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
||||
}
|
||||
bool Listen(int sock_id, int backlog = 5) {
|
||||
return listen(sock_id, backlog) != -1;
|
||||
}
|
||||
|
||||
bool WaitForRead(int sock_id, int timeout_ms) override {
|
||||
fd_set set;
|
||||
FD_ZERO(&set);
|
||||
FD_SET(sock_id, &set);
|
||||
|
||||
timeval timeout{};
|
||||
timeout.tv_sec = timeout_ms / 1000;
|
||||
timeout.tv_usec = (timeout_ms % 1000) * 1000;
|
||||
|
||||
int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout);
|
||||
return (result > 0 && FD_ISSET(sock_id, &set));
|
||||
}
|
||||
|
||||
bool Accept(int sock_id, Net::Socket::Ref client) {
|
||||
int client_soc = accept(sock_id, nullptr, nullptr);
|
||||
if (client_soc == -1) {
|
||||
return false;
|
||||
}
|
||||
client->pSocket = client_soc;
|
||||
return true;
|
||||
}
|
||||
bool Connect(int sock_id, const std::string& ip, u16 port) {
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
inet_pton(AF_INET, ip.c_str(), &addr.sin_addr);
|
||||
return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
||||
}
|
||||
int Send(int sock_id, const std::string& data) {
|
||||
return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0);
|
||||
}
|
||||
int Receive(int sock_id, std::string& data, int size = 1024) {
|
||||
char* tmp = new char[size];
|
||||
int res = recv(sock_id, tmp, size, 0);
|
||||
if (res > 0) {
|
||||
data.assign(tmp, res);
|
||||
}
|
||||
delete[] tmp;
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
/** using libctru u32 here */
|
||||
const uint32_t pSocAlign = 0x1000;
|
||||
const uint32_t pSocBufferSize = 0x100000;
|
||||
uint32_t* pSocBuffer = nullptr;
|
||||
};
|
||||
} // namespace PD
|
231
backends/3ds/source/li_backend_c3d.cpp
Normal file
231
backends/3ds/source/li_backend_c3d.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
#include <li_backend_c3d.hpp>
|
||||
|
||||
/// @brief Shader Code (Unused as i dont want to use libpicasso here (yet))
|
||||
const char* LIShaderCTR = R"(
|
||||
; LI7 Shader
|
||||
; Constants
|
||||
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
|
||||
.alias ones myconst.yyyy ; Vector full of ones
|
||||
|
||||
; Uniforms
|
||||
.fvec projection[4]
|
||||
|
||||
; Outputs
|
||||
.out out_position position
|
||||
.out out_color color
|
||||
.out out_uv texcoord0
|
||||
|
||||
; Inputs
|
||||
.alias in_xy v0
|
||||
.alias in_uvc v1
|
||||
.alias in_col v2
|
||||
|
||||
.entry vmain
|
||||
.proc vmain
|
||||
mov r0.xy, in_xy.xy
|
||||
mov r0.w, ones
|
||||
|
||||
dp4 out_position.x, projection[0], r0
|
||||
dp4 out_position.y, projection[1], r0
|
||||
dp4 out_position.z, projection[2], r0
|
||||
dp4 out_position.w, projection[3], r0
|
||||
|
||||
mov out_uv, in_uvc.xy
|
||||
|
||||
mul r1, myconst.zzzz, in_col
|
||||
mov out_color, r1
|
||||
end
|
||||
.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 {
|
||||
namespace LI {
|
||||
GPU_TEXCOLOR GetTexFmt(Texture::Type type) {
|
||||
if (type == Texture::RGBA32)
|
||||
return GPU_RGBA8;
|
||||
else if (type == Texture::RGB24)
|
||||
return GPU_RGB8;
|
||||
else if (type == Texture::A8)
|
||||
return GPU_A8;
|
||||
return GPU_RGBA8; // Default
|
||||
}
|
||||
int GetBPP(Texture::Type type) {
|
||||
if (type == Texture::RGBA32)
|
||||
return 4;
|
||||
else if (type == Texture::RGB24)
|
||||
return 3;
|
||||
else if (type == Texture::A8)
|
||||
return 1;
|
||||
return 0; // Error
|
||||
}
|
||||
void Backend_C3D::Init() {
|
||||
std::cout << "[BACKEND_C3D]: Setting up Buffers" << std::endl;
|
||||
VertexBuffer.Resize(4 * 8192);
|
||||
IndexBuffer.Resize(6 * 8192);
|
||||
|
||||
Flags |= LIBackendFlags_FlipUV_Y;
|
||||
|
||||
std::cout << "[BACKEND_C3D]: Loading shader..." << std::endl;
|
||||
ShaderCode = DVLB_ParseFile((uint32_t*)li_shader, li_shader_size);
|
||||
shaderProgramInit(&Shader);
|
||||
shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]);
|
||||
pLocProjection =
|
||||
shaderInstanceGetUniformLocation(Shader.vertexShader, "projection");
|
||||
|
||||
std::cout << "[BACKEND_C3D]: Setting up Attr Info" << std::endl;
|
||||
AttrInfo_Init(&ShaderInfo);
|
||||
AttrInfo_AddLoader(&ShaderInfo, 0, GPU_FLOAT, 2);
|
||||
AttrInfo_AddLoader(&ShaderInfo, 1, GPU_FLOAT, 2);
|
||||
AttrInfo_AddLoader(&ShaderInfo, 2, GPU_UNSIGNED_BYTE, 4);
|
||||
std::cout << "[BACKEND_C3D]: Backend init done!" << std::endl;
|
||||
}
|
||||
|
||||
void Backend_C3D::Deinit() {
|
||||
shaderProgramFree(&Shader);
|
||||
DVLB_Free(ShaderCode);
|
||||
}
|
||||
|
||||
void Backend_C3D::NewFrame() {
|
||||
C3D_BindProgram(&Shader);
|
||||
C3D_SetAttrInfo(&ShaderInfo);
|
||||
CurrentIndex = 0;
|
||||
CurrentVertex = 0;
|
||||
FrameCounter++;
|
||||
VertexCounter = num_vtx;
|
||||
IndexCounter = num_idx;
|
||||
num_vtx = 0;
|
||||
num_idx = 0;
|
||||
}
|
||||
|
||||
void Backend_C3D::BindTexture(PD::LI::TexAddress addr) {
|
||||
C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr));
|
||||
}
|
||||
|
||||
void Backend_C3D::RenderDrawData(
|
||||
const PD::Vec<PD::LI::Command::Ref>& Commands) {
|
||||
C3D_BindProgram(&Shader);
|
||||
C3D_SetAttrInfo(&ShaderInfo);
|
||||
C3D_Mtx proj;
|
||||
Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false);
|
||||
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, &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;
|
||||
if (!Tex) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
bool ScissorEnabled = Commands[index]->ScissorEnabled;
|
||||
ivec4 ScissorRect = Commands[index]->ScissorRect;
|
||||
size_t StartIndex = CurrentIndex;
|
||||
|
||||
while (index < Commands.Size() && Commands[index]->Tex == Tex &&
|
||||
Commands[index]->ScissorEnabled == ScissorEnabled &&
|
||||
Commands[index]->ScissorRect == ScissorRect) {
|
||||
auto c = Commands[index];
|
||||
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
|
||||
num_idx++;
|
||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
|
||||
}
|
||||
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
|
||||
num_vtx++;
|
||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (ScissorEnabled) {
|
||||
// Figure out this setup was pain
|
||||
C3D_SetScissor(GPU_SCISSOR_NORMAL,
|
||||
ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
||||
ViewPort.x - (ScissorRect.x + ScissorRect.z),
|
||||
ViewPort.y - ScissorRect.y, ViewPort.x - ScissorRect.x);
|
||||
} else {
|
||||
C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0);
|
||||
}
|
||||
BindTexture(Tex->Address);
|
||||
auto bufInfo = C3D_GetBufInfo();
|
||||
BufInfo_Init(bufInfo);
|
||||
BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Vertex), 3, 0x210);
|
||||
|
||||
C3D_DrawElements(GPU_TRIANGLES, CurrentIndex - StartIndex,
|
||||
C3D_UNSIGNED_SHORT, IndexBuffer.Data() + StartIndex);
|
||||
}
|
||||
C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
|
||||
}
|
||||
|
||||
PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels,
|
||||
int w, int h,
|
||||
PD::LI::Texture::Type type,
|
||||
PD::LI::Texture::Filter filter) {
|
||||
std::cout << "Loading Tex " << std::format("[{}, {}]", w, h) << std::endl;
|
||||
if (w > 1024 || h > 1024) {
|
||||
return nullptr;
|
||||
}
|
||||
// Don't check here as check done before
|
||||
PD::LI::Texture::Ref res = PD::LI::Texture::New();
|
||||
int bpp = GetBPP(type);
|
||||
ivec2 tex_size(w, h);
|
||||
// Pow2
|
||||
if (!PD::BitUtil::IsSingleBit(w)) {
|
||||
tex_size.x = PD::BitUtil::GetPow2((unsigned int)w);
|
||||
}
|
||||
if (!PD::BitUtil::IsSingleBit(h)) {
|
||||
tex_size.y = PD::BitUtil::GetPow2((unsigned int)h);
|
||||
}
|
||||
res->Size.x = w;
|
||||
res->Size.y = h;
|
||||
res->UV = fvec4(0.f, 1.f, ((float)w / (float)tex_size.x),
|
||||
1.0 - ((float)h / (float)tex_size.y));
|
||||
|
||||
// Texture Setup
|
||||
auto fltr = (filter == Texture::NEAREST ? GPU_NEAREST : GPU_LINEAR);
|
||||
auto tex_fmt = GetTexFmt(type);
|
||||
auto tex = new C3D_Tex;
|
||||
C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt);
|
||||
C3D_TexSetFilter(tex, fltr, fltr);
|
||||
|
||||
// Using std::fill_n instead cause i hate this error lines
|
||||
// under the memset func in my editor
|
||||
std::fill_n((PD::u8*)tex->data, tex->size, 0);
|
||||
// memset(tex->data, 0, tex->size);s
|
||||
|
||||
/// Probably Remove this if statement in future
|
||||
/// This are the things confirmed as working
|
||||
if (bpp == 3 || bpp == 4 || bpp == 1) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
for (int y = 0; y < h; y++) {
|
||||
int dst_pos = ((((y >> 3) * ((int)tex_size.x >> 3) + (x >> 3)) << 6) +
|
||||
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
||||
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
||||
bpp;
|
||||
int src_pos = (y * w + x) * bpp;
|
||||
/// Best idea i had
|
||||
for (int i = 0; i < bpp; i++) {
|
||||
((u8*)tex->data)[dst_pos + bpp - 1 - i] = pixels[src_pos + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
C3D_TexFlush(tex);
|
||||
}
|
||||
|
||||
tex->border = 0x00000000;
|
||||
C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT);
|
||||
res->Address = (TexAddress)tex;
|
||||
std::cout << std::format("Tex {:#08x} Addr {:#08X}", (TexAddress)res.get(),
|
||||
res->Address)
|
||||
<< std::endl;
|
||||
return res;
|
||||
}
|
||||
} // namespace LI
|
||||
} // namespace PD
|
60
backends/3ds/source/pd_hid_3ds.cpp
Normal file
60
backends/3ds/source/pd_hid_3ds.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include <3ds.h>
|
||||
|
||||
#include <pd_hid_3ds.hpp>
|
||||
|
||||
namespace PD {
|
||||
Hid3DS::Hid3DS() : Hid("3DS") {
|
||||
binds[KEY_A] = A;
|
||||
binds[KEY_B] = B;
|
||||
binds[KEY_X] = X;
|
||||
binds[KEY_Y] = Y;
|
||||
binds[KEY_START] = Start;
|
||||
binds[KEY_SELECT] = Select;
|
||||
binds[KEY_L] = L;
|
||||
binds[KEY_R] = R;
|
||||
binds[KEY_DUP] = DUp;
|
||||
binds[KEY_DDOWN] = DDown;
|
||||
binds[KEY_DLEFT] = DLeft;
|
||||
binds[KEY_DRIGHT] = DRight;
|
||||
binds[KEY_CPAD_UP] = CPUp;
|
||||
binds[KEY_CPAD_DOWN] = CPDown;
|
||||
binds[KEY_CPAD_LEFT] = CPLeft;
|
||||
binds[KEY_CPAD_RIGHT] = CPRight;
|
||||
binds[KEY_CSTICK_UP] = CSUp;
|
||||
binds[KEY_CSTICK_DOWN] = CSDown;
|
||||
binds[KEY_CSTICK_LEFT] = CSLeft;
|
||||
binds[KEY_CSTICK_RIGHT] = CSRight;
|
||||
binds[KEY_ZL] = ZL;
|
||||
binds[KEY_ZR] = ZR;
|
||||
binds[KEY_TOUCH] = Touch;
|
||||
}
|
||||
void Hid3DS::Update() {
|
||||
hidScanInput();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
key_events[i][Event_Down] = 0;
|
||||
key_events[i][Event_Held] = 0;
|
||||
key_events[i][Event_Up] = 0;
|
||||
}
|
||||
u32 kd = hidKeysDown();
|
||||
u32 kh = hidKeysHeld();
|
||||
u32 ku = hidKeysUp();
|
||||
for (auto &b : binds) {
|
||||
if (b.first & kd) {
|
||||
key_events[0][Event_Down] |= b.second;
|
||||
}
|
||||
if (b.first & kh) {
|
||||
key_events[0][Event_Held] |= b.second;
|
||||
}
|
||||
if (b.first & ku) {
|
||||
key_events[0][Event_Up] |= b.second;
|
||||
}
|
||||
}
|
||||
if (locked) {
|
||||
SwappyTable();
|
||||
}
|
||||
touchPosition t;
|
||||
hidTouchRead(&t);
|
||||
touch[1] = touch[0]; // Cycle touch pos
|
||||
touch[0] = fvec2(t.px, t.py);
|
||||
}
|
||||
} // namespace PD
|
27
backends/desktop/CMakeLists.txt
Normal file
27
backends/desktop/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
if(WIN32)
|
||||
set(EXTRA_LIBS ws2_32)
|
||||
else()
|
||||
set(EXTRA_LIBS)
|
||||
endif()
|
||||
|
||||
add_subdirectory(glfw)
|
||||
add_subdirectory(glad)
|
||||
|
||||
# if(PD_BUILD_SHARED)
|
||||
# add_library(pd-backend-desktop SHARED
|
||||
# source/li_backend_gl2.cpp
|
||||
# source/pd_hid_glfw.cpp)
|
||||
# target_compile_definitions(pd-backend-desktop PUBLIC
|
||||
# -DPD_BKND_DESKTOP_BUILD_SHARED=1)
|
||||
# else()
|
||||
add_library(pd-backend-desktop STATIC
|
||||
source/li_backend_gl2.cpp
|
||||
source/pd_hid_glfw.cpp)
|
||||
#endif()
|
||||
|
||||
target_compile_definitions(pd-backend-desktop PUBLIC
|
||||
-DPD_BKND_DESKTOP_STATIC=1)
|
||||
target_include_directories(pd-backend-desktop PUBLIC include)
|
||||
target_link_libraries(pd-backend-desktop PUBLIC glad glfw palladium ${EXTRA_LIBS})
|
4
backends/desktop/glad/CMakeLists.txt
Normal file
4
backends/desktop/glad/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
add_library(glad source/glad.c)
|
||||
target_include_directories(glad PUBLIC include)
|
311
backends/desktop/glad/include/KHR/khrplatform.h
Normal file
311
backends/desktop/glad/include/KHR/khrplatform.h
Normal file
@ -0,0 +1,311 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are 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 Materials.
|
||||
**
|
||||
** THE MATERIALS ARE 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
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
/*
|
||||
* To support platform where unsigned long cannot be used interchangeably with
|
||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||
* unsigned long long or similar (this results in different C++ name mangling).
|
||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||
* platforms where the size of a pointer is larger than the size of long.
|
||||
*/
|
||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||
#define KHRONOS_USE_INTPTR_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef KHRONOS_USE_INTPTR_T
|
||||
typedef intptr_t khronos_intptr_t;
|
||||
typedef uintptr_t khronos_uintptr_t;
|
||||
#elif defined(_WIN64)
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64)
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
5169
backends/desktop/glad/include/glad/glad.h
Normal file
5169
backends/desktop/glad/include/glad/glad.h
Normal file
File diff suppressed because it is too large
Load Diff
2532
backends/desktop/glad/source/glad.c
Normal file
2532
backends/desktop/glad/source/glad.c
Normal file
File diff suppressed because it is too large
Load Diff
1
backends/desktop/glfw
Submodule
1
backends/desktop/glfw
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 7b6aead9fb88b3623e3b3725ebb42670cbe4c579
|
46
backends/desktop/include/li_backend_gl2.hpp
Normal file
46
backends/desktop/include/li_backend_gl2.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <glad/glad.h>
|
||||
|
||||
/** SEPARATOR */
|
||||
#include <GLFW/glfw3.h>
|
||||
/** SEPARATOR */
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/backend.hpp>
|
||||
#include <pd_p_bknd_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class PD_BKND_DESKTOP_API Backend_GL2 : public PD::LI::Backend {
|
||||
public:
|
||||
Backend_GL2() : LI::Backend("OpenGL2") {}
|
||||
~Backend_GL2() {}
|
||||
|
||||
PD_SMART_CTOR(Backend_GL2)
|
||||
|
||||
void Init() override;
|
||||
void Deinit() override;
|
||||
void NewFrame() override;
|
||||
void BindTexture(PD::LI::TexAddress addr) override;
|
||||
void RenderDrawData(const PD::Vec<PD::LI::Command::Ref>& Commands) override;
|
||||
PD::LI::Texture::Ref LoadTexture(
|
||||
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;
|
||||
|
||||
private:
|
||||
PD::Vec<PD::LI::Vertex> VertexBuffer;
|
||||
PD::Vec<PD::u16> IndexBuffer;
|
||||
size_t CurrentVertex = 0;
|
||||
size_t CurrentIndex = 0;
|
||||
GLuint Shader;
|
||||
GLuint pLocProjection;
|
||||
GLuint pLocTex;
|
||||
Mat4 Projection;
|
||||
GLuint VBO, IBO;
|
||||
// For Stats
|
||||
PD::u32 num_vtx = 0;
|
||||
PD::u32 num_idx = 0;
|
||||
};
|
||||
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -23,18 +23,28 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <pd/core/hid_driver.hpp>
|
||||
#include <pd_p_bknd_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Function to Throw an Error Screen
|
||||
* @param error Error Message to Display
|
||||
*/
|
||||
void Error(const std::string& error);
|
||||
/**
|
||||
* Custom Assert Function that Shows an Error Screen if it fails
|
||||
* @param v The bool var to check `(Throws error if it is false)`
|
||||
* @param msg The Message that Should be displayed if the Assert fails
|
||||
*/
|
||||
void Assert(bool v, const std::string& msg);
|
||||
class PD_BKND_DESKTOP_API HidGLFW : public Hid {
|
||||
public:
|
||||
/**
|
||||
* Constructor to setup Key binds
|
||||
*/
|
||||
HidGLFW(GLFWwindow* win);
|
||||
~HidGLFW() = default;
|
||||
PD_SMART_CTOR(HidGLFW)
|
||||
|
||||
/**
|
||||
* Overrideing the Update Function for Input Checking etc
|
||||
*/
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
GLFWwindow* Window;
|
||||
int PrevState;
|
||||
};
|
||||
} // namespace PD
|
132
backends/desktop/include/pd_net_desktop.hpp
Normal file
132
backends/desktop/include/pd_net_desktop.hpp
Normal file
@ -0,0 +1,132 @@
|
||||
#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.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#ifdef _MSVC
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#endif
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <pd/net/backend.hpp>
|
||||
namespace PD {
|
||||
class NetBackendDesktop : public PD::Net::Backend {
|
||||
public:
|
||||
#ifdef _WIN32
|
||||
NetBackendDesktop() : Net::Backend("Desktop (Windows)") {
|
||||
#else
|
||||
NetBackendDesktop() : Net::Backend("Desktop (Unix)") {
|
||||
#endif
|
||||
}
|
||||
~NetBackendDesktop() = default;
|
||||
PD_SMART_CTOR(NetBackendDesktop)
|
||||
bool Init() override {
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa_data;
|
||||
return (WSAStartup(MAKEWORD(2, 2), &wsa_data) == 0);
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
void Deinit() override {
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
int NewSocket() override { return socket(AF_INET, SOCK_STREAM, 0); }
|
||||
void Close(int sock_id) override {
|
||||
#ifdef _WIN32
|
||||
closesocket(sock_id);
|
||||
#else
|
||||
close(sock_id);
|
||||
#endif
|
||||
}
|
||||
int GetInvalidRef() const override {
|
||||
#ifdef _WIN32
|
||||
return INVALID_SOCKET;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Bind(int sock_id, u16 port) override {
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
||||
}
|
||||
bool Listen(int sock_id, int backlog = 5) override {
|
||||
return listen(sock_id, backlog) != -1;
|
||||
}
|
||||
|
||||
bool WaitForRead(int sock_id, int timeout_ms) override {
|
||||
fd_set set;
|
||||
FD_ZERO(&set);
|
||||
FD_SET(sock_id, &set);
|
||||
|
||||
timeval timeout{};
|
||||
timeout.tv_sec = timeout_ms / 1000;
|
||||
timeout.tv_usec = (timeout_ms % 1000) * 1000;
|
||||
|
||||
int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout);
|
||||
return (result > 0 && FD_ISSET(sock_id, &set));
|
||||
}
|
||||
|
||||
bool Accept(int sock_id, Net::Socket::Ref client) override {
|
||||
int client_soc = accept(sock_id, nullptr, nullptr);
|
||||
if (client_soc == GetInvalidRef()) {
|
||||
return false;
|
||||
}
|
||||
client->pSocket = client_soc;
|
||||
return true;
|
||||
}
|
||||
bool Connect(int sock_id, const std::string& ip, u16 port) override {
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
inet_pton(AF_INET, ip.c_str(), &addr.sin_addr);
|
||||
return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
||||
}
|
||||
int Send(int sock_id, const std::string& data) override {
|
||||
return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0);
|
||||
}
|
||||
int Receive(int sock_id, std::string& data, int size = 1024) override {
|
||||
char* tmp = new char[size];
|
||||
int res = recv(sock_id, tmp, size, 0);
|
||||
if (res > 0) {
|
||||
data.assign(tmp, res);
|
||||
}
|
||||
delete[] tmp;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
} // namespace PD
|
58
backends/desktop/include/pd_p_bknd_api.hpp
Normal file
58
backends/desktop/include/pd_p_bknd_api.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
#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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef PD_BKND_DESKTOP_STATIC
|
||||
#if defined(__3DS__) // 3ds Specific
|
||||
#error "Desktop backend is not supported on the 3ds!"
|
||||
#endif
|
||||
#define PD_BKND_DESKTOP_API
|
||||
#else
|
||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
|
||||
#define PD_BKND_DESKTOP_API __declspec(dllexport)
|
||||
#else
|
||||
#define PD_BKND_DESKTOP_API __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined(__APPLE__) // macOS (untested yet)
|
||||
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
|
||||
#define PD_BKND_DESKTOP_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_BKND_DESKTOP_API
|
||||
#endif
|
||||
#elif defined(__linux__) // Linux (untested yet)
|
||||
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
|
||||
#define PD_BKND_DESKTOP_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_BKND_DESKTOP_API
|
||||
#endif
|
||||
#elif defined(__3DS__) // 3ds Specific
|
||||
#error "Desktop backend is not supported on the 3ds!"
|
||||
#else
|
||||
#define PD_BKND_DESKTOP_API
|
||||
#endif
|
||||
#endif
|
230
backends/desktop/source/li_backend_gl2.cpp
Normal file
230
backends/desktop/source/li_backend_gl2.cpp
Normal file
@ -0,0 +1,230 @@
|
||||
#include <li_backend_gl2.hpp>
|
||||
|
||||
const char* vertex_shader = R"(
|
||||
#version 120
|
||||
|
||||
attribute vec2 pos;
|
||||
attribute vec2 uv;
|
||||
attribute vec4 color;
|
||||
|
||||
varying vec2 oUV;
|
||||
varying vec4 oColor;
|
||||
|
||||
// Probably forgot about this matric 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 120
|
||||
|
||||
varying vec2 oUV;
|
||||
varying vec4 oColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
vec4 tc = texture2D(tex, oUV);
|
||||
gl_FragColor = tc*oColor;
|
||||
}
|
||||
)";
|
||||
|
||||
GLuint compileShader(const std::string& source,
|
||||
GLenum type) {
|
||||
GLuint shader = glCreateShader(type);
|
||||
const char* src = source.c_str();
|
||||
glShaderSource(shader, 1, &src, nullptr);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint success;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
char infoLog[512];
|
||||
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
|
||||
std::cerr << "Shader Compilation Error: " << infoLog << std::endl;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint
|
||||
createShaderProgram(const std::string& vertexShaderSource,
|
||||
const std::string& fragmentShaderSource) {
|
||||
GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||
GLuint fragmentShader =
|
||||
compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER);
|
||||
|
||||
GLuint shaderProgram = glCreateProgram();
|
||||
glAttachShader(shaderProgram, vertexShader);
|
||||
glAttachShader(shaderProgram, fragmentShader);
|
||||
glLinkProgram(shaderProgram);
|
||||
|
||||
GLint success;
|
||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
char infoLog[512];
|
||||
glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog);
|
||||
std::cerr << "Shader Program Linking Error: " << infoLog << std::endl;
|
||||
}
|
||||
|
||||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
return shaderProgram;
|
||||
}
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::Init() {
|
||||
VertexBuffer.Resize(4 * 8192);
|
||||
IndexBuffer.Resize(6 * 8192);
|
||||
Shader = createShaderProgram(vertex_shader, frag_shader);
|
||||
glUseProgram(Shader);
|
||||
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
|
||||
GLint _pos = glGetAttribLocation(Shader, "pos");
|
||||
GLint _uv = glGetAttribLocation(Shader, "uv");
|
||||
GLint _color = glGetAttribLocation(Shader, "color");
|
||||
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::LI::Vertex),
|
||||
(void*)offsetof(PD::LI::Vertex, Pos));
|
||||
glEnableVertexAttribArray(_pos);
|
||||
|
||||
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::LI::Vertex),
|
||||
(void*)offsetof(PD::LI::Vertex, UV));
|
||||
glEnableVertexAttribArray(_uv);
|
||||
|
||||
glVertexAttribPointer(_color, 4, GL_UNSIGNED_BYTE, GL_TRUE,
|
||||
sizeof(PD::LI::Vertex),
|
||||
(void*)offsetof(PD::LI::Vertex, Color));
|
||||
glEnableVertexAttribArray(_color);
|
||||
|
||||
glGenBuffers(1, &IBO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
|
||||
pLocTex = glGetUniformLocation(Shader, "tex");
|
||||
pLocProjection = glGetUniformLocation(Shader, "projection");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::Deinit() {
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &IBO);
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::NewFrame() {
|
||||
glViewport(0, 0, ViewPort.x, ViewPort.y);
|
||||
glClearColor(ClearColor.x, ClearColor.y, ClearColor.z, ClearColor.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
Projection.Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, -1.f, 1.f);
|
||||
glUniformMatrix4fv(pLocProjection, 1, GL_TRUE, Projection.m);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
CurrentIndex = 0;
|
||||
CurrentVertex = 0;
|
||||
FrameCounter++;
|
||||
VertexCounter = num_vtx;
|
||||
IndexCounter = num_idx;
|
||||
num_vtx = 0;
|
||||
num_idx = 0;
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::BindTexture(PD::LI::TexAddress addr) {
|
||||
// Actually not using the Address as Address
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
|
||||
glUniform1i(pLocTex, 0);
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::RenderDrawData(
|
||||
const PD::Vec<PD::LI::Command::Ref>& Commands) {
|
||||
glUseProgram(Shader);
|
||||
size_t index = 0;
|
||||
while (index < Commands.Size()) {
|
||||
PD::LI::Texture::Ref Tex = Commands[index]->Tex;
|
||||
if (!Tex) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
size_t StartIndex = CurrentIndex;
|
||||
bool ScissorEnabled = Commands[index]->ScissorEnabled;
|
||||
ivec4 ScissorRect = Commands[index]->ScissorRect;
|
||||
|
||||
while (index < Commands.Size() && Commands[index]->Tex == Tex &&
|
||||
Commands[index]->ScissorEnabled == ScissorEnabled &&
|
||||
Commands[index]->ScissorRect == ScissorRect) {
|
||||
auto c = Commands[index];
|
||||
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
|
||||
num_idx++;
|
||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
|
||||
}
|
||||
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
|
||||
num_vtx++;
|
||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (ScissorEnabled) {
|
||||
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
||||
ScissorRect.z, ScissorRect.w);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
BindTexture(Tex->Address);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::LI::Vertex),
|
||||
&VertexBuffer[0], GL_DYNAMIC_DRAW);
|
||||
|
||||
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);
|
||||
BindTexture(0);
|
||||
}
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API PD::LI::Texture::Ref Backend_GL2::LoadTexture(
|
||||
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);
|
||||
auto res = PD::LI::Texture::New(texID, PD::ivec2(w, h));
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace LI
|
||||
} // namespace PD
|
33
backends/desktop/source/pd_hid_glfw.cpp
Normal file
33
backends/desktop/source/pd_hid_glfw.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <pd_hid_glfw.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD_BKND_DESKTOP_API HidGLFW::HidGLFW(GLFWwindow* win) : Hid("GLFW") {
|
||||
Window = win;
|
||||
binds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
|
||||
}
|
||||
PD_BKND_DESKTOP_API void HidGLFW::Update() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
key_events[i][Event_Down] = 0;
|
||||
key_events[i][Event_Held] = 0;
|
||||
key_events[i][Event_Up] = 0;
|
||||
}
|
||||
int state = glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT);
|
||||
if (state == GLFW_PRESS) {
|
||||
if (PrevState == GLFW_RELEASE) {
|
||||
key_events[0][Event_Down] |= Touch;
|
||||
}
|
||||
key_events[0][Event_Held] |= Touch;
|
||||
} else if (state == GLFW_RELEASE && PrevState == GLFW_PRESS) {
|
||||
key_events[0][Event_Up] |= Touch;
|
||||
}
|
||||
|
||||
PrevState = state;
|
||||
if (locked) {
|
||||
SwappyTable();
|
||||
}
|
||||
double x, y;
|
||||
glfwGetCursorPos(Window, &x, &y);
|
||||
touch[1] = touch[0]; // Cycle touch pos
|
||||
touch[0] = fvec2(x, y);
|
||||
}
|
||||
} // namespace PD
|
@ -25,47 +25,27 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
// Core
|
||||
#include <pd/core/bit_util.hpp>
|
||||
#include <pd/core/color.hpp>
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/io.hpp>
|
||||
#include <pd/core/strings.hpp>
|
||||
#include <pd/core/sys.hpp>
|
||||
#include <pd/core/timer.hpp>
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
// Graphics
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
#include <pd/lithium/spritesheet.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
// Image
|
||||
#include <pd/image/image.hpp>
|
||||
#include <pd/image/img_blur.hpp>
|
||||
#include <pd/image/img_convert.hpp>
|
||||
// Drivers
|
||||
#include <pd/drivers/hid.hpp>
|
||||
// Overlays
|
||||
#include <pd/overlays/keyboard.hpp>
|
||||
#include <pd/overlays/message_mgr.hpp>
|
||||
#include <pd/overlays/overlay_mgr.hpp>
|
||||
#include <pd/overlays/performance.hpp>
|
||||
#include <pd/overlays/settings.hpp>
|
||||
// UI7
|
||||
#include <pd/ui7/ui7.hpp>
|
||||
// Lib3ds
|
||||
#include <pd/lib3ds/hwinfo.hpp>
|
||||
#include <pd/lib3ds/memory.hpp>
|
||||
#include <pd/lib3ds/os.hpp>
|
||||
#include <pd/lib3ds/result_decoder.hpp>
|
||||
// App
|
||||
#include <pd/app/app.hpp>
|
||||
#include <pd/app/error.hpp>
|
||||
#include <pd/app/lang.hpp>
|
||||
// Net
|
||||
#include <pd/net/backend.hpp>
|
||||
#include <pd/net/socket.hpp>
|
||||
|
||||
/// Setup these as non Namespaced access by default
|
||||
#ifndef PD_MATH_NAMESPACED
|
||||
using vec2 = PD::vec2;
|
||||
using vec3 = PD::vec3;
|
||||
using vec4 = PD::vec4;
|
||||
using fvec2 = PD::fvec2;
|
||||
using fvec3 = PD::fvec3;
|
||||
using fvec4 = PD::fvec4;
|
||||
using dvec2 = PD::dvec2;
|
||||
using dvec3 = PD::dvec3;
|
||||
using dvec4 = PD::dvec4;
|
||||
using ivec2 = PD::ivec2;
|
||||
using ivec3 = PD::ivec3;
|
||||
using ivec4 = PD::ivec4;
|
||||
#endif
|
||||
|
||||
// namespace Palladium = PD;
|
@ -1,231 +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/timer.hpp>
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/lib3ds/drv_hid.hpp>
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
#include <pd/overlays/message_mgr.hpp>
|
||||
#include <pd/overlays/overlay_mgr.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Template Class for a User Application on the 3ds
|
||||
*/
|
||||
class App {
|
||||
public:
|
||||
/**
|
||||
* alias for AppFlags
|
||||
*/
|
||||
using AppFlags = u32;
|
||||
/**
|
||||
* App Flags
|
||||
*
|
||||
* - Probably only the default Setup should be used
|
||||
*/
|
||||
enum AppFlags_ {
|
||||
AppFlags_None = 0, ///< Do Nothing
|
||||
AppFLags_UserLoop = 1 << 0, ///< Handle User MainLoop
|
||||
AppFlags_HandleOverlays = 1 << 1, ///< Process Overlays
|
||||
AppFlags_HandleMessageMgr = 1 << 2, ///< Process Messages
|
||||
AppFlags_HandleRendering = 1 << 3, ///< Handle Rendering
|
||||
/// Default Flags
|
||||
AppFlags_Default = AppFlags_HandleMessageMgr | AppFlags_HandleOverlays |
|
||||
AppFlags_HandleRendering | AppFLags_UserLoop,
|
||||
};
|
||||
/**
|
||||
* alias for AppInitFlags
|
||||
*/
|
||||
using AppInitFlags = u32;
|
||||
/**
|
||||
* App Init Flags
|
||||
*/
|
||||
enum AppInitFlags_ {
|
||||
AppInitFlags_None = 0, ///< Do nothing (probably a useles ability)
|
||||
AppInitFlags_MountRomfs = 1 << 0, ///< Mount Romfs on PreInit
|
||||
AppInitFlags_InitGraphics = 1 << 1, ///< Default Init Graphics for GPU use
|
||||
AppInitFlags_New3dsMode = 1 << 2, ///< Enable New3DS Speedup
|
||||
AppInitFlags_InitGraphicsNoC3D = 1 << 3, ///< Init GFX for Buf Modification
|
||||
AppInitFlags_InitLithium = 1 << 4, ///< Init 2D Rendering Engine
|
||||
/// I dont have a name for this one yet
|
||||
/// It Inits Internal Directory structure
|
||||
AppInitFlags_UnnamedOption1 = 1 << 5,
|
||||
AppInitFlags_InitHwInfo = 1 << 6, ///< Init HwInfo from lib3ds
|
||||
/// Default App Init Flags
|
||||
AppInitFlags_Default = AppInitFlags_MountRomfs | AppInitFlags_InitGraphics |
|
||||
AppInitFlags_New3dsMode | AppInitFlags_InitLithium,
|
||||
};
|
||||
/**
|
||||
* App Constructor that can Optionally set a name for the App
|
||||
* @param name App Name Defaults to 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 Deconstructor
|
||||
*/
|
||||
~App() { too--; }
|
||||
|
||||
/**
|
||||
* Templete function where the user can Init his stuff
|
||||
*/
|
||||
virtual void Init() {}
|
||||
/**
|
||||
* Template function to deinit stuff (most is deinit automatically
|
||||
* but it is still possible that some things need to be ordered manually)
|
||||
*/
|
||||
virtual void Deinit() {}
|
||||
/**
|
||||
* Template User MainLoop
|
||||
* @param delta Delta time
|
||||
* @param time App Run time
|
||||
* @return false to exit the App
|
||||
*/
|
||||
virtual bool MainLoop(float delta, float time) { return false; }
|
||||
|
||||
/**
|
||||
* Function to actually run the app
|
||||
*
|
||||
* Example:
|
||||
* ```cpp
|
||||
* int main() {
|
||||
* UserApp app;
|
||||
* app.Run();
|
||||
* return 0;
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
void Run();
|
||||
/**
|
||||
* Get the Renderer Reference
|
||||
* @return Renderer Reference
|
||||
*/
|
||||
LI::Renderer::Ref Renderer() { return renderer; }
|
||||
/**
|
||||
* Get Message Manager Reference
|
||||
* @return Message Manager Reference
|
||||
*/
|
||||
MessageMgr::Ref Messages() { return msg_mgr; }
|
||||
/**
|
||||
* Get Overlay Manager Reference
|
||||
* @return Overlay Manager Reference
|
||||
*/
|
||||
OverlayMgr::Ref Overlays() { return overlay_mgr; }
|
||||
/**
|
||||
* Get Input Driver Reference
|
||||
* @return Input Driver Reference
|
||||
*/
|
||||
Hid::Ref Input() { return input_mgr; }
|
||||
/**
|
||||
* Get Framerate
|
||||
* @return frames per second
|
||||
*/
|
||||
float GetFps() const { return fps; }
|
||||
|
||||
/**
|
||||
* Enable Runtime Feature(s) (AppFlags)
|
||||
* @param flags Flag(s) to enable
|
||||
*/
|
||||
void FeatureEnable(AppFlags flags) { runtimeflags |= flags; }
|
||||
/**
|
||||
* Disable Runtime Feature(s) (AppFlags)
|
||||
* @param flags Flag(s) to disable
|
||||
*/
|
||||
void FeatureDisable(AppFlags flags) { runtimeflags &= ~flags; }
|
||||
/**
|
||||
* Get Reference Access to runtimeflags
|
||||
* @return reference to runtimeflags
|
||||
*/
|
||||
AppFlags& GetFeatureSet() { return runtimeflags; }
|
||||
|
||||
/**
|
||||
* Get App Datadirectory (if enabled in AppInitFlags)
|
||||
* @return App Data Directory
|
||||
*/
|
||||
std::string GetDataDirectory();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Top Screen Reference
|
||||
*/
|
||||
Screen::Ref Top;
|
||||
/**
|
||||
* Bottom Screen Reference
|
||||
*/
|
||||
Screen::Ref Bottom;
|
||||
/**
|
||||
* AppInitFlags
|
||||
*
|
||||
* - Can only be edited in your App class Constructor
|
||||
* - Editing them Later will not effect the Deinit Process
|
||||
* Example:
|
||||
* ```cpp
|
||||
* class YourApp : public PD::App {
|
||||
* public:
|
||||
* YourApp(): App("YourApp") {
|
||||
* AppInitFlags |= AppInitFlags_InitLithium;
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
AppInitFlags InitFlags = AppInitFlags_Default;
|
||||
|
||||
private:
|
||||
/** Runtime Flags (can be edited) */
|
||||
AppFlags runtimeflags = AppFlags_Default;
|
||||
/** Safe Copy to prevent from editing befor Deinit */
|
||||
AppInitFlags SafeInitFlags = AppInitFlags_Default;
|
||||
/** PreInit Handler */
|
||||
void PreInit();
|
||||
/** Post Deinit Handler */
|
||||
void PostDeinit();
|
||||
/** Renderer Reference */
|
||||
LI::Renderer::Ref renderer;
|
||||
/** Message Manager */
|
||||
MessageMgr::Ref msg_mgr;
|
||||
/** Overlay Manager */
|
||||
OverlayMgr::Ref overlay_mgr;
|
||||
/** Input Driver */
|
||||
Hid::Ref input_mgr;
|
||||
/** Timer to track the App Runtime */
|
||||
Timer::Ref app_time;
|
||||
/** Last Time (for delta time and fps calculation) */
|
||||
u64 last_time;
|
||||
/** Framerate */
|
||||
float fps;
|
||||
|
||||
/** App Name */
|
||||
std::string name;
|
||||
|
||||
/** A static variable to make sure only one App instance can exist */
|
||||
static int too;
|
||||
};
|
||||
} // namespace PD
|
@ -1,98 +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>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Language System
|
||||
*
|
||||
* - Translations are saved into json files
|
||||
* - path should point to a directory containing the json files
|
||||
* - example for filenames: `en.json`, `de.json`, `fr.json`
|
||||
*/
|
||||
class Lang : public SmartCtor<Lang> {
|
||||
public:
|
||||
Lang() = default;
|
||||
~Lang() = default;
|
||||
|
||||
/**
|
||||
* Function to set the path to search for Language files
|
||||
* @param path Path to search the files
|
||||
*/
|
||||
void SetBasePath(const std::string &path) { langs_path = path; }
|
||||
/**
|
||||
* Load a language file by the language key
|
||||
* @param lang_key Language key for example `de`
|
||||
*/
|
||||
void Load(const std::string &lang_key) {
|
||||
LoadFile(langs_path + "/" + lang_key + ".json");
|
||||
}
|
||||
/**
|
||||
* Directly load a Language file from a specific path
|
||||
* @param path Path to load the file from
|
||||
*/
|
||||
void LoadFile(const std::string &path);
|
||||
/**
|
||||
* Get a String by a `Keyword`
|
||||
* @param k Keyword to search for
|
||||
* @return Returns the string or if none found it returns the Keyword
|
||||
*/
|
||||
const std::string &Get(const std::string &k);
|
||||
/**
|
||||
* Get the Language Name
|
||||
* @return Returns the Language Name
|
||||
*/
|
||||
const std::string &GetName() { return lang_name; }
|
||||
/**
|
||||
* Get the Language ID / Key
|
||||
* @return Returns the Language ID
|
||||
*/
|
||||
const std::string &GetID() { return lang_id; }
|
||||
/**
|
||||
* Get the Language Author(s)
|
||||
* @return Returns the Author(s) of the Language file
|
||||
*/
|
||||
const std::string &GetAuthor() { return lang_author; }
|
||||
/**
|
||||
* Get the Language File Search Path
|
||||
* @return Returns Path where the Files are searched for
|
||||
*/
|
||||
const std::string &GetPath() { return langs_path; }
|
||||
|
||||
private:
|
||||
const int ver = 0;
|
||||
/** Language Files Root path */
|
||||
std::string langs_path = "romfs:/lang";
|
||||
/** Language Name */
|
||||
std::string lang_name;
|
||||
/** Language ID / Key */
|
||||
std::string lang_id;
|
||||
/** Language Author */
|
||||
std::string lang_author;
|
||||
/** KEY - STRING Table for faster Key access */
|
||||
std::map<std::string, std::string> ltable;
|
||||
};
|
||||
} // namespace PD
|
@ -36,12 +36,12 @@ namespace BitUtil {
|
||||
* @param v 32 bit unsigned int
|
||||
* @return true if its a single bit number
|
||||
*/
|
||||
bool IsSingleBit(u32 v);
|
||||
PD_CORE_API bool IsSingleBit(u32 v);
|
||||
/**
|
||||
* Get the Next Power of two Number
|
||||
* @param v Current Number
|
||||
* @return Next Number thats a Pow of 2
|
||||
*/
|
||||
u32 GetPow2(u32 v);
|
||||
PD_CORE_API u32 GetPow2(u32 v);
|
||||
} // namespace BitUtil
|
||||
} // namespace PD
|
@ -36,17 +36,29 @@ namespace PD {
|
||||
* - Supports 32Bit input color
|
||||
* @note Safetey checks are disabled for maximum performance
|
||||
*/
|
||||
class Color {
|
||||
class PD_CORE_API Color {
|
||||
private:
|
||||
/** Red Value */
|
||||
u8 m_r;
|
||||
/** Green Value */
|
||||
u8 m_g;
|
||||
/** Blue Value */
|
||||
u8 m_b;
|
||||
/** Alpha Value */
|
||||
u8 m_a;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default Constructor (all variables are set to 0)
|
||||
*/
|
||||
Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
||||
// Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
||||
constexpr Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
||||
constexpr ~Color() {}
|
||||
/**
|
||||
* Constructor for 32Bit Color Input
|
||||
* @param color 32Bit Color value
|
||||
*/
|
||||
Color(u32 color) {
|
||||
constexpr Color(u32 color) {
|
||||
m_a = (color >> 24) & 0xff;
|
||||
m_b = (color >> 16) & 0xff;
|
||||
m_g = (color >> 8) & 0xff;
|
||||
@ -59,7 +71,7 @@ class Color {
|
||||
* @param b Blue Value
|
||||
* @param a Optional Alpha Value (Defaults to 255)
|
||||
*/
|
||||
Color(u8 r, u8 g, u8 b, u8 a = 255) {
|
||||
constexpr Color(int r, int g, int b, int a = 255) {
|
||||
m_r = r;
|
||||
m_g = g;
|
||||
m_b = b;
|
||||
@ -73,7 +85,7 @@ class Color {
|
||||
* @param a Optional Alpha Value (Defaults to 1.0f)
|
||||
* @note There is no Check if the number is between 0.0 and 1.0
|
||||
*/
|
||||
Color(float r, float g, float b, float a = 1.f) {
|
||||
constexpr Color(float r, float g, float b, float a = 1.f) {
|
||||
m_r = static_cast<u8>(255.f * r);
|
||||
m_g = static_cast<u8>(255.f * g);
|
||||
m_b = static_cast<u8>(255.f * b);
|
||||
@ -87,7 +99,7 @@ class Color {
|
||||
/**
|
||||
* Unused Deconstructor
|
||||
*/
|
||||
~Color() {}
|
||||
// ~Color() {}
|
||||
|
||||
/**
|
||||
* Create Color Object by Hex String
|
||||
@ -196,15 +208,24 @@ class Color {
|
||||
* @return 32Bit Color Value
|
||||
*/
|
||||
operator u32() const { return Get(); }
|
||||
|
||||
private:
|
||||
/** Red Value */
|
||||
u8 m_r;
|
||||
/** Green Value */
|
||||
u8 m_g;
|
||||
/** Blue Value */
|
||||
u8 m_b;
|
||||
/** Alpha Value */
|
||||
u8 m_a;
|
||||
};
|
||||
namespace Colors {
|
||||
constexpr Color White = Color(1.f, 1.f, 1.f, 1.f);
|
||||
constexpr Color Black = Color(0.f, 0.f, 0.f, 1.f);
|
||||
constexpr Color Red = Color(1.f, 0.f, 0.f, 1.f);
|
||||
constexpr Color Green = Color(0.f, 1.f, 0.f, 1.f);
|
||||
constexpr Color Blue = Color(0.f, 0.f, 1.f, 1.f);
|
||||
constexpr Color Yellow = Color(1.f, 1.f, 0.f, 1.f);
|
||||
constexpr Color Cyan = Color(0.f, 1.f, 1.f, 1.f);
|
||||
constexpr Color Magenta = Color(1.f, 0.f, 1.f, 1.f);
|
||||
constexpr Color Gray = Color(0.5f, 0.5f, 0.5f, 1.f);
|
||||
constexpr Color LightGray = Color(0.75f, 0.75f, 0.75f, 1.f);
|
||||
constexpr Color DarkGray = Color(0.25f, 0.25f, 0.25f, 1.f);
|
||||
constexpr Color Orange = Color(1.f, 0.65f, 0.f, 1.f);
|
||||
constexpr Color Pink = Color(1.f, 0.75f, 0.8f, 1.f);
|
||||
constexpr Color Brown = Color(0.6f, 0.4f, 0.2f, 1.f);
|
||||
constexpr Color Purple = Color(0.5f, 0.f, 0.5f, 1.f);
|
||||
constexpr Color Teal = Color(0.f, 0.5f, 0.5f, 1.f);
|
||||
constexpr Color Transparent = Color(0.f, 0.f, 0.f, 0.f);
|
||||
} // namespace Colors
|
||||
} // namespace PD
|
@ -38,6 +38,17 @@ SOFTWARE.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Platform API
|
||||
#include <pd/core/pd_p_api.hpp>
|
||||
|
||||
// Legacy Smart Pointer
|
||||
#define PD_SMART_CTOR(x) \
|
||||
using Ref = std::shared_ptr<x>; \
|
||||
template <typename... args> \
|
||||
static Ref New(args&&... cargs) { \
|
||||
return std::make_shared<x>(std::forward<args>(cargs)...); \
|
||||
}
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* SmartCtor (std::shared_ptr) Template class for Smart Pointers
|
||||
@ -90,31 +101,31 @@ namespace LibInfo {
|
||||
* Get the Compiler Name and Version the lib got Compiled with
|
||||
* @return Compiler Name / Version
|
||||
*/
|
||||
const std::string CompiledWith();
|
||||
PD_CORE_API const std::string CompiledWith();
|
||||
/**
|
||||
* Get the C++ Version used to compile the lib
|
||||
* @return C++ Version (__cplusplus)
|
||||
*/
|
||||
const std::string CxxVersion();
|
||||
PD_CORE_API const std::string CxxVersion();
|
||||
/**
|
||||
* Get the Buildtime of the Library
|
||||
* @return Build Time
|
||||
*/
|
||||
const std::string BuildTime();
|
||||
PD_CORE_API const std::string BuildTime();
|
||||
/**
|
||||
* Get the Library Version
|
||||
* @return Library Version String
|
||||
*/
|
||||
const std::string Version();
|
||||
PD_CORE_API const std::string Version();
|
||||
/**
|
||||
* Get the Git Commit the Lib got compiled in
|
||||
* @return Git Commit 7digit short hash
|
||||
*/
|
||||
const std::string Commit();
|
||||
PD_CORE_API const std::string Commit();
|
||||
/**
|
||||
* Get the Git Branch which was active when compiling the lib
|
||||
* @return Git Branch
|
||||
*/
|
||||
const std::string Branch();
|
||||
PD_CORE_API const std::string Branch();
|
||||
} // namespace LibInfo
|
||||
} // namespace PD
|
39
include/pd/core/core.hpp
Normal file
39
include/pd/core/core.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
#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/bit_util.hpp>
|
||||
#include <pd/core/color.hpp>
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/hid_driver.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/sys.hpp>
|
||||
#include <pd/core/timer.hpp>
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/core/tween.hpp>
|
||||
#include <pd/core/vec.hpp>
|
@ -28,7 +28,7 @@ SOFTWARE.
|
||||
|
||||
namespace PD {
|
||||
/** Input Driver Template class */
|
||||
class Hid : public SmartCtor<Hid> {
|
||||
class PD_CORE_API Hid : public SmartCtor<Hid> {
|
||||
public:
|
||||
/** Key [Controller] */
|
||||
enum Key : u32 {
|
||||
@ -67,19 +67,19 @@ class Hid : public SmartCtor<Hid> {
|
||||
Event_Held, ///< Key Held
|
||||
Event_Up, ///< Key released
|
||||
};
|
||||
Hid() = default;
|
||||
Hid(const std::string& name = "NullBackend") : pName(name) {}
|
||||
~Hid() = default;
|
||||
|
||||
/**
|
||||
* Get TOuch Position
|
||||
* @return touch pos
|
||||
*/
|
||||
vec2 TouchPos() const { return touch[0]; }
|
||||
fvec2 TouchPos() const { return touch[0]; }
|
||||
/**
|
||||
* Get Last Touch Position (from last frame)
|
||||
* @return touch pos
|
||||
*/
|
||||
vec2 TouchPosLast() const { return touch[1]; }
|
||||
fvec2 TouchPosLast() const { return touch[1]; }
|
||||
|
||||
/**
|
||||
* Check for a Button Event
|
||||
@ -157,13 +157,16 @@ class Hid : public SmartCtor<Hid> {
|
||||
*/
|
||||
virtual void Update() {}
|
||||
|
||||
/** Backend Identification Name */
|
||||
const std::string pName;
|
||||
|
||||
protected:
|
||||
/** Key binds map */
|
||||
std::unordered_map<u32, u32> binds;
|
||||
/** Function to swap around the Table */
|
||||
void SwappyTable();
|
||||
/** Using 2 Touch positions for current and last frame */
|
||||
vec2 touch[2];
|
||||
fvec2 touch[2];
|
||||
/** locked state */
|
||||
bool locked = false;
|
||||
/** Key event tables */
|
@ -35,12 +35,12 @@ namespace IO {
|
||||
* @param path Path to the File
|
||||
* @return 8Bit FileBuffer
|
||||
*/
|
||||
std::vector<u8> LoadFile2Mem(const std::string& path);
|
||||
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
|
||||
/**
|
||||
* Hash a 8Bit Memory Buffer
|
||||
* @param data 8Bit input Buffer
|
||||
* @return 32Bit Hash
|
||||
*/
|
||||
u32 HashMemory(const std::vector<u8>& data);
|
||||
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
|
||||
} // namespace IO
|
||||
} // namespace PD
|
@ -1,103 +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>
|
||||
|
||||
namespace PD {
|
||||
class Markdown {
|
||||
public:
|
||||
Markdown() = default;
|
||||
~Markdown() = default;
|
||||
|
||||
void Header(const std::string& hdr, int lvl = 2) {
|
||||
if (task != 0 || lvl < 1 || lvl > 10) {
|
||||
return;
|
||||
}
|
||||
/// Directly create the string with its amount of #
|
||||
std::string str(lvl, '#');
|
||||
str += " ";
|
||||
str += hdr;
|
||||
s << str << std::endl << std::endl;
|
||||
}
|
||||
|
||||
void BeginTable(const std::vector<std::string>& head) {
|
||||
if (task != 0) {
|
||||
return;
|
||||
}
|
||||
ctc = head.size();
|
||||
for (auto& it : head) {
|
||||
s << "| " << it << " ";
|
||||
}
|
||||
s << "|\n";
|
||||
for (int i = 0; i < ctc; i++) {
|
||||
s << "|---";
|
||||
}
|
||||
s << "|\n";
|
||||
task = 1;
|
||||
}
|
||||
|
||||
Markdown& TableAddEntry(const std::string& e) {
|
||||
if (task != 1) {
|
||||
return *this;
|
||||
}
|
||||
ctci++;
|
||||
s << "| " << e << " ";
|
||||
if (ctci == ctc) {
|
||||
s << "|\n";
|
||||
ctci = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void EndTable() {
|
||||
if (task != 1) {
|
||||
return;
|
||||
}
|
||||
s << std::endl;
|
||||
task = 0;
|
||||
}
|
||||
|
||||
void Write(const std::string& path) {
|
||||
std::ofstream f(path);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
f << s.str();
|
||||
f.close();
|
||||
}
|
||||
|
||||
private:
|
||||
/// @brief Tasks
|
||||
/// 0 = free
|
||||
/// 1 = table
|
||||
/// 2 = text
|
||||
int task = 0;
|
||||
/// @brief Current Table Columns
|
||||
int ctc = 0;
|
||||
/// @brief Current Table Column Index
|
||||
int ctci = 0;
|
||||
std::stringstream s;
|
||||
};
|
||||
} // namespace PD
|
@ -2,7 +2,8 @@
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
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
|
||||
@ -21,16 +22,20 @@ 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>
|
||||
#include <pd/core/markdown.hpp>
|
||||
|
||||
namespace PD {
|
||||
class ResultDecoder {
|
||||
class PD_CORE_API Mat4 {
|
||||
public:
|
||||
ResultDecoder(Result res);
|
||||
Mat4() { Zeros(); }
|
||||
~Mat4() = default;
|
||||
|
||||
void Zeros();
|
||||
void Ortho(float left, float right, float bottom, float top, float near,
|
||||
float far);
|
||||
|
||||
float m[16];
|
||||
};
|
||||
} // namespace PD
|
@ -2,7 +2,8 @@
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
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
|
||||
@ -21,37 +22,29 @@ 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 {
|
||||
/**
|
||||
* static Namespace containing Access to some 3ds Hardware Info
|
||||
*/
|
||||
namespace HwInfo {
|
||||
/**
|
||||
* Init connecttion to required sys modules
|
||||
*/
|
||||
void Init();
|
||||
/**
|
||||
* Deinit connection to sys modules
|
||||
*/
|
||||
void Deinit();
|
||||
/**
|
||||
* Check if the Console is Charging
|
||||
* @return true if the console is charging
|
||||
*/
|
||||
bool IsCharging();
|
||||
/**
|
||||
* Get the Current Battery Percentage
|
||||
* @return Battery Percentage (from 0 to 100)
|
||||
*/
|
||||
int GetBatteryPercentage();
|
||||
/**
|
||||
* Get Current Wifi Level
|
||||
* @return wifi level (0 to 4)
|
||||
*/
|
||||
int GetWifiLevel();
|
||||
} // namespace HwInfo
|
||||
} // namespace PD
|
||||
#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
|
@ -2,7 +2,8 @@
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
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
|
||||
@ -21,53 +22,30 @@ 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/drivers/hid.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Simple Table Containing the codepoint references
|
||||
* for the Controller Icons on the 3ds
|
||||
* Custom Allocator for Custom Vec and probably other stuff in future
|
||||
*/
|
||||
namespace GamePadIcons {
|
||||
/**
|
||||
* Icon ID
|
||||
*/
|
||||
enum ID {
|
||||
A,
|
||||
B,
|
||||
X,
|
||||
Y,
|
||||
L,
|
||||
R,
|
||||
Dpad,
|
||||
Start,
|
||||
Select,
|
||||
Home,
|
||||
Steps,
|
||||
PlayCoin,
|
||||
AnalogStick,
|
||||
Power3DS,
|
||||
DpadUp,
|
||||
DpadDown,
|
||||
DpadLeft,
|
||||
DpadRight,
|
||||
DpadHorizontal,
|
||||
DpadVertical,
|
||||
template <typename T>
|
||||
class Allocator {
|
||||
public:
|
||||
Allocator() = default;
|
||||
~Allocator() = default;
|
||||
|
||||
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(); }
|
||||
};
|
||||
/**
|
||||
* Get Icon by ID
|
||||
* @param id ID to Get
|
||||
* @return codepoint
|
||||
*/
|
||||
std::string GetIcon(ID id);
|
||||
/**
|
||||
* Get Icon By Input Driver Key
|
||||
* @param key Key to find
|
||||
* @return codepoint
|
||||
*/
|
||||
std::string GetIcon(Hid::Key key);
|
||||
} // namespace GamePadIcons
|
||||
} // namespace PD
|
71
include/pd/core/sl/hashmap.hpp
Normal file
71
include/pd/core/sl/hashmap.hpp
Normal file
@ -0,0 +1,71 @@
|
||||
#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
include/pd/core/sl/list.hpp
Normal file
210
include/pd/core/sl/list.hpp
Normal file
@ -0,0 +1,210 @@
|
||||
#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
|
@ -2,7 +2,8 @@
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
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
|
||||
@ -21,20 +22,20 @@ 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 {
|
||||
/**
|
||||
* Namespace to Everything that has to
|
||||
* do with the 3ds (very empty currently)
|
||||
*/
|
||||
namespace Ctr {
|
||||
/**
|
||||
* Get the System Language key (for lang system)
|
||||
* @return language key
|
||||
*/
|
||||
std::string GetSystemLanguage();
|
||||
} // namespace Ctr
|
||||
template <typename T1, typename T2>
|
||||
class Pair {
|
||||
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;
|
||||
|
||||
T1 First;
|
||||
T2 Second;
|
||||
};
|
||||
} // namespace PD
|
@ -1,10 +1,9 @@
|
||||
// THIS FILE WAS GENERATED BY build_shaders.py!!!
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tobid7
|
||||
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
|
||||
@ -23,9 +22,12 @@ 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 <cstddef>
|
||||
|
||||
extern unsigned char li7_shader[];
|
||||
extern size_t li7_shader_size;
|
||||
#include <pd/core/sl/allocator.hpp>
|
||||
#include <pd/core/sl/hashmap.hpp>
|
||||
#include <pd/core/sl/list.hpp>
|
||||
#include <pd/core/sl/pair.hpp>
|
||||
#include <pd/core/sl/stack.hpp>
|
||||
#include <pd/core/sl/tools.hpp>
|
||||
#include <pd/core/sl/vector.hpp>
|
70
include/pd/core/sl/stack.hpp
Normal file
70
include/pd/core/sl/stack.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
#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/vector.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Custom Stack class (caus std::stack ofsten lead to memory coruption)
|
||||
*/
|
||||
template <typename T, typename Alloc = Allocator<T>>
|
||||
class Stack {
|
||||
public:
|
||||
Stack() = default;
|
||||
explicit Stack(size_t cap) : pVec(cap) {}
|
||||
|
||||
void Push(const T& val) { pVec.Add(val); }
|
||||
|
||||
void Pop() {
|
||||
if (pVec.Size() == 0) {
|
||||
exit(1);
|
||||
}
|
||||
pVec.PopBack();
|
||||
}
|
||||
|
||||
T& Top() {
|
||||
if (pVec.Size() == 0) {
|
||||
exit(1);
|
||||
}
|
||||
return pVec[pVec.Size() - 1];
|
||||
}
|
||||
|
||||
const T& Top() const {
|
||||
if (pVec.Size() == 0) {
|
||||
exit(1);
|
||||
}
|
||||
return pVec[pVec.Size() - 1];
|
||||
}
|
||||
|
||||
bool IsEmpty() const { return pVec.Size() == 0; }
|
||||
size_t Size() const { return pVec.Size(); }
|
||||
void Clear() { pVec.Clear(); }
|
||||
|
||||
private:
|
||||
Vec<T, Alloc> pVec;
|
||||
};
|
||||
} // namespace PD
|
43
include/pd/core/sl/tools.hpp
Normal file
43
include/pd/core/sl/tools.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
#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
include/pd/core/sl/vector.hpp
Normal file
165
include/pd/core/sl/vector.hpp
Normal file
@ -0,0 +1,165 @@
|
||||
#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
|
@ -36,48 +36,47 @@ namespace Strings {
|
||||
* @param exts List of Extensions to check for
|
||||
* @return true if one of the extensions is found in the String
|
||||
*/
|
||||
bool StringEndsWith(const std::string& str,
|
||||
const std::vector<std::string>& exts);
|
||||
PD_CORE_API bool StringEndsWith(const std::string& str,
|
||||
const std::vector<std::string>& exts);
|
||||
/**
|
||||
* Function to Create a wstring of a string
|
||||
* @param s Input String to Convert
|
||||
* @return Result wstring
|
||||
* @note Currently using std::filesystem::path for this as wstring_convert
|
||||
* got removed in c++ 20
|
||||
* @note Returns Empty if it has an error
|
||||
*/
|
||||
std::wstring MakeWstring(const std::string& s);
|
||||
PD_CORE_API std::wstring MakeWstring(const std::string& s);
|
||||
/**
|
||||
* Generate a Formatted String by an Nanoseconds Input
|
||||
* @param nanos Nanoseconds Input
|
||||
* @return Result String
|
||||
*/
|
||||
const std::string FormatNanos(unsigned long long nanos);
|
||||
PD_CORE_API const std::string FormatNanos(unsigned long long nanos);
|
||||
/**
|
||||
* Generate a Formatted String by an Milliseconds Input
|
||||
* @param millis Milliseconds Input
|
||||
* @return Result String
|
||||
*/
|
||||
const std::string FormatMillis(unsigned long long millis);
|
||||
PD_CORE_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`
|
||||
*/
|
||||
const std::string FormatBytes(unsigned long long bytes);
|
||||
PD_CORE_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
|
||||
*/
|
||||
const std::string GetFileName(const std::string& path,
|
||||
const std::string& saperators = "/\\");
|
||||
PD_CORE_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
|
||||
*/
|
||||
const std::string PathRemoveExtension(const std::string& path);
|
||||
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
|
||||
/**
|
||||
* Function to Convert a Type to a hex value
|
||||
* @tparam T Type
|
||||
@ -95,7 +94,7 @@ inline const std::string ToHex(const T& v) {
|
||||
* @param s String to hash
|
||||
* @return 32Bit Hash
|
||||
*/
|
||||
u32 FastHash(const std::string& s);
|
||||
PD_CORE_API u32 FastHash(const std::string& s);
|
||||
/**
|
||||
* Function to Generate a Compiler Name and Version String
|
||||
* Based on their Macros
|
||||
@ -105,14 +104,14 @@ inline const std::string GetCompilerVersion() {
|
||||
/// As the function looks like this Project is meant to
|
||||
/// Be ported to other systems as well
|
||||
std::stringstream res;
|
||||
#ifdef __GNUC__
|
||||
res << "GCC: " << __GNUC__;
|
||||
res << "." << __GNUC_MINOR__ << ".";
|
||||
res << __GNUC_PATCHLEVEL__;
|
||||
#elif __clang__
|
||||
#ifdef __clang__ // Check clang first
|
||||
res << "Clang: " << __clang_major__ << ".";
|
||||
res << __clang_minor__ << ".";
|
||||
res << __clang_patchlevel__;
|
||||
#elif __GNUC__
|
||||
res << "GCC: " << __GNUC__;
|
||||
res << "." << __GNUC_MINOR__ << ".";
|
||||
res << __GNUC_PATCHLEVEL__;
|
||||
#elif _MSC_VER
|
||||
res << "MSVC: " << _MSC_VER;
|
||||
#else
|
||||
|
@ -39,28 +39,28 @@ using TraceMap = std::map<std::string, TT::Res::Ref>;
|
||||
* Get Current Time in Milliseconds
|
||||
* @return 64Bit value of millis
|
||||
*/
|
||||
u64 GetTime();
|
||||
PD_CORE_API u64 GetTime();
|
||||
/**
|
||||
* Get Current Time in Nanoseconds
|
||||
* @return 64Bit value of nanos
|
||||
*/
|
||||
u64 GetNanoTime();
|
||||
PD_CORE_API u64 GetNanoTime();
|
||||
/**
|
||||
* Get a TimeTrace Reference by its string ID
|
||||
* @param id trace name
|
||||
* @return Trace reference or nullptr if not found
|
||||
*/
|
||||
TT::Res::Ref& GetTraceRef(const std::string& id);
|
||||
PD_CORE_API TT::Res::Ref& GetTraceRef(const std::string& id);
|
||||
/**
|
||||
* Check if a Trace with the name exists
|
||||
* @param id tracename to search
|
||||
* @return true if exist
|
||||
*/
|
||||
bool TraceExist(const std::string& id);
|
||||
PD_CORE_API bool TraceExist(const std::string& id);
|
||||
/**
|
||||
* Get TraceMap Reference
|
||||
* @return edidable Reference to the TraceMap
|
||||
*/
|
||||
TraceMap& GetTraceMap();
|
||||
PD_CORE_API TraceMap& GetTraceMap();
|
||||
} // namespace Sys
|
||||
} // namespace PD
|
||||
|
@ -30,7 +30,7 @@ namespace PD {
|
||||
/**
|
||||
* Timer class
|
||||
*/
|
||||
class Timer : public SmartCtor<Timer> {
|
||||
class PD_CORE_API Timer : public SmartCtor<Timer> {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -211,12 +211,12 @@ class Res : public SmartCtor<Res> {
|
||||
* Begin a Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
void Beg(const std::string &id);
|
||||
PD_CORE_API void Beg(const std::string &id);
|
||||
/**
|
||||
* End a Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
void End(const std::string &id);
|
||||
PD_CORE_API void End(const std::string &id);
|
||||
/**
|
||||
* Collect Start end end of the trace by tracking
|
||||
* when the Scope object goes out of scope
|
||||
|
@ -23,7 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
@ -146,11 +150,7 @@ class Tween {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator that returns the current value calculated
|
||||
* by time and effect
|
||||
*/
|
||||
operator T() {
|
||||
T Get() const {
|
||||
float t = 0.f;
|
||||
switch (effect) {
|
||||
case EaseInQuad:
|
||||
@ -199,6 +199,12 @@ class Tween {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator that returns the current value calculated
|
||||
* by time and effect
|
||||
*/
|
||||
operator T() const { return Get(); }
|
||||
|
||||
private:
|
||||
/** Animation Effect */
|
||||
Effect effect;
|
||||
|
@ -23,402 +23,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// Why Creating this:
|
||||
// Cause using makes coding much better structured
|
||||
// and easy to use like in glsl or glm
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
struct vec2 {
|
||||
// Init Funcs
|
||||
vec2() {
|
||||
v[0] = 0;
|
||||
v[1] = 0;
|
||||
}
|
||||
vec2(float x, float y) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
}
|
||||
vec2(const vec2 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
}
|
||||
vec2(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
}
|
||||
|
||||
// Operations
|
||||
// Add
|
||||
vec2 &operator+=(const vec2 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 &operator+=(const float &i) {
|
||||
v[0] += i;
|
||||
v[1] += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 operator+(const vec2 &i) const { return vec2(v[0] + i[0], v[1] + i[1]); }
|
||||
vec2 operator+(const float &i) const { return vec2(v[0] + i, v[1] + i); }
|
||||
|
||||
// Sub
|
||||
vec2 &operator-=(const vec2 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 &operator-=(const float &i) {
|
||||
v[0] -= i;
|
||||
v[1] -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 operator-(const vec2 &i) const { return vec2(v[0] - i[0], v[1] - i[1]); }
|
||||
vec2 operator-(const float &i) const { return vec2(v[0] - i, v[1] - i); }
|
||||
|
||||
// Mul
|
||||
vec2 &operator*=(const vec2 &i) {
|
||||
v[0] *= i[0];
|
||||
v[1] *= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 &operator*=(const float &i) {
|
||||
v[0] *= i;
|
||||
v[1] *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 operator*(const vec2 &i) const { return vec2(v[0] * i[0], v[1] * i[1]); }
|
||||
vec2 operator*(const float &i) const { return vec2(v[0] * i, v[1] * i); }
|
||||
|
||||
// Div
|
||||
vec2 &operator/=(const vec2 &i) {
|
||||
v[0] /= i[0];
|
||||
v[1] /= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 &operator/=(const float &i) {
|
||||
v[0] /= i;
|
||||
v[1] /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 operator/(const vec2 &i) const { return vec2(v[0] / i[0], v[1] / i[1]); }
|
||||
vec2 operator/(const float &i) const { return vec2(v[0] / i, v[1] / i); }
|
||||
|
||||
// Compare
|
||||
bool operator==(const vec2 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1];
|
||||
}
|
||||
|
||||
bool operator!=(const vec2 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
vec2 operator-() const { return vec2(-v[0], -v[1]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const { return v[0] * v[0] + v[1] * v[1]; }
|
||||
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
// Internal Values
|
||||
float v[2];
|
||||
};
|
||||
|
||||
struct vec3 {
|
||||
// Init Funcs
|
||||
vec3() {
|
||||
v[0] = 0.f;
|
||||
v[1] = 0.f;
|
||||
v[2] = 0.f;
|
||||
}
|
||||
vec3(float x, float y, float z) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
}
|
||||
vec3(const vec3 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
v[2] = i[2];
|
||||
}
|
||||
vec3(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
v[2] = i;
|
||||
}
|
||||
//// PD REWRITE ADDITIONAL CONTENT ////
|
||||
vec3(const vec2 &xy, float z) {
|
||||
v[0] = xy[0];
|
||||
v[1] = xy[1];
|
||||
v[2] = z;
|
||||
}
|
||||
vec3(float x, const vec2 &yz) {
|
||||
v[0] = x;
|
||||
v[1] = yz[0];
|
||||
v[2] = yz[1];
|
||||
}
|
||||
|
||||
// Operations
|
||||
// Add
|
||||
vec3 &operator+=(const vec3 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
v[2] += i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 &operator+=(const float &i) {
|
||||
v[0] += i;
|
||||
v[1] += i;
|
||||
v[2] += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 operator+(const vec3 &i) const {
|
||||
return vec3(v[0] + i[0], v[1] + i[1], v[2] + i[2]);
|
||||
}
|
||||
vec3 operator+(const float &i) const {
|
||||
return vec3(v[0] + i, v[1] + i, v[2] + i);
|
||||
}
|
||||
|
||||
// Sub
|
||||
vec3 &operator-=(const vec3 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
v[2] -= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 &operator-=(const float &i) {
|
||||
v[0] -= i;
|
||||
v[1] -= i;
|
||||
v[2] -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 operator-(const vec3 &i) const {
|
||||
return vec3(v[0] - i[0], v[1] - i[1], v[2] - i[2]);
|
||||
}
|
||||
vec3 operator-(const float &i) const {
|
||||
return vec3(v[0] - i, v[1] - i, v[2] - i);
|
||||
}
|
||||
|
||||
// Mul
|
||||
vec3 &operator*=(const vec3 &i) {
|
||||
v[0] *= i[0];
|
||||
v[1] *= i[1];
|
||||
v[2] *= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 &operator*=(const float &i) {
|
||||
v[0] *= i;
|
||||
v[1] *= i;
|
||||
v[2] *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 operator*(const vec3 &i) const {
|
||||
return vec3(v[0] * i[0], v[1] * i[1], v[2] * i[2]);
|
||||
}
|
||||
vec3 operator*(const float &i) const {
|
||||
return vec3(v[0] * i, v[1] * i, v[2] * i);
|
||||
}
|
||||
|
||||
// Div
|
||||
vec3 &operator/=(const vec3 &i) {
|
||||
v[0] /= i[0];
|
||||
v[1] /= i[1];
|
||||
v[2] /= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 &operator/=(const float &i) {
|
||||
v[0] /= i;
|
||||
v[1] /= i;
|
||||
v[2] /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 operator/(const vec3 &i) const {
|
||||
return vec3(v[0] / i[0], v[1] / i[1], v[2] / i[2]);
|
||||
}
|
||||
vec3 operator/(const float &i) const {
|
||||
return vec3(v[0] / i, v[1] / i, v[2] / i);
|
||||
}
|
||||
|
||||
// Compare
|
||||
bool operator==(const vec3 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1] && v[2] == v[2];
|
||||
}
|
||||
|
||||
bool operator!=(const vec3 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
// Base
|
||||
vec3 operator-() const { return vec3(-v[0], -v[1], -v[2]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const { return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; }
|
||||
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
float z() const { return v[2]; }
|
||||
float &z() { return v[2]; }
|
||||
|
||||
//// PALLADIUM REWRITE ADDITIONAL CONTENT ////
|
||||
vec2 xy() const { return vec2(v[0], v[1]); }
|
||||
vec2 yz() const { return vec2(v[1], v[2]); }
|
||||
|
||||
float v[3];
|
||||
};
|
||||
|
||||
struct vec4 {
|
||||
// Init Funcs
|
||||
vec4() {
|
||||
v[0] = 0.f;
|
||||
v[1] = 0.f;
|
||||
v[2] = 0.f;
|
||||
v[3] = 0.f;
|
||||
}
|
||||
vec4(float x, float y, float z, float w) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
v[3] = w;
|
||||
}
|
||||
vec4(const vec4 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
v[2] = i[2];
|
||||
v[3] = i[3];
|
||||
}
|
||||
|
||||
vec4(const vec2 &i0, const vec2 &i1) {
|
||||
v[0] = i0[0];
|
||||
v[1] = i0[1];
|
||||
v[2] = i1[0];
|
||||
v[3] = i1[1];
|
||||
}
|
||||
vec4(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
v[2] = i;
|
||||
v[3] = i;
|
||||
}
|
||||
|
||||
vec4(const vec3 &xyz, float w) {
|
||||
v[0] = xyz[0];
|
||||
v[1] = xyz[1];
|
||||
v[2] = xyz[2];
|
||||
v[3] = w;
|
||||
}
|
||||
|
||||
vec4(float x, const vec3 &yzw) {
|
||||
v[0] = x;
|
||||
v[1] = yzw[1];
|
||||
v[2] = yzw[2];
|
||||
v[3] = yzw[3];
|
||||
}
|
||||
|
||||
// Operators
|
||||
// Add
|
||||
vec4 &operator+=(const vec4 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
v[2] += i[2];
|
||||
v[3] += i[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec4 operator+(const vec4 &i) const {
|
||||
return vec4(v[0] + i[0], v[1] + i[1], v[2] + i[2], v[3] + i[3]);
|
||||
}
|
||||
|
||||
// Sub
|
||||
vec4 &operator-=(const vec4 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
v[2] -= i[2];
|
||||
v[3] -= i[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec4 operator-(const vec4 &i) const {
|
||||
return vec4(v[0] - i[0], v[1] - i[1], v[2] - i[2], v[3] - i[3]);
|
||||
}
|
||||
|
||||
// Compare
|
||||
bool operator==(const vec4 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1] && v[2] == in[2] && v[3] == in[3];
|
||||
}
|
||||
|
||||
bool operator!=(const vec4 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
// Base
|
||||
vec4 operator-() const { return vec4(-v[0], -v[1], -v[2], -v[3]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const {
|
||||
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
|
||||
}
|
||||
|
||||
// Vec Acess
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
float z() const { return v[2]; }
|
||||
float &z() { return v[2]; }
|
||||
float w() const { return v[3]; }
|
||||
float &w() { return v[3]; }
|
||||
vec2 xy() const { return vec2(v[0], v[1]); }
|
||||
vec2 zw() const { return vec2(v[2], v[3]); }
|
||||
vec3 xyz() const { return vec3(v[0], v[1], v[2]); }
|
||||
vec3 yzw() const { return vec3(v[1], v[2], v[3]); }
|
||||
// Quaternion Acess
|
||||
float r() const { return v[0]; }
|
||||
float &r() { return v[0]; }
|
||||
float k() const { return v[1]; }
|
||||
float &k() { return v[1]; }
|
||||
float j() const { return v[2]; }
|
||||
float &j() { return v[2]; }
|
||||
float i() const { return v[3]; }
|
||||
float &i() { return v[3]; }
|
||||
vec2 rk() const { return vec2(v[0], v[1]); }
|
||||
vec2 ji() const { return vec2(v[2], v[3]); }
|
||||
vec3 rkj() const { return vec3(v[0], v[1], v[2]); }
|
||||
vec3 kji() const { return vec3(v[1], v[2], v[3]); }
|
||||
// Internal Values
|
||||
float v[4];
|
||||
};
|
||||
} // namespace PD
|
||||
#include <pd/core/vec2.hpp>
|
||||
#include <pd/core/vec3.hpp>
|
||||
#include <pd/core/vec4.hpp>
|
135
include/pd/core/vec2.hpp
Normal file
135
include/pd/core/vec2.hpp
Normal file
@ -0,0 +1,135 @@
|
||||
#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>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class vec2 {
|
||||
public:
|
||||
// SECTION: Constructors //
|
||||
|
||||
vec2() = default;
|
||||
vec2(T v) {
|
||||
x = v;
|
||||
y = v;
|
||||
}
|
||||
vec2(T x, T y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
vec2(const vec2<T> &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
}
|
||||
|
||||
// SECTION: Operators //
|
||||
|
||||
// ADD //
|
||||
|
||||
vec2 &operator+=(T v) {
|
||||
x += v;
|
||||
y += v;
|
||||
return *this;
|
||||
}
|
||||
vec2 &operator+=(const vec2 &v) {
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
return *this;
|
||||
}
|
||||
vec2 operator+(T v) const { return vec2(x + v, y + v); }
|
||||
vec2 operator+(vec2 v) const { return vec2(x + v.x, y + v.y); }
|
||||
|
||||
// SUB //
|
||||
|
||||
vec2 &operator-=(T v) {
|
||||
x -= v;
|
||||
y -= v;
|
||||
return *this;
|
||||
}
|
||||
vec2 &operator-=(const vec2 &v) {
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
return *this;
|
||||
}
|
||||
vec2 operator-(T v) const { return vec2(x - v, y - v); }
|
||||
vec2 operator-(vec2 v) const { return vec2(x - v.x, y - v.y); }
|
||||
|
||||
// MUL //
|
||||
|
||||
vec2 &operator*=(T v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
return *this;
|
||||
}
|
||||
vec2 &operator*=(const vec2 &v) {
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
return *this;
|
||||
}
|
||||
vec2 operator*(T v) const { return vec2(x * v, y * v); }
|
||||
vec2 operator*(vec2 v) const { return vec2(x * v.x, y * v.y); }
|
||||
|
||||
// DIV //
|
||||
|
||||
vec2 &operator/=(T v) {
|
||||
x /= v;
|
||||
y /= v;
|
||||
return *this;
|
||||
}
|
||||
vec2 &operator/=(const vec2 &v) {
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
return *this;
|
||||
}
|
||||
vec2 operator/(T v) const { return vec2(x / v, y / v); }
|
||||
vec2 operator/(vec2 v) const { return vec2(x / v.x, y / v.y); }
|
||||
|
||||
// Make Negative //
|
||||
vec2 operator-() const { return vec2(-x, -y); }
|
||||
|
||||
bool operator==(const vec2 &v) const { return x == v.x && y == v.y; }
|
||||
bool operator!=(const vec2 &v) const { return !(*this == v); }
|
||||
|
||||
// SECTION: Additional Functions //
|
||||
|
||||
float Len() const { return sqrt(SqLen()); }
|
||||
float SqLen() const { return x * x + y * y; }
|
||||
void Swap() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
|
||||
// SECTION: DATA //
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
};
|
||||
|
||||
using dvec2 = vec2<double>;
|
||||
using fvec2 = vec2<float>;
|
||||
using ivec2 = vec2<int>;
|
||||
} // namespace PD
|
160
include/pd/core/vec3.hpp
Normal file
160
include/pd/core/vec3.hpp
Normal file
@ -0,0 +1,160 @@
|
||||
#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/vec2.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class vec3 {
|
||||
public:
|
||||
// SECTION: Constructors //
|
||||
|
||||
vec3() = default;
|
||||
vec3(T v) {
|
||||
x = v;
|
||||
y = v;
|
||||
z = v;
|
||||
}
|
||||
vec3(T x, T y, T z) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
vec3(const vec3 &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
}
|
||||
|
||||
// SECTION: Operators //
|
||||
|
||||
// ADD //
|
||||
|
||||
vec3 &operator+=(T v) {
|
||||
x += v;
|
||||
y += v;
|
||||
z += v;
|
||||
return *this;
|
||||
}
|
||||
vec3 &operator+=(const vec3 &v) {
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
z += v.z;
|
||||
return *this;
|
||||
}
|
||||
vec3 operator+(T v) const { return vec3(x + v, y + v, z + v); }
|
||||
vec3 operator+(vec3 v) const { return vec3(x + v.x, y + v.y, z + v.z); }
|
||||
|
||||
// SUB //
|
||||
|
||||
vec3 &operator-=(T v) {
|
||||
x -= v;
|
||||
y -= v;
|
||||
z -= v;
|
||||
return *this;
|
||||
}
|
||||
vec3 &operator-=(const vec3 &v) {
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
z -= v.z;
|
||||
return *this;
|
||||
}
|
||||
vec3 operator-(T v) const { return vec3(x - v, y - v, z - v); }
|
||||
vec3 operator-(vec3 v) const { return vec3(x - v.x, y - v.y, z - v.z); }
|
||||
|
||||
// MUL //
|
||||
|
||||
vec3 &operator*=(T v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
z *= v;
|
||||
return *this;
|
||||
}
|
||||
vec3 &operator*=(const vec3 &v) {
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
z *= v.z;
|
||||
return *this;
|
||||
}
|
||||
vec3 operator*(T v) const { return vec3(x * v, y * v, z * v); }
|
||||
vec3 operator*(vec3 v) const { return vec3(x * v.x, y * v.y, z * v.z); }
|
||||
|
||||
// DIV //
|
||||
|
||||
vec3 &operator/=(T v) {
|
||||
x /= v;
|
||||
y /= v;
|
||||
z /= v;
|
||||
return *this;
|
||||
}
|
||||
vec3 &operator/=(const vec3 &v) {
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
z /= v.z;
|
||||
return *this;
|
||||
}
|
||||
vec3 operator/(T v) const { return vec3(x / v, y / v, z / v); }
|
||||
vec3 operator/(vec3 v) const { return vec3(x / v.x, y / v.y, z / v.z); }
|
||||
|
||||
// Make Negative //
|
||||
vec3 operator-() const { return vec3(-x, -y, -z); }
|
||||
|
||||
bool operator==(const vec3 &v) const {
|
||||
return x == v.x && y == v.y && z == v.z;
|
||||
}
|
||||
bool operator!=(const vec3 &v) const { return !(*this == v); }
|
||||
|
||||
// SECTION: Additional Functions //
|
||||
|
||||
float Len() const { return sqrt(SqLen()); }
|
||||
float SqLen() const { return x * x + y * y + z * z; }
|
||||
void SwapXY() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapYZ() {
|
||||
T t = z;
|
||||
z = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapXZ() {
|
||||
T t = z;
|
||||
z = x;
|
||||
x = t;
|
||||
}
|
||||
|
||||
// SECTION: DATA //
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
T z = 0;
|
||||
};
|
||||
|
||||
using dvec3 = vec3<double>;
|
||||
using fvec3 = vec3<float>;
|
||||
using ivec3 = vec3<int>;
|
||||
} // namespace PD
|
193
include/pd/core/vec4.hpp
Normal file
193
include/pd/core/vec4.hpp
Normal file
@ -0,0 +1,193 @@
|
||||
#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/vec3.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class vec4 {
|
||||
public:
|
||||
// SECTION: Constructors //
|
||||
|
||||
vec4() = default;
|
||||
vec4(T v) {
|
||||
x = v;
|
||||
y = v;
|
||||
z = v;
|
||||
w = v;
|
||||
}
|
||||
vec4(T x, T y, T z, T w) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
this->w = w;
|
||||
}
|
||||
|
||||
vec4(const vec4 &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
w = v.w;
|
||||
}
|
||||
|
||||
vec4(const vec2<T> &xy, const vec2<T> &zw) {
|
||||
x = xy.x;
|
||||
y = xy.y;
|
||||
z = zw.x;
|
||||
w = zw.y;
|
||||
}
|
||||
|
||||
// SECTION: Operators //
|
||||
|
||||
// ADD //
|
||||
|
||||
vec4 &operator+=(T v) {
|
||||
x += v;
|
||||
y += v;
|
||||
z += v;
|
||||
w += v;
|
||||
return *this;
|
||||
}
|
||||
vec4 &operator+=(const vec4<T> &v) {
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
z += v.z;
|
||||
w += v.w;
|
||||
return *this;
|
||||
}
|
||||
vec4 operator+(T v) const { return vec4<T>(x + v, y + v, z + v, w + v); }
|
||||
vec4 operator+(vec4 v) const {
|
||||
return vec4(x + v.x, y + v.y, z + v.z, w + v.w);
|
||||
}
|
||||
|
||||
// SUB //
|
||||
|
||||
vec4 &operator-=(T v) {
|
||||
x -= v;
|
||||
y -= v;
|
||||
z -= v;
|
||||
w -= v;
|
||||
return *this;
|
||||
}
|
||||
vec4 &operator-=(const vec4 &v) {
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
z -= v.z;
|
||||
w -= v.w;
|
||||
return *this;
|
||||
}
|
||||
vec4 operator-(T v) const { return vec4(x - v, y - v, z - v, w - v); }
|
||||
vec4 operator-(vec4 v) const {
|
||||
return vec4(x - v.x, y - v.y, z - v.z, w - v.w);
|
||||
}
|
||||
|
||||
// MUL //
|
||||
|
||||
vec4 &operator*=(T v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
z *= v;
|
||||
w *= v;
|
||||
return *this;
|
||||
}
|
||||
vec4 &operator*=(const vec4 &v) {
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
z *= v.z;
|
||||
w *= v.w;
|
||||
return *this;
|
||||
}
|
||||
vec4 operator*(T v) const { return vec4(x * v, y * v, z * v, w * v); }
|
||||
vec4 operator*(vec4 v) const {
|
||||
return vec4(x * v.x, y * v.y, z * v.z, w * v.w);
|
||||
}
|
||||
|
||||
// DIV //
|
||||
|
||||
vec4 &operator/=(T v) {
|
||||
x /= v;
|
||||
y /= v;
|
||||
z /= v;
|
||||
w /= v;
|
||||
return *this;
|
||||
}
|
||||
vec4 &operator/=(const vec4 &v) {
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
z /= v.z;
|
||||
w /= v.w;
|
||||
return *this;
|
||||
}
|
||||
vec4 operator/(T v) const { return vec4(x / v, y / v, z / v, w / v); }
|
||||
vec4 operator/(vec4 v) const {
|
||||
return vec4(x / v.x, y / v.y, z / v.z, w / v.w);
|
||||
}
|
||||
|
||||
// Make Negative //
|
||||
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
|
||||
|
||||
bool operator==(const vec4 &v) const {
|
||||
return x == v.x && y == v.y && z == v.z && w == v.w;
|
||||
}
|
||||
bool operator!=(const vec4 &v) const { return !(*this == v); }
|
||||
|
||||
// SECTION: Additional Functions //
|
||||
|
||||
float Len() const { return sqrt(SqLen()); }
|
||||
float SqLen() const { return x * x + y * y + z * z + w * w; }
|
||||
void SwapXY() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapYZ() {
|
||||
T t = z;
|
||||
z = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapXZ() {
|
||||
T t = z;
|
||||
z = x;
|
||||
x = t;
|
||||
}
|
||||
// Adding ZW (to lazy to add all of those yet)
|
||||
void SwapZW() {
|
||||
T t = w;
|
||||
w = z;
|
||||
z = t;
|
||||
}
|
||||
|
||||
// SECTION: DATA //
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
T z = 0;
|
||||
T w = 0;
|
||||
};
|
||||
|
||||
using dvec4 = vec4<double>;
|
||||
using fvec4 = vec4<float>;
|
||||
using ivec4 = vec4<int>;
|
||||
} // namespace PD
|
@ -24,41 +24,59 @@ 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>
|
||||
#include <pd/image/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Image {
|
||||
class PD_IMAGE_API Image : public SmartCtor<Image> {
|
||||
public:
|
||||
enum Format {
|
||||
RGBA, // bpp == 4
|
||||
RGB, // bpp == 3
|
||||
RGB565, // bpp == 2 (not supported in laoding)
|
||||
BGR, // bpp == 3
|
||||
ABGR // bpp == 4
|
||||
};
|
||||
Image() = default;
|
||||
Image(const std::string& path) { this->Load(path); }
|
||||
Image(const std::vector<u8>& buf) { this->Load(buf); }
|
||||
Image(const std::vector<u8>& buf, int w, int h, int fmt = 4) {
|
||||
this->Copy(buf, w, h, fmt);
|
||||
Image(const std::vector<u8>& buf, int w, int h, int bpp = 4) {
|
||||
this->Copy(buf, w, h, bpp);
|
||||
}
|
||||
~Image() = default;
|
||||
|
||||
void Load(const std::string& path);
|
||||
void Load(const std::vector<u8>& buf);
|
||||
void Copy(const std::vector<u8>& buf, int w, int h, int fmt = 4);
|
||||
void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4);
|
||||
|
||||
std::vector<u8>& GetBuffer() { return buffer; }
|
||||
std::vector<u8> GetBuffer() const { return buffer; }
|
||||
std::vector<PD::u8>& GetBuffer() { return pBuffer; }
|
||||
std::vector<PD::u8> GetBuffer() const { return pBuffer; }
|
||||
|
||||
int Width() const { return w; }
|
||||
int Height() const { return h; }
|
||||
int Width() const { return pWidth; }
|
||||
int Height() const { return pHeight; }
|
||||
Format Fmt() const { return pFmt; }
|
||||
|
||||
u8& operator[](int idx) { return buffer[idx]; }
|
||||
u8 operator[](int idx) const { return buffer[idx]; }
|
||||
u8& operator[](int idx) { return pBuffer[idx]; }
|
||||
u8 operator[](int idx) const { return pBuffer[idx]; }
|
||||
|
||||
// Probably these make th eabove ones useless
|
||||
|
||||
operator std::vector<u8>&() { return buffer; }
|
||||
operator std::vector<u8>() const { return buffer; }
|
||||
operator std::vector<PD::u8>&() { return pBuffer; }
|
||||
operator std::vector<PD::u8>() const { return pBuffer; }
|
||||
|
||||
static void Convert(Image::Ref img, Image::Format dst);
|
||||
static void ReTile(Image::Ref img,
|
||||
std::function<u32(int x, int y, int w)> src,
|
||||
std::function<u32(int x, int y, int w)> dst);
|
||||
static int Fmt2Bpp(Format fmt);
|
||||
|
||||
std::vector<PD::u8> pBuffer;
|
||||
int pWidth;
|
||||
int pHeight;
|
||||
Format pFmt = Format::RGBA;
|
||||
|
||||
private:
|
||||
std::vector<u8> buffer;
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
/** Leftover variable used for stbi_load */
|
||||
int fmt = 0;
|
||||
};
|
||||
} // namespace PD
|
@ -24,8 +24,8 @@ 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/vec.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/image/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
@ -38,7 +38,7 @@ namespace ImgBlur {
|
||||
* @param si sigma value to use
|
||||
* @return list of kernel values
|
||||
*/
|
||||
std::vector<float> GaussianKernel(int radius, float si);
|
||||
PD_IMAGE_API std::vector<float> GaussianKernel(int radius, float si);
|
||||
/**
|
||||
* Gaussian Blur for basic Image Buffer
|
||||
* @param buf Image Buffer (unsigned char)
|
||||
@ -48,7 +48,7 @@ std::vector<float> GaussianKernel(int radius, float si);
|
||||
* @param si Blur sigma
|
||||
* @param idxfn Indexing function
|
||||
*/
|
||||
void GaussianBlur(
|
||||
PD_IMAGE_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 +63,7 @@ void GaussianBlur(
|
||||
* @param si Blur sigma
|
||||
* @param idxfn Indexing function
|
||||
*/
|
||||
void GaussianBlur(
|
||||
PD_IMAGE_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;
|
||||
|
@ -24,7 +24,9 @@ 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>
|
||||
#include <pd/image/image.hpp>
|
||||
#include <pd/image/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
@ -39,7 +41,11 @@ namespace ImgConvert {
|
||||
* @param w width of the image
|
||||
* @param h height of the image
|
||||
*/
|
||||
void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
|
||||
PD_IMAGE_API
|
||||
void RGB24toRGBA32(std::vector<PD::u8> &out, const std::vector<u8> &in,
|
||||
const int &w, const int &h);
|
||||
PD_IMAGE_API
|
||||
void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in,
|
||||
const int &w, const int &h);
|
||||
/**
|
||||
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
|
||||
@ -47,6 +53,30 @@ void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
|
||||
* @param w width
|
||||
* @param h height
|
||||
*/
|
||||
void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
|
||||
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);
|
||||
} // namespace ImgConvert
|
||||
} // namespace PD
|
52
include/pd/image/pd_p_api.hpp
Normal file
52
include/pd/image/pd_p_api.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
#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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#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
|
@ -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 <3ds.h>
|
||||
|
||||
#include <pd/app/error.hpp>
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Custom C++ Allocator for 3DS linear Memory
|
||||
* Used for Everything that has to do with Rendering or sound
|
||||
* Dont going into that much detail here
|
||||
*
|
||||
* Example:
|
||||
* ```cpp
|
||||
* // Index Buffer for Rendering using Linear Allocator
|
||||
* std::vector<u16, PD::LinearAllocator<u16>> index_buf;
|
||||
* ```
|
||||
*/
|
||||
template <typename T>
|
||||
class LinearAllocator : public std::allocator<T> {
|
||||
public:
|
||||
using size_type = size_t;
|
||||
using pointer = T*;
|
||||
using const_pointer = const T*;
|
||||
|
||||
template <typename T1>
|
||||
struct rebind {
|
||||
using other = LinearAllocator<T1>;
|
||||
};
|
||||
|
||||
pointer allocate(size_type n, const void* hint = nullptr) {
|
||||
if (n > this->max_size()) {
|
||||
Error("Linear Alloc failed (no space left)");
|
||||
return nullptr;
|
||||
}
|
||||
return (pointer)linearAlloc(n * sizeof(T));
|
||||
}
|
||||
void deallocate(pointer p, size_type) { linearFree((void*)p); }
|
||||
size_type max_size() { return linearSpaceFree(); }
|
||||
|
||||
LinearAllocator() noexcept {}
|
||||
LinearAllocator(const LinearAllocator<T>& a) noexcept
|
||||
: std::allocator<T>(a) {}
|
||||
~LinearAllocator() noexcept {}
|
||||
};
|
||||
} // namespace PD
|
76
include/pd/lithium/backend.hpp
Normal file
76
include/pd/lithium/backend.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
#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/core.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using LIBackendFlags = PD::u32;
|
||||
enum LIBackendFlags_ {
|
||||
LIBackendFlags_None = 0,
|
||||
LIBackendFlags_FlipUV_Y = 1 << 0, // Essential for Font Loading
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class Backend {
|
||||
public:
|
||||
Backend(const std::string& name = "NullBackend") : pName(name) {}
|
||||
~Backend() = default;
|
||||
// Using Legacy SmartCTOR API here
|
||||
PD_SMART_CTOR(Backend)
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void NewFrame() {}
|
||||
|
||||
virtual void BindTexture(TexAddress addr) {}
|
||||
|
||||
virtual void RenderDrawData(const Vec<Command::Ref>& Commands) {}
|
||||
|
||||
virtual Texture::Ref LoadTexture(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
Texture::Type type = Texture::Type::RGBA32,
|
||||
Texture::Filter filter = Texture::Filter::LINEAR) {
|
||||
// Texture loading not supported (when this func not get override)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** Backend identification name */
|
||||
const std::string pName = "NullBackend";
|
||||
LIBackendFlags Flags = 0;
|
||||
ivec2 ViewPort;
|
||||
fvec4 ClearColor;
|
||||
// Optional Index Counter
|
||||
int IndexCounter = 0;
|
||||
// Optional Vertex Counter
|
||||
int VertexCounter = 0;
|
||||
// Optional Frame Counter
|
||||
int FrameCounter = 0;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -24,9 +24,8 @@ 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/vec.hpp>
|
||||
#include <pd/lithium/flags.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
// #include <pd/lithium/flags.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
|
||||
@ -41,175 +40,23 @@ class Command : public SmartCtor<Command> {
|
||||
Command() = default;
|
||||
~Command() = default;
|
||||
|
||||
/**
|
||||
* Copy Constructor [to Copy the Data of a Command Reference]
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Commands layer
|
||||
* @param v layer value
|
||||
* @return command reference
|
||||
*/
|
||||
Command& Layer(int v) {
|
||||
layer = v;
|
||||
Command& AppendIndex(u16 idx) {
|
||||
IndexBuffer.Add(VertexBuffer.Size() + idx);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Layer
|
||||
* @return layer value
|
||||
*/
|
||||
int Layer() const { return layer; }
|
||||
|
||||
/**
|
||||
* Setter for the Commands Index [used in sorting]
|
||||
* @param v index value
|
||||
* @return command reference
|
||||
*/
|
||||
Command& Index(int v) {
|
||||
index = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the Index
|
||||
* @return index value
|
||||
*/
|
||||
int Index() const { return index; }
|
||||
|
||||
/**
|
||||
* Setter for the Commands Texture
|
||||
* @param v Texture reference
|
||||
* @return command reference
|
||||
*/
|
||||
Command& Tex(Texture::Ref v) {
|
||||
tex = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the Texture reference
|
||||
* @return Texture reference
|
||||
*/
|
||||
Texture::Ref Tex() const { return tex; }
|
||||
|
||||
/**
|
||||
* Function to Push a Vertex to the vertexbuffer
|
||||
* @param v Vertex to push
|
||||
* @return command reference
|
||||
*/
|
||||
Command& PushVertex(const Vertex& v) {
|
||||
vertex_buf.push_back(v);
|
||||
Command& AppendVertex(const Vertex& v) {
|
||||
VertexBuffer.Add(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access to the Index list [used to write index data
|
||||
* to the real indexbuffer]
|
||||
* @return const reference to commands idx buffer
|
||||
*/
|
||||
const std::vector<u16>& IndexList() const { return index_buf; }
|
||||
/**
|
||||
* Access to the Vertex list [used to write vertices
|
||||
* data to the real vertexbuffer]
|
||||
* @return const reference to commands vertex buffer
|
||||
*/
|
||||
const std::vector<Vertex>& VertexList() const { return vertex_buf; }
|
||||
|
||||
// ADVANCED
|
||||
|
||||
/**
|
||||
* Advanced function to access index list
|
||||
*
|
||||
* - This function is UNSAFE to use cause it allows to modify index data
|
||||
* @return reference to index list
|
||||
*/
|
||||
std::vector<u16>& IndexList() { return index_buf; }
|
||||
/**
|
||||
* Advanced function to access vertex list
|
||||
*
|
||||
* - This function is UNSAFE to use cause it allows to modify index data
|
||||
* - Using this in StaticText to change Position color and stuff after it is
|
||||
* rendered into commands
|
||||
* @return reference to vertex list
|
||||
*/
|
||||
std::vector<Vertex>& VertexList() { return vertex_buf; }
|
||||
|
||||
/**
|
||||
* Function to Push an index value to indexbuffer
|
||||
* @param v Index value
|
||||
* @return command reference
|
||||
*/
|
||||
Command& PushIndex(u16 v) {
|
||||
index_buf.push_back(vertex_buf.size() + v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Commands RenderMode
|
||||
* @param v RenderMode
|
||||
* @return command reference
|
||||
*/
|
||||
Command& Rendermode(const RenderMode& v) {
|
||||
mode = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Commands RenderMode
|
||||
* @return RenderMode
|
||||
*/
|
||||
RenderMode Rendermode() const { return mode; }
|
||||
|
||||
/** Setter for Scissor Mode */
|
||||
Command& SetScissorMode(ScissorMode mode) {
|
||||
scissor = mode;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Getter for Scissor Mode */
|
||||
ScissorMode GetScissorMode() const { return scissor; }
|
||||
|
||||
/** Setter for Scissor Area */
|
||||
Command& ScissorRect(const vec4& v) {
|
||||
scissor_area = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Getter for Scissor Area */
|
||||
vec4 ScissorRect() const { return scissor_area; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Vertex Buffer
|
||||
*
|
||||
* - Using default vector here as its data will be copied later
|
||||
*/
|
||||
std::vector<Vertex> vertex_buf;
|
||||
/**
|
||||
* Index Buffer
|
||||
*
|
||||
* - Using default vector here as its data will be copied later
|
||||
*/
|
||||
std::vector<u16> index_buf;
|
||||
/** Layer */
|
||||
int layer;
|
||||
/** Texture Reference */
|
||||
Texture::Ref tex;
|
||||
/** Index */
|
||||
int index;
|
||||
/** RenderMode (Default to RenderMode_RGBA) */
|
||||
RenderMode mode = RenderMode_RGBA;
|
||||
/** Scissor Mode (for defined area to render) */
|
||||
ScissorMode scissor = ScissorMode_None;
|
||||
/** scissor box (top left and bottom right) */
|
||||
vec4 scissor_area;
|
||||
Vec<Vertex> VertexBuffer;
|
||||
Vec<u16> IndexBuffer;
|
||||
ivec4 ScissorRect;
|
||||
bool ScissorEnabled = false;
|
||||
int Layer;
|
||||
int Index;
|
||||
Texture::Ref Tex;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
145
include/pd/lithium/drawlist.hpp
Normal file
145
include/pd/lithium/drawlist.hpp
Normal file
@ -0,0 +1,145 @@
|
||||
#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/lithium/command.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/lithium/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
|
||||
public:
|
||||
DrawList(Texture::Ref solid) {
|
||||
WhitePixel = solid;
|
||||
CurrentTex = solid;
|
||||
}
|
||||
~DrawList() {}
|
||||
|
||||
Command::Ref PreGenerateCmd();
|
||||
void AddCommand(Command::Ref v) { pDrawList.Add(v); }
|
||||
void Clear() { pDrawList.Clear(); }
|
||||
|
||||
void SetFont(Font::Ref font) { pCurrentFont = font; }
|
||||
void SetFontScale(float scale) { pFontScale = scale; }
|
||||
|
||||
void DrawSolid() { CurrentTex = WhitePixel; }
|
||||
void DrawTexture(Texture::Ref tex) { CurrentTex = tex; }
|
||||
|
||||
// SECTION: Draw API //
|
||||
|
||||
void DrawRect(const fvec2& pos, const fvec2& size, u32 color,
|
||||
int thickness = 1);
|
||||
void DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color);
|
||||
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, u32 color,
|
||||
int thickness = 1);
|
||||
void DrawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
u32 color);
|
||||
void DrawCircle(const fvec2& center, float rad, u32 color, int num_segments,
|
||||
int thickness = 1);
|
||||
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
|
||||
int num_segments);
|
||||
void DrawText(const fvec2& p, const std::string& text, u32 color);
|
||||
|
||||
/**
|
||||
* Take list of points and display it as a line on screen
|
||||
* @param points List of Positions
|
||||
* @param clr Color of the Line
|
||||
* @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,
|
||||
int thickness = 1);
|
||||
/**
|
||||
* Take a List ofpoints and display it as Filled Shape
|
||||
* @note Keep in mind to setup the list of points clockwise
|
||||
* @param points List of Points
|
||||
* @param clr Color of the shape
|
||||
*/
|
||||
void DrawConvexPolyFilled(const Vec<fvec2>& points, u32 clr);
|
||||
|
||||
// SECTION: PATH API //
|
||||
|
||||
/**
|
||||
* Function to reserve Memory to prevent overhead on
|
||||
* pusing a lot of points with PathNext
|
||||
* @param num_points Number of Positions you want to add
|
||||
*/
|
||||
void PathReserve(size_t num_points) {
|
||||
pPath.Reserve(pPath.Size() + num_points);
|
||||
}
|
||||
/**
|
||||
* Clear current Path
|
||||
* @note PathStroke and PathFill will automatically 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); }
|
||||
/**
|
||||
* Path Stroke Create Line from point to point
|
||||
* @note For Primitives like Rect or Triangle mak sure to use
|
||||
* UI7DrawFlags_Close to add a line back to the starting point
|
||||
* @param clr Color od the line
|
||||
* @param thickness Thickness of the line
|
||||
* @param flags Additional Drawflags
|
||||
*/
|
||||
void PathStroke(u32 clr, int thickness = 1, u32 flags = 0) {
|
||||
DrawPolyLine(pPath, clr, flags, thickness);
|
||||
pPath.Clear();
|
||||
}
|
||||
/**
|
||||
* Fill a Path with a Color
|
||||
* @note **IMPORTANT: ** Paths need to be setup clockwise
|
||||
* to be rendered correctly
|
||||
* @param clr Fill Color
|
||||
*/
|
||||
void PathFill(u32 clr) {
|
||||
DrawConvexPolyFilled(pPath, clr);
|
||||
pPath.Clear();
|
||||
}
|
||||
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
|
||||
int segments);
|
||||
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
||||
/// @param a Top Left Position
|
||||
/// @param b Bottom Right Position
|
||||
/// @param rounding rounding
|
||||
/// @param flags DrawFlags (for special rounding rules)
|
||||
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
|
||||
|
||||
int Layer = 0;
|
||||
float pFontScale = 0.7f;
|
||||
Font::Ref pCurrentFont = nullptr;
|
||||
Texture::Ref CurrentTex = nullptr;
|
||||
Texture::Ref WhitePixel = nullptr;
|
||||
PD::Vec<Command::Ref> pDrawList;
|
||||
PD::Vec<fvec2> pPath;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -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>
|
||||
|
||||
/** Alias for Lithium Text Flags */
|
||||
using LITextFlags = PD::u32;
|
||||
|
||||
/** LITextFlags */
|
||||
enum LITextFlags_ {
|
||||
LITextFlags_None = 0, ///< Do nothing
|
||||
LITextFlags_AlignRight = 1 << 0, ///< Align Right of position
|
||||
LITextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
|
||||
LITextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
|
||||
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_RenderOOS = 1 << 6 ///< Render Out of Screen
|
||||
};
|
||||
|
||||
/** Aliad for Lithium Render Flags */
|
||||
using LIRenderFlags = PD::u32;
|
||||
/** LIRenderFlags */
|
||||
enum LIRenderFlags_ {
|
||||
LIRenderFlags_None = 0, ///< Nothing
|
||||
LIRenderFlags_TMS = 1 << 0, ///< Text Map System
|
||||
LIRenderFlags_LRS = 1 << 1, ///< Layer Render System
|
||||
LIRenderFlags_AST = 1 << 2, ///< Auto Static Text
|
||||
/** Default Enables all of them */
|
||||
LIRenderFlags_Default =
|
||||
LIRenderFlags_TMS | LIRenderFlags_LRS | LIRenderFlags_AST,
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/** RenderMode [Required to modify TexENV] */
|
||||
enum RenderMode {
|
||||
RenderMode_RGBA, ///< RGBA [for textures or solid colors]
|
||||
RenderMode_Font, ///< A8 [for textures only crated by 1 color channel]
|
||||
};
|
||||
/** Scissor Mode (for ClipRect related rendering) */
|
||||
enum ScissorMode {
|
||||
ScissorMode_None = 0, ///< No Scissor
|
||||
ScissorMode_Inverted = 1, ///< Render Pixels outside the box
|
||||
ScissorMode_Normal = 3, ///< Only render pixels inside the box
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -24,122 +24,38 @@ 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/vec.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/backend.hpp>
|
||||
#include <pd/lithium/pd_p_api.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using LITextFlags = PD::u32;
|
||||
enum LITextFlags_ {
|
||||
LITextFlags_None = 0, ///< Do nothing
|
||||
LITextFlags_AlignRight = 1 << 0, ///< Align Right of position
|
||||
LITextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
|
||||
LITextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
|
||||
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]
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/** Font Loader for Lithium */
|
||||
class Font : public SmartCtor<Font> {
|
||||
class PD_LITHIUM_API Font : public SmartCtor<Font> {
|
||||
public:
|
||||
/** Codepoint Data holder */
|
||||
class Codepoint {
|
||||
public:
|
||||
Codepoint() = default;
|
||||
~Codepoint() = default;
|
||||
|
||||
/**
|
||||
* Codepoint ID Getter
|
||||
* @return 32Bit codepoint value
|
||||
*/
|
||||
u32 cp() const { return m_cp; }
|
||||
/**
|
||||
* Codepoint ID Setter
|
||||
* @param v codepoint id
|
||||
* @return DataHolder reference
|
||||
*/
|
||||
Codepoint& cp(u32 v) {
|
||||
m_cp = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the UV Coords
|
||||
* @return uv coords
|
||||
*/
|
||||
vec4 uv() const { return m_uv; }
|
||||
/**
|
||||
* Setter for the UV Coords
|
||||
* @param v uv coords
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& uv(const vec4& v) {
|
||||
m_uv = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the Texture reference
|
||||
* @return Texture Reference
|
||||
*/
|
||||
Texture::Ref tex() const { return m_tex; }
|
||||
/**
|
||||
* Setter for the Texture Reference
|
||||
* @param v Texture Reference
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& tex(Texture::Ref v) {
|
||||
m_tex = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the size
|
||||
* @return Size
|
||||
*/
|
||||
vec2 size() const { return m_size; }
|
||||
/**
|
||||
* Setter for the Size
|
||||
* @param v size
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& size(const vec2& v) {
|
||||
m_size = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the Position offset
|
||||
* @return offset
|
||||
*/
|
||||
float off() const { return m_off; }
|
||||
/**
|
||||
* Setter for the Render Offset
|
||||
* @param v offset
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& off(float v) {
|
||||
m_off = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter to check if Codepoint is invalid
|
||||
* @return true if invalid
|
||||
*/
|
||||
bool invalid() const { return m_invalid; }
|
||||
/**
|
||||
* Setter for invald state
|
||||
* @param v true or false
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& invalid(bool v) {
|
||||
m_invalid = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
/** 32Bit Codepoint ID */
|
||||
u32 m_cp = 0;
|
||||
/** UvMap */
|
||||
vec4 m_uv;
|
||||
/** Texture Reference */
|
||||
Texture::Ref m_tex = nullptr;
|
||||
/** Codepoint Size */
|
||||
vec2 m_size;
|
||||
/** Render Position Offset */
|
||||
float m_off = 0;
|
||||
/** Invalid check (for skip in renderer) */
|
||||
bool m_invalid = false;
|
||||
struct Codepoint {
|
||||
u32 pCodepoint = 0;
|
||||
fvec4 SimpleUV;
|
||||
Texture::Ref Tex;
|
||||
fvec2 Size;
|
||||
float Offset = 0.f;
|
||||
bool pInvalid = false;
|
||||
};
|
||||
Font() = default;
|
||||
Font(Backend::Ref backend) { pBackend = backend; };
|
||||
~Font() = default;
|
||||
/**
|
||||
* Load a TTF File
|
||||
@ -147,35 +63,33 @@ class Font : public SmartCtor<Font> {
|
||||
* @param px_height Pixelheight of the codepoints (limit by 64)
|
||||
*/
|
||||
void LoadTTF(const std::string& path, int px_height = 32);
|
||||
/**
|
||||
* Load 3DS System Font
|
||||
*/
|
||||
void LoadSystemFont();
|
||||
/**
|
||||
* Getter for PixelHeight
|
||||
* @return pixelheigt
|
||||
*/
|
||||
int PixelHeight() const { return pixel_height; }
|
||||
/**
|
||||
* Getter for Codepoint reference
|
||||
* @return codepoint dataholder reference
|
||||
*/
|
||||
Codepoint& GetCodepoint(u32 c);
|
||||
|
||||
/**
|
||||
* Check if Systemfont is used
|
||||
* @return true if is system font
|
||||
* Get Text Bounding Box
|
||||
*/
|
||||
bool SystemFont() const { return sysfont; }
|
||||
fvec2 GetTextBounds(const std::string& text, float scale);
|
||||
/**
|
||||
* Extended Draw Text Function that vreates a Command List
|
||||
*/
|
||||
void CmdTextEx(Vec<Command::Ref>& cmds, const fvec2& pos, u32 color,
|
||||
float scale, const std::string& text, LITextFlags flags = 0,
|
||||
const fvec2& box = 0);
|
||||
|
||||
/** Pixelheight */
|
||||
int PixelHeight;
|
||||
int DefaultPixelHeight = 24;
|
||||
|
||||
private:
|
||||
/** sysfont set to true if LoadSystemFont got called */
|
||||
bool sysfont;
|
||||
/** Pixelheight */
|
||||
int pixel_height;
|
||||
/** List of textures (codepoints are using) */
|
||||
std::vector<Texture::Ref> textures;
|
||||
std::vector<Texture::Ref> Textures;
|
||||
/** 32Bit Codepoint Dataholder Reference Map */
|
||||
std::map<u32, Codepoint> cpmap;
|
||||
std::map<u32, Codepoint> CodeMap;
|
||||
Backend::Ref pBackend = nullptr;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,349 +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/vec.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/flags.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class Renderer;
|
||||
/**
|
||||
* Prerendered Object that can be edidet at runtime
|
||||
* and supports diffrent textures as well
|
||||
*/
|
||||
class StaticObject : public SmartCtor<StaticObject> {
|
||||
public:
|
||||
StaticObject() = default;
|
||||
~StaticObject() = default;
|
||||
|
||||
/**
|
||||
* Push a Draw Command to the Static Object
|
||||
* @param v Command to add
|
||||
*/
|
||||
void PushCommand(Command::Ref v) { cmds.push_back(v); }
|
||||
|
||||
/**
|
||||
* Copy the root Object to a copy buffer for modification
|
||||
*/
|
||||
void ReCopy() {
|
||||
cpy.clear();
|
||||
for (auto it : cmds) {
|
||||
cpy.push_back(Command::New(it));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the Color of a specific Command in the List
|
||||
* @param idx Index of the Command
|
||||
* @param col new COlor to replace with
|
||||
*/
|
||||
void ReColorQuad(int idx, u32 col) {
|
||||
if (idx > (int)cpy.size()) {
|
||||
return;
|
||||
}
|
||||
for (auto& it : cpy[idx]->VertexList()) {
|
||||
it.Color(col);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the every Command in the Object by a specific offset
|
||||
* @param off offset position to apply
|
||||
*/
|
||||
void MoveIt(vec2 off) {
|
||||
for (auto& it : cpy) {
|
||||
for (auto& jt : it->VertexList()) {
|
||||
jt.pos += off;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Color of all Commands in the List
|
||||
* @param col new Color to use
|
||||
*/
|
||||
void ReColor(u32 col) {
|
||||
for (auto& it : cpy) {
|
||||
for (auto& jt : it->VertexList()) {
|
||||
jt.Color(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a New Layer to all Objects
|
||||
* @param layer new layer to set to all its commands
|
||||
*/
|
||||
void ReLayer(int layer) {
|
||||
for (auto& it : cpy) {
|
||||
it->Layer(layer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the Commands Index by setting a start index
|
||||
* @param start Start index position
|
||||
*/
|
||||
void ReIndex(int start) {
|
||||
for (int i = 0; i < (int)cpy.size(); i++) {
|
||||
cpy[i]->Index(start + i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a Custom Scissor Mode for Object Copy List
|
||||
* @param m New Mode to Set
|
||||
*/
|
||||
void ReSetScissorMode(ScissorMode m) {
|
||||
for (auto& i : cpy) {
|
||||
i->SetScissorMode(m);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Custom Scissor Rect to All Objects
|
||||
* @param v Scissor Rect to set
|
||||
*/
|
||||
void ReScissorRect(const vec4& v) {
|
||||
for (auto& i : cpy) {
|
||||
i->ScissorRect(v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Reference to the Copy Commands List
|
||||
* @return command list reference
|
||||
*/
|
||||
std::vector<Command::Ref>& List() {
|
||||
if (cpy.size() != 0) {
|
||||
return cpy;
|
||||
}
|
||||
return cmds;
|
||||
}
|
||||
|
||||
private:
|
||||
/** Copy Buffer */
|
||||
std::vector<Command::Ref> cpy;
|
||||
/** Source Buffer */
|
||||
std::vector<Command::Ref> cmds;
|
||||
};
|
||||
/**
|
||||
* Text Box container for TMS and AST
|
||||
*/
|
||||
class TextBox {
|
||||
public:
|
||||
TextBox() = default;
|
||||
/**
|
||||
* Baisc Constructor
|
||||
* @param s Size of the text
|
||||
* @param time creation time
|
||||
*/
|
||||
TextBox(const vec2& s, float time) {
|
||||
size = s;
|
||||
time_created = time;
|
||||
optional = false;
|
||||
}
|
||||
~TextBox() = default;
|
||||
|
||||
/**
|
||||
* Setter for Time created
|
||||
* @param v time
|
||||
*/
|
||||
void TimeCreated(float v) { time_created = v; }
|
||||
/**
|
||||
* Setter for Size
|
||||
* @param v size
|
||||
*/
|
||||
void Size(const vec2& v) { size = v; }
|
||||
/**
|
||||
* Setter for is optional
|
||||
*
|
||||
* - optional text contains the result string of wrap/short
|
||||
* @param v optional
|
||||
*/
|
||||
void Optional(bool v) { optional = v; }
|
||||
/**
|
||||
* set Result of Short Text or Wrap Text
|
||||
* @param v text
|
||||
*/
|
||||
void Text(const std::string& v) { text = v; }
|
||||
|
||||
/**
|
||||
* Get Size
|
||||
* @return size
|
||||
*/
|
||||
vec2 Size() const { return size; }
|
||||
/**
|
||||
* Get Time Created / Updated
|
||||
* @param time created/updated
|
||||
*/
|
||||
float TimeCreated() const { return time_created; }
|
||||
/**
|
||||
* Check if Optional or not
|
||||
* @return is optional
|
||||
*/
|
||||
bool Optional() const { return optional; }
|
||||
/**
|
||||
* Get Optional Text
|
||||
* @return text
|
||||
*/
|
||||
std::string Text() const { return text; }
|
||||
|
||||
private:
|
||||
/** Text Size */
|
||||
vec2 size;
|
||||
/** Time Created / Updated */
|
||||
float time_created;
|
||||
/** Is Optional */
|
||||
bool optional;
|
||||
/** Text Wrap / Short */
|
||||
std::string text;
|
||||
};
|
||||
/**
|
||||
* Static Text [abillity to Prerender Texts into a list of Commands]
|
||||
*/
|
||||
class StaticText : public SmartCtor<StaticText> {
|
||||
public:
|
||||
StaticText() = default;
|
||||
/**
|
||||
* Wrap Constructor to Setup
|
||||
* @param ren Renderer direct pointer reference
|
||||
* @param pos Position
|
||||
* @param clr Color
|
||||
* @param text Text to Render
|
||||
* @param flags Text Flags
|
||||
* @param box Additional textbox for specific flags
|
||||
*/
|
||||
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() = default;
|
||||
/**
|
||||
* Function that Sets Up the Rendering
|
||||
* @param ren Renderer direct pointer reference
|
||||
* @param pos Position
|
||||
* @param clr Color
|
||||
* @param text Text to Render
|
||||
* @param flags Text Flags
|
||||
* @param box Additional textbox for specific flags
|
||||
*/
|
||||
void Setup(Renderer* ren, const vec2& pos, u32 clr, const std::string& text,
|
||||
LITextFlags flags = 0, const vec2& box = 0);
|
||||
|
||||
/**
|
||||
* Get Text Size
|
||||
* @return size
|
||||
*/
|
||||
vec2 GetDim() const { return tdim; }
|
||||
/**
|
||||
* Get Text Posiotion
|
||||
* @return position
|
||||
*/
|
||||
vec2 GetPos() const { return pos; }
|
||||
/**
|
||||
* Setter to Update Color
|
||||
* @param col color
|
||||
*/
|
||||
void SetColor(u32 col);
|
||||
/**
|
||||
* Setter to raplace the texts Commands Position
|
||||
* @param pos new position
|
||||
*/
|
||||
void SetPos(const vec2& pos);
|
||||
/**
|
||||
* Set Layer of the Text
|
||||
* @param l layer
|
||||
*/
|
||||
void SetLayer(int l);
|
||||
|
||||
/**
|
||||
* Function to unset the used variable
|
||||
*/
|
||||
void SetUnused() { used = false; }
|
||||
/**
|
||||
* Function to check if the text got rendered
|
||||
* @return is used
|
||||
*/
|
||||
bool Used() const { return used; }
|
||||
/**
|
||||
* Function to check if the text got setup
|
||||
* @return is setup
|
||||
*/
|
||||
bool IsSetup() { return text != nullptr; }
|
||||
|
||||
/**
|
||||
* Draw the Text
|
||||
*/
|
||||
void Draw();
|
||||
|
||||
/** Get the Raw Object for Custom API's */
|
||||
StaticObject::Ref GetRawObject() { return text; }
|
||||
|
||||
/**
|
||||
* Set Font used by the static Text
|
||||
* @param fnt Font used
|
||||
*/
|
||||
void Font(Font::Ref fnt) { font = fnt; }
|
||||
/**
|
||||
* Get Font used by the Text
|
||||
* @return Font Reference
|
||||
*/
|
||||
Font::Ref Font() { return font; }
|
||||
|
||||
/**
|
||||
* Set a Custom Scissor Mode Static Text
|
||||
* @param m New Mode to Set
|
||||
*/
|
||||
void SetScissorMode(ScissorMode m) { text->ReSetScissorMode(m); }
|
||||
|
||||
/**
|
||||
* Set Custom Scissor Rect to Static Text
|
||||
* @param v Scissor Rect to set
|
||||
*/
|
||||
void ScissorRect(const vec4& v) { text->ReScissorRect(v); }
|
||||
|
||||
private:
|
||||
/** Font */
|
||||
Font::Ref font;
|
||||
/** Text got Rendered */
|
||||
bool used;
|
||||
/** Renderer pointer Reference */
|
||||
Renderer* ren;
|
||||
/** Text Size */
|
||||
vec2 tdim;
|
||||
/** Text Position */
|
||||
vec2 pos;
|
||||
/** Static Text Object */
|
||||
StaticObject::Ref text;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
52
include/pd/lithium/pd_p_api.hpp
Normal file
52
include/pd/lithium/pd_p_api.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
#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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#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
|
@ -23,8 +23,7 @@ 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/vec.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
@ -40,7 +39,7 @@ class Rect {
|
||||
* @param t Top left and right corner positions.
|
||||
* @param b Bottom left and right corner positions.
|
||||
*/
|
||||
Rect(const vec4& t, const vec4& b) {
|
||||
Rect(const fvec4& t, const fvec4& b) {
|
||||
top = t;
|
||||
bot = b;
|
||||
}
|
||||
@ -53,9 +52,9 @@ class Rect {
|
||||
* @param bl Bottom left corner position.
|
||||
* @param br Bottom right corner position.
|
||||
*/
|
||||
Rect(const vec2& tl, const vec2& tr, const vec2& bl, const vec2& br) {
|
||||
top = vec4(tl, tr);
|
||||
bot = vec4(bl, br);
|
||||
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) {
|
||||
top = fvec4(tl, tr);
|
||||
bot = fvec4(bl, br);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,9 +65,9 @@ class Rect {
|
||||
*
|
||||
* @param uv Vec4 UV map.
|
||||
*/
|
||||
Rect(const vec4& uv) {
|
||||
top = vec4(uv.x(), uv.y(), uv.z(), uv.y());
|
||||
bot = vec4(uv.x(), uv.w(), uv.z(), uv.w());
|
||||
Rect(const fvec4& uv) {
|
||||
top = vec4(uv.x, uv.y, uv.z, uv.y);
|
||||
bot = vec4(uv.x, uv.w, uv.z, uv.w);
|
||||
}
|
||||
|
||||
~Rect() = default;
|
||||
@ -77,20 +76,20 @@ class Rect {
|
||||
* Get the top left and right corner positions.
|
||||
* @return Top positions.
|
||||
*/
|
||||
vec4 Top() const { return top; }
|
||||
fvec4 Top() const { return top; }
|
||||
|
||||
/**
|
||||
* Get the bottom left and right corner positions.
|
||||
* @return Bottom positions.
|
||||
*/
|
||||
vec4 Bot() const { return bot; }
|
||||
fvec4 Bot() const { return bot; }
|
||||
|
||||
/**
|
||||
* Set the top left and right corner positions.
|
||||
* @param v New top positions.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& Top(const vec4& v) {
|
||||
Rect& Top(const fvec4& v) {
|
||||
top = v;
|
||||
return *this;
|
||||
}
|
||||
@ -100,7 +99,7 @@ class Rect {
|
||||
* @param v New bottom positions.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& Bot(const vec4& v) {
|
||||
Rect& Bot(const fvec4& v) {
|
||||
bot = v;
|
||||
return *this;
|
||||
}
|
||||
@ -109,34 +108,34 @@ class Rect {
|
||||
* Get the top-left corner position.
|
||||
* @return Top-left position as vec2.
|
||||
*/
|
||||
vec2 TopLeft() const { return vec2(top[0], top[1]); }
|
||||
fvec2 TopLeft() const { return vec2(top.x, top.y); }
|
||||
|
||||
/**
|
||||
* Get the top-right corner position.
|
||||
* @return Top-right position as vec2.
|
||||
*/
|
||||
vec2 TopRight() const { return vec2(top[2], top[3]); }
|
||||
fvec2 TopRight() const { return vec2(top.z, top.w); }
|
||||
|
||||
/**
|
||||
* Get the bottom-left corner position.
|
||||
* @return Bottom-left position as vec2.
|
||||
*/
|
||||
vec2 BotLeft() const { return vec2(bot[0], bot[1]); }
|
||||
fvec2 BotLeft() const { return vec2(bot.x, bot.y); }
|
||||
|
||||
/**
|
||||
* Get the bottom-right corner position.
|
||||
* @return Bottom-right position as vec2.
|
||||
*/
|
||||
vec2 BotRight() const { return vec2(bot[2], bot[3]); }
|
||||
fvec2 BotRight() const { return vec2(bot.z, bot.w); }
|
||||
|
||||
/**
|
||||
* Set the top-left corner position.
|
||||
* @param v New top-left position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& TopLeft(const vec2& v) {
|
||||
top[0] = v[0];
|
||||
top[1] = v[1];
|
||||
Rect& TopLeft(const fvec2& v) {
|
||||
top.x = v.x;
|
||||
top.y = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -145,9 +144,9 @@ class Rect {
|
||||
* @param v New top-right position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& TopRight(const vec2& v) {
|
||||
top[2] = v[0];
|
||||
top[3] = v[1];
|
||||
Rect& TopRight(const fvec2& v) {
|
||||
top.z = v.x;
|
||||
top.w = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -156,9 +155,9 @@ class Rect {
|
||||
* @param v New bottom-left position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& BotLeft(const vec2& v) {
|
||||
bot[0] = v[0];
|
||||
bot[1] = v[1];
|
||||
Rect& BotLeft(const fvec2& v) {
|
||||
bot.x = v.x;
|
||||
bot.y = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -167,9 +166,9 @@ class Rect {
|
||||
* @param v New bottom-right position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& BotRight(const vec2& v) {
|
||||
bot[2] = v[0];
|
||||
bot[3] = v[1];
|
||||
Rect& BotRight(const fvec2& v) {
|
||||
bot.z = v.x;
|
||||
bot.w = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -179,19 +178,15 @@ class Rect {
|
||||
* - Used in SpiteSheet for the rotated images.
|
||||
*/
|
||||
void SwapVec2XY() {
|
||||
for (int i = 0; i < 4; i += 2) {
|
||||
float t = top[i];
|
||||
top[i] = top[i + 1];
|
||||
top[i + 1] = t;
|
||||
t = bot[i];
|
||||
bot[i] = bot[i + 1];
|
||||
bot[i + 1] = t;
|
||||
}
|
||||
top.SwapXY();
|
||||
top.SwapZW();
|
||||
bot.SwapXY();
|
||||
bot.SwapZW();
|
||||
}
|
||||
|
||||
private:
|
||||
vec4 top; ///< Top left and right corner positions.
|
||||
vec4 bot; ///< Bottom left and right corner positions.
|
||||
fvec4 top; ///< Top left and right corner positions.
|
||||
fvec4 bot; ///< Bottom left and right corner positions.
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -24,359 +24,56 @@ 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/vec.hpp>
|
||||
#include <pd/lib3ds/memory.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/flags.hpp>
|
||||
#include <pd/lithium/backend.hpp>
|
||||
#include <pd/lithium/drawlist.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/lithium/objects.hpp>
|
||||
#include <pd/lithium/screen.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
#include <pd/lithium/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/**
|
||||
* Lithium base renderer Class.
|
||||
*/
|
||||
class Renderer : public SmartCtor<Renderer> {
|
||||
class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> {
|
||||
public:
|
||||
/**
|
||||
* Constructor setting up the 2d Rendering Engine
|
||||
* @param flags Flags to use [can be changed at runtime].
|
||||
*/
|
||||
Renderer(LIRenderFlags flags = LIRenderFlags_Default);
|
||||
/**
|
||||
* Deconstructor that unloads all the renderer data
|
||||
*/
|
||||
~Renderer();
|
||||
Renderer(Backend::Ref backend);
|
||||
~Renderer() = default;
|
||||
|
||||
/**
|
||||
* Prepare render stage for rendering.
|
||||
*/
|
||||
void PrepareRender();
|
||||
/**
|
||||
* Render a screens Command list.
|
||||
* @param s Screen to Draw its list on.
|
||||
*/
|
||||
void Render(Screen::Ref s);
|
||||
/**
|
||||
* Finalize rendering stage.
|
||||
*/
|
||||
void FinalizeRender();
|
||||
void Render();
|
||||
|
||||
/**
|
||||
* Register Screens (For UI7, probably move this).
|
||||
* @param bottom set if you register bottom ot top screen.
|
||||
* @param s Screen to register.
|
||||
*/
|
||||
void RegisterScreen(bool bottom, Screen::Ref s) { screens[bottom] = s; }
|
||||
/**
|
||||
* Set the Screen next commands will be add to
|
||||
* @param s Screen of choice
|
||||
*/
|
||||
void OnScreen(Screen::Ref s) {
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
this->screen = s;
|
||||
area_size = screen->GetSize();
|
||||
}
|
||||
// SECTION: ADVANCED API
|
||||
|
||||
/**
|
||||
* Get cobst reference to active screen.
|
||||
* @return current screen.
|
||||
*/
|
||||
Screen::Ref CurrentScreen() const { return screen; }
|
||||
/**
|
||||
* Get Screen of screen regestry.
|
||||
* @param bottom bottom ot top screen.
|
||||
* @return screen reference
|
||||
*/
|
||||
Screen::Ref GetScreen(bool bottom) {
|
||||
auto res = screens[bottom];
|
||||
Assert(res.get(), "Screen is not registered!");
|
||||
return res;
|
||||
}
|
||||
void AddCommand(Command::Ref v) { DrawList.Add(v); }
|
||||
void RegisterDrawList(DrawList::Ref list) { pDrawLists.Add(list); }
|
||||
Command::Ref PreGenerateCmd();
|
||||
|
||||
void Rotation(float v) { rot = v; }
|
||||
float Rotation() const { return rot; }
|
||||
void TextScale(float v) { text_size = v; }
|
||||
void DefaultTextScale() { text_size = default_text_size; }
|
||||
float TextScale() const { return text_size; }
|
||||
void Layer(int v) { current_layer = v; }
|
||||
int Layer() const { return current_layer; }
|
||||
LIRenderFlags& GetFlags() { return flags; }
|
||||
void Font(Font::Ref v) {
|
||||
font = v;
|
||||
font_update = true;
|
||||
}
|
||||
Font::Ref Font() const { return font; }
|
||||
// SECTION: Open Command and Object creation API
|
||||
static void RotateCorner(fvec2& pos, float sinus, float cosinus);
|
||||
static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
|
||||
static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1);
|
||||
static void CmdQuad(Command::Ref cmd, const Rect& quad, const Rect& uv,
|
||||
u32 color);
|
||||
static void CmdTriangle(Command::Ref 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::Ref cmd, const Vec<fvec2>& points,
|
||||
u32 clr, Texture::Ref tex);
|
||||
|
||||
/**
|
||||
* Use a specific Texture for Next Rectangle.
|
||||
* @param v texture reference to use.
|
||||
*/
|
||||
void UseTex(Texture::Ref v = nullptr) {
|
||||
if (v == nullptr) {
|
||||
current_tex = white;
|
||||
return;
|
||||
}
|
||||
current_tex = v;
|
||||
}
|
||||
// SECTION: InBounds Checks
|
||||
|
||||
/**
|
||||
* Draws a Rect based on current Texture
|
||||
* @param pos Position of the Rect
|
||||
* @param size Size of the Rect
|
||||
* @param color Color of the Rect [0xffffffff]
|
||||
* for full visible texture
|
||||
* @param uv UV Map (if texture needs a custom uv)
|
||||
* @note This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawRect(const vec2& pos, const vec2& size, u32 color,
|
||||
const Rect& uv = vec4(0.f, 1.f, 1.f, 0.f));
|
||||
/**
|
||||
* Draw a Solid Rect (uses white tex)
|
||||
* @note
|
||||
* - acts as a simplified Draw rect Wrapper
|
||||
* - This function is part of Simple Draw API.
|
||||
* @param pos Position of the rect
|
||||
* @param size Size of the rect
|
||||
* @param color Color of the rect
|
||||
*/
|
||||
void DrawRectSolid(const vec2& pos, const vec2& size, u32 color);
|
||||
/**
|
||||
* Render a Triangle
|
||||
* @param a Position A
|
||||
* @param b Position B
|
||||
* @param c Position C
|
||||
* @param color Color of the triangle
|
||||
* @note
|
||||
* - Uses Solid color [white tex]
|
||||
* - This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawTriangle(const vec2& a, const vec2& b, const vec2& c, u32 color);
|
||||
/**
|
||||
* Draw a Circle (Supports Textures)
|
||||
* @param center_pos Center Position
|
||||
* @param r Radius of the circle
|
||||
* @param color Color of the circle
|
||||
* @param segments Segments to use
|
||||
* @note
|
||||
* - Textures could look a bit janky due to uv mapping
|
||||
* - This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawCircle(const vec2& center_pos, float r, u32 color, int segments);
|
||||
/**
|
||||
* Draw a Line between to Positions
|
||||
* @param a Position A
|
||||
* @param b Position B
|
||||
* @param color Color of the line
|
||||
* @param t Thickness
|
||||
* @note This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawLine(const vec2& a, const vec2& b, u32 color, int t);
|
||||
/**
|
||||
* Render a Text
|
||||
* @param pos Position of the text
|
||||
* @param color Color of the Text
|
||||
* @param text Text to Render
|
||||
* @param flags flags to use
|
||||
* @param ap optional size for specific flags
|
||||
* @note This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawText(const vec2& pos, u32 color, const std::string& text,
|
||||
u32 flags = 0, const vec2& ap = vec2());
|
||||
/**
|
||||
* Draw a Texture as 2D Image
|
||||
* @param pos Position
|
||||
* @param tex Texture reference
|
||||
* @param scale Scale (cause maybe wants to be resized)
|
||||
* @note
|
||||
* - Acts as a Simplified wrapper to DrawRect
|
||||
* - This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawImage(const vec2& pos, Texture::Ref tex,
|
||||
const vec2& scale = vec2(1.f));
|
||||
static bool InBox(const fvec2& pos, const fvec2& size, const fvec4& area);
|
||||
static bool InBox(const fvec2& pos, const fvec4& area);
|
||||
static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
const fvec4& area);
|
||||
|
||||
// Debug STUFF
|
||||
// SECTION: Data //
|
||||
|
||||
/** DEBUG Get the Number of Vertices of last Frame */
|
||||
u32 Vertices() const { return vertices; }
|
||||
/** DEBUG Get the Number of Indices of last frame */
|
||||
u32 Indices() const { return indices; }
|
||||
/** DEBUG Get the Number of Commands of last frame */
|
||||
u32 Commands() const { return commands; }
|
||||
/** DEBUG Get the Number of Drawcalls of last frame */
|
||||
u32 DrawCalls() const { return drawcalls; }
|
||||
/** Auto Static Text Number of Texts */
|
||||
u32 AstUsage() const { return ast.size(); }
|
||||
/** Text Map System number of texts */
|
||||
u32 TmsUsage() const { return tms.size(); }
|
||||
|
||||
// TOOLS
|
||||
|
||||
/** Rotate a rect corner position by sine and cosine value */
|
||||
static void RotateCorner(vec2& v, float s, float c);
|
||||
/** Create a Rect by Position, Size and rotation angle */
|
||||
static Rect CreateRect(const vec2& pos, const vec2& size, float angle);
|
||||
/** Create a Line Rect by 2 Position and a thickness value */
|
||||
static Rect CreateLine(const vec2& a, const vec2& b, int t);
|
||||
/** Check if a pos and size are inside a vec4 rect */
|
||||
static bool InBox(const vec2& pos, const vec2& size, const vec4& rect);
|
||||
/** Check if a pos is inside a vec4 rect */
|
||||
static bool InBox(const vec2& pos, const vec4& rect);
|
||||
/** Check if one or all of three positions are somehow inside a vec4 rect */
|
||||
static bool InBox(const vec2& alpha, const vec2& bravo, const vec2& charlie,
|
||||
const vec4& rect);
|
||||
/**
|
||||
* Get The Address of a Screen
|
||||
* @note **IMPORTANT** THIS IS FOR 32Bit System
|
||||
*
|
||||
* Should find a better way to do this for porting this lib
|
||||
*/
|
||||
static u32 Screen32(Screen::Ref s) { return (u32)s.get(); }
|
||||
/** Function to optimize command order for rendering */
|
||||
static void OptiCommandList(std::vector<Command::Ref>& list);
|
||||
/** Returns Viewport with xy */
|
||||
vec4 GetViewport();
|
||||
/** Push a Self Created command */
|
||||
void PushCommand(Command::Ref cmd) {
|
||||
cmd->Index(cmd_idx++); // Indexing
|
||||
draw_list[Screen32(screen)].push_back(cmd);
|
||||
}
|
||||
/** Automatically sets up a command */
|
||||
void SetupCommand(Command::Ref cmd);
|
||||
/** Creates a default Quad Render Command */
|
||||
void QuadCommand(Command::Ref cmd, const Rect& quad, const Rect& uv, u32 col);
|
||||
/** Create a Default Triangle */
|
||||
void TriangleCommand(Command::Ref cmd, const vec2& a, const vec2& b,
|
||||
const vec2& c, u32 col);
|
||||
/**
|
||||
* Create List of a Text Commands
|
||||
* @param cmds Link to a command List
|
||||
* @param pos Position
|
||||
* @param color Color
|
||||
* @param text Text
|
||||
* @param flags Flags
|
||||
* @param box (Size for wrapping / Offset for Centered Text)
|
||||
*/
|
||||
void TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos, u32 color,
|
||||
const std::string& text, LITextFlags flags, const vec2& box);
|
||||
vec2 GetTextDimensions(const std::string& text);
|
||||
/**
|
||||
* Function to short a text and replace the rest by ...
|
||||
* @param text Text to short
|
||||
* @param maxlen Maximum width
|
||||
* @param newsize New Textbox size
|
||||
* @return shorted text
|
||||
*/
|
||||
std::string ShortText(const std::string& text, int maxlen, vec2& newsize);
|
||||
/**
|
||||
* Function to Wrap Text by specific width
|
||||
*
|
||||
* **NOT IMPLEMENTED YET**
|
||||
* @param text text to wrap
|
||||
* @param maxlen maximum width per line
|
||||
* @param newsize new textbox size
|
||||
* @return wrapped text
|
||||
*/
|
||||
std::string WrapText(const std::string& text, int maxlen, vec2& newsize);
|
||||
Texture::Ref WhitePixel = nullptr;
|
||||
Backend::Ref pBackend = nullptr;
|
||||
Texture::Ref CurrentTex = nullptr;
|
||||
int Layer = 0;
|
||||
|
||||
private:
|
||||
// Helper Funcitons
|
||||
|
||||
/**
|
||||
* Update the 3DS citro3d texenv for specific RenderMode
|
||||
* @param mode RenderMode to use.
|
||||
*/
|
||||
void UpdateRenderMode(const RenderMode& mode);
|
||||
|
||||
/** Current Screen */
|
||||
Screen::Ref screen;
|
||||
/** Screen Regestry */
|
||||
Screen::Ref screens[2];
|
||||
|
||||
// Context Related
|
||||
|
||||
/** Renderer flags */
|
||||
LIRenderFlags flags = LIRenderFlags_Default;
|
||||
/** Area Size */
|
||||
vec2 area_size;
|
||||
/** Current Layer */
|
||||
int current_layer = 0;
|
||||
/** Current Texture */
|
||||
Texture::Ref current_tex = nullptr;
|
||||
/** Single Color Texture (for solid color objs) */
|
||||
Texture::Ref white = nullptr;
|
||||
/** Current Font Reference */
|
||||
Font::Ref font = nullptr;
|
||||
/** Font updated */
|
||||
bool font_update;
|
||||
/** Current Rendermode */
|
||||
RenderMode mode = RenderMode_RGBA;
|
||||
/** Text Map System */
|
||||
std::map<std::string, TextBox> tms;
|
||||
/** (Auto) Static Text */
|
||||
std::unordered_map<u32, StaticText::Ref> ast;
|
||||
|
||||
// Text Rendering
|
||||
|
||||
/** Default FOnt height */
|
||||
const float default_font_h = 24.f;
|
||||
/** Default Text Scale */
|
||||
const float default_text_size = 0.7f;
|
||||
/** Current Text Scale */
|
||||
float text_size = 0.7f;
|
||||
// Special
|
||||
|
||||
/** Current Rotation (RECTS) */
|
||||
float rot = 0.f;
|
||||
// Rendering
|
||||
|
||||
/** Map of drawlist by 32Bit memory Address of their Screen */
|
||||
std::unordered_map<u32, std::vector<Command::Ref>> draw_list;
|
||||
/** Vertex Buffer in linear Ram */
|
||||
std::vector<Vertex, LinearAllocator<Vertex>> vertex_buf;
|
||||
/** 16Bit index buffer in linear Ram */
|
||||
std::vector<u16, LinearAllocator<u16>> index_buf;
|
||||
/** vertex index (render stage) */
|
||||
u32 vertex_idx = 0;
|
||||
/** index buf index (render stage) */
|
||||
u32 index_idx = 0;
|
||||
/** command index (used for debug count) */
|
||||
u32 cmd_idx = 0;
|
||||
|
||||
// Debug
|
||||
|
||||
/** Num of Vertices */
|
||||
u32 vertices = 0;
|
||||
/** Num of indices */
|
||||
u32 indices = 0;
|
||||
/** Num of Commands */
|
||||
u32 commands = 0;
|
||||
/** Num of Drawcalls */
|
||||
u32 drawcalls = 0;
|
||||
|
||||
// Shader
|
||||
|
||||
/** Shader code */
|
||||
DVLB_s* dvlb = nullptr;
|
||||
/** Shader program */
|
||||
shaderProgram_s shader;
|
||||
/** Shader Attribute info */
|
||||
C3D_AttrInfo attr;
|
||||
/** projection matrix location */
|
||||
int uLoc_projection = 0;
|
||||
|
||||
// Matrix
|
||||
|
||||
/** Precalculated Projectrion Matrix for top screen */
|
||||
C3D_Mtx top_proj;
|
||||
/** Precalculated Projectrion Matrix for bottom screen */
|
||||
C3D_Mtx bot_proj;
|
||||
PD::Vec<Command::Ref> DrawList;
|
||||
PD::Vec<DrawList::Ref> pDrawLists;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,98 +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 <3ds.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* 3DS Screen (RenderTarget)
|
||||
*/
|
||||
class Screen : public SmartCtor<Screen> {
|
||||
public:
|
||||
/** Screens */
|
||||
enum Screen_ {
|
||||
Top, ///< Top Screen
|
||||
Bottom, ///< Bottom Screen
|
||||
TopRight ///< Top Right Screen area
|
||||
};
|
||||
/**
|
||||
* Constructor to create Screen by Screen Type
|
||||
* @param screen Screen to grab default init values for
|
||||
*/
|
||||
Screen(Screen_ screen) : type(screen) {
|
||||
if (screen == Top) {
|
||||
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
} else if (screen == Bottom) {
|
||||
target = C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_BOTTOM, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
} else if (screen == TopRight) {
|
||||
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_RIGHT,
|
||||
DisplayTransferFlags);
|
||||
}
|
||||
}
|
||||
~Screen() = default;
|
||||
|
||||
/** Clear the Screen */
|
||||
void Clear() { C3D_RenderTargetClear(target, C3D_CLEAR_ALL, 0x00000000, 0); }
|
||||
/** Set the Screen active for Rendering */
|
||||
void Use() { C3D_FrameDrawOn(target); }
|
||||
|
||||
/** Get the Screens Size */
|
||||
vec2 GetSize() const {
|
||||
return vec2(target->frameBuf.height, target->frameBuf.width);
|
||||
}
|
||||
|
||||
/** Get the Screen Type */
|
||||
Screen_ ScreenType() const { return type; }
|
||||
|
||||
/** Get the Raw Rendertarget object */
|
||||
C3D_RenderTarget* Get() const { return target; }
|
||||
/** Operartor to get the raw RenderTarget */
|
||||
operator C3D_RenderTarget*() const { return target; }
|
||||
|
||||
private:
|
||||
/** Screen Type */
|
||||
Screen_ type;
|
||||
/** Default Init Flags */
|
||||
const u32 DisplayTransferFlags =
|
||||
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
|
||||
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
|
||||
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
|
||||
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
|
||||
/** RenderTarget */
|
||||
C3D_RenderTarget* target;
|
||||
};
|
||||
} // namespace PD
|
@ -24,15 +24,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
using TexAddress = uintptr_t;
|
||||
/**
|
||||
* Lithium Texture Loader / DataHolder
|
||||
* Lithium Texture Data Holder
|
||||
* Memory management is handled by backend
|
||||
*/
|
||||
class Texture : public SmartCtor<Texture> {
|
||||
public:
|
||||
@ -48,106 +48,29 @@ class Texture : public SmartCtor<Texture> {
|
||||
LINEAR, ///< Linear
|
||||
};
|
||||
/** Default constructor */
|
||||
Texture() : uv(0.f, 1.f, 1.f, 0.f) {}
|
||||
/**
|
||||
* Load file Constructor
|
||||
* @param path path to file
|
||||
* @param t3x set true if file is a t3x file
|
||||
*/
|
||||
Texture(const std::string& path, bool t3x = false) : uv(0.f, 1.f, 1.f, 0.f) {
|
||||
if (t3x) {
|
||||
this->LoadT3X(path);
|
||||
} else {
|
||||
this->LoadFile(path);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Load Memory constructor
|
||||
* @param data File Data reference
|
||||
*/
|
||||
Texture(const std::vector<u8>& data) : uv(0.f, 1.f, 1.f, 0.f) {
|
||||
this->LoadMemory(data);
|
||||
}
|
||||
/**
|
||||
* Load Pixels constructor
|
||||
* @param data Pixel Buffer reference
|
||||
* @param w width
|
||||
* @param h height
|
||||
* @param type Buffer Type [Default RGBA32]
|
||||
* @param filter Filter [DEFAULT NEAREST]
|
||||
*/
|
||||
Texture(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST)
|
||||
: uv(0.f, 1.f, 1.f, 0.f) {
|
||||
this->LoadPixels(data, w, h, type, filter);
|
||||
}
|
||||
/** Deconstructor (aka auto delete) */
|
||||
~Texture() {
|
||||
if (autounload) {
|
||||
Delete();
|
||||
}
|
||||
Texture() : UV(0.f, 0.f, 1.f, 1.f) {}
|
||||
Texture(TexAddress addr, ivec2 size,
|
||||
LI::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
|
||||
Address = addr;
|
||||
Size = size;
|
||||
UV = uv;
|
||||
}
|
||||
|
||||
/// @brief Deletes image (if not already unloaded)
|
||||
void Delete();
|
||||
|
||||
/// @brief Load a png/jpg/bmp from fs into a gpu tex
|
||||
/// @param path path to image file
|
||||
void LoadFile(const std::string& path);
|
||||
/// @brief Load a png/jpg/bmp from memory
|
||||
/// @param data reference to data buffer of the file
|
||||
void LoadMemory(const std::vector<u8>& data);
|
||||
/// @brief Create Texture out of Pixel Data
|
||||
/// @param data Data reference
|
||||
/// @param w width
|
||||
/// @param h heigt
|
||||
/// @param type Type of the databuffer
|
||||
/// @param filter Filter (NEAREST OR LINEAR)
|
||||
void LoadPixels(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST);
|
||||
|
||||
/// @brief Load a texture of a T3X File
|
||||
/// @note This is used for single texture T3X
|
||||
/// Not for SpriteSheets
|
||||
/// @param path path to .t3x file
|
||||
void LoadT3X(const std::string& path);
|
||||
|
||||
/// @brief Input a Texture that you had set up on your own
|
||||
/// @param tex Texture reference (deletes itself)
|
||||
/// @param rszs The size of the source image
|
||||
/// @param uvs Your uv Setup
|
||||
void LoadExternal(C3D_Tex* tex, vec2 rszs, LI::Rect uvs) {
|
||||
this->Delete();
|
||||
this->tex = tex;
|
||||
this->size = rszs;
|
||||
this->uv = uvs;
|
||||
void CopyOther(Texture::Ref tex) {
|
||||
Address = tex->Address;
|
||||
Size = tex->Size;
|
||||
UV = tex->UV;
|
||||
}
|
||||
|
||||
vec2 GetRealSize() {
|
||||
if (!tex) {
|
||||
return vec2();
|
||||
}
|
||||
return vec2(tex->width, tex->height);
|
||||
}
|
||||
vec2 GetSize() const { return size; }
|
||||
C3D_Tex* GetTex() const { return tex; }
|
||||
LI::Rect GetUV() const { return uv; }
|
||||
bool IsValid() const { return tex != 0; }
|
||||
ivec2 GetSize() const { return Size; }
|
||||
LI::Rect GetUV() const { return UV; }
|
||||
|
||||
bool AutoUnLoad() const { return autounload; }
|
||||
void AutoUnLoad(bool v) { autounload = v; }
|
||||
operator ivec2() const { return Size; }
|
||||
operator LI::Rect() const { return UV; }
|
||||
|
||||
operator C3D_Tex*() const { return tex; }
|
||||
operator vec2() const { return size; }
|
||||
operator LI::Rect() const { return uv; }
|
||||
operator bool() const { return tex != 0; }
|
||||
|
||||
private:
|
||||
void MakeTex(std::vector<u8>& buf, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST);
|
||||
vec2 size;
|
||||
LI::Rect uv;
|
||||
C3D_Tex* tex = nullptr;
|
||||
bool autounload = true;
|
||||
TexAddress Address;
|
||||
ivec2 Size;
|
||||
LI::Rect UV;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -24,39 +24,25 @@ 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/vec.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
|
||||
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(const fvec2& p, const fvec2& u, u32 c) {
|
||||
Pos.x = p.x;
|
||||
Pos.y = p.y;
|
||||
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;
|
||||
fvec2 Pos;
|
||||
fvec2 UV;
|
||||
u32 Color;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -23,44 +23,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <citro3d.h>
|
||||
#include <tex3ds.h>
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/net/socket.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Tex 3DS Spritesheet integration to Lithium
|
||||
*/
|
||||
class SpriteSheet : public SmartCtor<SpriteSheet> {
|
||||
namespace Net {
|
||||
class Backend {
|
||||
public:
|
||||
SpriteSheet() = default;
|
||||
/**
|
||||
* Constructor to directly load a spritesheet
|
||||
* @param path Path to spritesheet
|
||||
*/
|
||||
SpriteSheet(const std::string& path) { this->LoadFile(path); }
|
||||
/**
|
||||
* Deconstructor to unload the Spritesheet
|
||||
*/
|
||||
~SpriteSheet();
|
||||
Backend(const std::string& name = "NullBackend") : pName(name) {}
|
||||
~Backend() = default;
|
||||
PD_SMART_CTOR(Backend)
|
||||
virtual bool Init() = 0;
|
||||
virtual void Deinit() = 0;
|
||||
virtual int NewSocket() = 0;
|
||||
virtual void Close(int sock_id) = 0;
|
||||
virtual int GetInvalidRef() const = 0;
|
||||
virtual bool Bind(int sock_id, u16 port) = 0;
|
||||
virtual bool Listen(int sock_id, int backlog = 5) = 0;
|
||||
virtual bool WaitForRead(int sock_id, int timeout_ms) = 0;
|
||||
virtual bool Accept(int sock_id, Socket::Ref client) = 0;
|
||||
virtual bool Connect(int sock_id, const std::string& ip, u16 port) = 0;
|
||||
virtual int Send(int sock_id, const std::string& data) = 0;
|
||||
virtual int Receive(int sock_id, std::string& data, int size = 1024) = 0;
|
||||
|
||||
/**
|
||||
* Function to load a Spritesheet
|
||||
* @param path Path to the file
|
||||
*/
|
||||
void LoadFile(const std::string& path);
|
||||
/** Get a Textures Reference */
|
||||
Texture::Ref Get(int idx);
|
||||
/** Get Number of Textures in spritesheet */
|
||||
int NumTextures() const;
|
||||
|
||||
/** Operator to get Texture reference */
|
||||
Texture::Ref operator[](int idx) { return Get(idx); }
|
||||
|
||||
private:
|
||||
/** Storage of the Spritesheets textures */
|
||||
std::vector<Texture::Ref> textures;
|
||||
/** Backend identification name */
|
||||
const std::string pName;
|
||||
};
|
||||
} // namespace Net
|
||||
} // namespace PD
|
52
include/pd/net/pd_p_api.hpp
Normal file
52
include/pd/net/pd_p_api.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
#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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||
#ifdef PD_NET_BUILD_SHARED
|
||||
#define PD_NET_API __declspec(dllexport)
|
||||
#else
|
||||
#define PD_NET_API __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined(__APPLE__) // macOS (untested yet)
|
||||
#ifdef PD_NET_BUILD_SHARED
|
||||
#define PD_NET_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_NET_API
|
||||
#endif
|
||||
#elif defined(__linux__) // Linux (untested yet)
|
||||
#ifdef PD_NET_BUILD_SHARED
|
||||
#define PD_NET_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_NET_API
|
||||
#endif
|
||||
#elif defined(__3DS__) // 3ds Specific
|
||||
// Only Static supported
|
||||
#define PD_NET_API
|
||||
#else
|
||||
#define PD_NET_API
|
||||
#endif
|
61
include/pd/net/socket.hpp
Normal file
61
include/pd/net/socket.hpp
Normal file
@ -0,0 +1,61 @@
|
||||
#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/core.hpp>
|
||||
#include <pd/net/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Net {
|
||||
class Backend;
|
||||
/**
|
||||
* Wrapper class around the functionality of Net::Backend
|
||||
*/
|
||||
class PD_NET_API Socket {
|
||||
public:
|
||||
Socket(PD::SmartCtor<Backend>::Ref bknd) { backend = bknd; };
|
||||
Socket(PD::SmartCtor<Backend>::Ref bknd, u16 port) {
|
||||
backend = bknd;
|
||||
this->Create();
|
||||
this->Bind(port);
|
||||
}
|
||||
~Socket() { Close(); };
|
||||
PD_SMART_CTOR(Socket);
|
||||
|
||||
bool Create();
|
||||
bool Bind(u16 port);
|
||||
bool Listen(int backlog = 5);
|
||||
bool WaitForRead(int timeout_ms);
|
||||
bool Accept(Socket::Ref client);
|
||||
bool Connect(const std::string& ip, u16 port);
|
||||
int Send(const std::string& data);
|
||||
int Receive(std::string& data, int size = 1024);
|
||||
void Close();
|
||||
bool IsValid() const;
|
||||
|
||||
int pSocket;
|
||||
PD::SmartCtor<Net::Backend>::Ref backend;
|
||||
};
|
||||
} // namespace Net
|
||||
} // namespace PD
|
@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/tween.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/overlays/overlay.hpp>
|
||||
|
||||
namespace PD {
|
||||
@ -153,11 +152,11 @@ class Keyboard : public Overlay {
|
||||
static int too;
|
||||
|
||||
// Tween for selector Movement
|
||||
Tween<vec2> selector;
|
||||
Tween<fvec2> selector;
|
||||
// Tween for Selector Size
|
||||
Tween<vec2> sel_szs;
|
||||
Tween<fvec2> sel_szs;
|
||||
// Current Cell size
|
||||
vec2 cselszs;
|
||||
fvec2 cselszs;
|
||||
// selector index
|
||||
int raw_sel;
|
||||
|
||||
@ -169,9 +168,9 @@ class Keyboard : public Overlay {
|
||||
// Remove Animation
|
||||
bool rem = false;
|
||||
/// Probably a float would've done the job as well ;)
|
||||
Tween<vec2> flymgr;
|
||||
Tween<fvec2> flymgr;
|
||||
// Secode Flymanager
|
||||
Tween<vec2> chflymgr;
|
||||
Tween<fvec2> chflymgr;
|
||||
// Show Help
|
||||
bool show_help = true;
|
||||
};
|
||||
|
@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/color.hpp>
|
||||
#include <pd/core/tween.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
|
||||
namespace PD {
|
||||
@ -68,10 +67,10 @@ class MessageMgr : public PD::SmartCtor<MessageMgr> {
|
||||
PD::Color col_bg; // Background Color
|
||||
PD::Color col_text; // Text Color
|
||||
float lifetime = 0.f; // LifeTime
|
||||
PD::Tween<vec2> pos; // Position effect
|
||||
PD::Tween<fvec2> pos; // Position effect
|
||||
std::string title; // Title
|
||||
std::string msg; // Message
|
||||
vec2 size; // Size of the Background
|
||||
fvec2 size; // Size of the Background
|
||||
bool tbr = false; // To be Removed ?
|
||||
bool kill = false; // Instant Kill
|
||||
int s = 0; // Slot
|
||||
|
@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
|
||||
namespace PD {
|
||||
|
@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
#include <pd/overlays/overlay.hpp>
|
||||
|
||||
|
@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/overlays/overlay.hpp>
|
||||
|
||||
namespace PD {
|
||||
@ -74,7 +74,7 @@ class Performance : public Overlay {
|
||||
* @param text Text to Show
|
||||
* @param ren Renderer Reference
|
||||
*/
|
||||
void Line(vec2& pos, const std::string& text, LI::Renderer::Ref ren);
|
||||
void Line(fvec2& pos, const std::string& text, LI::Renderer::Ref ren);
|
||||
// Trace String Average
|
||||
std::string TSA(const std::string& id);
|
||||
// Described in Keyboard
|
||||
|
@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/tween.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/overlays/overlay.hpp>
|
||||
#include <pd/ui7/ui7.hpp>
|
||||
|
||||
@ -68,7 +67,7 @@ class SettingsMenu : public Overlay {
|
||||
|
||||
// Some Animation
|
||||
bool rem = false;
|
||||
Tween<vec2> flymgr;
|
||||
Tween<fvec2> flymgr;
|
||||
|
||||
// Custom UI7 Context
|
||||
UI7::Context::Ref ctx;
|
||||
|
@ -35,7 +35,7 @@ namespace UI7 {
|
||||
* This only means that InPressed is responding the info in
|
||||
* the next frame
|
||||
*/
|
||||
class Button : public Container {
|
||||
class PD_UI7_API Button : public Container {
|
||||
public:
|
||||
/**
|
||||
* Button Object constructor
|
||||
@ -45,7 +45,7 @@ class Button : public Container {
|
||||
*/
|
||||
Button(const std::string& label, UI7::IO::Ref io) {
|
||||
this->label = label;
|
||||
this->tdim = io->Ren->GetTextDimensions(label);
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~Button() = default;
|
||||
|
||||
@ -54,9 +54,8 @@ class Button : public Container {
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* @param inp Reference to the Input Handler
|
||||
*/
|
||||
void HandleInput(Hid::Ref inp) override;
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
@ -67,7 +66,7 @@ class Button : public Container {
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
vec2 tdim; ///< Text size
|
||||
fvec2 tdim; ///< Text size
|
||||
UI7Color color = UI7Color_Button; ///< current button color
|
||||
std::string label; ///< Label of the Button
|
||||
bool pressed = false; ///< ispressed value
|
||||
|
@ -33,7 +33,7 @@ namespace UI7 {
|
||||
* Context::Update while the visual update is done
|
||||
* during the Update
|
||||
*/
|
||||
class Checkbox : public Container {
|
||||
class PD_UI7_API Checkbox : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor for Checkbox Object
|
||||
@ -44,15 +44,14 @@ class Checkbox : public Container {
|
||||
Checkbox(const std::string& label, bool& usr_ref, UI7::IO::Ref io)
|
||||
: usr_ref(usr_ref) {
|
||||
this->label = label;
|
||||
this->tdim = io->Ren->GetTextDimensions(label);
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~Checkbox() = default;
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* @param inp Reference to the Input Handler
|
||||
*/
|
||||
void HandleInput(Hid::Ref inp) override;
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
@ -63,8 +62,8 @@ class Checkbox : public Container {
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
vec2 tdim; ///< Text Size
|
||||
vec2 cbs = vec2(18); ///< Checkbox size
|
||||
fvec2 tdim; ///< Text Size
|
||||
fvec2 cbs = fvec2(18); ///< Checkbox size
|
||||
UI7Color color = UI7Color_FrameBackground; ///< Checkbox background Color
|
||||
std::string label; ///< Checkbox Label
|
||||
bool& usr_ref; ///< User bool reference
|
||||
|
@ -25,13 +25,14 @@ SOFTWARE.
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/layout.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Color Editor (Creating a PopUP when clicking)
|
||||
*/
|
||||
class ColorEdit : public Container {
|
||||
class PD_UI7_API ColorEdit : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
@ -40,20 +41,19 @@ class ColorEdit : public Container {
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
ColorEdit(const std::string& label, u32* color, UI7::IO::Ref io) {
|
||||
PD::Assert(color != nullptr, "Input Color Address is null!");
|
||||
// PD::Assert(color != nullptr, "Input Color Address is null!");
|
||||
this->label = label;
|
||||
this->color_ref = color;
|
||||
this->initial_color = *color;
|
||||
this->tdim = io->Ren->GetTextDimensions(label);
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~ColorEdit() = default;
|
||||
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* @param inp Reference to the Input Handler
|
||||
*/
|
||||
void HandleInput(Hid::Ref inp) override;
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
@ -64,10 +64,12 @@ class ColorEdit : public Container {
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
vec2 tdim; ///< Text size
|
||||
fvec2 tdim; ///< Text size
|
||||
u32* color_ref = nullptr; ///< Color Reference
|
||||
u32 initial_color; ///< Initial Color
|
||||
std::string label; ///< Label of the Button
|
||||
Layout::Ref layout; ///< Layout to open
|
||||
bool is_shown = false; ///< AHow Layout Editor
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -23,12 +23,10 @@ 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/strings.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
@ -36,7 +34,7 @@ namespace UI7 {
|
||||
* Container base class all Objects are based on
|
||||
* @note this class can be used to create custom Objects as well
|
||||
*/
|
||||
class Container : public SmartCtor<Container> {
|
||||
class PD_UI7_API Container : public SmartCtor<Container> {
|
||||
public:
|
||||
Container() = default;
|
||||
/**
|
||||
@ -44,12 +42,13 @@ class Container : public SmartCtor<Container> {
|
||||
* @param pos Container Position
|
||||
* @param size Container Size
|
||||
*/
|
||||
Container(const vec2& pos, const vec2& size) : pos(pos), size(size) {}
|
||||
Container(const fvec2& pos, const fvec2& size) : pos(pos), size(size) {}
|
||||
/**
|
||||
* Constructor by a vec4 box
|
||||
* @param box Box containing top left and bottom right coords
|
||||
*/
|
||||
Container(const vec4& box) : pos(box.xy()), size(box.zw() - box.xy()) {}
|
||||
Container(const fvec4& box)
|
||||
: pos(fvec2(box.x, box.y)), size(fvec2(box.z - box.x, box.w - box.y)) {}
|
||||
~Container() = default;
|
||||
|
||||
/**
|
||||
@ -61,22 +60,22 @@ class Container : public SmartCtor<Container> {
|
||||
void Init(UI7::IO::Ref io, UI7::DrawList::Ref l) {
|
||||
list = l;
|
||||
this->io = io;
|
||||
this->screen = io->Ren->CurrentScreen();
|
||||
// this->screen = io->Ren->CurrentScreen();
|
||||
}
|
||||
|
||||
/** Setter for Position */
|
||||
void SetPos(const vec2& pos) { this->pos = pos; }
|
||||
void SetPos(const fvec2& pos) { this->pos = pos; }
|
||||
/** Setter for Size */
|
||||
void SetSize(const vec2& size) { this->size = size; }
|
||||
void SetSize(const fvec2& size) { this->size = size; }
|
||||
/** Getter for Position */
|
||||
vec2 GetPos() { return pos; }
|
||||
fvec2 GetPos() { return pos; }
|
||||
/** Getter for Size */
|
||||
vec2 GetSize() { return size; }
|
||||
fvec2 GetSize() { return size; }
|
||||
/**
|
||||
* Get the Containers Final Position
|
||||
* for Rendering and Input (if it has a parent Object)
|
||||
*/
|
||||
vec2 FinalPos() {
|
||||
fvec2 FinalPos() {
|
||||
vec2 res = pos;
|
||||
if (parent) {
|
||||
/// Probably should use parant->FinalPos here
|
||||
@ -101,14 +100,17 @@ class Container : public SmartCtor<Container> {
|
||||
* @param scrolling Scrolling Position
|
||||
* @param viewport Viewport to check if the Object is skippable
|
||||
*/
|
||||
void HandleScrolling(vec2 scrolling, vec4 viewport);
|
||||
void HandleScrolling(fvec2 scrolling, fvec4 viewport);
|
||||
/** Template function for Input Handling */
|
||||
virtual void HandleInput(Hid::Ref inp) {}
|
||||
virtual void HandleInput() {}
|
||||
/** Tamplate function for Object rendering */
|
||||
virtual void Draw() {}
|
||||
/** Template function to update internal data (if needed) */
|
||||
virtual void Update() {}
|
||||
|
||||
/** Internal Input Handler */
|
||||
void HandleInternalInput();
|
||||
|
||||
/**
|
||||
* Function to unlock Input after Rendering is done in
|
||||
* Menu::Update
|
||||
@ -125,6 +127,9 @@ class Container : public SmartCtor<Container> {
|
||||
*/
|
||||
void SetID(u32 id) { this->id = id; }
|
||||
|
||||
/** Get a reference to IO */
|
||||
UI7::IO::Ref GetIO() { return io; }
|
||||
|
||||
protected:
|
||||
/** used to skip Input/Render preocessing ot not*/
|
||||
bool skippable = false;
|
||||
@ -135,11 +140,11 @@ class Container : public SmartCtor<Container> {
|
||||
/** Input done or not for current frame*/
|
||||
bool inp_done = false;
|
||||
/** Reference to the Screen to draw the Object on*/
|
||||
Screen::Ref screen;
|
||||
// Screen::Ref screen;
|
||||
/** Container Position*/
|
||||
vec2 pos;
|
||||
fvec2 pos;
|
||||
/** Container Size*/
|
||||
vec2 size;
|
||||
fvec2 size;
|
||||
/** Reference to the Drawlist to Draw to*/
|
||||
UI7::DrawList::Ref list;
|
||||
/** IO Reference for Renderer and Theme */
|
||||
@ -148,6 +153,14 @@ class Container : public SmartCtor<Container> {
|
||||
Container::Ref parent;
|
||||
/** Object ID (0 if unused)*/
|
||||
u32 id = 0;
|
||||
/** Internal Flags */
|
||||
u32 pFlags = 0;
|
||||
/** Is Selected? */
|
||||
bool pSelected = false;
|
||||
/** Was Pressed */
|
||||
bool pPressed = false;
|
||||
/** Was Pressed Twice */
|
||||
bool pPressedTwice = false;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
|
90
include/pd/ui7/container/dragdata.hpp
Normal file
90
include/pd/ui7/container/dragdata.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
#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/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* DragData Object can take a datatype or a list
|
||||
* and modifys these by moving left or right when dragging
|
||||
*/
|
||||
template <typename T>
|
||||
class PD_UI7_API DragData : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param data Data reference (Supported types can be seen in dragdata.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
|
||||
*/
|
||||
DragData(const std::string& label, T* data, size_t num_elms, UI7::IO::Ref io,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), T step = 1,
|
||||
int precision = 1) {
|
||||
// PD::Assert(data != nullptr, "Input Data Address is null!");
|
||||
this->label = label;
|
||||
this->data = data;
|
||||
this->elm_count = num_elms;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
this->step = step;
|
||||
this->precision = precision;
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~DragData() = default;
|
||||
|
||||
/**
|
||||
* 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
|
||||
std::string label; ///< Label of the Button
|
||||
T* data;
|
||||
size_t elm_count = 0;
|
||||
T min;
|
||||
T max;
|
||||
T step;
|
||||
int precision = 1;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
75
include/pd/ui7/container/dynobj.hpp
Normal file
75
include/pd/ui7/container/dynobj.hpp
Normal file
@ -0,0 +1,75 @@
|
||||
#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/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Button Object
|
||||
* @note Button Press is delayed by 1 frame
|
||||
* (but the visual reaction is done in the same frame)
|
||||
* This only means that InPressed is responding the info in
|
||||
* the next frame
|
||||
*/
|
||||
class PD_UI7_API DynObj : public Container {
|
||||
public:
|
||||
/**
|
||||
* Button Object constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
DynObj(std::function<void(UI7::IO::Ref, UI7::DrawList::Ref, Container*)>
|
||||
RenderFunc) {
|
||||
pRenFun = RenderFunc;
|
||||
}
|
||||
~DynObj() = default;
|
||||
|
||||
/** Return true if butten is pressed*/
|
||||
bool IsPressed() { return pressed; }
|
||||
/**
|
||||
* 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:
|
||||
UI7Color color = UI7Color_Button; ///< current button color
|
||||
bool pressed = false; ///< ispressed value
|
||||
std::function<void(UI7::IO::Ref, UI7::DrawList::Ref, Container*)> pRenFun;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -30,21 +30,21 @@ namespace UI7 {
|
||||
/**
|
||||
* Image Object
|
||||
*/
|
||||
class Image : public Container {
|
||||
class PD_UI7_API Image : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor for the Image Object
|
||||
* @param img Image Texture Reference
|
||||
* @param size Custom Size of the Image
|
||||
*/
|
||||
Image(Texture::Ref img, vec2 size = 0.f, LI::Rect uv = vec4(0.f)) {
|
||||
Image(LI::Texture::Ref img, fvec2 size = 0.f, LI::Rect uv = vec4(0.f)) {
|
||||
this->img = img;
|
||||
this->newsize = size;
|
||||
this->cuv = uv;
|
||||
if (size.x() != 0 || size.y() != 0) {
|
||||
if (size.x != 0 || size.y != 0) {
|
||||
this->SetSize(size);
|
||||
} else {
|
||||
this->SetSize(img->GetSize());
|
||||
this->SetSize(fvec2(img->GetSize().x, img->GetSize().y));
|
||||
}
|
||||
}
|
||||
~Image() = default;
|
||||
@ -56,9 +56,9 @@ class Image : public Container {
|
||||
void Draw() override;
|
||||
|
||||
private:
|
||||
Texture::Ref img; ///< Texture reference to the Image
|
||||
vec2 newsize = 0.f; ///< New Size
|
||||
LI::Rect cuv; ///< Custom UV
|
||||
LI::Texture::Ref img; ///< Texture reference to the Image
|
||||
fvec2 newsize = 0.f; ///< New Size
|
||||
LI::Rect cuv; ///< Custom UV
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -30,16 +30,16 @@ namespace UI7 {
|
||||
/**
|
||||
* Label [Text] Object
|
||||
*/
|
||||
class Label : public Container {
|
||||
class PD_UI7_API Label : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor for Label Object
|
||||
* @param label Label [Text] to Draw
|
||||
* @param lr Renderer Reference
|
||||
*/
|
||||
Label(const std::string& label, LI::Renderer::Ref lr) {
|
||||
Label(const std::string& label, IO::Ref io) {
|
||||
this->label = label;
|
||||
this->tdim = lr->GetTextDimensions(label);
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
this->SetSize(tdim);
|
||||
}
|
||||
~Label() = default;
|
||||
@ -51,7 +51,7 @@ class Label : public Container {
|
||||
void Draw() override;
|
||||
|
||||
private:
|
||||
vec2 tdim; ///< Text Size
|
||||
fvec2 tdim; ///< Text Size
|
||||
UI7Color color = UI7Color_Text; ///< Color
|
||||
std::string label; ///< Text to Render
|
||||
};
|
||||
|
@ -26,5 +26,7 @@ SOFTWARE.
|
||||
#include <pd/ui7/container/button.hpp>
|
||||
#include <pd/ui7/container/checkbox.hpp>
|
||||
#include <pd/ui7/container/coloredit.hpp>
|
||||
#include <pd/ui7/container/dragdata.hpp>
|
||||
#include <pd/ui7/container/dynobj.hpp>
|
||||
#include <pd/ui7/container/image.hpp>
|
||||
#include <pd/ui7/container/label.hpp>
|
||||
|
@ -23,37 +23,80 @@ 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>
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/pd_p_api.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class IO;
|
||||
/** DrawList class */
|
||||
class DrawList : public SmartCtor<DrawList> {
|
||||
class PD_UI7_API DrawList : public SmartCtor<DrawList> {
|
||||
public:
|
||||
/**
|
||||
* Constructor for a new Drawlist
|
||||
* @param r Renderer reference
|
||||
*/
|
||||
DrawList(LI::Renderer::Ref r) { ren = r; }
|
||||
DrawList(UI7::IO* io_ref) { pIO = io_ref; }
|
||||
~DrawList() = default;
|
||||
|
||||
/**
|
||||
* Draw a Rectangle (LINED)
|
||||
* @param pos position of the rect
|
||||
* @param size Size of the rect
|
||||
* @param clr Color of the rect
|
||||
* @param thickness Thickness of the lines
|
||||
*/
|
||||
void AddRect(const fvec2& pos, const fvec2& size, const UI7Color& clr,
|
||||
int thickness = 1);
|
||||
/**
|
||||
* Render a Rectangle
|
||||
* @param pos Position
|
||||
* @param szs Size
|
||||
* @param clr Color
|
||||
*/
|
||||
void AddRectangle(vec2 pos, vec2 szs, const UI7Color& clr);
|
||||
void AddRectangle(fvec2 pos, fvec2 szs, const UI7Color& clr);
|
||||
/**
|
||||
* Render a Triangle
|
||||
* @param pos0 Position a
|
||||
* @param pos1 Position b
|
||||
* @param pos2 Position c
|
||||
* @param a Position a
|
||||
* @param b Position b
|
||||
* @param c Position c
|
||||
* @param clr Color
|
||||
* @param thickness Thickness of the lines
|
||||
*/
|
||||
void AddTriangle(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
const UI7Color& clr, int thickness = 1);
|
||||
/**
|
||||
* Render a Filled Triangle
|
||||
* @param a Position a
|
||||
* @param b Position b
|
||||
* @param c Position c
|
||||
* @param clr Color
|
||||
*/
|
||||
void AddTriangle(vec2 pos0, vec2 pos1, vec2 pos2, const UI7Color& clr);
|
||||
void AddTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
const UI7Color& clr);
|
||||
|
||||
/**
|
||||
* Add a Lined Circle
|
||||
* @param pos Center position
|
||||
* @param rad radius of the circle
|
||||
* @param col Color of the Circle
|
||||
* @param num_segments Number of Segments (0 = auto)
|
||||
* @param thickness thickness of the line
|
||||
*/
|
||||
void AddCircle(const fvec2& pos, float rad, UI7Color col,
|
||||
int num_segments = 0, int thickness = 1);
|
||||
/**
|
||||
* Add a Circle
|
||||
* @param pos Center position
|
||||
* @param rad radius of the circle
|
||||
* @param col Color of the Circle
|
||||
* @param num_segments Number of Segments (0 = auto)
|
||||
*/
|
||||
void AddCircleFilled(const fvec2& pos, float rad, UI7Color col,
|
||||
int num_segments = 0);
|
||||
/**
|
||||
* Render a Text
|
||||
* @param pos Position
|
||||
@ -62,8 +105,8 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
* @param flags Flags
|
||||
* @param box Aditional Text Box limit (for specific flags)
|
||||
*/
|
||||
void AddText(vec2 pos, const std::string& text, const UI7Color& clr,
|
||||
LITextFlags flags = 0, vec2 box = vec2());
|
||||
void AddText(fvec2 pos, const std::string& text, const UI7Color& clr,
|
||||
u32 flags = 0, fvec2 box = fvec2());
|
||||
/**
|
||||
* Render an Image
|
||||
* @param pos Position
|
||||
@ -71,8 +114,8 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
* @param size Optional Size of the Image
|
||||
* @param uv Custom UV coords
|
||||
*/
|
||||
void AddImage(vec2 pos, Texture::Ref img, vec2 size = 0.f,
|
||||
LI::Rect uv = vec4(0.f));
|
||||
void AddImage(fvec2 pos, LI::Texture::Ref img, fvec2 size = 0.f,
|
||||
LI::Rect uv = fvec4(0.f));
|
||||
/**
|
||||
* Render a Line from Position A to Position B
|
||||
* @param a Pos a
|
||||
@ -80,44 +123,114 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
* @param clr Color
|
||||
* @param t Thcikness
|
||||
*/
|
||||
void AddLine(const vec2& a, const vec2& b, const UI7Color& clr, int t = 1);
|
||||
void AddLine(const fvec2& a, const fvec2& b, const UI7Color& clr, int t = 1);
|
||||
|
||||
/**
|
||||
* Take list of points and display it as a line on screen
|
||||
* @param points List of Positions
|
||||
* @param clr Color of the Line
|
||||
* @param flags Additional Flags (Close for go back to starting point)
|
||||
* @param thickness Thickness of the Line
|
||||
*/
|
||||
void AddPolyLine(const Vec<fvec2>& points, const UI7Color& clr,
|
||||
UI7DrawFlags flags = 0, int thickness = 1);
|
||||
/**
|
||||
* Take a List ofpoints and display it as Filled Shape
|
||||
* @note Keep in mind to setup the list of points clockwise
|
||||
* @param points List of Points
|
||||
* @param clr Color of the shape
|
||||
*/
|
||||
void AddConvexPolyFilled(const Vec<fvec2>& points, const UI7Color& clr);
|
||||
|
||||
/** Clear the Drawlist */
|
||||
void Clear();
|
||||
/** Process [Render] the Drawlist */
|
||||
void Process();
|
||||
void Process(LI::DrawList::Ref d);
|
||||
|
||||
/** Push a Clip Rect */
|
||||
void PushClipRect(const vec4& v) { clip_rects.push(v); }
|
||||
void PushClipRect(const fvec4& v) { pClipRects.Push(v); }
|
||||
|
||||
/** Revert Last Clip Rect */
|
||||
void PopClipRect() { clip_rects.pop(); }
|
||||
void PopClipRect() { pClipRects.Pop(); }
|
||||
|
||||
/** Getter for the Layer */
|
||||
int Layer() const { return layer; }
|
||||
/** Setter fot the Layer */
|
||||
void Layer(int v) { layer = v; }
|
||||
/** Path API */
|
||||
|
||||
/**
|
||||
* Function to reserve Memory to prevent overhead on
|
||||
* pusing a lot of points with PathNext
|
||||
* @param num_points Number of Positions you want to add
|
||||
*/
|
||||
void PathReserve(size_t num_points) {
|
||||
Path.Reserve(Path.Size() + num_points);
|
||||
}
|
||||
/**
|
||||
* Clear current Path
|
||||
* @note PathStroke and PathFill will automatically clear
|
||||
*/
|
||||
void PathClear() { Path.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 PathNext(const fvec2& v) { Path.Add(v); }
|
||||
/**
|
||||
* Path Stroke Create Line from point to point
|
||||
* @note For Primitives like Rect or Triangle mak sure to use
|
||||
* UI7DrawFlags_Close to add a line back to the starting point
|
||||
* @param clr Color od the line
|
||||
* @param thickness Thickness of the line
|
||||
* @param flags Additional Drawflags
|
||||
*/
|
||||
void PathStroke(const UI7Color& clr, int thickness = 1,
|
||||
UI7DrawFlags flags = 0) {
|
||||
AddPolyLine(Path, clr, flags, thickness);
|
||||
Path.Clear();
|
||||
}
|
||||
/**
|
||||
* Fill a Path with a Color
|
||||
* @note **IMPORTANT: ** Paths need to be setup clockwise
|
||||
* to be rendered correctly
|
||||
* @param clr Fill Color
|
||||
*/
|
||||
void PathFill(const UI7Color& clr) {
|
||||
AddConvexPolyFilled(Path, clr);
|
||||
Path.Clear();
|
||||
}
|
||||
|
||||
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
|
||||
int segments);
|
||||
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
||||
/// @param a Top Left Position
|
||||
/// @param b Bottom Right Position
|
||||
/// @param rounding rounding
|
||||
/// @param flags DrawFlags (for special rounding rules)
|
||||
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f, UI7DrawFlags flags = 0);
|
||||
|
||||
int Layer; ///< Layer
|
||||
int Base; ///< Base Layer
|
||||
Stack<fvec4> pClipRects; ///< ClipRects
|
||||
u32 NumVertices; ///< Num vertices
|
||||
u32 NumIndices; ///< Num Indices
|
||||
UI7::IO* pIO; ///< IO Reference
|
||||
LI::Texture::Ref CurrentTex; ///< Current Texture
|
||||
|
||||
private:
|
||||
/** Base Layer offset (Internal Used) */
|
||||
int BaseLayer() const { return base; }
|
||||
/** Base Layer offset (Internal Used) */
|
||||
void BaseLayer(int v) { base = v; }
|
||||
/**
|
||||
* One liner to setup command cliprect
|
||||
*/
|
||||
void ClipCmd(LI::Command::Ref cmd);
|
||||
|
||||
// Set friendclass here to not expose private functions as public
|
||||
friend class Menu;
|
||||
friend class Context;
|
||||
|
||||
int layer; ///< Current Layer
|
||||
int base; ///< Base Layer
|
||||
LI::Renderer::Ref ren; ///< Renderer Reference
|
||||
std::stack<vec4> clip_rects; ///< Stack containing Scissor Areas
|
||||
u32 num_vertices; ///< Number of Vertices
|
||||
u32 num_indices; ///< Number of Indices
|
||||
Vec<fvec2> Path;
|
||||
// Map for Auto Static Text
|
||||
std::unordered_map<u32, LI::StaticText::Ref> static_text;
|
||||
// std::unordered_map<u32, LI::StaticText::Ref> static_text;
|
||||
// List of Drawcommands generated
|
||||
std::vector<std::pair<bool, LI::Command::Ref>> commands;
|
||||
Vec<LI::Command::Ref> Commands;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -29,6 +29,10 @@ using UI7MenuFlags = unsigned int;
|
||||
using UI7Align = unsigned int;
|
||||
/** 32Bit Value to store Context (IO) flags */
|
||||
using UI7IOFlags = unsigned int;
|
||||
/** 32Bit Value for Layout Flags */
|
||||
using UI7LayoutFlags = unsigned int;
|
||||
/** 32Bit value for DrawFlags */
|
||||
using UI7DrawFlags = unsigned int;
|
||||
|
||||
/** Menu Flags */
|
||||
enum UI7MenuFlags_ {
|
||||
@ -48,6 +52,18 @@ enum UI7MenuFlags_ {
|
||||
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
|
||||
};
|
||||
|
||||
/** UI7 Layout Flags */
|
||||
enum UI7LayoutFlags_ {
|
||||
UI7LayoutFlags_None = 0, ///< No Flags used
|
||||
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
|
||||
};
|
||||
|
||||
enum UI7DrawFlags_ {
|
||||
UI7DrawFlags_None = 0,
|
||||
UI7DrawFlags_Close = 1 << 0, ///< Close a PolyLine
|
||||
UI7DrawFlags_AALines = 1 << 1, ///< Anti aliased Lines
|
||||
};
|
||||
|
||||
/** UI7 Context Flags */
|
||||
enum UI7IOFlags_ {
|
||||
UI7IOFlags_None = 0, ///< No Additional Config available
|
||||
@ -66,3 +82,18 @@ enum UI7Align_ {
|
||||
// Default Horizontal and Vertical Alignment
|
||||
UI7Align_Default = UI7Align_Left | UI7Align_Top,
|
||||
};
|
||||
|
||||
/** Special flags for Layout::AddObjectEx */
|
||||
enum UI7LytAdd_ {
|
||||
UI7LytAdd_None = 0, ///< Also known as default or ->AddObject
|
||||
UI7LytAdd_NoCursorUpdate = 1 << 0, ///< Add without cursor alignment
|
||||
UI7LytAdd_NoScrollHandle = 1 << 1, ///< Skip HandleScrolling
|
||||
UI7LytAdd_Front = 1 << 2, ///< Add in front of the list
|
||||
};
|
||||
|
||||
enum UI7ContainerFlags_ {
|
||||
UI7ContainerFlags_None = 0,
|
||||
UI7ContainerFlags_EnableInternalInput = 1 << 0,
|
||||
UI7ContainerFlags_Selectable = 1 << 1,
|
||||
UI7ContainerFlags_OutlineSelected = 1 << 2,
|
||||
};
|
@ -23,8 +23,7 @@ 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/strings.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
|
130
include/pd/ui7/input_api.hpp
Normal file
130
include/pd/ui7/input_api.hpp
Normal file
@ -0,0 +1,130 @@
|
||||
#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/core.hpp>
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class InputHandler : public SmartCtor<InputHandler> {
|
||||
public:
|
||||
InputHandler(Hid::Ref inp_drv) {
|
||||
DragTime = Timer::New(false);
|
||||
Inp = inp_drv;
|
||||
}
|
||||
~InputHandler() = default;
|
||||
|
||||
/**
|
||||
* Function to Check if current Object is dragged
|
||||
* or set it dragged
|
||||
* @param id ID to identify this specific Object
|
||||
* @param area Area where to start dragging
|
||||
* @return if inputs to this objects are alowed or not
|
||||
*/
|
||||
bool DragObject(const UI7::ID& id, fvec4 area) {
|
||||
if (CurrentMenu != FocusedMenu) {
|
||||
return false;
|
||||
}
|
||||
if (IsObjectDragged()) {
|
||||
// Only block if the Dragged Object has a difrent id
|
||||
if (DraggedObject != id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Get a Short define for touch pos
|
||||
vec2 p = Inp->TouchPos();
|
||||
// Check if Drag starts in the area position
|
||||
if (Inp->IsDown(Inp->Touch) && LI::Renderer::InBox(p, area)) {
|
||||
// Set ID and iniatial Positions
|
||||
DraggedObject = id;
|
||||
DragSourcePos = p;
|
||||
DragPosition = p;
|
||||
DragLastPosition = p;
|
||||
DragDestination = area;
|
||||
// Reset and Start DragTimer
|
||||
DragTime->Reset();
|
||||
DragTime->Rseume();
|
||||
return false; // To make sure the Object is "Dragged"
|
||||
} else if (Inp->IsHeld(Inp->Touch) && IsObjectDragged()) {
|
||||
// Update DragLast and DragPoisition
|
||||
DragLastPosition = DragPosition;
|
||||
DragPosition = p;
|
||||
} else if (Inp->IsUp(Inp->Touch) && IsObjectDragged()) {
|
||||
// Released... Everything gets reset
|
||||
DraggedObject = 0;
|
||||
DragPosition = 0;
|
||||
DragSourcePos = 0;
|
||||
DragLastPosition = 0;
|
||||
DragDestination = 0;
|
||||
// Set Drag released to true (only one frame)
|
||||
// and Only if still in Box
|
||||
DragReleased = LI::Renderer::InBox(Inp->TouchPosLast(), area);
|
||||
DragReleasedAW = true; // Advanced
|
||||
u64 d_rel = Sys::GetTime();
|
||||
if (d_rel - DragLastReleased < DoubleClickTime) {
|
||||
DragDoubleRelease = true;
|
||||
DragLastReleased = 0; // Set 0 to prevent double exec
|
||||
} else {
|
||||
DragLastReleased = d_rel;
|
||||
}
|
||||
// Ensure timer is paused
|
||||
DragTime->Pause();
|
||||
DragTime->Reset();
|
||||
// Still return The Object is Dragged to ensure
|
||||
// the DragReleased var can be used
|
||||
return true;
|
||||
}
|
||||
return IsObjectDragged();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
DragTime->Update();
|
||||
DragReleased = false;
|
||||
DragReleasedAW = false;
|
||||
DragDoubleRelease = false;
|
||||
}
|
||||
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
u32 FocusedMenu = 0;
|
||||
fvec4 FocusedMenuRect;
|
||||
u32 CurrentMenu = 0;
|
||||
u32 DraggedObject = 0;
|
||||
fvec2 DragSourcePos = 0;
|
||||
fvec2 DragPosition = 0;
|
||||
fvec2 DragLastPosition = 0;
|
||||
fvec4 DragDestination = 0;
|
||||
Timer::Ref DragTime;
|
||||
u64 DragLastReleased = 0;
|
||||
bool DragReleased = false; ///< Drag Releaded in Box
|
||||
bool DragReleasedAW = false; ///< Drag Released Anywhere
|
||||
bool DragDoubleRelease = false; ///< Double Click
|
||||
/** Check if an object is Dragged already */
|
||||
bool IsObjectDragged() const { return DraggedObject != 0; }
|
||||
|
||||
Hid::Ref Inp;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -23,12 +23,12 @@ 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/timer.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
#include <pd/ui7/input_api.hpp>
|
||||
#include <pd/ui7/pd_p_api.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
|
||||
namespace PD {
|
||||
@ -36,20 +36,23 @@ namespace UI7 {
|
||||
/**
|
||||
* Shared Configuration and Runtime Data for a UI7 Context
|
||||
*/
|
||||
class IO : public SmartCtor<IO> {
|
||||
class PD_UI7_API IO : public SmartCtor<IO> {
|
||||
public:
|
||||
/**
|
||||
* IO Constructor setting UP References
|
||||
*/
|
||||
IO(Hid::Ref input_driver, LI::Renderer::Ref ren) {
|
||||
Time = Timer::New();
|
||||
DragTime = Timer::New(false);
|
||||
InputHandler = UI7::InputHandler::New(input_driver);
|
||||
Theme = UI7::Theme::New();
|
||||
Inp = input_driver;
|
||||
Ren = ren;
|
||||
Back = UI7::DrawList::New(Ren);
|
||||
Front = UI7::DrawList::New(Ren);
|
||||
RegisterDrawList("CtxBackList", Back);
|
||||
Back = UI7::DrawList::New(this);
|
||||
Front = UI7::DrawList::New(this);
|
||||
pRDL = LI::DrawList::New(Ren->WhitePixel);
|
||||
DrawListRegestry.PushFront(
|
||||
Pair<UI7::ID, DrawList::Ref>("CtxBackList", Back));
|
||||
// RegisterDrawList("CtxBackList", Back);
|
||||
DeltaStats = TimeStats::New(60);
|
||||
};
|
||||
~IO() = default;
|
||||
@ -61,104 +64,39 @@ class IO : public SmartCtor<IO> {
|
||||
|
||||
float Framerate = 0.f;
|
||||
float Delta = 0.f;
|
||||
u64 LastTime = 0;
|
||||
TimeStats::Ref DeltaStats;
|
||||
Timer::Ref Time;
|
||||
Hid::Ref Inp;
|
||||
LI::Renderer::Ref Ren;
|
||||
LI::DrawList::Ref pRDL;
|
||||
LI::Font::Ref Font;
|
||||
float FontScale = 0.7f;
|
||||
UI7::Theme::Ref Theme;
|
||||
vec2 MenuPadding = 5.f;
|
||||
vec2 FramePadding = 5.f;
|
||||
vec2 ItemSpace = vec2(5.f, 2.f);
|
||||
fvec2 MenuPadding = 5.f;
|
||||
fvec2 FramePadding = 5.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
|
||||
float OverScrollMod = 0.15f;
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
std::vector<std::pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
|
||||
PD::List<Pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
|
||||
// Short define for DrawKistRegestryLast
|
||||
PD::List<Pair<UI7::ID, DrawList::Ref>> pDLRL;
|
||||
// std::vector<std::pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
|
||||
DrawList::Ref Back;
|
||||
DrawList::Ref Front;
|
||||
u32 NumVertices = 0; ///< Debug Vertices Num
|
||||
u32 NumIndices = 0; ///< Debug Indices Num
|
||||
Vec<u32> MenuOrder;
|
||||
|
||||
// DrawListApi
|
||||
void RegisterDrawList(const UI7::ID& id, DrawList::Ref v) {
|
||||
DrawListRegestry.push_back(std::make_pair(id, v));
|
||||
DrawListRegestry.PushBack(Pair(id, v));
|
||||
}
|
||||
|
||||
// Input API
|
||||
u32 FocusedMenu = 0;
|
||||
vec4 FocusedMenuRect;
|
||||
u32 CurrentMenu = 0;
|
||||
u32 DraggedObject = 0;
|
||||
vec2 DragSourcePos = 0;
|
||||
vec2 DragPosition = 0;
|
||||
vec2 DragLastPosition = 0;
|
||||
vec4 DragDestination = 0;
|
||||
Timer::Ref DragTime;
|
||||
u64 DragLastReleased = 0;
|
||||
bool DragReleased = false; ///< Drag Releaded in Box
|
||||
bool DragReleasedAW = false; ///< Drag Released Anywhere
|
||||
bool DragDoubleRelease = false; ///< Double Click
|
||||
/** Check if an object is Dragged already */
|
||||
bool IsObjectDragged() const { return DraggedObject != 0; }
|
||||
/**
|
||||
* Function to Check if current Object is dragged
|
||||
* or set it dragged
|
||||
* @param id ID to identify this specific Object
|
||||
* @param area Area where to start dragging
|
||||
* @return if inputs to this objects are alowed or not
|
||||
*/
|
||||
bool DragObject(const UI7::ID& id, vec4 area) {
|
||||
if (CurrentMenu != FocusedMenu) {
|
||||
return false;
|
||||
}
|
||||
if (IsObjectDragged()) {
|
||||
// Only block if the Dragged Object has a difrent id
|
||||
if (DraggedObject != id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Get a Short define for touch pos
|
||||
vec2 p = Inp->TouchPos();
|
||||
// Check if Drag starts in the area position
|
||||
if (Inp->IsDown(Inp->Touch) && Ren->InBox(p, area)) {
|
||||
// Set ID and iniatial Positions
|
||||
DraggedObject = id;
|
||||
DragSourcePos = p;
|
||||
DragPosition = p;
|
||||
DragLastPosition = p;
|
||||
DragDestination = area;
|
||||
// Reset and Start DragTimer
|
||||
DragTime->Reset();
|
||||
DragTime->Rseume();
|
||||
return false; // To make sure the Object is "Dragged"
|
||||
} else if (Inp->IsHeld(Inp->Touch) && IsObjectDragged()) {
|
||||
// Update DragLast and DragPoisition
|
||||
DragLastPosition = DragPosition;
|
||||
DragPosition = p;
|
||||
} else if (Inp->IsUp(Inp->Touch) && IsObjectDragged()) {
|
||||
// Released... Everything gets reset
|
||||
DraggedObject = 0;
|
||||
DragPosition = 0;
|
||||
DragSourcePos = 0;
|
||||
DragLastPosition = 0;
|
||||
DragDestination = 0;
|
||||
// Set Drag released to true (only one frame)
|
||||
// and Only if still in Box
|
||||
DragReleased = Ren->InBox(Inp->TouchPosLast(), area);
|
||||
DragReleasedAW = true; // Advanced
|
||||
u64 d_rel = Sys::GetTime();
|
||||
if (d_rel - DragLastReleased < DoubleClickTime) {
|
||||
DragDoubleRelease = true;
|
||||
DragLastReleased = 0; // Set 0 to prevent double exec
|
||||
} else {
|
||||
DragLastReleased = d_rel;
|
||||
}
|
||||
// Ensure timer is paused
|
||||
DragTime->Pause();
|
||||
DragTime->Reset();
|
||||
// Still return The Object is Dragged to ensure
|
||||
// the DragReleased var can be used
|
||||
return true;
|
||||
}
|
||||
return IsObjectDragged();
|
||||
}
|
||||
UI7::InputHandler::Ref InputHandler;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
134
include/pd/ui7/layout.hpp
Normal file
134
include/pd/ui7/layout.hpp
Normal file
@ -0,0 +1,134 @@
|
||||
#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/core.hpp>
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class PD_UI7_API Layout : public PD::SmartCtor<Layout> {
|
||||
public:
|
||||
Layout(const ID& id, IO::Ref io) : ID(id) {
|
||||
this->IO = io;
|
||||
DrawList = UI7::DrawList::New(io.get());
|
||||
Scrolling[0] = false;
|
||||
Scrolling[1] = false;
|
||||
CursorInit();
|
||||
Pos = fvec2(0, 0);
|
||||
Size = fvec2(320, 240);
|
||||
WorkRect = fvec4(IO->MenuPadding, Size - (fvec2(2) * IO->MenuPadding));
|
||||
}
|
||||
~Layout() = default;
|
||||
|
||||
const std::string& GetName() const { return ID.GetName(); }
|
||||
const UI7::ID& GetID() const { return this->ID; }
|
||||
|
||||
const fvec2& GetPosition() const { return Pos; }
|
||||
void SetPosition(const fvec2& v) { Pos = v; }
|
||||
const fvec2& GetSize() const { return Size; }
|
||||
void SetSize(const fvec2& v) { Size = v; }
|
||||
|
||||
UI7::DrawList::Ref GetDrawList() { return DrawList; }
|
||||
|
||||
void CursorInit();
|
||||
void SameLine();
|
||||
void CursorMove(const fvec2& size);
|
||||
|
||||
bool ObjectWorkPos(fvec2& movpos);
|
||||
|
||||
/**
|
||||
* Extended Object Add Func to Add Object in Front or disable
|
||||
* Position by cursor as well as cursor update...
|
||||
* Should only be used in special cases as the
|
||||
* AddObject function is faster
|
||||
* Using Flags for its features cause dont want to have too much args
|
||||
*/
|
||||
void AddObjectEx(Container::Ref obj, u32 Flags);
|
||||
/**
|
||||
* Fast Function to Add Object in Layout SPace like
|
||||
* button Label images etc
|
||||
*/
|
||||
void AddObject(Container::Ref obj);
|
||||
Container::Ref FindObject(u32 id);
|
||||
void ClearIDObjects() { IDObjects.clear(); }
|
||||
|
||||
fvec2 AlignPosition(fvec2 pos, fvec2 size, fvec4 area, UI7Align alignment);
|
||||
|
||||
/** Get the Alignment for Current State */
|
||||
UI7Align GetAlignment() {
|
||||
/// if temp alignment is used then return it and
|
||||
/// reset tmpalign
|
||||
if (TempAlign) {
|
||||
auto t = TempAlign;
|
||||
TempAlign = 0;
|
||||
return t;
|
||||
}
|
||||
return Alignment;
|
||||
}
|
||||
|
||||
void SetAlign(UI7Align a) { Alignment = a; }
|
||||
void NextAlign(UI7Align a) { TempAlign = a; }
|
||||
|
||||
void Update();
|
||||
|
||||
private:
|
||||
friend class Menu;
|
||||
friend class Context;
|
||||
friend class ReMenu;
|
||||
// Base Components
|
||||
UI7::ID ID;
|
||||
UI7::IO::Ref IO;
|
||||
UI7::DrawList::Ref DrawList;
|
||||
|
||||
// Positioning
|
||||
fvec2 Pos;
|
||||
fvec2 Size;
|
||||
UI7Align Alignment = UI7Align_Default;
|
||||
UI7Align TempAlign;
|
||||
|
||||
// Cursor
|
||||
fvec2 Cursor;
|
||||
fvec2 InitialCursorOffset;
|
||||
fvec2 BackupCursor;
|
||||
fvec2 SamelineCursor;
|
||||
fvec2 BeforeSameLine;
|
||||
fvec2 LastObjSize;
|
||||
fvec2 MaxPosition;
|
||||
fvec4 WorkRect;
|
||||
|
||||
// Scrolling
|
||||
fvec2 ScrollOffset;
|
||||
bool Scrolling[2];
|
||||
|
||||
// Objects
|
||||
PD::List<Container::Ref> Objects;
|
||||
std::vector<Container::Ref> IDObjects;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -23,18 +23,18 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/tween.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ui7/containers.hpp>
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/layout.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/** Menu Class for UI7 */
|
||||
class Menu : public SmartCtor<Menu> {
|
||||
class PD_UI7_API Menu : public SmartCtor<Menu> {
|
||||
public:
|
||||
/**
|
||||
* Menu COnstructor (Unly used by UI7::Context)
|
||||
@ -47,12 +47,11 @@ class Menu : public SmartCtor<Menu> {
|
||||
this->id = id;
|
||||
this->name = id.GetName();
|
||||
/// Set Default Values here
|
||||
scrolling[0] = false;
|
||||
scrolling[1] = false;
|
||||
scrollbar[0] = false;
|
||||
scrollbar[1] = false;
|
||||
scroll_allowed[0] = false;
|
||||
scroll_allowed[1] = false;
|
||||
Layout = UI7::Layout::New(id, io);
|
||||
}
|
||||
~Menu() = default;
|
||||
|
||||
@ -80,7 +79,7 @@ class Menu : public SmartCtor<Menu> {
|
||||
* @param img Texture reference of the image
|
||||
* @param size a Custom Size if needed
|
||||
*/
|
||||
void Image(Texture::Ref img, vec2 size = 0.f, LI::Rect uv = vec4(0));
|
||||
void Image(LI::Texture::Ref img, fvec2 size = 0.f, LI::Rect uv = fvec4(0));
|
||||
|
||||
/**
|
||||
* Color Edit Object that opens a popup editor if clicked
|
||||
@ -88,6 +87,22 @@ class Menu : public SmartCtor<Menu> {
|
||||
* @param color Color reference to edit
|
||||
*/
|
||||
void ColorEdit(const std::string& label, u32* color);
|
||||
|
||||
void DragFloat(const std::string& label, float* data, size_t num_elms);
|
||||
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 = Layout->FindObject(id);
|
||||
if (!r) {
|
||||
r = PD::New<UI7::DragData<T>>(label, data, num_elms, io, min, max, step,
|
||||
precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
Layout->AddObject(r);
|
||||
}
|
||||
// Basic API
|
||||
|
||||
/**
|
||||
@ -102,7 +117,7 @@ class Menu : public SmartCtor<Menu> {
|
||||
void EndTreeNode();
|
||||
|
||||
/** Add the Next Objext to the same line */
|
||||
void SameLine();
|
||||
void SameLine() { Layout->SameLine(); }
|
||||
/** Add a Separator Line */
|
||||
void Separator();
|
||||
/**
|
||||
@ -128,23 +143,14 @@ class Menu : public SmartCtor<Menu> {
|
||||
* Set a Temp alignment op for the next Object
|
||||
* @param a Alignment Operation
|
||||
*/
|
||||
void NextAlign(UI7Align a) { tmpalign = a; }
|
||||
void NextAlign(UI7Align a) { Layout->NextAlign(a); }
|
||||
/**
|
||||
* Align Every Single Object by this operationset
|
||||
* @param a Alignment
|
||||
*/
|
||||
void PushAlignment(UI7Align a) { alignment = a; }
|
||||
void PushAlignment(UI7Align a) { Layout->SetAlign(a); }
|
||||
/** Use default alignment */
|
||||
void PopAlignment() { alignment = UI7Align_Default; }
|
||||
/**
|
||||
* Get a New Position depending on the Alignment
|
||||
* @param pos Current Position
|
||||
* @param size Object size
|
||||
* @param view Viewport [position and size]
|
||||
* @param a Alignment Operations
|
||||
* @return new position based on the alignment
|
||||
*/
|
||||
static vec2 AlignPos(vec2 pos, vec2 size, vec4 view, UI7Align a);
|
||||
void PopAlignment() { Layout->Alignment = UI7Align_Default; }
|
||||
/**
|
||||
* Returns a Reference to the theme
|
||||
* @return Reference to the base Theme of the context
|
||||
@ -166,35 +172,6 @@ class Menu : public SmartCtor<Menu> {
|
||||
|
||||
// API for Custom Objects
|
||||
|
||||
/**
|
||||
* Handles the Position of Objects in Scrolling Menu
|
||||
* @note As Containers have their own FUnc to handle this, this
|
||||
* function is only useful to Render Live Objects whicch cannot be aligned
|
||||
* by the internal Alignment Api
|
||||
* @param pos position reference to write the new position to
|
||||
* @param size size of the Object
|
||||
* @return if the object can be skipped in rendering
|
||||
*/
|
||||
bool HandleScrolling(vec2& pos, const vec2& size);
|
||||
/**
|
||||
* Get the Cursor Position
|
||||
* @return Cursor Pos
|
||||
*/
|
||||
vec2 Cursor() const { return view_area.xy() + cursor; }
|
||||
/**
|
||||
* Set the Cursor position
|
||||
* @note The old Position can be restored with RestoreCursor
|
||||
* @param v New Position
|
||||
*/
|
||||
void Cursor(const vec2& v) {
|
||||
bcursor = cursor;
|
||||
cursor = v;
|
||||
}
|
||||
/** Restore to the last cursor Position */
|
||||
void RestoreCursor() {
|
||||
cursor = bcursor;
|
||||
bcursor = vec2();
|
||||
}
|
||||
/** Return if a Vertical Scrollbar exists */
|
||||
bool HasVerticalScrollbar() { return scrollbar[1]; }
|
||||
/** Return if a Horizontal Scrollbar exists */
|
||||
@ -206,43 +183,13 @@ class Menu : public SmartCtor<Menu> {
|
||||
* @note Could destroy some basic functionality
|
||||
*/
|
||||
void TitleBarHeight(float v) { tbh = v; }
|
||||
/**
|
||||
* Init the Cursor
|
||||
* @note Useful when using with a Custom TitlebarHeight
|
||||
*/
|
||||
void CursorInit() { Cursor(io->MenuPadding + vec2(0, tbh)); }
|
||||
/**
|
||||
* Move the Cursor for new Object
|
||||
* @param szs Size of the current Object
|
||||
*/
|
||||
void CursorMove(const vec2& szs);
|
||||
/** Get the ViewArea of the Menu */
|
||||
vec4 ViewArea() const { return view_area; }
|
||||
/**
|
||||
* Get the Main Area of the Menu
|
||||
* (only relevant for input)
|
||||
*/
|
||||
vec4 MainArea() const { return main_area; }
|
||||
/**
|
||||
* Set a MainArea for input
|
||||
* @param v Area where Objects can receive inputs
|
||||
*/
|
||||
void MainArea(const vec4& v) { main_area = v; }
|
||||
/** Get The Scrolling offset */
|
||||
vec2 ScrollOffset() const { return scrolling_off; }
|
||||
/**
|
||||
* Set a Scrolling offset
|
||||
* @param v Custom Scrolling offset
|
||||
*/
|
||||
void ScrollOffset(const vec2& v) { scrolling_off = v; }
|
||||
/** Get the Current Scrollmodification value */
|
||||
vec2 ScrollMod() const { return scroll_mod; }
|
||||
|
||||
/**
|
||||
* Animated Scroll to Position
|
||||
* @param pos Destination Position
|
||||
*/
|
||||
void ScrollTo(vec2 pos) {
|
||||
scroll_anim.From(scrolling_off)
|
||||
void ScrollTo(fvec2 pos) {
|
||||
scroll_anim.From(Layout->ScrollOffset)
|
||||
.To(pos)
|
||||
.In(1.f)
|
||||
.As(scroll_anim.EaseInOutSine);
|
||||
@ -252,19 +199,6 @@ class Menu : public SmartCtor<Menu> {
|
||||
|
||||
// Objects API
|
||||
|
||||
/**
|
||||
* Push an object to the current ListHandler
|
||||
* @param obj Object reference to use
|
||||
* @return Reference to the Object (from a time
|
||||
* where ObjectPush(Container::New()) was used)
|
||||
*/
|
||||
Container::Ref ObjectPush(Container::Ref obj);
|
||||
/**
|
||||
* Search for an Object by an id
|
||||
* @param id 32 Bit hash/id
|
||||
* @return the found Object or nullptr
|
||||
*/
|
||||
Container::Ref FindIDObj(u32 id);
|
||||
/**
|
||||
* Create a Parent Container to move and edit all sub
|
||||
* instances at once
|
||||
@ -276,7 +210,8 @@ class Menu : public SmartCtor<Menu> {
|
||||
// Draw List
|
||||
|
||||
/** Get DrawList */
|
||||
DrawList::Ref GetDrawList() { return main; }
|
||||
DrawList::Ref GetDrawList() { return Layout->DrawList; }
|
||||
UI7::Layout::Ref GetLayout() { return Layout; }
|
||||
|
||||
// Advanced
|
||||
|
||||
@ -305,43 +240,6 @@ class Menu : public SmartCtor<Menu> {
|
||||
/** Handle things like scrolling */
|
||||
void PostHandler();
|
||||
|
||||
// Basic Settings
|
||||
|
||||
/**
|
||||
* Set Backup Cursor
|
||||
* @param v Position
|
||||
*/
|
||||
void BackupCursor(const vec2& v) { bcursor = v; }
|
||||
/** Get Sameline Cursor */
|
||||
vec2 SameLineCursor() const { return slcursor; }
|
||||
/**
|
||||
* Set Sameline Cursor
|
||||
* @param v Position
|
||||
*/
|
||||
void SameLineCursor(const vec2& v) { slcursor = v; }
|
||||
/**
|
||||
* Set View Area
|
||||
* @param v vec4 containing pos and size
|
||||
*/
|
||||
void ViewArea(const vec4& v) { view_area = v; }
|
||||
/**
|
||||
* Set Scroll Modification
|
||||
* @param v Mod
|
||||
*/
|
||||
void ScrollMod(const vec2& v) { scroll_mod = v; }
|
||||
|
||||
/** Get the Alignment for Current State */
|
||||
UI7Align GetAlignment() {
|
||||
/// if temp alignment is used then return it and
|
||||
/// reset tmpalign
|
||||
if (tmpalign) {
|
||||
auto t = tmpalign;
|
||||
tmpalign = 0;
|
||||
return t;
|
||||
}
|
||||
return alignment;
|
||||
}
|
||||
|
||||
/** Internal Processing */
|
||||
void Update(float delta);
|
||||
|
||||
@ -357,27 +255,17 @@ class Menu : public SmartCtor<Menu> {
|
||||
void CollapseHandler();
|
||||
/** Scroll Handler (Includes Slider Drag) */
|
||||
void PostScrollHandler();
|
||||
/** Handler to Set menu focused or not */
|
||||
void MenuFocusHandler();
|
||||
|
||||
// This ability is crazy useful
|
||||
friend class Context;
|
||||
|
||||
// Data
|
||||
|
||||
// Default Alignment for all Objects
|
||||
UI7Align alignment = UI7Align_Default;
|
||||
UI7Align tmpalign = 0; ///< Temp Alignment [only used once]
|
||||
UI7MenuFlags flags = 0; ///< Menu Flags
|
||||
u32 id; ///< Menu ID
|
||||
std::string name; ///< Menu Name
|
||||
vec2 cursor; ///< Current Cursor Position
|
||||
vec2 icursoroff; ///< Initial Cursor Offset (Also in Newline)
|
||||
vec2 bcursor; ///< Backup Cursor
|
||||
vec2 slcursor; ///< Sameline Cursor
|
||||
vec4 view_area; ///< view Area (Position and Size)
|
||||
vec4 main_area; ///< Main Area [Input related]
|
||||
vec2 scrolling_off; ///< Scrolling Position
|
||||
bool scrolling[2]; ///< Is Hz or Vt Scrolling Enabled
|
||||
vec2 scroll_mod; ///< Scroll Modificator
|
||||
float tbh; ///< Titlebar height
|
||||
bool scrollbar[2]; ///< Is Hz or Vt Scrollbar rendered
|
||||
bool scroll_allowed[2]; ///< Is Hz or Vt Scrolling Alowed
|
||||
@ -389,20 +277,9 @@ class Menu : public SmartCtor<Menu> {
|
||||
|
||||
// Objects API
|
||||
|
||||
std::vector<Container::Ref> objects; ///< Current frame Objects
|
||||
std::vector<Container::Ref> idobjs; ///< Objects using an ID
|
||||
std::vector<Container*> join; ///< List of Combined Objects
|
||||
int count_btn = 0; ///< Count for Button ID Prefix
|
||||
int count_cbx = 0; ///< Cound for Checkbox ID Prefix
|
||||
|
||||
// DrawList
|
||||
|
||||
DrawList::Ref main; ///< Main Drawlist
|
||||
|
||||
vec2 max; ///< Max Position
|
||||
vec2 mouse; ///< Mouse/Touch Position
|
||||
vec2 bslpos; ///< Before Sameline Position
|
||||
vec2 last_size; ///< Last Object Size
|
||||
std::vector<Container*> join; ///< List of Combined Objects
|
||||
int count_btn = 0; ///< Count for Button ID Prefix
|
||||
int count_cbx = 0; ///< Cound for Checkbox ID Prefix
|
||||
|
||||
UI7::IO::Ref io; ///< IO Reference
|
||||
|
||||
@ -410,7 +287,14 @@ class Menu : public SmartCtor<Menu> {
|
||||
|
||||
// Animations System
|
||||
|
||||
Tween<vec2> scroll_anim; ///< for Scroll to Animation
|
||||
Tween<fvec2> scroll_anim; ///< for Scroll to Animation
|
||||
|
||||
// Layout API
|
||||
PD::UI7::Layout::Ref Layout;
|
||||
|
||||
UI7Color clr_close_btn = UI7Color_FrameBackground;
|
||||
UI7Color clr_collapse_tri = UI7Color_FrameBackground;
|
||||
UI7Color header = UI7Color_HeaderDead;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
52
include/pd/ui7/pd_p_api.hpp
Normal file
52
include/pd/ui7/pd_p_api.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
#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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||
#ifdef PD_UI7_BUILD_SHARED
|
||||
#define PD_UI7_API __declspec(dllexport)
|
||||
#else
|
||||
#define PD_UI7_API __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined(__APPLE__) // macOS (untested yet)
|
||||
#ifdef PD_UI7_BUILD_SHARED
|
||||
#define PD_UI7_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_UI7_API
|
||||
#endif
|
||||
#elif defined(__linux__) // Linux (untested yet)
|
||||
#ifdef PD_UI7_BUILD_SHARED
|
||||
#define PD_UI7_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_UI7_API
|
||||
#endif
|
||||
#elif defined(__3DS__) // 3ds Specific
|
||||
// Only Static supported
|
||||
#define PD_UI7_API
|
||||
#else
|
||||
#define PD_UI7_API
|
||||
#endif
|
107
include/pd/ui7/remenu.hpp
Normal file
107
include/pd/ui7/remenu.hpp
Normal file
@ -0,0 +1,107 @@
|
||||
#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/ui7/layout.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* ReMenu (Should get something like MenuBase or so)
|
||||
* to define basic functionality and extend it by using this as a
|
||||
* template class
|
||||
*/
|
||||
class PD_UI7_API ReMenu {
|
||||
public:
|
||||
ReMenu(const UI7::ID& id, UI7::IO::Ref io) : pID(id) {
|
||||
pLayout = UI7::Layout::New(id, io);
|
||||
pIO = io;
|
||||
TitleBarHeight = io->FontScale * 30.f;
|
||||
pLayout->WorkRect.y += TitleBarHeight;
|
||||
pLayout->CursorInit();
|
||||
}
|
||||
~ReMenu() = default;
|
||||
/** Using the Legacy version here */
|
||||
PD_SMART_CTOR(ReMenu)
|
||||
|
||||
/**
|
||||
* Render a Simple Label
|
||||
* @param label The text to draw
|
||||
*/
|
||||
void Label(const std::string& label);
|
||||
/**
|
||||
* 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));
|
||||
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 = pLayout->FindObject(id);
|
||||
if (!r) {
|
||||
r = PD::New<UI7::DragData<T>>(label, data, num_elms, pIO, min, max, step,
|
||||
precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
pLayout->AddObject(r);
|
||||
}
|
||||
void Sameline() { pLayout->SameLine(); }
|
||||
void Separator();
|
||||
void SeparatorText(const std::string& label);
|
||||
|
||||
void HandleFocus();
|
||||
void HandleScrolling();
|
||||
void HandleTitlebarActions();
|
||||
void DrawBaseLayout();
|
||||
|
||||
void Update();
|
||||
|
||||
UI7MenuFlags Flags = 0;
|
||||
UI7::Layout::Ref pLayout;
|
||||
UI7::IO::Ref pIO;
|
||||
UI7::ID pID;
|
||||
bool* pIsShown = nullptr;
|
||||
bool pIsOpen = true;
|
||||
|
||||
float TitleBarHeight = 0.f;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -23,7 +23,8 @@ 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>
|
||||
#include <pd/ui7/pd_p_api.hpp>
|
||||
|
||||
/**
|
||||
* Using this to support 32bit color values as well as
|
||||
@ -34,6 +35,7 @@ using UI7Color = PD::u32;
|
||||
/** Theme Color */
|
||||
enum UI7Color_ {
|
||||
UI7Color_Background, ///< UI7 Menu Background
|
||||
UI7Color_Border, ///< Menu/Frame Border Color
|
||||
UI7Color_Button, ///< UI7 Button Idle Color
|
||||
UI7Color_ButtonDead, ///< UI7 Disabled Button Color
|
||||
UI7Color_ButtonActive, ///< UI7 Pressed Button Color
|
||||
@ -54,7 +56,7 @@ enum UI7Color_ {
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/** Theme Class */
|
||||
class Theme : public SmartCtor<Theme> {
|
||||
class PD_UI7_API Theme : public SmartCtor<Theme> {
|
||||
public:
|
||||
/**
|
||||
* Default Constructor Setting up the Default theme
|
||||
|
@ -23,13 +23,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/menu.hpp>
|
||||
#include <pd/ui7/remenu.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
/**
|
||||
* Declare UI7 Version
|
||||
@ -37,7 +37,7 @@ SOFTWARE.
|
||||
* Major Minor Patch Build
|
||||
* 0x01010000 -> 1.1.0-0
|
||||
*/
|
||||
#define UI7_VERSION 0x00030000
|
||||
#define UI7_VERSION 0x00040000
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
@ -46,9 +46,9 @@ namespace UI7 {
|
||||
* @param show_build Ahow build num (mostly unused)
|
||||
* @return Version String (1.0.0-1 for example)
|
||||
*/
|
||||
std::string GetVersion(bool show_build = false);
|
||||
PD_UI7_API std::string GetVersion(bool show_build = false);
|
||||
/** Base Context for UI7 */
|
||||
class Context : public SmartCtor<Context> {
|
||||
class PD_UI7_API Context : public SmartCtor<Context> {
|
||||
public:
|
||||
/**
|
||||
* Constructor for UI7 Context
|
||||
@ -69,6 +69,8 @@ class Context : public SmartCtor<Context> {
|
||||
* (useless as false results in an error screen)
|
||||
*/
|
||||
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0, bool* show = nullptr);
|
||||
bool DoMenuEx(const ID& id, UI7MenuFlags flags,
|
||||
std::function<void(ReMenu::Ref m)> f);
|
||||
/**
|
||||
* Get the Current Menu
|
||||
* for example for auto m = ctx->GetCurrentMenu
|
||||
@ -140,7 +142,9 @@ class Context : public SmartCtor<Context> {
|
||||
// Map of The Menus by ID
|
||||
std::unordered_map<u32, Menu::Ref> menus;
|
||||
std::vector<u32> amenus; ///< Active ones
|
||||
std::vector<u32> aml; ///< Copy of Active Menus
|
||||
Menu::Ref current; ///< Current Menu
|
||||
ReMenu::Ref Current;
|
||||
// IO
|
||||
IO::Ref io;
|
||||
};
|
||||
|
@ -1,138 +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 <3ds.h>
|
||||
|
||||
#include <pd/app/app.hpp>
|
||||
#include <pd/core/sys.hpp>
|
||||
#include <pd/lib3ds/hwinfo.hpp>
|
||||
|
||||
namespace PD {
|
||||
int App::too;
|
||||
|
||||
void App::Run() {
|
||||
this->PreInit();
|
||||
this->Init();
|
||||
last_time = Sys::GetNanoTime();
|
||||
while (aptMainLoop()) {
|
||||
input_mgr->Update();
|
||||
u64 current = Sys::GetNanoTime();
|
||||
float dt = static_cast<float>(current - last_time) / 1000000.f;
|
||||
app_time->Update();
|
||||
last_time = current;
|
||||
fps = 1000.f / dt;
|
||||
if (runtimeflags & AppFLags_UserLoop) {
|
||||
PD::TT::Beg("App_MainLoop");
|
||||
if (!this->MainLoop(dt, app_time->GetSeconds())) {
|
||||
break;
|
||||
}
|
||||
PD::TT::End("App_MainLoop");
|
||||
}
|
||||
PD::TT::Beg("Ovl_Update");
|
||||
if (runtimeflags & AppFlags_HandleOverlays &&
|
||||
SafeInitFlags & AppInitFlags_InitLithium) {
|
||||
renderer->Layer(90);
|
||||
overlay_mgr->Update(dt);
|
||||
}
|
||||
if (runtimeflags & AppFlags_HandleMessageMgr &&
|
||||
SafeInitFlags & AppInitFlags_InitLithium) {
|
||||
/// Messages have their own special Layer
|
||||
renderer->Layer(93);
|
||||
msg_mgr->Update(dt);
|
||||
}
|
||||
PD::TT::End("Ovl_Update");
|
||||
if (runtimeflags & AppFlags_HandleRendering &&
|
||||
SafeInitFlags & AppInitFlags_InitLithium) {
|
||||
renderer->PrepareRender();
|
||||
renderer->Render(Top);
|
||||
renderer->Render(Bottom);
|
||||
renderer->FinalizeRender();
|
||||
}
|
||||
}
|
||||
this->Deinit();
|
||||
this->PostDeinit();
|
||||
}
|
||||
|
||||
std::string App::GetDataDirectory() {
|
||||
Assert(SafeInitFlags & AppInitFlags_UnnamedOption1,
|
||||
"Data Dir is not enabled!");
|
||||
return "sdmc:/palladium/apps/" + name;
|
||||
}
|
||||
|
||||
void App::PreInit() {
|
||||
/// Create a Copy that won't get edit
|
||||
SafeInitFlags = InitFlags;
|
||||
osSetSpeedupEnable(InitFlags & AppInitFlags_New3dsMode);
|
||||
if (InitFlags & AppInitFlags_InitGraphics) {
|
||||
gfxInitDefault();
|
||||
if (!(InitFlags & AppInitFlags_InitGraphicsNoC3D)) {
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||
}
|
||||
}
|
||||
cfguInit();
|
||||
if (InitFlags & AppInitFlags_MountRomfs) {
|
||||
romfsInit();
|
||||
}
|
||||
if (InitFlags & AppInitFlags_InitHwInfo) {
|
||||
PD::HwInfo::Init();
|
||||
}
|
||||
if (InitFlags & AppInitFlags_UnnamedOption1) {
|
||||
std::filesystem::create_directories("sdmc:/palladium/apps/" + name);
|
||||
}
|
||||
input_mgr = PD::New<CtrHid>();
|
||||
if (InitFlags & AppInitFlags_InitLithium) {
|
||||
Assert(!(InitFlags & AppInitFlags_InitGraphicsNoC3D),
|
||||
"InitGraphicsNoC3D is not compatible with InitLithium!");
|
||||
Top = Screen::New(Screen::Top);
|
||||
Bottom = Screen::New(Screen::Bottom);
|
||||
renderer = LI::Renderer::New();
|
||||
renderer->RegisterScreen(false, Top);
|
||||
renderer->RegisterScreen(true, Bottom);
|
||||
renderer->OnScreen(Top);
|
||||
msg_mgr = MessageMgr::New(renderer);
|
||||
overlay_mgr = OverlayMgr::New(renderer, input_mgr);
|
||||
}
|
||||
app_time = Timer::New();
|
||||
}
|
||||
|
||||
void App::PostDeinit() {
|
||||
renderer = nullptr;
|
||||
msg_mgr = nullptr;
|
||||
overlay_mgr = nullptr;
|
||||
input_mgr = nullptr;
|
||||
if (SafeInitFlags & AppInitFlags_InitGraphics) {
|
||||
if (!(SafeInitFlags & AppInitFlags_InitGraphicsNoC3D)) {
|
||||
C3D_Fini();
|
||||
}
|
||||
gfxExit();
|
||||
}
|
||||
if (SafeInitFlags & AppInitFlags_InitHwInfo) {
|
||||
PD::HwInfo::Deinit();
|
||||
}
|
||||
cfguExit();
|
||||
if (SafeInitFlags & AppInitFlags_MountRomfs) {
|
||||
romfsExit();
|
||||
}
|
||||
}
|
||||
} // namespace PD
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
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/app/lang.hpp>
|
||||
#include <pd/external/json.hpp>
|
||||
|
||||
namespace PD {
|
||||
void Lang::LoadFile(const std::string &path) {
|
||||
nlohmann::json js;
|
||||
std::fstream iff(path, std::ios::in);
|
||||
if (iff.is_open()) {
|
||||
js = nlohmann::json::parse(iff);
|
||||
iff.close();
|
||||
if (js.is_discarded()) {
|
||||
return;
|
||||
}
|
||||
if (!js.contains("ver") || !js.contains("id") || !js.contains("name") ||
|
||||
!js.contains("author") || !js.contains("keys")) {
|
||||
return;
|
||||
}
|
||||
if (js["ver"].get<int>() != ver) {
|
||||
return;
|
||||
}
|
||||
lang_id = js["id"];
|
||||
lang_name = js["name"];
|
||||
lang_author = js["author"];
|
||||
ltable.clear();
|
||||
for (auto k : js["keys"].items()) {
|
||||
ltable.insert(std::make_pair(k.key(), k.value().get<std::string>()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::string &Lang::Get(const std::string &k) {
|
||||
auto e = ltable.find(k);
|
||||
if (e != ltable.end()) {
|
||||
return e->second;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
} // namespace PD
|
@ -24,8 +24,8 @@ SOFTWARE.
|
||||
#include <pd/core/bit_util.hpp>
|
||||
|
||||
namespace PD::BitUtil {
|
||||
bool IsSingleBit(u32 v) { return v && !(v & (v - 1)); }
|
||||
u32 GetPow2(u32 v) {
|
||||
PD_CORE_API bool IsSingleBit(u32 v) { return v && !(v & (v - 1)); }
|
||||
PD_CORE_API u32 GetPow2(u32 v) {
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user