Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfb6a9b3dd
|
||
|
|
799e779fe6
|
||
|
|
7f708a565e
|
||
|
|
280ce524bf
|
||
|
|
b99fc39444
|
||
|
|
6dbf5a4812
|
||
|
|
ff3b241dd2
|
||
|
|
7a1751589e
|
||
|
|
8a4b3c119d
|
||
|
|
1f7d96a455
|
||
|
|
c9768010f2
|
||
|
|
679de3ae94
|
||
|
|
af7fc026df
|
||
|
|
5bc8046ebe
|
||
|
|
8215baac99
|
||
|
|
a776addf11
|
||
|
|
1cf3b6f8e6
|
||
|
|
b5321ca1a1
|
||
|
|
4498c2c0fb
|
||
|
|
818b086f08
|
||
|
|
e560496512
|
||
|
|
7b6e611f12
|
||
|
|
72deaad28d
|
||
|
|
2e652a3c24
|
||
|
|
784421fa6c
|
||
|
|
bc06a3fee8
|
@@ -1,4 +1,5 @@
|
||||
CompileFlags:
|
||||
CompilationDatabase: build/default-release
|
||||
Add: []
|
||||
|
||||
Completion:
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
build*/
|
||||
.cache
|
||||
.vscode
|
||||
.vscode
|
||||
.DS_Store
|
||||
+84
-72
@@ -15,62 +15,72 @@ option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
|
||||
option(PD_INCLUDE_STB_IMAGE "Inlude stb image symbols in palladium" ON)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
add_compile_options(-Wno-psabi)
|
||||
add_compile_options(-Wno-psabi)
|
||||
endif()
|
||||
|
||||
if(${PD_BUILD_TOOLS})
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(tools)
|
||||
endif()
|
||||
|
||||
add_subdirectory(vendor)
|
||||
|
||||
# # Include Library Source
|
||||
set(PD_SOURCES
|
||||
# Common
|
||||
source/common.cpp
|
||||
# Common
|
||||
source/common.cpp
|
||||
|
||||
# Core
|
||||
source/core/bits.cpp
|
||||
source/core/color.cpp
|
||||
source/core/io.cpp
|
||||
source/core/mat.cpp
|
||||
source/core/strings.cpp
|
||||
source/core/timer.cpp
|
||||
source/core/timetrace.cpp
|
||||
# Core
|
||||
source/core/bits.cpp
|
||||
source/core/color.cpp
|
||||
source/core/io.cpp
|
||||
source/core/mat.cpp
|
||||
source/core/strings.cpp
|
||||
source/core/timer.cpp
|
||||
source/core/timetrace.cpp
|
||||
|
||||
# Image
|
||||
source/image/image.cpp
|
||||
# Image
|
||||
source/image/image.cpp
|
||||
|
||||
# Drivers
|
||||
source/drivers/os.cpp
|
||||
source/drivers/gfx.cpp
|
||||
# Drivers
|
||||
source/drivers/os.cpp
|
||||
source/drivers/gfx.cpp
|
||||
source/drivers/hid.cpp
|
||||
|
||||
# Lithium
|
||||
source/lithium/drawlist.cpp
|
||||
source/lithium/font.cpp
|
||||
source/lithium/math.cpp
|
||||
source/lithium/pools.cpp
|
||||
# Lithium
|
||||
source/lithium/drawlist.cpp
|
||||
source/lithium/font.cpp
|
||||
source/lithium/math.cpp
|
||||
source/lithium/pools.cpp
|
||||
|
||||
# Ultra
|
||||
source/ultra/canvas.cpp
|
||||
source/ultra/layout.cpp
|
||||
source/ultra/elems/element.cpp
|
||||
source/ultra/elems/rect.cpp
|
||||
source/ultra/elems/text.cpp
|
||||
source/ultra/elems/image.cpp
|
||||
source/ultra/elems/button.cpp
|
||||
)
|
||||
|
||||
if(${PD_BUILD_SHARED})
|
||||
add_library(palladium SHARED ${PD_SOURCES})
|
||||
target_compile_definitions(palladium PRIVATE PD_BUILD_SHARED)
|
||||
add_library(palladium SHARED ${PD_SOURCES})
|
||||
target_compile_definitions(palladium PRIVATE PD_BUILD_SHARED)
|
||||
else()
|
||||
add_library(palladium STATIC ${PD_SOURCES})
|
||||
target_compile_definitions(palladium PUBLIC PD_BUILD_STATIC)
|
||||
add_library(palladium STATIC ${PD_SOURCES})
|
||||
target_compile_definitions(palladium PUBLIC PD_BUILD_STATIC)
|
||||
endif()
|
||||
|
||||
target_link_libraries(palladium
|
||||
PUBLIC stb
|
||||
PUBLIC stb
|
||||
)
|
||||
|
||||
target_compile_definitions(palladium
|
||||
PUBLIC
|
||||
PD_DEBUG
|
||||
$<$<OR:$<BOOL:${PD_INCLUDE_STB_IMAGE}>,$<BOOL:${PD_BUILD_SHARED}>>:PD_INCLUDE_STB_IMAGE> # Always on in shared build
|
||||
PUBLIC
|
||||
PD_DEBUG
|
||||
$<$<OR:$<BOOL:${PD_INCLUDE_STB_IMAGE}>,$<BOOL:${PD_BUILD_SHARED}>>:PD_INCLUDE_STB_IMAGE> # Always on in shared build
|
||||
)
|
||||
target_compile_options(palladium
|
||||
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
|
||||
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
|
||||
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/source=source
|
||||
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/include=include
|
||||
>
|
||||
@@ -79,76 +89,78 @@ target_compile_options(palladium
|
||||
add_library(palladium::palladium ALIAS palladium)
|
||||
|
||||
target_include_directories(palladium
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
target_compile_options(palladium
|
||||
PRIVATE
|
||||
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU,Clang>>:-O0 -g>
|
||||
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:GNU,Clang>>:-O3>
|
||||
PRIVATE
|
||||
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU,Clang>>:-O0 -g>
|
||||
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:GNU,Clang>>:-O3>
|
||||
|
||||
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Od /Zi>
|
||||
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2>
|
||||
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Od /Zi>
|
||||
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2>
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS palladium
|
||||
EXPORT palladiumTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
TARGETS palladium
|
||||
EXPORT palladiumTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
install(
|
||||
DIRECTORY include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
DIRECTORY include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
install(EXPORT palladiumTargets
|
||||
FILE palladiumTargets.cmake
|
||||
NAMESPACE palladium::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||
FILE palladiumTargets.cmake
|
||||
NAMESPACE palladium::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||
)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(
|
||||
cmake/palladiumConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
|
||||
INSTALL_DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||
cmake/palladiumConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
|
||||
INSTALL_DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
|
||||
VERSION
|
||||
${PROJECT_VERSION}
|
||||
COMPATIBILITY
|
||||
SameMajorVersion
|
||||
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
|
||||
VERSION
|
||||
${PROJECT_VERSION}
|
||||
COMPATIBILITY
|
||||
SameMajorVersion
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||
FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||
)
|
||||
|
||||
find_program(CLANG_FORMAT clang-format)
|
||||
|
||||
file(GLOB_RECURSE PD_FMTFILES
|
||||
CONFIGURE_DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/backends/source/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/backends/include/*.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/core/source/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/gfx/source/*.cpp
|
||||
CONFIGURE_DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/backends/source/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/backends/include/*.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/core/source/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/gfx/source/*.cpp
|
||||
)
|
||||
|
||||
add_custom_target(pd-clang-format
|
||||
COMMAND ${CLANG_FORMAT} --style=file -i ${PD_FMTFILES}
|
||||
COMMENT "Formatting Project Sources"
|
||||
COMMAND ${CLANG_FORMAT} --style=file -i ${PD_FMTFILES}
|
||||
COMMENT "Formatting Project Sources"
|
||||
)
|
||||
|
||||
add_subdirectory(backends)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": 10,
|
||||
"cmakeMinimumRequired": {
|
||||
"major": 3,
|
||||
"minor": 22,
|
||||
"patch": 0
|
||||
},
|
||||
"include": [
|
||||
"cmake/presets/default.json",
|
||||
"cmake/presets/3ds.json",
|
||||
"cmake/presets/switch.json",
|
||||
"cmake/presets/msvc.json"
|
||||
]
|
||||
}
|
||||
+49
-55
@@ -7,86 +7,80 @@ option(PD_ENABLE_OPENGL3 "Enable OpenGL 3.3 (On Supported Hardware)" ON)
|
||||
option(PD_ENABLE_DIRECTX9 "Enable DirectX9 Support" ON)
|
||||
option(PD_ENABLE_CITRO3D "Enable Citro3D Support (3DS)" OFF)
|
||||
option(PD_ENABLE_VULKAN "Not implemented yet" OFF)
|
||||
option(PD_ENABLE_HID_GLFW "Enable GLFW Input Driver" ON)
|
||||
option(PD_ENABLE_HID_NX "Enable NX Input Driver" OFF)
|
||||
|
||||
if(NOT WIN32) # cause we are not on windows...
|
||||
set(PD_ENABLE_DIRECTX9 OFF)
|
||||
set(PD_ENABLE_DIRECTX9 OFF)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
set(PD_ENABLE_OPENGL2 OFF)
|
||||
set(PD_ENABLE_OPENGL3 OFF)
|
||||
set(PD_ENABLE_VULKAN OFF)
|
||||
set(PD_ENABLE_CITRO3D ON)
|
||||
set(PD_ENABLE_OPENGL2 OFF)
|
||||
set(PD_ENABLE_OPENGL3 OFF)
|
||||
set(PD_ENABLE_VULKAN OFF)
|
||||
set(PD_ENABLE_CITRO3D ON)
|
||||
set(PD_ENABLE_HID_GLFW OFF)
|
||||
set(PD_ENABLE_HID_NX OFF)
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "NintendoSwitch")
|
||||
set(PD_ENABLE_OPENGL2 OFF)
|
||||
set(PD_ENABLE_OPENGL3 ON)
|
||||
set(PD_ENABLE_VULKAN OFF)
|
||||
set(PD_ENABLE_CITRO3D OFF)
|
||||
set(PD_ENABLE_OPENGL2 OFF)
|
||||
set(PD_ENABLE_OPENGL3 ON)
|
||||
set(PD_ENABLE_VULKAN OFF)
|
||||
set(PD_ENABLE_CITRO3D OFF)
|
||||
set(PD_ENABLE_HID_NX ON) # Best case for Nintendo Switch
|
||||
set(PD_ENABLE_HID_GLFW ON) # Technically supported but not recommended
|
||||
endif()
|
||||
|
||||
add_library(pd-system STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gl-helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl2.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl3.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gl-helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl2.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl3.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/hid_glfw.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/hid_nx.cpp
|
||||
)
|
||||
|
||||
target_include_directories(pd-system
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
# Why is this not a default include (same problem as with the __SWITCH__ define)
|
||||
$<$<STREQUAL:${CMAKE_SYSTEM_NAME},NintendoSwitch>:${DEVKITPRO}/portlibs/switch/include>
|
||||
)
|
||||
|
||||
target_compile_options(palladium
|
||||
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
|
||||
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
|
||||
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/source=source
|
||||
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/include=include
|
||||
>
|
||||
)
|
||||
|
||||
target_compile_definitions(pd-system
|
||||
PUBLIC
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL2}>:PD_ENABLE_OPENGL2>
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL3}>:PD_ENABLE_OPENGL3>
|
||||
$<$<BOOL:${PD_ENABLE_VULKAN}>:PD_ENABLE_VULKAN>
|
||||
$<$<BOOL:${PD_ENABLE_DIRECTX9}>:PD_ENABLE_DIRECTX9>
|
||||
$<$<BOOL:${PD_ENABLE_CITRO3D}>:PD_ENABLE_CITRO3D>
|
||||
PUBLIC
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL2}>:PD_ENABLE_OPENGL2>
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL3}>:PD_ENABLE_OPENGL3>
|
||||
$<$<BOOL:${PD_ENABLE_VULKAN}>:PD_ENABLE_VULKAN>
|
||||
$<$<BOOL:${PD_ENABLE_DIRECTX9}>:PD_ENABLE_DIRECTX9>
|
||||
$<$<BOOL:${PD_ENABLE_CITRO3D}>:PD_ENABLE_CITRO3D>
|
||||
$<$<BOOL:${PD_ENABLE_HID_GLFW}>:PD_ENABLE_HID_GLFW>
|
||||
$<$<BOOL:${PD_ENABLE_HID_NX}>:PD_ENABLE_HID_NX>
|
||||
)
|
||||
|
||||
# Palladium
|
||||
target_link_libraries(pd-system PUBLIC palladium::palladium)
|
||||
|
||||
# glad (if we have any OpenGL version included)
|
||||
if(PD_ENABLE_OPENGL2 OR PD_ENABLE_OPENGL3)
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC glad
|
||||
)
|
||||
endif()
|
||||
|
||||
# DirectX9
|
||||
if(PD_ENABLE_DIRECTX9)
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC
|
||||
d3d9
|
||||
d3dcompiler
|
||||
)
|
||||
endif()
|
||||
# Depandant Lib includes (i love this cmake feature)
|
||||
target_link_libraries(pd-system PUBLIC
|
||||
$<$<BOOL:${PD_ENABLE_DIRECTX9}>:d3d9 d3dcompiler> # DirectX9
|
||||
$<$<BOOL:${PD_ENABLE_CITRO3D}>:pica::pica citro3d ctru> # 3ds
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL3}>:spirv-helper> # OpenGL3
|
||||
# Include Glad if we have any OpenGL Usage
|
||||
$<$<OR:$<BOOL:${PD_ENABLE_OPENGL2}>,$<BOOL:${PD_ENABLE_OPENGL3}>>:glad>
|
||||
$<$<BOOL:${PD_ENABLE_HID_NX}>:nx> # Hid NX requirement
|
||||
# Hid GLFW requirement
|
||||
$<$<BOOL:${PD_ENABLE_HID_GLFW}>:
|
||||
$<$<STREQUAL:${CMAKE_SYSTEM_NAME},NintendoSwitch>:glfw3>
|
||||
$<$<NOT:$<STREQUAL:${CMAKE_SYSTEM_NAME},NintendoSwitch>>:glfw>>
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC
|
||||
pica::pica
|
||||
citro3d
|
||||
ctru
|
||||
)
|
||||
else()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "NintendoSwitch")
|
||||
target_include_directories(pd-system
|
||||
PUBLIC $ENV{DEVKITPRO}/portlibs/switch/include
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC spirv-helper
|
||||
)
|
||||
endif()
|
||||
)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/hid.hpp>
|
||||
|
||||
typedef struct GLFWwindow GLFWwindow;
|
||||
typedef struct GLFWgamepadstate GLFWgamepadstate;
|
||||
|
||||
namespace PD {
|
||||
class HidGlfw : public HidDriver {
|
||||
public:
|
||||
HidGlfw(GLFWwindow* window);
|
||||
~HidGlfw();
|
||||
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
void HandleAxisKey(GLFWgamepadstate s, int iK, int eA, bool negative);
|
||||
struct Impl;
|
||||
Impl* impl;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/hid.hpp>
|
||||
|
||||
namespace PD {
|
||||
class HidNX : public HidDriver {
|
||||
public:
|
||||
HidNX();
|
||||
~HidNX();
|
||||
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
Impl* impl;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,6 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
// Gfx
|
||||
#include <pd_system/gfx_citro3d.hpp>
|
||||
#include <pd_system/gfx_directx9.hpp>
|
||||
#include <pd_system/gfx_opengl2.hpp>
|
||||
#include <pd_system/gfx_opengl3.hpp>
|
||||
|
||||
// Hid
|
||||
#include <pd_system/hid_glfw.hpp>
|
||||
@@ -119,7 +119,7 @@ void GfxCitro3D::SysInit() {
|
||||
if (impl) return;
|
||||
PDLOG("GfxCitro3D::SysInit();");
|
||||
impl = new Impl();
|
||||
Flags |= PDBackendFlags_FlipUV_Y;
|
||||
Flags |= PDGfxBackendFlags_FlipUV_Y;
|
||||
impl->pShaderRaw = Pica::AssembleCode(LIShaderCTR);
|
||||
impl->pCode = DVLB_ParseFile((uint32_t*)impl->pShaderRaw.data(),
|
||||
impl->pShaderRaw.size());
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
#include <pd_system/hid_glfw.hpp>
|
||||
#ifdef PD_ENABLE_HID_GLFW
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace PD {
|
||||
struct HidGlfw::Impl {
|
||||
GLFWwindow* Win;
|
||||
int PrevState;
|
||||
std::unordered_map<int, int> PrevStates;
|
||||
std::unordered_map<int, int> GPPrevStates;
|
||||
GLFWcharfun OldTextCB;
|
||||
std::string* Text;
|
||||
bool InTextMode = false;
|
||||
};
|
||||
|
||||
constexpr int KEY_BASE = GLFW_GAMEPAD_BUTTON_LAST;
|
||||
constexpr int KEY_LSTICK_LEFT = KEY_BASE + 1;
|
||||
constexpr int KEY_LSTICK_RIGHT = KEY_BASE + 2;
|
||||
constexpr int KEY_LSTICK_UP = KEY_BASE + 3;
|
||||
constexpr int KEY_LSTICK_DOWN = KEY_BASE + 4;
|
||||
constexpr int KEY_RSTICK_LEFT = KEY_BASE + 5;
|
||||
constexpr int KEY_RSTICK_RIGHT = KEY_BASE + 6;
|
||||
constexpr int KEY_RSTICK_UP = KEY_BASE + 7;
|
||||
constexpr int KEY_RSTICK_DOWN = KEY_BASE + 8;
|
||||
constexpr int KEY_LEFT_TRIGGER = KEY_BASE + 9;
|
||||
constexpr int KEY_RIGHT_TRIGGER = KEY_BASE + 10;
|
||||
constexpr int KEY_LAST = KEY_RIGHT_TRIGGER;
|
||||
|
||||
HidGlfw::HidGlfw(GLFWwindow* win) : HidDriver("HidGlfw") {
|
||||
impl = new Impl;
|
||||
impl->Win = win;
|
||||
|
||||
pFlags |= PDHidBackendFlags_HasMouse;
|
||||
pFlags |= PDHidBackendFlags_HasKeyboard;
|
||||
if (glfwJoystickPresent(GLFW_JOYSTICK_1)) {
|
||||
pFlags |= PDHidBackendFlags_HasGamepad;
|
||||
}
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_A] = HidInternal::Gamepad::A;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_B] = HidInternal::Gamepad::B;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_X] = HidInternal::Gamepad::X;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_Y] = HidInternal::Gamepad::Y;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_START] = HidInternal::Gamepad::Start;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_BACK] = HidInternal::Gamepad::Select;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_DPAD_LEFT] = HidInternal::Gamepad::DLeft;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_DPAD_RIGHT] = HidInternal::Gamepad::DRight;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_DPAD_UP] = HidInternal::Gamepad::DUp;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_DPAD_DOWN] = HidInternal::Gamepad::DDown;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_LEFT_BUMPER] = HidInternal::Gamepad::L;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER] = HidInternal::Gamepad::R;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_LEFT_THUMB] = HidInternal::Gamepad::LStick;
|
||||
pGamepad[GLFW_GAMEPAD_BUTTON_RIGHT_THUMB] = HidInternal::Gamepad::RStick;
|
||||
pGamepad[KEY_LEFT_TRIGGER] = HidInternal::Gamepad::ZL;
|
||||
pGamepad[KEY_RIGHT_TRIGGER] = HidInternal::Gamepad::ZR;
|
||||
pGamepad[KEY_LSTICK_LEFT] = HidInternal::Gamepad::CPLeft;
|
||||
pGamepad[KEY_LSTICK_RIGHT] = HidInternal::Gamepad::CPRight;
|
||||
pGamepad[KEY_LSTICK_UP] = HidInternal::Gamepad::CPUp;
|
||||
pGamepad[KEY_LSTICK_DOWN] = HidInternal::Gamepad::CPDown;
|
||||
pGamepad[KEY_RSTICK_LEFT] = HidInternal::Gamepad::CSLeft;
|
||||
pGamepad[KEY_RSTICK_RIGHT] = HidInternal::Gamepad::CSRight;
|
||||
pGamepad[KEY_RSTICK_UP] = HidInternal::Gamepad::CSUp;
|
||||
pGamepad[KEY_RSTICK_DOWN] = HidInternal::Gamepad::CSDown;
|
||||
for (int i = 0; i <= KEY_LAST; i++) {
|
||||
impl->GPPrevStates[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
HidGlfw::~HidGlfw() {}
|
||||
|
||||
void HidGlfw::Update() {
|
||||
HidDriver::Update(); // clear stats
|
||||
GLFWgamepadstate gpstate;
|
||||
int gps = glfwGetGamepadState(GLFW_JOYSTICK_1, &gpstate);
|
||||
if (gps == GLFW_TRUE) {
|
||||
HandleAxisKey(gpstate, KEY_LEFT_TRIGGER, GLFW_GAMEPAD_AXIS_LEFT_TRIGGER,
|
||||
false);
|
||||
HandleAxisKey(gpstate, KEY_RIGHT_TRIGGER, GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER,
|
||||
false);
|
||||
HandleAxisKey(gpstate, KEY_LSTICK_LEFT, GLFW_GAMEPAD_AXIS_LEFT_X, true);
|
||||
HandleAxisKey(gpstate, KEY_LSTICK_RIGHT, GLFW_GAMEPAD_AXIS_LEFT_X, false);
|
||||
HandleAxisKey(gpstate, KEY_LSTICK_UP, GLFW_GAMEPAD_AXIS_LEFT_Y, true);
|
||||
HandleAxisKey(gpstate, KEY_LSTICK_DOWN, GLFW_GAMEPAD_AXIS_LEFT_Y, false);
|
||||
HandleAxisKey(gpstate, KEY_RSTICK_LEFT, GLFW_GAMEPAD_AXIS_RIGHT_X, true);
|
||||
HandleAxisKey(gpstate, KEY_RSTICK_RIGHT, GLFW_GAMEPAD_AXIS_RIGHT_X, false);
|
||||
HandleAxisKey(gpstate, KEY_RSTICK_UP, GLFW_GAMEPAD_AXIS_RIGHT_Y, true);
|
||||
HandleAxisKey(gpstate, KEY_RSTICK_DOWN, GLFW_GAMEPAD_AXIS_RIGHT_Y, false);
|
||||
pLStick[0].x = gpstate.axes[GLFW_GAMEPAD_AXIS_LEFT_X];
|
||||
pLStick[0].y = gpstate.axes[GLFW_GAMEPAD_AXIS_LEFT_Y];
|
||||
pRStick[0].x = gpstate.axes[GLFW_GAMEPAD_AXIS_RIGHT_X];
|
||||
pRStick[0].y = gpstate.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y];
|
||||
for (int i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++) {
|
||||
if (gpstate.buttons[i] == GLFW_PRESS) {
|
||||
if (impl->GPPrevStates[i] == GLFW_RELEASE) {
|
||||
pGamepadEvents[0][Event::Down] |= pGamepad[i];
|
||||
}
|
||||
pGamepadEvents[0][Event::Held] |= pGamepad[i];
|
||||
} else if (gpstate.buttons[i] == GLFW_RELEASE &&
|
||||
impl->GPPrevStates[i] == GLFW_PRESS) {
|
||||
pGamepadEvents[0][Event::Up] |= pGamepad[i];
|
||||
}
|
||||
impl->GPPrevStates[i] = gpstate.buttons[i];
|
||||
}
|
||||
}
|
||||
int state = glfwGetMouseButton(impl->Win, GLFW_MOUSE_BUTTON_LEFT);
|
||||
if (state == GLFW_PRESS) {
|
||||
if (impl->PrevState == GLFW_RELEASE) {
|
||||
pGamepadEvents[0][Event::Down] |= HidInternal::Touch;
|
||||
}
|
||||
pGamepadEvents[0][Event::Held] |= HidInternal::Touch;
|
||||
} else if (state == GLFW_RELEASE && impl->PrevState == GLFW_PRESS) {
|
||||
pGamepadEvents[0][Event::Up] |= HidInternal::Touch;
|
||||
}
|
||||
|
||||
impl->PrevState = state;
|
||||
// if (pLocked) {
|
||||
// SwapTab();
|
||||
// }
|
||||
double x, y;
|
||||
glfwGetCursorPos(impl->Win, &x, &y);
|
||||
pMouse[0] = fvec2(x, y);
|
||||
}
|
||||
|
||||
void HidGlfw::HandleAxisKey(GLFWgamepadstate s, int iK, int eA, bool negative) {
|
||||
if (s.axes[eA] <= 1.f && s.axes[eA] >= -1.f) {
|
||||
if (s.axes[eA] > 0.05f && !negative) {
|
||||
if (impl->GPPrevStates[iK] == GLFW_RELEASE) {
|
||||
pGamepadEvents[0][Event::Down] |= pGamepad[iK];
|
||||
}
|
||||
pGamepadEvents[0][Event::Held] |= pGamepad[iK];
|
||||
}
|
||||
if (s.axes[eA] < -0.05f && negative) {
|
||||
if (impl->GPPrevStates[iK] == GLFW_RELEASE) {
|
||||
pGamepadEvents[0][Event::Down] |= pGamepad[iK];
|
||||
}
|
||||
pGamepadEvents[0][Event::Held] |= pGamepad[iK];
|
||||
}
|
||||
}
|
||||
impl->GPPrevStates[iK] = (s.axes[eA] <= -0.05 && s.axes[eA] >= 0.05 &&
|
||||
s.axes[eA] >= -1.f && s.axes[eA] <= 1);
|
||||
}
|
||||
} // namespace PD
|
||||
#else
|
||||
struct GLFWgamepadstate {};
|
||||
namespace PD {
|
||||
|
||||
HidGlfw::HidGlfw(GLFWwindow* win) : HidDriver("HidGlfw") {}
|
||||
|
||||
HidGlfw::~HidGlfw() {}
|
||||
|
||||
void HidGlfw::Update() {
|
||||
HidDriver::Update(); // clear stats
|
||||
}
|
||||
void HidGlfw::HandleAxisKey(GLFWgamepadstate s, int iK, int eA, bool negative) {
|
||||
}
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
#include <pd_system/hid_nx.hpp>
|
||||
|
||||
#ifdef PD_ENABLE_HID_NX
|
||||
#include <switch.h>
|
||||
|
||||
namespace PD {
|
||||
struct HidNX::Impl {
|
||||
PadState Pad;
|
||||
};
|
||||
|
||||
HidNX::HidNX() : HidDriver("HidNX") { impl = new Impl; }
|
||||
|
||||
HidNX::~HidNX() {}
|
||||
|
||||
void HidNX::Update() {
|
||||
HidDriver::Update(); // clear stats
|
||||
}
|
||||
} // namespace PD
|
||||
#else
|
||||
namespace PD {
|
||||
|
||||
HidNX::HidNX() : HidDriver("HidNX") {}
|
||||
|
||||
HidNX::~HidNX() {}
|
||||
|
||||
void HidNX::Update() {
|
||||
HidDriver::Update(); // clear stats
|
||||
}
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"version": 10,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "3ds-debug",
|
||||
"generator": "Ninja",
|
||||
"displayName": "Nintendo 3DS Debug",
|
||||
"binaryDir": "${sourceDir}/build/3ds-debug",
|
||||
"toolchainFile": "/opt/devkitPro/cmake/3DS.cmake",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "3ds-release",
|
||||
"generator": "Ninja",
|
||||
"displayName": "Nintendo 3DS Release",
|
||||
"binaryDir": "${sourceDir}/build/3ds-release",
|
||||
"toolchainFile": "/opt/devkitPro/cmake/3DS.cmake",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "3ds-release",
|
||||
"configurePreset": "3ds-release"
|
||||
},
|
||||
{
|
||||
"name": "3ds-debug",
|
||||
"configurePreset": "3ds-debug"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"version": 10,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "default-debug",
|
||||
"generator": "Ninja",
|
||||
"displayName": "Default Debug",
|
||||
"binaryDir": "${sourceDir}/build/default-debug",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "default-release",
|
||||
"generator": "Ninja",
|
||||
"displayName": "Default Release",
|
||||
"binaryDir": "${sourceDir}/build/default-release",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "default-release",
|
||||
"configurePreset": "default-release"
|
||||
},
|
||||
{
|
||||
"name": "default-debug",
|
||||
"configurePreset": "default-debug"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": 10,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "msvc",
|
||||
"cmakeExecutable": "C:\\Program Files\\CMake\\bin\\cmake.exe",
|
||||
"displayName": "MSVC",
|
||||
"generator": "Visual Studio 17 2022",
|
||||
"binaryDir": "${sourceDir}/build/msvc-build"
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "msvc-release",
|
||||
"configuration": "Release",
|
||||
"configurePreset": "msvc"
|
||||
},
|
||||
{
|
||||
"name": "msvc-debug",
|
||||
"configuration": "Debug",
|
||||
"configurePreset": "msvc"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"version": 10,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "switch-debug",
|
||||
"generator": "Ninja",
|
||||
"displayName": "Nintendo Switch Debug",
|
||||
"binaryDir": "${sourceDir}/build/switch-debug",
|
||||
"toolchainFile": "/opt/devkitPro/cmake/Switch.cmake",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"SPV_EXCLUDE_GLSLANG": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "switch-release",
|
||||
"generator": "Ninja",
|
||||
"displayName": "Nintendo Switch Release",
|
||||
"binaryDir": "${sourceDir}/build/switch-release",
|
||||
"toolchainFile": "/opt/devkitPro/cmake/Switch.cmake",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"SPV_EXCLUDE_GLSLANG": "ON"
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "switch-release",
|
||||
"configurePreset": "switch-release"
|
||||
},
|
||||
{
|
||||
"name": "switch-debug",
|
||||
"configurePreset": "switch-debug"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -71,6 +71,12 @@ class PD_API Color {
|
||||
*/
|
||||
constexpr Color(const std::string_view& hex) { Hex(hex); }
|
||||
|
||||
/**
|
||||
* Constructor for Hex Input (is abel to run at compile time xD)
|
||||
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
||||
*/
|
||||
constexpr Color(const char* hex) { Hex(std::string_view{hex}); }
|
||||
|
||||
/**
|
||||
* Create Color Object by Hex String (at compile time btw)
|
||||
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
||||
@@ -115,6 +121,20 @@ class PD_API Color {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lerp
|
||||
* @param v Target color
|
||||
* @param t interpolation factor
|
||||
* @return Class Reference
|
||||
*/
|
||||
constexpr Color& Lerp(const Color& v, float t) {
|
||||
a = static_cast<u8>(a + (v.a - a) * t);
|
||||
b = static_cast<u8>(b + (v.b - b) * t);
|
||||
g = static_cast<u8>(g + (v.g - g) * t);
|
||||
r = static_cast<u8>(r + (v.r - r) * t);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get 32Bit Color Value
|
||||
* @return 32Bit Color Value (ABGR iirc)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
#include <pd/lithium/pools.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using PDBackendFlags = PD::u32;
|
||||
enum PDBackendFlags_ {
|
||||
PDBackendFlags_None = 0,
|
||||
PDBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading
|
||||
PDBackendFlags_WindingCW = 1 << 0, // Use CW instead of CCW winding
|
||||
using PDGfxBackendFlags = PD::u32;
|
||||
enum PDGfxBackendFlags_ {
|
||||
PDGfxBackendFlags_None = 0,
|
||||
PDGfxBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading
|
||||
PDGfxBackendFlags_WindingCW = 1 << 0, // Use CW instead of CCW winding
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
@@ -40,7 +40,7 @@ class PD_API GfxDriver : public DriverInterface {
|
||||
virtual void DeleteTexture(const Li::Texture& tex) {}
|
||||
virtual void Draw(const Pool<Li::Command>& commands) {}
|
||||
Li::Texture::Ptr GetWhiteTexture() { return &pWhite; }
|
||||
PDBackendFlags GetFlags() { return Flags; }
|
||||
PDGfxBackendFlags GetFlags() { return Flags; }
|
||||
|
||||
size_t GetNumVertices() const { return CountVertices; }
|
||||
size_t GetNumIndices() const { return CountIndices; }
|
||||
@@ -70,7 +70,7 @@ class PD_API GfxDriver : public DriverInterface {
|
||||
ivec2 ViewPort;
|
||||
std::unordered_map<TextureID, Li::Texture> pTextureRegestry;
|
||||
Li::Texture pWhite;
|
||||
PDBackendFlags Flags = 0;
|
||||
PDGfxBackendFlags Flags = 0;
|
||||
};
|
||||
|
||||
struct DefaultGfxConfig {
|
||||
@@ -174,7 +174,7 @@ class PD_API Gfx {
|
||||
return driver->GetWhiteTexture();
|
||||
}
|
||||
|
||||
static PDBackendFlags GetFlags() { return driver->GetFlags(); }
|
||||
static PDGfxBackendFlags GetFlags() { return driver->GetFlags(); }
|
||||
|
||||
static const char* GetDriverName() { return driver->GetName(); }
|
||||
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/drivers/interface.hpp>
|
||||
|
||||
using PDHidBackendFlags = PD::u32;
|
||||
enum PDHidBackendFlags_ {
|
||||
PDHidBackendFlags_None = 0,
|
||||
PDHidBackendFlags_HasTouch = 1 << 1,
|
||||
PDHidBackendFlags_HasGamepad = 1 << 2,
|
||||
PDHidBackendFlags_HasMouse = 1 << 3,
|
||||
PDHidBackendFlags_HasKeyboard = 1 << 4,
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace HidInternal {
|
||||
class Keyboard {
|
||||
public:
|
||||
Keyboard() = default;
|
||||
virtual ~Keyboard() = default;
|
||||
using Key = u128;
|
||||
constexpr static Key No = 0;
|
||||
constexpr static Key Escape = Key::Flag(0);
|
||||
constexpr static Key Q = Key::Flag(1);
|
||||
constexpr static Key W = Key::Flag(2);
|
||||
constexpr static Key E = Key::Flag(3);
|
||||
constexpr static Key R = Key::Flag(4);
|
||||
constexpr static Key T = Key::Flag(5);
|
||||
constexpr static Key Z = Key::Flag(6);
|
||||
constexpr static Key U = Key::Flag(7);
|
||||
constexpr static Key I = Key::Flag(8);
|
||||
constexpr static Key O = Key::Flag(9);
|
||||
constexpr static Key P = Key::Flag(10);
|
||||
constexpr static Key A = Key::Flag(11);
|
||||
constexpr static Key S = Key::Flag(12);
|
||||
constexpr static Key D = Key::Flag(13);
|
||||
constexpr static Key F = Key::Flag(14);
|
||||
constexpr static Key G = Key::Flag(15);
|
||||
constexpr static Key H = Key::Flag(16);
|
||||
constexpr static Key J = Key::Flag(17);
|
||||
constexpr static Key K = Key::Flag(18);
|
||||
constexpr static Key L = Key::Flag(19);
|
||||
constexpr static Key Y = Key::Flag(20);
|
||||
constexpr static Key X = Key::Flag(21);
|
||||
constexpr static Key C = Key::Flag(22);
|
||||
constexpr static Key V = Key::Flag(23);
|
||||
constexpr static Key B = Key::Flag(24);
|
||||
constexpr static Key N = Key::Flag(25);
|
||||
constexpr static Key M = Key::Flag(26);
|
||||
constexpr static Key _1 = Key::Flag(27);
|
||||
constexpr static Key _2 = Key::Flag(28);
|
||||
constexpr static Key _3 = Key::Flag(29);
|
||||
constexpr static Key _4 = Key::Flag(30);
|
||||
constexpr static Key _5 = Key::Flag(31);
|
||||
constexpr static Key _6 = Key::Flag(32);
|
||||
constexpr static Key _7 = Key::Flag(33);
|
||||
constexpr static Key _8 = Key::Flag(34);
|
||||
constexpr static Key _9 = Key::Flag(35);
|
||||
constexpr static Key _0 = Key::Flag(36);
|
||||
constexpr static Key F1 = Key::Flag(37);
|
||||
constexpr static Key F2 = Key::Flag(38);
|
||||
constexpr static Key F3 = Key::Flag(39);
|
||||
constexpr static Key F4 = Key::Flag(40);
|
||||
constexpr static Key F5 = Key::Flag(41);
|
||||
constexpr static Key F6 = Key::Flag(42);
|
||||
constexpr static Key F7 = Key::Flag(43);
|
||||
constexpr static Key F8 = Key::Flag(44);
|
||||
constexpr static Key F9 = Key::Flag(45);
|
||||
constexpr static Key F10 = Key::Flag(46);
|
||||
constexpr static Key F11 = Key::Flag(47);
|
||||
constexpr static Key F12 = Key::Flag(48);
|
||||
constexpr static Key MouseLeft = Key::Flag(120);
|
||||
};
|
||||
|
||||
using GamepadKey = u32;
|
||||
enum Gamepad : GamepadKey {
|
||||
None = 0, ///< No Key
|
||||
A = 1 << 0, ///< A
|
||||
B = 1 << 1, ///< B
|
||||
X = 1 << 2, ///< X
|
||||
Y = 1 << 3, ///< Y
|
||||
Start = 1 << 4, ///< Start
|
||||
Select = 1 << 5, ///< Select
|
||||
L = 1 << 6, ///< L
|
||||
R = 1 << 7, ///< R
|
||||
DUp = 1 << 8, ///< Dpad Up
|
||||
DDown = 1 << 9, ///< Dpad down
|
||||
DLeft = 1 << 10, ///< Dpad left
|
||||
DRight = 1 << 11, ///< Dpad right
|
||||
CPUp = 1 << 12, ///< Cpad up
|
||||
CPDown = 1 << 13, ///< cpad down
|
||||
CPLeft = 1 << 14, ///< cpad left
|
||||
CPRight = 1 << 15, ///< Cpad right
|
||||
CSUp = 1 << 16, ///< Cstick up
|
||||
CSDown = 1 << 17, ///< cstick down
|
||||
CSLeft = 1 << 18, ///< cstick left
|
||||
CSRight = 1 << 19, ///< cstick right
|
||||
ZL = 1 << 20, ///< ZL
|
||||
ZR = 1 << 21, ///< ZR
|
||||
Touch = 1 << 22, ///< Touch
|
||||
LStick = 1 << 23, ///< Left Stick
|
||||
RStick = 1 << 24, ///< Right Stick
|
||||
Up = DUp | CPUp, ///< DPad or CPad Up
|
||||
Down = DDown | CPDown, ///< DPad or CPad Down
|
||||
Left = DLeft | CPLeft, ///< DPad or CPad Left
|
||||
Right = DRight | CPRight, ///< DPad or CPad Right
|
||||
};
|
||||
} // namespace HidInternal
|
||||
// Pre interface class
|
||||
class PD_API HidDriver : public DriverInterface {
|
||||
public:
|
||||
enum class Event {
|
||||
Null, ///< Nothing happended
|
||||
Down, ///< Key Pressed
|
||||
Held, ///< Key held
|
||||
Up, ///< Key released
|
||||
};
|
||||
HidDriver(std::string_view name = "HidNull");
|
||||
virtual ~HidDriver();
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual const fvec2& MousePos() const { return pMouse[0]; }
|
||||
virtual const fvec2& MousePosLast() const { return pMouse[1]; }
|
||||
virtual const fvec2& TouchPos() const { return pMouse[0]; }
|
||||
virtual const fvec2& TouchPosLast() const { return pMouse[1]; }
|
||||
virtual void Update();
|
||||
virtual bool IsEvent(Event e, HidInternal::GamepadKey keys);
|
||||
virtual bool IsEvent(Event e, HidInternal::Keyboard::Key keys);
|
||||
virtual const fvec2& GetLeftStick() const { return pLStick[0]; }
|
||||
virtual const fvec2& GetRightStick() const { return pRStick[0]; }
|
||||
|
||||
PDHidBackendFlags GetFlags() const { return pFlags; }
|
||||
|
||||
protected:
|
||||
void SwapTab();
|
||||
PDHidBackendFlags pFlags = PDHidBackendFlags_None;
|
||||
fvec2 pMouse[2]; // Current And last pos
|
||||
fvec2 pLStick[2];
|
||||
fvec2 pRStick[2];
|
||||
std::unordered_map<u32, u32> pGamepad;
|
||||
std::unordered_map<u128, u128> pKeyboard;
|
||||
std::unordered_map<Event, u32> pGamepadEvents[2];
|
||||
std::unordered_map<Event, u128> pKeyboardEvents[2];
|
||||
};
|
||||
|
||||
class PD_API Hid {
|
||||
public:
|
||||
using Gamepad = HidInternal::Gamepad;
|
||||
using Keyboard = HidInternal::Keyboard;
|
||||
using Event = HidDriver::Event;
|
||||
Hid() = default;
|
||||
~Hid() = default;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static void UseDriver(Args&&... args) {
|
||||
// assert(driver == nullptr && "OS Driver already set");
|
||||
driver = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static void Init() { driver->Init(); }
|
||||
static void Deinit() { driver->Deinit(); }
|
||||
static const fvec2& MousePos() { return driver->MousePos(); }
|
||||
static const fvec2& MousePosLast() { return driver->MousePosLast(); }
|
||||
static const fvec2& TouchPos() { return driver->TouchPos(); }
|
||||
static const fvec2& TouchPosLast() { return driver->TouchPosLast(); }
|
||||
static void Update() { driver->Update(); }
|
||||
static bool IsEvent(Event e, HidInternal::GamepadKey keys) {
|
||||
return driver->IsEvent(e, keys);
|
||||
}
|
||||
static bool IsEvent(Event e, HidInternal::Keyboard::Key keys) {
|
||||
return driver->IsEvent(e, keys);
|
||||
}
|
||||
static PDHidBackendFlags GetFlags() { return driver->GetFlags(); }
|
||||
static const fvec2& GetLeftStick() { return driver->GetLeftStick(); }
|
||||
static const fvec2& GetRightStick() { return driver->GetRightStick(); }
|
||||
|
||||
static const char* GetDriverName() { return driver->GetName(); }
|
||||
|
||||
private:
|
||||
static std::unique_ptr<HidDriver> driver;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -25,7 +25,7 @@ class PD_API Image {
|
||||
void Copy(const std::vector<u8>& pixels, int w, int h, int bpp = 4);
|
||||
|
||||
const int& Width() const { return pSize.x; }
|
||||
const int& Height() const { return pSize.x; }
|
||||
const int& Height() const { return pSize.y; }
|
||||
const ivec2& Size() const { return pSize; }
|
||||
|
||||
const std::vector<u8>& data() const { return pData; }
|
||||
|
||||
@@ -26,6 +26,7 @@ using LiDrawFlags = PD::u32;
|
||||
enum LiDrawFlags_ : PD::u32 {
|
||||
LiDrawFlags_None = 0,
|
||||
LiDrawFlags_Close = 1 << 0,
|
||||
LiDrawFlags_AA = 1 << 1,
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
@@ -55,8 +56,11 @@ class PD_API Drawlist {
|
||||
* only for special use cases
|
||||
*/
|
||||
void PathReserve(size_t num) { pPath.ExpandIf(num); }
|
||||
void PathStroke(u32 color, int t = 1, LiDrawFlags flags = LiDrawFlags_None);
|
||||
void PathFill(u32 color);
|
||||
void PathStroke(const PD::Color& color, int t = 1,
|
||||
LiDrawFlags flags = LiDrawFlags_None);
|
||||
void PathFill(const PD::Color& color);
|
||||
void PathFillGradient(const PD::Color& a, const PD::Color& b,
|
||||
float rad = 0.f);
|
||||
void PathArcToN(const fvec2& c, float r, float amin, float amax, int s);
|
||||
void PathFastArcToN(const fvec2& c, float r, float amin, float amax, int s);
|
||||
void PathRect(const fvec2& tl, const fvec2& br, float r = 0.f);
|
||||
@@ -70,33 +74,39 @@ class PD_API Drawlist {
|
||||
/** Font Handling */
|
||||
void SetFont(Font* font) { pFont = font; }
|
||||
void SetFontscale(float fontscale = 1.f) { pFontScale = fontscale; }
|
||||
const float& GetFontScale() const { return pFontScale; }
|
||||
|
||||
/** Data geters */
|
||||
const Pool<Command>& Data() const { return pCommands; }
|
||||
operator const Pool<Command>&() const { return pCommands; }
|
||||
|
||||
/** Drawing functions */
|
||||
void DrawRect(const fvec2& pos, const fvec2& size, u32 color, int t = 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 t = 1);
|
||||
void DrawRect(const fvec2& pos, const fvec2& size, const PD::Color& color,
|
||||
int t = 1);
|
||||
void DrawRectFilled(const fvec2& pos, const fvec2& size,
|
||||
const PD::Color& color);
|
||||
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
const PD::Color& color, int t = 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 t = 1);
|
||||
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
|
||||
const PD::Color& color);
|
||||
void DrawCircle(const fvec2& center, float rad, const PD::Color& color,
|
||||
int num_segments, int t = 1);
|
||||
void DrawCircleFilled(const fvec2& center, float rad, const PD::Color& color,
|
||||
int num_segments);
|
||||
void DrawText(const fvec2& p, const char* text, u32 color);
|
||||
void DrawTextEx(const fvec2& p, const char* text, u32 color,
|
||||
void DrawText(const fvec2& p, const char* text, const PD::Color& color);
|
||||
void DrawTextEx(const fvec2& p, const char* text, const PD::Color& color,
|
||||
LiTextFlags flags, const fvec2& box = fvec2(0.f));
|
||||
|
||||
void DrawPolyLine(const Pool<fvec2>& points, u32 color,
|
||||
void DrawPolyLine(const Pool<fvec2>& points, const PD::Color& color,
|
||||
LiDrawFlags flags = LiDrawFlags_None, int t = 1);
|
||||
void DrawConvexPolyFilled(const Pool<fvec2>& points, u32 color);
|
||||
void DrawConvexPolyFilled(const Pool<fvec2>& points, const PD::Color& color);
|
||||
void DrawConvexPolyFilled(const Pool<fvec2>& points, const PD::Color& a,
|
||||
const PD::Color b, float rad = 0.f);
|
||||
|
||||
void PrimQuad(Command& cmd, const Rect& quad, const Rect& uv, u32 color);
|
||||
void PrimQuad(Command& cmd, const Rect& quad, const Rect& uv,
|
||||
const PD::Color& color);
|
||||
void PrimTriangle(Command& cmd, const fvec2& a, const fvec2& b,
|
||||
const fvec2& c, u32 color);
|
||||
const fvec2& c, const PD::Color& color);
|
||||
|
||||
private:
|
||||
Texture pCurrentTexture;
|
||||
|
||||
@@ -64,6 +64,11 @@ class PD_API Font {
|
||||
void CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color, float scale,
|
||||
const char* text, LiTextFlags flags = 0, const fvec2& box = 0);
|
||||
|
||||
/**
|
||||
* Cleanup Font and unload Textures
|
||||
*/
|
||||
void Delete();
|
||||
|
||||
/**
|
||||
* Garbage collection for TextMapSystem
|
||||
*/
|
||||
@@ -80,7 +85,7 @@ class PD_API Font {
|
||||
|
||||
/** Data Section */
|
||||
int PixelHeight = 0;
|
||||
int DefaultPixelHeight = 24;
|
||||
int DefaultPixelHeight = 32;
|
||||
std::vector<TextureID> Textures;
|
||||
/**
|
||||
* 32Bit Codepoint Dataholder reference map
|
||||
|
||||
@@ -10,6 +10,7 @@ PD_API bool InBounds(const fvec2& pos, const fvec2& size, const fvec4& rect);
|
||||
PD_API bool InBounds(const fvec2& pos, const fvec4& rect);
|
||||
PD_API bool InBounds(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
const fvec4& rect);
|
||||
PD_API bool InSpace(const PD::fvec2& pos, const Rect& rect);
|
||||
PD_API void RotateCorner(fvec2& pos, float sinus, float cosinus);
|
||||
PD_API Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
|
||||
PD_API Rect PrimLine(const fvec2& a, const fvec2& b, int t = 1);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
#include <pd/ultra/flags.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
class PD_API Canvas {
|
||||
public:
|
||||
Canvas();
|
||||
Canvas(const PD::fvec2& size);
|
||||
~Canvas();
|
||||
|
||||
void SetVirtualViewport(const PD::fvec2& size);
|
||||
void SetViewport(const PD::fvec2& size);
|
||||
|
||||
PD::fvec2 VTranslatePos(const PD::fvec2& p) const;
|
||||
PD::fvec2 VTranslateAlignPos(const PD::fvec2& pos, const PD::fvec2& size,
|
||||
UltraAlignment align) const;
|
||||
PD::Li::Rect VTranslateObject(const PD::fvec2& pos, const PD::fvec2& size,
|
||||
UltraAlignment align,
|
||||
bool size_modified = false) const;
|
||||
PD::Li::Rect TranslateObject(const PD::fvec2& pos, const PD::fvec2& size,
|
||||
UltraAlignment align,
|
||||
bool size_modified = false) const;
|
||||
PD::fvec2 TranslatePos(const PD::fvec2& p) const;
|
||||
PD::fvec2 VTranslateSize(const PD::fvec2& s) const;
|
||||
PD::fvec2 TranslateSize(const PD::fvec2& s) const;
|
||||
float VTranslateFontscale(float f) const;
|
||||
float TranslateFontscale(float f) const;
|
||||
const PD::u32& GetRevision() const;
|
||||
|
||||
private:
|
||||
PD::fvec2 pViewport;
|
||||
PD::fvec2 pVirtualViewPort;
|
||||
float pVfactor = 0.f;
|
||||
PD::fvec2 pVoff;
|
||||
PD::u32 pRev; // revision
|
||||
};
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
#include <pd/ultra/canvas.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
class Container {
|
||||
public:
|
||||
Container() {}
|
||||
Container(const PD::Li::Rect& r) : pRect(r) {}
|
||||
virtual ~Container() {}
|
||||
|
||||
void Push(PD::Ultra::ElementBase& elem) {
|
||||
elem.SetParent(this);
|
||||
pElems.Push(&elem);
|
||||
}
|
||||
void Reset() { pElems.ResetFast(); }
|
||||
const PD::Li::Rect& GetRenderspace() const { return pRect; }
|
||||
|
||||
void SetViewport(const PD::fvec2& vp) {
|
||||
pCanvas.SetViewport(vp);
|
||||
pRect = PD::fvec4(PD::fvec2(0), vp);
|
||||
}
|
||||
void SetBaseViewport(const PD::ivec2& vp) { pCanvas.SetVirtualViewport(vp); }
|
||||
|
||||
const PD::fvec2 GetTopLeft() const { return pRect.TopLeft(); }
|
||||
const PD::fvec2 GetTopRight() const { return pRect.TopRight(); }
|
||||
const PD::fvec2 GetBotLeft() const { return pRect.BotLeft(); }
|
||||
const PD::fvec2 GetBotRight() const { return pRect.BotRight(); }
|
||||
const PD::fvec2 GetSize() const { return pRect.BotRight() - pRect.TopLeft(); }
|
||||
const PD::fvec2 GetPosition() const { return pRect.TopLeft(); }
|
||||
const Canvas& GetCanvas() const { return pCanvas; }
|
||||
|
||||
protected:
|
||||
PD::Pool<PD::Ultra::ElementBase*>& GetElements() { return pElems; }
|
||||
|
||||
private:
|
||||
PD::Li::Rect pRect;
|
||||
Canvas pCanvas;
|
||||
PD::Pool<PD::Ultra::ElementBase*> pElems;
|
||||
};
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
class PD_API Button : public ElementBase {
|
||||
public:
|
||||
Button() {}
|
||||
Button(const PD::fvec2& pos, const PD::fvec2& size, const PD::Color& color,
|
||||
float rounding = 0.f, UltraAlignment align = 0)
|
||||
: pColor(color), pRounding(rounding) {
|
||||
this->pAlignment = align;
|
||||
this->pPos = pos;
|
||||
this->pSize = size;
|
||||
}
|
||||
Button(float x, float y, float w, float h, const PD::Color& color,
|
||||
float rounding = 0.f, UltraAlignment align = 0)
|
||||
: pColor(color), pRounding(rounding) {
|
||||
this->pAlignment = align;
|
||||
this->pPos = PD::fvec2(x, y);
|
||||
this->pSize = PD::fvec2(w, h);
|
||||
}
|
||||
~Button() {}
|
||||
|
||||
void Draw(PD::Li::Drawlist& l) override;
|
||||
void Update() override;
|
||||
void SetColor(const PD::Color& color) { pColor = color; }
|
||||
void SetFocusedColor(const PD::Color& color) { pHovered = color; }
|
||||
void SetTextColor(const PD::Color& color) { pTextColor = color; }
|
||||
void SetRounding(float r) { pRounding = r; }
|
||||
void SetLined(bool v) { pLined = v; }
|
||||
void SetThickness(int v) { pThickness = v; }
|
||||
void SetText(const std::string& text) { pText = text; }
|
||||
void SetAutoSizePadding(const PD::fvec2& size) { pAsp = size; }
|
||||
|
||||
// Discard these funcs
|
||||
void OnFocus(EventFunc func) override {}
|
||||
void OnUnFocus(EventFunc func) override {}
|
||||
|
||||
private:
|
||||
std::string pText;
|
||||
PD::Color pRenderColor;
|
||||
PD::Color pColor;
|
||||
PD::Color pHovered;
|
||||
PD::Color pTextColor;
|
||||
float pRounding = 0.f;
|
||||
bool pLined = false;
|
||||
int pThickness = 1.f;
|
||||
// Auto-Size-Padding
|
||||
PD::fvec2 pAsp = PD::fvec2(30, 10);
|
||||
};
|
||||
} // namespace Ultra
|
||||
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
#include <pd/ultra/flags.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
class Canvas;
|
||||
class Container;
|
||||
using EventFunc = std::function<void()>;
|
||||
class PD_API ElementBase {
|
||||
public:
|
||||
ElementBase() {}
|
||||
~ElementBase() {}
|
||||
|
||||
virtual void Draw(PD::Li::Drawlist& dl) = 0;
|
||||
/**
|
||||
* Reset Function (for PD::Pool::FastReset)
|
||||
*/
|
||||
virtual void Reset() {}
|
||||
virtual void Update();
|
||||
|
||||
void SetAlignment(UltraAlignment a) { pAlignment = a; }
|
||||
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
|
||||
void SetPosition(float x, float y) { pPos = PD::fvec2(x, y); }
|
||||
void SetSize(const PD::fvec2& size) { pSize = size; }
|
||||
void SetSize(float w, float h) { pSize = PD::fvec2(w, h); }
|
||||
/**
|
||||
* Executed on Hovering
|
||||
* Elemnents can override / discard this func
|
||||
*/
|
||||
virtual void OnFocus(EventFunc func) { pHover = func; }
|
||||
/**
|
||||
* Executed on Mocing out of the space
|
||||
* Elemnents can override / discard this func
|
||||
*/
|
||||
virtual void OnUnFocus(EventFunc func) { pUnHover = func; }
|
||||
/**
|
||||
* Executrd on KeyUp event
|
||||
* Elemnents can override / discard this func
|
||||
*/
|
||||
virtual void OnPress(EventFunc func) { pPress = func; }
|
||||
|
||||
void SetFontScale(float s = 1.f) { pFontScale = 1.f; }
|
||||
float GetFontScale() const { return pFontScale; }
|
||||
|
||||
void SetFont(PD::Li::Font& font) { pFont = &font; }
|
||||
|
||||
void SetFontIfNull(PD::Li::Font& font) {
|
||||
if (!pFont) pFont = &font;
|
||||
}
|
||||
|
||||
virtual void UpdateInput();
|
||||
|
||||
protected:
|
||||
friend class Container;
|
||||
void SetParent(Container* c) { pParent = c; }
|
||||
bool RevisionUpdate(PD::u32 req);
|
||||
Container* pParent = nullptr;
|
||||
PD::u32 pCanvasRev = 0;
|
||||
UltraAlignment pAlignment = 0;
|
||||
PD::fvec2 pPos;
|
||||
PD::fvec2 pSize;
|
||||
PD::Li::Rect pRenderspace;
|
||||
EventFunc pHover = nullptr;
|
||||
EventFunc pUnHover = nullptr;
|
||||
EventFunc pPress = nullptr;
|
||||
bool pFocued = false;
|
||||
// Not used by every object btw
|
||||
PD::Li::Font* pFont = nullptr;
|
||||
float pFontScale = 1.f;
|
||||
};
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
class PD_API Image : public ElementBase {
|
||||
public:
|
||||
Image() {}
|
||||
Image(PD::Li::Texture* tex, const PD::fvec2& pos, float rounding = 0.f,
|
||||
UltraAlignment align = 0)
|
||||
: pColor(0xffffffff), pRounding(rounding) {
|
||||
this->pAlignment = align;
|
||||
this->pPos = pos;
|
||||
SetTexture(tex);
|
||||
}
|
||||
Image(PD::Li::Texture* tex, float x, float y, float rounding = 0.f,
|
||||
UltraAlignment align = 0)
|
||||
: pColor(0xffffffff), pRounding(rounding) {
|
||||
this->pAlignment = align;
|
||||
this->pPos = PD::fvec2(x, y);
|
||||
SetTexture(tex);
|
||||
}
|
||||
~Image() {}
|
||||
|
||||
void Draw(PD::Li::Drawlist& l) override;
|
||||
|
||||
void SetColor(const PD::Color& color) { pColor = color; }
|
||||
void SetRounding(float r) { pRounding = r; }
|
||||
void SetTexture(PD::Li::Texture* tex) {
|
||||
pTex = tex;
|
||||
SetSize(pTex->GetSize());
|
||||
}
|
||||
|
||||
private:
|
||||
PD::Color pColor = 0xffffffff;
|
||||
PD::Li::Texture* pTex = nullptr;
|
||||
float pRounding = 0.f;
|
||||
};
|
||||
} // namespace Ultra
|
||||
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
class PD_API Rect : public ElementBase {
|
||||
public:
|
||||
Rect() {}
|
||||
Rect(const PD::fvec2& pos, const PD::fvec2& size, const PD::Color& color,
|
||||
float rounding = 0.f, UltraAlignment align = 0)
|
||||
: pColor(color), pRounding(rounding) {
|
||||
this->pAlignment = align;
|
||||
this->pPos = pos;
|
||||
this->pSize = size;
|
||||
}
|
||||
Rect(float x, float y, float w, float h, const PD::Color& color,
|
||||
float rounding = 0.f, UltraAlignment align = 0)
|
||||
: pColor(color), pRounding(rounding) {
|
||||
this->pAlignment = align;
|
||||
this->pPos = PD::fvec2(x, y);
|
||||
this->pSize = PD::fvec2(w, h);
|
||||
}
|
||||
~Rect() {}
|
||||
|
||||
void Draw(PD::Li::Drawlist& l) override;
|
||||
|
||||
void SetColor(const PD::Color& color) { pColor = color; }
|
||||
void SetRounding(float r) { pRounding = r; }
|
||||
void SetLined(bool v) { pLined = v; }
|
||||
void SetThickness(int v) { pThickness = v; }
|
||||
|
||||
private:
|
||||
PD::Color pColor;
|
||||
float pRounding = 0.f;
|
||||
bool pLined = false;
|
||||
int pThickness = 1.f;
|
||||
};
|
||||
} // namespace Ultra
|
||||
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
class PD_API Text : public ElementBase {
|
||||
public:
|
||||
Text() {}
|
||||
~Text() {}
|
||||
|
||||
void Draw(PD::Li::Drawlist& l) override;
|
||||
void Update() override;
|
||||
|
||||
void SetColor(const PD::Color& color) { pColor = color; }
|
||||
void SetText(const std::string& text) { pText = text; }
|
||||
|
||||
private:
|
||||
PD::Color pColor;
|
||||
std::string pText;
|
||||
};
|
||||
} // namespace Ultra
|
||||
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/common.hpp>
|
||||
|
||||
using UltraAlignment = PD::u32;
|
||||
enum UltraAlignment_ {
|
||||
UltraAlignment_None = 0,
|
||||
UltraAlignment_Top = 1 << 0,
|
||||
UltraAlignment_Bot = 1 << 1,
|
||||
UltraAlignment_Left = 1 << 2,
|
||||
UltraAlignment_Right = 1 << 3,
|
||||
UltraAlignment_CenterVertical = 1 << 4,
|
||||
UltraAlignment_CenterHorizontal = 1 << 5,
|
||||
UltraAlignment_TopLeft = UltraAlignment_Top | UltraAlignment_Left,
|
||||
UltraAlignment_TopRight = UltraAlignment_Top | UltraAlignment_Right,
|
||||
UltraAlignment_BotLeft = UltraAlignment_Bot | UltraAlignment_Left,
|
||||
UltraAlignment_BotRight = UltraAlignment_Bot | UltraAlignment_Right,
|
||||
UltraAlignment_Center =
|
||||
UltraAlignment_CenterVertical | UltraAlignment_CenterHorizontal,
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/ultra/canvas.hpp>
|
||||
#include <pd/ultra/container.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
class PD_API Layout : public Container {
|
||||
public:
|
||||
Layout() {}
|
||||
~Layout() {}
|
||||
|
||||
/**
|
||||
* Set a fallback font if you dont want to explicitly set a font for every
|
||||
* objectt individually
|
||||
*/
|
||||
void SetFont(PD::Li::Font& font) { pFont = &font; }
|
||||
void Render(PD::Li::Drawlist& list);
|
||||
|
||||
private:
|
||||
PD::Li::Font* pFont = nullptr;
|
||||
};
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
+2
-3
@@ -7,15 +7,14 @@ constexpr const char* pColorYellow = "\033[33m";
|
||||
constexpr const char* pColorRed = "\033[31m";
|
||||
static LogLevel pFilter = LogLevel::Info;
|
||||
|
||||
PD_API void LogFilter(LogLevel lvl) {
|
||||
pFilter = lvl;
|
||||
}
|
||||
PD_API void LogFilter(LogLevel lvl) { pFilter = lvl; }
|
||||
|
||||
PD_API void Log(const std::string& txt, LogLevel lvl) {
|
||||
if ((int)lvl < (int)pFilter) return;
|
||||
const char* clr = pColorNo;
|
||||
const char* plvl = "INFO";
|
||||
switch (lvl) {
|
||||
case PD::LogLevel::None:
|
||||
case PD::LogLevel::Info:
|
||||
clr = pColorNo;
|
||||
plvl = "INFO";
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <pd/drivers/hid.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD_API std::unique_ptr<HidDriver> Hid::driver;
|
||||
|
||||
PD_API HidDriver::HidDriver(std::string_view name) : DriverInterface(name) {}
|
||||
|
||||
PD_API HidDriver::~HidDriver() {}
|
||||
|
||||
PD_API bool HidDriver::IsEvent(Event e, HidInternal::GamepadKey keys) {
|
||||
return pGamepadEvents[0][e] & keys;
|
||||
}
|
||||
|
||||
PD_API bool HidDriver::IsEvent(Event e, HidInternal::Keyboard::Key keys) {
|
||||
return pKeyboardEvents[0][e].Has(keys);
|
||||
}
|
||||
/**
|
||||
* Todo: Keyboard support
|
||||
*/
|
||||
PD_API void HidDriver::SwapTab() {
|
||||
auto tkd = pGamepadEvents[1][Event::Down];
|
||||
auto tkh = pGamepadEvents[1][Event::Held];
|
||||
auto tku = pGamepadEvents[1][Event::Up];
|
||||
pGamepadEvents[1][Event::Down] = pGamepadEvents[0][Event::Down];
|
||||
pGamepadEvents[1][Event::Held] = pGamepadEvents[0][Event::Held];
|
||||
pGamepadEvents[1][Event::Up] = pGamepadEvents[0][Event::Up];
|
||||
pGamepadEvents[0][Event::Down] = tkd;
|
||||
pGamepadEvents[0][Event::Held] = tkh;
|
||||
pGamepadEvents[0][Event::Up] = tku;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this func has no verride, still clear the stats
|
||||
* cause if they are empty this leads to a crash
|
||||
*/
|
||||
PD_API void HidDriver::Update() {
|
||||
// Clear States
|
||||
for (int i = 0; i < 2; i++) {
|
||||
pGamepadEvents[i][Event::Down] = 0;
|
||||
pGamepadEvents[i][Event::Held] = 0;
|
||||
pGamepadEvents[i][Event::Up] = 0;
|
||||
for (auto& it : pKeyboardEvents[i]) {
|
||||
it.second = 0; // ? why was this Event_Null
|
||||
}
|
||||
}
|
||||
pMouse[1] = pMouse[0]; // cycle here
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -10,7 +10,7 @@ PD_API u64 OsDriver::GetTime() const {
|
||||
}
|
||||
|
||||
PD_API u64 OsDriver::GetTimeNano() const {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count();
|
||||
}
|
||||
|
||||
+93
-28
@@ -34,16 +34,23 @@ PD_API Command& Drawlist::NewCommand() {
|
||||
PD_API void Drawlist::BindTexture(const Texture& tex) { pCurrentTexture = tex; }
|
||||
|
||||
/** Path API */
|
||||
PD_API void Drawlist::PathStroke(u32 color, int t, LiDrawFlags flags) {
|
||||
PD_API void Drawlist::PathStroke(const PD::Color& color, int t,
|
||||
LiDrawFlags flags) {
|
||||
DrawPolyLine(pPath, color, flags, t);
|
||||
PathClear();
|
||||
}
|
||||
|
||||
PD_API void Drawlist::PathFill(u32 color) {
|
||||
PD_API void Drawlist::PathFill(const PD::Color& color) {
|
||||
DrawConvexPolyFilled(pPath, color);
|
||||
PathClear();
|
||||
}
|
||||
|
||||
PD_API void Drawlist::PathFillGradient(const PD::Color& a, const PD::Color& b,
|
||||
float rad) {
|
||||
DrawConvexPolyFilled(pPath, a, b, rad);
|
||||
PathClear();
|
||||
}
|
||||
|
||||
PD_API void Drawlist::PathArcToN(const fvec2& c, float r, float amin,
|
||||
float amax, int s) {
|
||||
// Path.push_back(c);
|
||||
@@ -68,15 +75,15 @@ PD_API void Drawlist::PathFastArcToN(const fvec2& c, float r, float amin,
|
||||
}
|
||||
}
|
||||
|
||||
PD_API void Drawlist::PathRect(const fvec2& tl, const fvec2& br, float r) {
|
||||
if (r == 0.f) {
|
||||
PD_API void Drawlist::PathRect(const fvec2& tl, const fvec2& br,
|
||||
float rounding) {
|
||||
if (rounding == 0.f) {
|
||||
PathAdd(tl);
|
||||
PathAdd(vec2(br.x, tl.y));
|
||||
PathAdd(br);
|
||||
PathAdd(vec2(tl.x, br.y));
|
||||
} else {
|
||||
float r = 0.f;
|
||||
r = std::min({r, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
||||
float r = std::min({rounding, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
||||
/** Calculate Optimal segment count automatically */
|
||||
float corner = M_PI * 0.5f;
|
||||
int segments = std::max(3, int(std::ceil(corner / (6.0f * M_PI / 180.0f))));
|
||||
@@ -101,15 +108,15 @@ PD_API void Drawlist::PathRect(const fvec2& tl, const fvec2& br, float r) {
|
||||
}
|
||||
}
|
||||
|
||||
PD_API void Drawlist::PathRectEx(const fvec2& tl, const fvec2& br, float r,
|
||||
LiPathRectFlags flags) {
|
||||
if (r == 0.f) {
|
||||
PD_API void Drawlist::PathRectEx(const fvec2& tl, const fvec2& br,
|
||||
float rounding, LiPathRectFlags flags) {
|
||||
if (rounding == 0.f) {
|
||||
PathAdd(tl);
|
||||
PathAdd(vec2(br.x, tl.y));
|
||||
PathAdd(br);
|
||||
PathAdd(vec2(tl.x, br.y));
|
||||
} else {
|
||||
float r = std::min({r, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
||||
float r = std::min({rounding, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
||||
/** Calculate Optimal segment count automatically */
|
||||
float corner = M_PI * 0.5f;
|
||||
int segments = std::max(3, int(std::ceil(corner / (6.0f * M_PI / 180.0f))));
|
||||
@@ -152,20 +159,21 @@ PD_API void Drawlist::PathRectEx(const fvec2& tl, const fvec2& br, float r,
|
||||
}
|
||||
|
||||
/** Drawing functions */
|
||||
PD_API void Drawlist::DrawRect(const fvec2& pos, const fvec2& size, u32 color,
|
||||
int t) {
|
||||
PD_API void Drawlist::DrawRect(const fvec2& pos, const fvec2& size,
|
||||
const PD::Color& color, int t) {
|
||||
PathRect(pos, pos + size);
|
||||
PathStroke(color, t, LiDrawFlags_Close);
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawRectFilled(const fvec2& pos, const fvec2& size,
|
||||
u32 color) {
|
||||
const PD::Color& color) {
|
||||
PathRect(pos, pos + size);
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawTriangle(const fvec2& a, const fvec2& b,
|
||||
const fvec2& c, u32 color, int t) {
|
||||
const fvec2& c, const PD::Color& color,
|
||||
int t) {
|
||||
PathAdd(a);
|
||||
PathAdd(b);
|
||||
PathAdd(c);
|
||||
@@ -173,15 +181,17 @@ PD_API void Drawlist::DrawTriangle(const fvec2& a, const fvec2& b,
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawTriangleFilled(const fvec2& a, const fvec2& b,
|
||||
const fvec2& c, u32 color) {
|
||||
const fvec2& c,
|
||||
const PD::Color& color) {
|
||||
PathAdd(a);
|
||||
PathAdd(b);
|
||||
PathAdd(c);
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawCircle(const fvec2& center, float rad, u32 color,
|
||||
int num_segments, int t) {
|
||||
PD_API void Drawlist::DrawCircle(const fvec2& center, float rad,
|
||||
const PD::Color& color, int num_segments,
|
||||
int t) {
|
||||
if (num_segments <= 0) {
|
||||
// Auto Segment
|
||||
} else {
|
||||
@@ -193,7 +203,8 @@ PD_API void Drawlist::DrawCircle(const fvec2& center, float rad, u32 color,
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawCircleFilled(const fvec2& center, float rad,
|
||||
u32 color, int num_segments) {
|
||||
const PD::Color& color,
|
||||
int num_segments) {
|
||||
if (num_segments <= 0) {
|
||||
// Auto Segment
|
||||
} else {
|
||||
@@ -203,27 +214,30 @@ PD_API void Drawlist::DrawCircleFilled(const fvec2& center, float rad,
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawText(const fvec2& p, const char* text, u32 color) {
|
||||
PD_API void Drawlist::DrawText(const fvec2& p, const char* text,
|
||||
const PD::Color& color) {
|
||||
if (!pFont) return;
|
||||
pFont->CmdTextEx(*this, p, color, pFontScale, text);
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawTextEx(const fvec2& p, const char* text, u32 color,
|
||||
LiTextFlags flags, const fvec2& box) {
|
||||
PD_API void Drawlist::DrawTextEx(const fvec2& p, const char* text,
|
||||
const PD::Color& color, LiTextFlags flags,
|
||||
const fvec2& box) {
|
||||
if (!pFont) return;
|
||||
pFont->CmdTextEx(*this, p, color, pFontScale, text, flags, box);
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawPolyLine(const Pool<fvec2>& points, u32 color,
|
||||
LiDrawFlags flags, int t) {
|
||||
PD_API void Drawlist::DrawPolyLine(const Pool<fvec2>& points,
|
||||
const PD::Color& color, LiDrawFlags flags,
|
||||
int t) {
|
||||
if (points.size() < 2) {
|
||||
return;
|
||||
}
|
||||
UnbindTexture();
|
||||
auto& cmd = NewCommand();
|
||||
bool close = (flags & (1 << 0));
|
||||
bool close = (flags & LiDrawFlags_Close);
|
||||
int num_points = close ? (int)points.size() : (int)points.size() - 1;
|
||||
if (flags & (1 << 1)) {
|
||||
if (flags & LiDrawFlags_AA) {
|
||||
// TODO: Find a way to draw less garbage looking lines
|
||||
} else {
|
||||
// Non antialiased lines look awful when rendering with thickness != 1
|
||||
@@ -236,7 +250,7 @@ PD_API void Drawlist::DrawPolyLine(const Pool<fvec2>& points, u32 color,
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawConvexPolyFilled(const Pool<fvec2>& points,
|
||||
u32 color) {
|
||||
const PD::Color& color) {
|
||||
if (points.size() < 3) {
|
||||
return; // Need at least three points
|
||||
}
|
||||
@@ -274,8 +288,59 @@ PD_API void Drawlist::DrawConvexPolyFilled(const Pool<fvec2>& points,
|
||||
}
|
||||
}
|
||||
|
||||
PD_API void Drawlist::DrawConvexPolyFilled(const Pool<fvec2>& points,
|
||||
const PD::Color& a,
|
||||
const PD::Color b, float rad) {
|
||||
if (points.size() < 3) {
|
||||
return; // Need at least three points
|
||||
}
|
||||
|
||||
fvec2 dir = fvec2(std::cos(rad), std::sin(rad));
|
||||
// Support for Custom Textures (UV calculation)
|
||||
float minX = points[0].x, minY = points[0].y;
|
||||
float maxX = minX, maxY = minY;
|
||||
// Check for the max and min Positions
|
||||
for (const auto& it : points) {
|
||||
if (it.x < minX) minX = it.x;
|
||||
if (it.y < minY) minY = it.y;
|
||||
if (it.x > maxX) maxX = it.x;
|
||||
if (it.y > maxY) maxY = it.y;
|
||||
}
|
||||
// Get Short defines for UV
|
||||
// (Bottom Right is not required)
|
||||
auto uv_tl = pCurrentTexture.GetUV().TopLeft();
|
||||
auto uv_tr = pCurrentTexture.GetUV().TopRight();
|
||||
auto uv_bl = pCurrentTexture.GetUV().BotLeft();
|
||||
|
||||
// Gradient
|
||||
float tmin = std::numeric_limits<float>::max();
|
||||
float tmax = std::numeric_limits<float>::lowest();
|
||||
for (const auto& p : points) {
|
||||
float t = p.x * dir.x + p.y * dir.y;
|
||||
if (t < tmin) tmin = t;
|
||||
if (t > tmax) tmax = t;
|
||||
}
|
||||
// potential div0
|
||||
float irange = (tmax != tmin) ? (1.0f / (tmax - tmin)) : 0.0f;
|
||||
// Command building (oder so)
|
||||
auto& cmd = NewCommand();
|
||||
cmd.Reserve(points.size(), (points.size() - 2) * 3);
|
||||
// Render
|
||||
for (int i = 2; i < (int)points.size(); i++) {
|
||||
cmd.Add(0, i, i - 1);
|
||||
}
|
||||
// Why was this for loop not used in normal Convex Poly filled???
|
||||
for (auto& it : points) {
|
||||
// Calculate U and V coords
|
||||
float u = uv_tl.x + ((it.x - minX) / (maxX - minX)) * (uv_tr.x - uv_tl.x);
|
||||
float v = uv_tl.y + ((it.y - minY) / (maxY - minY)) * (uv_bl.y - uv_tl.y);
|
||||
float t = it.x * dir.x + it.y * dir.y;
|
||||
cmd.Add(Vertex(it, fvec2(u, v), PD::Color(a).Lerp(b, (t - tmin) * irange)));
|
||||
}
|
||||
}
|
||||
|
||||
PD_API void Drawlist::PrimQuad(Command& cmd, const Rect& quad, const Rect& uv,
|
||||
u32 color) {
|
||||
const PD::Color& color) {
|
||||
cmd.Reserve(4, 6);
|
||||
cmd.Add(2, 1, 0);
|
||||
cmd.Add(3, 2, 0);
|
||||
@@ -286,7 +351,7 @@ PD_API void Drawlist::PrimQuad(Command& cmd, const Rect& quad, const Rect& uv,
|
||||
}
|
||||
|
||||
PD_API void Drawlist::PrimTriangle(Command& cmd, const fvec2& a, const fvec2& b,
|
||||
const fvec2& c, u32 color) {
|
||||
const fvec2& c, const PD::Color& color) {
|
||||
cmd.Reserve(3, 3);
|
||||
cmd.Add(2, 1, 0);
|
||||
cmd.Add(Vertex(a, vec2(0.f, 1.f), color));
|
||||
|
||||
+11
-1
@@ -103,7 +103,7 @@ PD_API void Font::LoadTTF(const std::vector<u8>& data, int px_height) {
|
||||
uvs.z = (off.x + w) / static_cast<float>(texszs);
|
||||
uvs.w = (off.y + h) / static_cast<float>(texszs);
|
||||
// Flip if needed
|
||||
if (PD::Gfx::GetFlags() & PDBackendFlags_FlipUV_Y) {
|
||||
if (PD::Gfx::GetFlags() & PDGfxBackendFlags_FlipUV_Y) {
|
||||
uvs.y = 1.f - uvs.y;
|
||||
uvs.w = 1.f - uvs.w;
|
||||
}
|
||||
@@ -271,5 +271,15 @@ PD_API std::string Font::pShortText(const std::string& txt, float scale,
|
||||
return "";
|
||||
}
|
||||
|
||||
PD_API void Font::Delete() {
|
||||
for (auto& it : Textures) {
|
||||
// Creating a tmp fake Li tex for deletion
|
||||
PD::Gfx::DeleteTexture(PD::Li::Texture(it, 0));
|
||||
}
|
||||
pCurrentTex = 0;
|
||||
PixelHeight = 0;
|
||||
pTMS.clear();
|
||||
CodeMap.clear();
|
||||
}
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -20,6 +20,11 @@ PD_API bool InBounds(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
(a.x > 0 && b.x > 0 && c.x > 0) || (a.y > 0 && b.y > 0 && c.y > 0));
|
||||
}
|
||||
|
||||
PD_API bool InSpace(const PD::fvec2& pos, const Rect& rect) {
|
||||
return (pos.x > rect.Top.x && pos.x < rect.Top.z && pos.y > rect.Top.y &&
|
||||
pos.y < rect.Bot.y);
|
||||
}
|
||||
|
||||
PD_API void RotateCorner(fvec2& pos, float sinus, float cosinus) {
|
||||
float x = pos.x * cosinus - pos.y * sinus;
|
||||
float y = pos.y * cosinus - pos.x * sinus;
|
||||
@@ -53,6 +58,7 @@ PD_API Rect PrimLine(const fvec2& a, const fvec2& b, int t) {
|
||||
// Using the vec maths api makes the code as short as it is
|
||||
vec2 dir = a - b;
|
||||
float len = dir.Len();
|
||||
if (len == 0.0f) return Rect();
|
||||
vec2 unit_dir = dir / len;
|
||||
vec2 perpendicular(-unit_dir.y, unit_dir.x);
|
||||
vec2 off = perpendicular * ((float)t * 0.5f);
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
#include <pd/ultra/canvas.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API Canvas::Canvas() { pRev = 0; }
|
||||
|
||||
PD_API Canvas::Canvas(const PD::fvec2& size) : pViewport(size) { pRev = 0; }
|
||||
|
||||
PD_API Canvas::~Canvas() {}
|
||||
|
||||
PD_API void Canvas::SetVirtualViewport(const PD::fvec2& size) {
|
||||
pVirtualViewPort = size;
|
||||
if (pVirtualViewPort.x && pVirtualViewPort.y) {
|
||||
pVfactor = std::min(pViewport.x / pVirtualViewPort.x,
|
||||
pViewport.y / pVirtualViewPort.y);
|
||||
pVoff = (pViewport - (pVirtualViewPort * pVfactor)) * 0.5f;
|
||||
}
|
||||
pRev++;
|
||||
}
|
||||
|
||||
PD_API void Canvas::SetViewport(const PD::fvec2& size) {
|
||||
if (pViewport == size) return;
|
||||
pViewport = size;
|
||||
SetVirtualViewport(pVirtualViewPort); // recalculate Vfactor
|
||||
}
|
||||
|
||||
PD_API PD::fvec2 Canvas::VTranslatePos(const PD::fvec2& p) const {
|
||||
return p * pVfactor + pVoff;
|
||||
}
|
||||
|
||||
PD_API PD::fvec2 Canvas::TranslatePos(const PD::fvec2& p) const {
|
||||
return p * pViewport;
|
||||
}
|
||||
|
||||
PD_API PD::fvec2 Canvas::VTranslateSize(const PD::fvec2& s) const {
|
||||
return s * pVfactor;
|
||||
}
|
||||
|
||||
PD_API PD::fvec2 Canvas::TranslateSize(const PD::fvec2& s) const {
|
||||
return s * pViewport.y;
|
||||
}
|
||||
|
||||
PD_API float Canvas::VTranslateFontscale(float f) const { return f * pVfactor; }
|
||||
|
||||
PD_API float Canvas::TranslateFontscale(float f) const {
|
||||
return f * pViewport.y;
|
||||
}
|
||||
|
||||
PD_API PD::Li::Rect Canvas::VTranslateObject(const PD::fvec2& pos,
|
||||
const PD::fvec2& size,
|
||||
UltraAlignment align,
|
||||
bool size_modified) const {
|
||||
PD::fvec2 nsize = size;
|
||||
if (!size_modified) nsize *= pVfactor;
|
||||
PD::fvec2 final;
|
||||
if (align & UltraAlignment_Left) {
|
||||
final.x = pos.x * pVfactor;
|
||||
} else if (align & UltraAlignment_Right) {
|
||||
final.x = pViewport.x - (pos.x * pVfactor) - nsize.x;
|
||||
} else if (align & UltraAlignment_CenterHorizontal) {
|
||||
final.x = pViewport.x * 0.5 - nsize.x * 0.5 + pos.x * pVfactor;
|
||||
} else {
|
||||
final.x = pVoff.x + (pos.x * pVfactor) - nsize.x * 0.5;
|
||||
}
|
||||
if (align & UltraAlignment_Top) {
|
||||
final.y = pos.y * pVfactor;
|
||||
} else if (align & UltraAlignment_Bot) {
|
||||
final.y = pViewport.y - (pos.y * pVfactor) - nsize.y;
|
||||
} else if (align & UltraAlignment_CenterVertical) {
|
||||
final.y = pViewport.y * 0.5 - nsize.y * 0.5 + pos.y * pVfactor;
|
||||
} else {
|
||||
final.y = pVoff.y + (pos.y * pVfactor) - nsize.y * 0.5;
|
||||
}
|
||||
return PD::fvec4(final, final + nsize);
|
||||
}
|
||||
|
||||
PD_API PD::Li::Rect Canvas::TranslateObject(const PD::fvec2& pos,
|
||||
const PD::fvec2& size,
|
||||
UltraAlignment align,
|
||||
bool size_modified) const {
|
||||
PD::fvec2 nsize = size;
|
||||
if (!size_modified) nsize *= pViewport;
|
||||
PD::fvec2 final;
|
||||
if (align & UltraAlignment_Left) {
|
||||
final.x = pos.x * pViewport.x;
|
||||
} else if (align & UltraAlignment_Right) {
|
||||
final.x = pViewport.x - (pos.x * pViewport.x) - nsize.x;
|
||||
} else if (align & UltraAlignment_CenterHorizontal) {
|
||||
final.x = pViewport.x * 0.5 - nsize.x * 0.5 + pos.x * pViewport.x;
|
||||
} else {
|
||||
final.x = pVoff.x + (pos.x * pViewport.x) - nsize.x * 0.5;
|
||||
}
|
||||
if (align & UltraAlignment_Top) {
|
||||
final.y = pos.y * pViewport.y;
|
||||
} else if (align & UltraAlignment_Bot) {
|
||||
final.y = pViewport.y - (pos.y * pViewport.y) - nsize.y;
|
||||
} else if (align & UltraAlignment_CenterVertical) {
|
||||
final.y = pViewport.y * 0.5 - nsize.y * 0.5 + pos.y * pViewport.y;
|
||||
} else {
|
||||
final.y = pVoff.y + (pos.y * pViewport.y) - nsize.y * 0.5;
|
||||
}
|
||||
return PD::fvec4(final, final + nsize);
|
||||
}
|
||||
|
||||
PD_API PD::fvec2 Canvas::VTranslateAlignPos(const PD::fvec2& pos,
|
||||
const PD::fvec2& size,
|
||||
UltraAlignment align) const {
|
||||
return VTranslateObject(pos, size, align).TopLeft();
|
||||
}
|
||||
|
||||
PD_API const PD::u32& Canvas::GetRevision() const { return pRev; }
|
||||
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
#include <pd/ultra/container.hpp>
|
||||
#include <pd/ultra/elems/button.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API void Button::Draw(PD::Li::Drawlist& l) {
|
||||
float r = pRounding;
|
||||
if (pParent) r = pParent->GetCanvas().VTranslateSize(r).x;
|
||||
l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), r);
|
||||
if (pLined) {
|
||||
l.PathStroke(pRenderColor, pThickness, LiDrawFlags_Close);
|
||||
} else {
|
||||
l.PathFill(pRenderColor);
|
||||
}
|
||||
if (!pFont) return; // discard here if we dont have a font
|
||||
PD::fvec2 off = 0.f;
|
||||
if (pParent) off = pParent->GetCanvas().VTranslateSize(pAsp) * 0.5;
|
||||
l.SetFont(pFont);
|
||||
l.SetFontscale(pParent->GetCanvas().VTranslateFontscale(pFontScale));
|
||||
l.DrawText(pRenderspace.TopLeft() + off, pText.c_str(), pTextColor);
|
||||
}
|
||||
|
||||
PD_API void Button::Update() {
|
||||
pRenderColor = pColor;
|
||||
if (!pParent || !pFont) ElementBase::Update();
|
||||
PD::fvec2 size = pSize;
|
||||
if (size == PD::fvec2(0)) {
|
||||
size = pFont->GetTextBounds(
|
||||
pText.c_str(),
|
||||
pParent->GetCanvas().VTranslateFontscale(pFontScale)) +
|
||||
pParent->GetCanvas().VTranslateSize(pAsp);
|
||||
} else {
|
||||
size = pParent->GetCanvas().VTranslateSize(size);
|
||||
}
|
||||
pRenderspace = pParent->GetCanvas().VTranslateObject(
|
||||
pParent->GetTopLeft() + pPos, size, pAlignment, true);
|
||||
if (PD::Li::Math::InSpace(PD::Hid::MousePos(), pRenderspace)) {
|
||||
pRenderColor = pHovered;
|
||||
} else {
|
||||
pRenderColor = pColor;
|
||||
}
|
||||
UpdateInput();
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
#include <pd/ultra/container.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API bool ElementBase::RevisionUpdate(PD::u32 req) {
|
||||
if (req != pCanvasRev) {
|
||||
pCanvasRev = req;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
PD_API void ElementBase::Update() {
|
||||
if (!pParent)
|
||||
pRenderspace = PD::fvec4(pPos, pPos + pSize);
|
||||
else
|
||||
pRenderspace = pParent->GetCanvas().VTranslateObject(
|
||||
pParent->GetTopLeft() + pPos, pSize, pAlignment);
|
||||
UpdateInput();
|
||||
/*pRenderspace = PD::fvec4(pParent->GetTopLeft() + pPos,
|
||||
pParent->GetTopLeft() + pPos + pSize);*/
|
||||
}
|
||||
|
||||
PD_API void ElementBase::UpdateInput() {
|
||||
if (PD::Li::Math::InSpace(
|
||||
PD::Hid::MousePos(),
|
||||
PD::fvec4(pRenderspace.TopLeft(), pRenderspace.BotRight()))) {
|
||||
if (pHover && !pFocued) {
|
||||
pHover();
|
||||
pFocued = true;
|
||||
}
|
||||
if (PD::Hid::IsEvent(PD::Hid::Event::Up, PD::Hid::Gamepad::Touch)) {
|
||||
if (pPress) {
|
||||
pPress();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (pUnHover && pFocued) {
|
||||
pUnHover();
|
||||
pFocued = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <pd/ultra/elems/image.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API void Image::Draw(PD::Li::Drawlist& l) {
|
||||
l.BindTexture(*pTex);
|
||||
l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding);
|
||||
l.PathFill(pColor);
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <pd/ultra/elems/rect.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API void Rect::Draw(PD::Li::Drawlist& l) {
|
||||
l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding);
|
||||
if (pLined) {
|
||||
l.PathStroke(pColor, pThickness, LiDrawFlags_Close);
|
||||
} else {
|
||||
l.PathFill(pColor);
|
||||
}
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <pd/ultra/container.hpp>
|
||||
#include <pd/ultra/elems/text.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API void Text::Draw(PD::Li::Drawlist& l) {
|
||||
if (!pFont) return;
|
||||
l.SetFont(pFont);
|
||||
l.SetFontscale(pParent->GetCanvas().VTranslateFontscale(pFontScale));
|
||||
l.DrawText(pRenderspace.TopLeft(), pText.c_str(), pColor);
|
||||
}
|
||||
|
||||
PD_API void Text::Update() {
|
||||
if (!pFont) return;
|
||||
if (!pParent) ElementBase::Update();
|
||||
pRenderspace = pParent->GetCanvas().VTranslateObject(
|
||||
pParent->GetTopLeft() + pPos,
|
||||
pFont->GetTextBounds(
|
||||
pText.c_str(), pParent->GetCanvas().VTranslateFontscale(pFontScale)),
|
||||
pAlignment, true);
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <pd/lithium/formatters.hpp>
|
||||
#include <pd/ultra/layout.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API void Layout::Render(PD::Li::Drawlist& list) {
|
||||
float fc = list.GetFontScale();
|
||||
list.SetFontscale(GetCanvas().VTranslateFontscale(fc));
|
||||
for (auto& it : GetElements()) {
|
||||
it->SetFontIfNull(*pFont);
|
||||
it->Update();
|
||||
it->Draw(list);
|
||||
}
|
||||
list.DrawText(PD::fvec2(5, GetBotLeft().y - 40),
|
||||
std::format("Lyt: [{}]", GetRenderspace()).c_str(), 0xffff00ff);
|
||||
list.SetFontscale(fc);
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -16,7 +16,7 @@ function(make_3ds_target _NAME TITLE AUTHOR _VERSION ICON ROMFS)
|
||||
DEPENDS ${_NAME}.elf
|
||||
COMMENT "Creating ${_NAME}.smdh"
|
||||
)
|
||||
add_custom_target(${_NAME}.3dsx
|
||||
add_custom_target(${_NAME}.3dsx ALL
|
||||
COMMAND ${3DSXTOOL} ${_NAME}.elf ${_NAME}.3dsx --smdh=${_NAME}.smdh
|
||||
--romfs="${ROMFS}"
|
||||
DEPENDS ${_NAME}.smdh
|
||||
@@ -35,7 +35,7 @@ function(make_nx_target _NAME TITLE AUTHOR _VERSION ICON ROMFS)
|
||||
DEPENDS ${_NAME}.elf
|
||||
COMMENT "Creating ${_NAME}.nacp"
|
||||
)
|
||||
add_custom_target(${_NAME}.nro
|
||||
add_custom_target(${_NAME}.nro ALL
|
||||
COMMAND ${ELF2NRO} ${_NAME}.elf ${_NAME}.nro --nacp=${_NAME}.nacp
|
||||
--romfsdir="${ROMFS}" --icon="${ICON}"
|
||||
DEPENDS ${_NAME}.nacp
|
||||
|
||||
@@ -29,6 +29,8 @@ class OsCtx {
|
||||
return fvec2(in.x * pViewPort.y, in.y * pViewPort.y);
|
||||
}
|
||||
|
||||
const PD::ivec2& GetViewport() const { return pViewPort; }
|
||||
|
||||
protected:
|
||||
PD::ivec2 pViewPort;
|
||||
const Driver pDriver;
|
||||
|
||||
+219
-16
@@ -3,6 +3,16 @@
|
||||
#include <os/horizon-nx.hpp>
|
||||
#include <palladium>
|
||||
|
||||
////
|
||||
#include <pd/ultra/elems/button.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
#include <pd/ultra/elems/image.hpp>
|
||||
#include <pd/ultra/elems/rect.hpp>
|
||||
#include <pd/ultra/elems/text.hpp>
|
||||
#include <pd/ultra/layout.hpp>
|
||||
|
||||
////
|
||||
|
||||
PD::OsCtx* pOs = nullptr;
|
||||
|
||||
const char* ResourcePath(const char* in) {
|
||||
@@ -15,6 +25,147 @@ const char* ResourcePath(const char* in) {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string Key2String(PD::Hid::Gamepad gp) {
|
||||
std::string res;
|
||||
if (gp & PD::Hid::Gamepad::A) {
|
||||
res += "A";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::B) {
|
||||
res += "B";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::X) {
|
||||
res += "X";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::Y) {
|
||||
res += "Y";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::Start) {
|
||||
res += "Start";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::Select) {
|
||||
res += "Select";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::DDown) {
|
||||
res += "DDown";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::DUp) {
|
||||
res += "DUp";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::DLeft) {
|
||||
res += "DLeft";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::DRight) {
|
||||
res += "DRight";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::CPDown) {
|
||||
res += "CPDown";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::CPUp) {
|
||||
res += "CPUp";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::CPLeft) {
|
||||
res += "CPLeft";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::CPRight) {
|
||||
res += "CPRight";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::CSDown) {
|
||||
res += "CSDown";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::CSUp) {
|
||||
res += "CSUp";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::CSLeft) {
|
||||
res += "CSLeft";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::CSRight) {
|
||||
res += "CSRight";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::L) {
|
||||
res += "L";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::R) {
|
||||
res += "R";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::ZL) {
|
||||
res += "ZL";
|
||||
}
|
||||
if (gp & PD::Hid::Gamepad::ZR) {
|
||||
res += "ZR";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string ComboGpOut(PD::Hid::Gamepad gp) {
|
||||
std::string res = Key2String(gp);
|
||||
if (PD::Hid::IsEvent(PD::Hid::Event::Down, gp)) {
|
||||
res += ": 1";
|
||||
} else if (PD::Hid::IsEvent(PD::Hid::Event::Held, gp)) {
|
||||
res += ": 2";
|
||||
} else if (PD::Hid::IsEvent(PD::Hid::Event::Up, gp)) {
|
||||
res += ": 3";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
class MainMenu : public PD::Ultra::Layout {
|
||||
public:
|
||||
MainMenu(PD::Li::Font& font) {
|
||||
SetFont(font);
|
||||
SetBaseViewport(PD::ivec2(1280, 720));
|
||||
pBackground.SetSize(800, 450);
|
||||
pBackground.SetColor("#ffffffff");
|
||||
pBackground.SetAlignment(UltraAlignment_Center);
|
||||
Push(pBackground);
|
||||
pText.SetColor("#ffffff");
|
||||
pText.SetText("MousePos: ");
|
||||
pText.SetAlignment(UltraAlignment_TopLeft);
|
||||
Push(pText);
|
||||
pBtn.SetText("Test");
|
||||
pBtn.SetAlignment(UltraAlignment_Center);
|
||||
pBtn.SetColor("#1273fb");
|
||||
pBtn.SetFocusedColor("#0011ff");
|
||||
pBtn.SetTextColor("#ffffff");
|
||||
pBtn.SetRounding(10);
|
||||
pBtn.OnPress([]() { PD::Log("Btn Pressed..."); });
|
||||
Push(pBtn);
|
||||
}
|
||||
~MainMenu() {}
|
||||
|
||||
void Update() {
|
||||
pText.SetText(std::format("MousePos: {}", PD::Hid::MousePos()));
|
||||
}
|
||||
|
||||
private:
|
||||
PD::Ultra::Rect pBackground;
|
||||
PD::Ultra::Text pText;
|
||||
PD::Ultra::Button pBtn;
|
||||
};
|
||||
|
||||
class App {
|
||||
public:
|
||||
App(PD::Li::Font& font) : main(font) {}
|
||||
~App() {}
|
||||
|
||||
void Update(PD::ivec2 vp, PD::Li::Drawlist& list) {
|
||||
main.Update();
|
||||
main.SetViewport(vp);
|
||||
main.Render(list);
|
||||
}
|
||||
|
||||
private:
|
||||
MainMenu main;
|
||||
};
|
||||
|
||||
struct Cursor {
|
||||
PD::fvec2 pPos = 0;
|
||||
std::string name;
|
||||
PD::Color pColor = 0xffff00ff;
|
||||
void Render(PD::Li::Drawlist& l) {
|
||||
l.DrawCircleFilled(pPos, 32.f, pColor, 15);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// PD::LogFilter(PD::LogLevel::Warning);
|
||||
Driver drv = Driver::OpenGL3;
|
||||
@@ -40,32 +191,84 @@ int main(int argc, char** argv) {
|
||||
PD::Image img(ResourcePath("icon.png"));
|
||||
auto pTex = PD::Gfx::LoadTexture(img, img.Width(), img.Height());
|
||||
PD::Li::Font font;
|
||||
font.LoadTTF(ResourcePath("default.ttf"));
|
||||
font.LoadTTF(ResourcePath("default.ttf"), 64);
|
||||
pList.SetFont(&font);
|
||||
App app(font);
|
||||
Cursor LeftStick;
|
||||
Cursor RightStick;
|
||||
RightStick.pColor = "#00ffff";
|
||||
while (pOs->Mainloop()) {
|
||||
PD::Hid::Update();
|
||||
pOs->ClearViewPort();
|
||||
PD::Li::ResetPools();
|
||||
pList.SetFontscale(pOs->SizeTranslate(PD::fvec2(0.0017)).x);
|
||||
pList.PathRect(pOs->PositionTranslate(0.05), pOs->PositionTranslate(0.4f),
|
||||
10.f);
|
||||
pList.PathFill(0xff00ffff);
|
||||
pList.BindTexture(pTex);
|
||||
pList.DrawRectFilled(pOs->PositionTranslate(PD::fvec2(0.02f, 0.5f)),
|
||||
pOs->SizeTranslate(PD::fvec2(0.3)), 0xffffffff);
|
||||
pList.DrawText(5, "Hello World!", 0xff0000ff);
|
||||
PD::Li::ResetPools(); // Move to other place (or refactor this)
|
||||
app.Update(pOs->GetViewport(), pList);
|
||||
pList.SetFontscale(0.7);
|
||||
if (PD::Hid::IsEvent(PD::Hid::Event::Down, PD::Hid::Gamepad::CPLeft |
|
||||
PD::Hid::Gamepad::CPRight)) {
|
||||
LeftStick.pPos.x += PD::Hid::GetLeftStick().x * 15;
|
||||
}
|
||||
if (PD::Hid::IsEvent(PD::Hid::Event::Down,
|
||||
PD::Hid::Gamepad::CPUp | PD::Hid::Gamepad::CPDown)) {
|
||||
LeftStick.pPos.y += PD::Hid::GetLeftStick().y * 15;
|
||||
}
|
||||
if (PD::Hid::IsEvent(PD::Hid::Event::Down, PD::Hid::Gamepad::CSLeft |
|
||||
PD::Hid::Gamepad::CSRight)) {
|
||||
RightStick.pPos.x += PD::Hid::GetRightStick().x * 15;
|
||||
}
|
||||
if (PD::Hid::IsEvent(PD::Hid::Event::Down,
|
||||
PD::Hid::Gamepad::CSUp | PD::Hid::Gamepad::CSDown)) {
|
||||
RightStick.pPos.y += PD::Hid::GetRightStick().y * 15;
|
||||
}
|
||||
pList.DrawText(
|
||||
pOs->PositionTranslate(PD::fvec2(0.005, 0.9)),
|
||||
std::format("VIDC: [{}, {}, {}, {}]\nGfxDriver: {}",
|
||||
PD::Gfx::GetNumVertices(), PD::Gfx::GetNumIndices(),
|
||||
PD::Gfx::GetNumDrawcalls(), PD::Gfx::GetNumCommands(),
|
||||
PD::Gfx::GetDriverName())
|
||||
PD::fvec2(5, 37),
|
||||
std::format(
|
||||
"Input:\n Driver: {}\n Gamepad: {}\n {}\n {}\n "
|
||||
"{}\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n "
|
||||
"{}\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n "
|
||||
"{}\n {}\n "
|
||||
"{}\n {}\n LS: [{}]\n RS: [{}]\nLSP: {}",
|
||||
PD::Hid::GetDriverName(),
|
||||
bool(PD::Hid::GetFlags() & PDHidBackendFlags_HasGamepad),
|
||||
ComboGpOut(PD::Hid::Gamepad::Start),
|
||||
ComboGpOut(PD::Hid::Gamepad::Select),
|
||||
ComboGpOut(PD::Hid::Gamepad::A), ComboGpOut(PD::Hid::Gamepad::B),
|
||||
ComboGpOut(PD::Hid::Gamepad::X), ComboGpOut(PD::Hid::Gamepad::Y),
|
||||
ComboGpOut(PD::Hid::Gamepad::DDown),
|
||||
ComboGpOut(PD::Hid::Gamepad::DUp),
|
||||
ComboGpOut(PD::Hid::Gamepad::DLeft),
|
||||
ComboGpOut(PD::Hid::Gamepad::DRight),
|
||||
ComboGpOut(PD::Hid::Gamepad::L), ComboGpOut(PD::Hid::Gamepad::R),
|
||||
ComboGpOut(PD::Hid::Gamepad::ZL), ComboGpOut(PD::Hid::Gamepad::ZR),
|
||||
ComboGpOut(PD::Hid::Gamepad::CPLeft),
|
||||
ComboGpOut(PD::Hid::Gamepad::CPRight),
|
||||
ComboGpOut(PD::Hid::Gamepad::CPUp),
|
||||
ComboGpOut(PD::Hid::Gamepad::CPDown),
|
||||
ComboGpOut(PD::Hid::Gamepad::CSLeft),
|
||||
ComboGpOut(PD::Hid::Gamepad::CSRight),
|
||||
ComboGpOut(PD::Hid::Gamepad::CSUp),
|
||||
ComboGpOut(PD::Hid::Gamepad::CSDown), PD::Hid::GetLeftStick(),
|
||||
PD::Hid::GetRightStick(), LeftStick.pPos)
|
||||
.c_str(),
|
||||
PD::Color("#ffffff"));
|
||||
"#ffffff");
|
||||
LeftStick.Render(pList);
|
||||
RightStick.Render(pList);
|
||||
pList.UnbindTexture();
|
||||
pList.PathRect(50, PD::fvec2(450, 240));
|
||||
pList.PathFillGradient("#ff0000", "#990000", PD::Radians(135));
|
||||
pList.PathAdd(PD::fvec2(100, 120));
|
||||
pList.PathAdd(PD::fvec2(250, 260));
|
||||
pList.PathAdd(PD::fvec2(420, 180));
|
||||
pList.PathAdd(PD::fvec2(600, 320));
|
||||
pList.PathAdd(PD::fvec2(820, 220));
|
||||
pList.PathAdd(PD::fvec2(1000, 360));
|
||||
|
||||
pList.PathStroke("#ff00ff", 10, LiDrawFlags_AA);
|
||||
PD::Gfx::Reset();
|
||||
PD::Gfx::Draw(pList);
|
||||
pList.Clear();
|
||||
pOs->SwapBuffers();
|
||||
}
|
||||
font.Delete();
|
||||
PD::Gfx::DeleteTexture(pTex);
|
||||
PD::Gfx::Deinit();
|
||||
pOs->Deinit();
|
||||
|
||||
@@ -72,6 +72,7 @@ void DesktopOS::Init() {
|
||||
}
|
||||
#endif
|
||||
glfwSwapInterval(1);
|
||||
PD::Hid::UseDriver<HidGlfw>(impl->win);
|
||||
}
|
||||
|
||||
void DesktopOS::Deinit() {
|
||||
|
||||
@@ -42,6 +42,7 @@ void HorizonCtr::Init() {
|
||||
C3D_RenderTargetSetOutput(impl->Bottom, GFX_BOTTOM, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
PD::Gfx::UseDriver<PD::GfxCitro3D>();
|
||||
PD::Hid::UseDriver<PD::HidDriver>();
|
||||
}
|
||||
|
||||
void HorizonCtr::Deinit() {
|
||||
|
||||
@@ -29,6 +29,7 @@ void HorizonNX::Init() {
|
||||
gladLoadGL();
|
||||
glfwSwapInterval(1);
|
||||
PD::Gfx::UseDriver<PD::GfxOpenGL3>();
|
||||
PD::Hid::UseDriver<PD::HidGlfw>(impl->win);
|
||||
}
|
||||
|
||||
void HorizonNX::Deinit() {
|
||||
|
||||
Vendored
+1
-1
Submodule vendor/libpicasso updated: a6b1e8ddbd...27d11f8f64
Reference in New Issue
Block a user