Author SHA1 Message Date
tobid7 39e91b588f reset layers and give menus a base layer to gather perfect ordered rendering 2026-09-06 15:58:20 +02:00
tobid7 7bb1406365 Add FontStack to UI7 and uncomment layer lines 2026-09-06 15:58:20 +02:00
tobid7 438584e4f2 move and fix scrolling to layout
Scrolling was hardcoded to 3ds sCrEeNhEiGhT wTh
2026-09-06 15:58:20 +02:00
tobid7 acc4fd11eb Layers are back 2026-09-06 15:58:19 +02:00
tobid7 72bb76dcbc hotfix 2026-09-06 15:58:19 +02:00
tobid7 272b66f7f0 Add Hid3DS 2026-09-06 15:58:19 +02:00
tobid7 6637a3692b Bring back global lithium pools
why?
cause sorting around the global driver pool would basically use more cpu power then just copy data sequences into the right order
And sorting data references costs 0 performance at all
2026-09-06 15:58:19 +02:00
tobid7 feeb3b1ba8 Add Drawlist Vertex and Indexcount geteter (for debugging usage only) 2026-09-06 15:58:19 +02:00
tobid7 5a56bf3986 Fix The rest of UI7 Mem leaks
Throw OneFrame living objs into a pool
2026-09-06 15:58:19 +02:00
tobid7 1dfc538ae3 stop leaking idobj memory (and coloredit layout mem) 2026-09-06 15:58:19 +02:00
tobid7 36c05a9138 dx9: update device size on window size change 2026-09-06 15:58:18 +02:00
tobid7 a8d841c63c format documents 2026-09-06 15:58:18 +02:00
tobid7 8983371806 unload debugfont and add Gfx debug menu 2026-09-06 15:58:18 +02:00
tobid7 2b4c4bacd6 fix random garbage ptr issues 2026-09-06 15:58:18 +02:00
tobid7 859a4c96ae Fix Indexorder issues and patchfixsomehow dx9 tex filtering 2026-09-06 15:58:18 +02:00
tobid7 0e0d576954 No big update without msvc compiler errors :/ 2026-09-06 15:58:18 +02:00
tobid7 4a29cb4330 More timings 2026-09-06 15:58:18 +02:00
tobid7 e0b86ee3f6 UI7 is BACK!
took me about a full week to get something to render again withour shared_ptrs
as of now this is very unstable, untested and lacking a lot of features due to lithium is lacking the base for that
Added JetBrainsMono font as debug font for the metrics
2026-09-06 15:58:17 +02:00
tobid7 b121001db7 Add missing GetDriverName to Os 2026-09-06 15:58:17 +02:00
tobid7 2059772ad1 Draw the line (oder so) 2026-09-06 15:58:17 +02:00
tobid7 81aa08485b Load the font async for now 2026-09-06 15:58:17 +02:00
tobid7 ecadf0a44c n3ds-boost 2026-09-06 15:58:17 +02:00
tobid7 6dfc04378a SDF & MONOSPACE FONT RENDERING 2026-09-06 15:58:17 +02:00
tobid7 e3ffcbb596 save 75% of font memory 2026-09-06 15:58:16 +02:00
tobid7 469cd535fd Upload pools once per Gfx::Draw and FIX DX9 2026-09-06 15:58:16 +02:00
tobid7 b594e09bdb reset pools on newframe 2026-09-06 15:58:16 +02:00
tobid7 41b25e4476 move global pools into gfx driver
prevents double copy problems
saves memory
(needs to be optimized...)
2026-09-06 15:58:16 +02:00
tobid7 25607b865c faster rect command creation 2026-09-06 15:58:16 +02:00
tobid7 1bf103c894 cache ascii chars directly 2026-09-06 15:58:16 +02:00
tobid7 11a480136b insane performance boost (on 3ds) 2026-09-06 15:58:16 +02:00
tobid7 e6fcfe0650 time trace is back 2026-09-06 15:58:15 +02:00
tobid7 a8a80cfa47 implement Image::Convert and Image::Flip 2026-09-06 15:58:15 +02:00
tobid7 b7f1037b18 pool append move and copy 2026-09-06 15:58:15 +02:00
tobid7 de51a35734 # small fixes
- Fix Os::GetTimeNano()
- only build tests on non vendored usage
2026-09-06 15:58:15 +02:00
tobid7 13152a317a Fix 2026-09-06 15:58:15 +02:00
tobid7 5dd5907c43 Fix 3ds build and update libpicasso 2026-09-06 15:58:15 +02:00
tobid7 673e53935a remove poc func 2026-09-06 15:58:15 +02:00
tobid7 dda8258064 Add support for rotated gradients 2026-09-06 15:58:14 +02:00
tobid7 0c55291f9c Add stick and trigger input support 2026-09-06 15:58:14 +02:00
tobid7 c5f6f0cb33 Fix clang warning 2026-09-06 15:58:14 +02:00
tobid7 391eea100a fix preset names for Selection Views 2026-09-06 15:58:14 +02:00
tobid7 d70a9970e9 Add NX Hid Driver Template
- Add WIP HidNX Driver (clangd not working with devkitpro for switch on windows)
- Add default-release as default search path for compile_commands.json
- remove mingw preset (casue its exactly the default target)
- Move Mouse pos cycle into HidDriver::Update
- Test around with HidGlfw on Nintendo switch
2026-09-06 15:58:14 +02:00
tobid7 0f044538cc Add proper Gamepad support (WIP) 2026-09-06 15:58:14 +02:00
tobid7 546940aa77 allo wPD::Color in Drawlist 2026-09-06 15:58:14 +02:00
tobid7 dc365bc658 Add Input functionality to Ultra
- Add point InSpace check to PD::Li::Math
- Add Universal AlignmentCenter flag for Horizontal and and Vertical Alignment
-  Add Fallbackfont to Layout (if you dont want to set font per object)
- Add Button Object WIP
- Rename OnHover to OnFocus and add OnUnfocus
- Move font and FontScale to ElementBase (for fallback logic etc)
- Add UpdateInput func to ElementBase
- Corectly Set fontScale in Text Rendering
- Update ecample
2026-09-06 15:58:13 +02:00
tobid7 1ccc7075fa Allow implicit usage of "#ffffffff" etc 2026-09-06 15:58:13 +02:00
tobid7 b069f10841 Add HidDriver base and small HidGLFW driver 2026-09-06 15:58:13 +02:00
tobid7 bf3eef8d28 rename PDBackendFlags to PDGfxBackendFlags 2026-09-06 15:58:13 +02:00
tobid7 6298d4c816 Implement VCanvas and Update TextElem
- Text now requires a font and is able to take an individual scale
- Container requires &ref for Elements to make sure they always exist
- SetViewport now sets the canvas as well
- SetBaseViewport Sets the Virtual Canvas Size
- Layout Now requires a Drawlist reference in Render function
- main.cpp: updated the template
2026-09-06 15:58:13 +02:00
tobid7 212ba0c617 Actually implement ultra-rendering 2026-09-06 15:58:13 +02:00
tobid7 b4a7260cf2 Rework Project Ultra
- Added container
- Made container the base of Layout
- Set Containers theirself as pParent for Elements on Push
2026-09-06 15:58:13 +02:00
tobid7 5cf9ff0109 Fix path rects 2026-09-06 15:58:12 +02:00
tobid7 69b5e74d91 Fixing riunded rects 2026-09-06 15:58:12 +02:00
tobid7 9b69d78118 Add a default preset (for linux/macos default builds) 2026-09-06 15:58:12 +02:00
tobid7 e573523511 Add cmake presets
- MSVC requires cmake for Windows
- mingw only builds when GLSLANG is excluded due to wrong header generation
2026-09-06 15:58:12 +02:00
tobid7 1317599475 build 3dsx and nro in ALL stage 2026-09-06 15:58:12 +02:00
tobid7 1876ab9365 More stuff done at Project Ultra
- Added renderspace
- Revision System (to not always update pRenderspace
- added some test scene
2026-09-06 15:58:12 +02:00
tobid7 ce2dc94121 WIP (Codename Ultra) UI lib 2026-09-06 15:58:12 +02:00
tobid7 bef8ced350 implement font deletion 2026-09-06 15:58:11 +02:00
tobid7 dd038883a0 Fix font bugs 2026-09-06 15:58:11 +02:00
tobid7 7ad2b8b0c5 Add debug getters (and somehow text is not rendering :/) 2026-09-06 15:58:11 +02:00
tobid7 63fb09189d Fix Vertex Alloc usage at Index Alloc 2026-09-06 15:58:11 +02:00
tobid7 306ddfed53 Readd font support (not workign yet) 2026-09-06 15:58:11 +02:00
tobid7 c2b0fa01db Update lazyvec / vec api as well as rect are mostly constexpr now 2026-09-06 15:58:11 +02:00
tobid7 594cf5cca4 Always disable glslang build for NintendoSwitch on Windows 2026-09-06 15:58:10 +02:00
tobid7 191bca26d5 Present DX9 Frames ... 2026-09-06 15:58:10 +02:00
tobid7 85a92f8371 Add a PositionTranslate func and add Errors for TextureSize mismatch 2026-09-06 15:58:10 +02:00
tobid7 f3d326c237 Add PD::Image and add a setter for logfilter 2026-09-06 15:58:10 +02:00
tobid7 fda39b3d36 Forgot about dx9 (UNTESTED!!!) 2026-09-06 15:58:10 +02:00
tobid7 8e09025c40 Add Os Bridge into test framework 2026-09-06 15:58:10 +02:00
tobid7 2a57b7c08c Refactor PD::Li Pools system, Upgrade PD::Pool and add better logging
- Add ResetFast to Pool using c++20 concept
- Add Put function to Pool
- Use Pool Index instead of pointers in Command
- Add accessor to Li Pools to prevent wrong command usage
- Add Command Formatter
- Use ResetFast for all Pools
- Add Reset func to Li::Vertex (for ResetFast)
- Add Pool Expandor and Put funcs to Lithium pools
- Add getters for GfxDriverBase to PD::Li Pools
2026-09-06 15:58:10 +02:00
tobid7 9d0565f60c Add nintendo switch support 2026-09-06 15:58:09 +02:00
tobid7 4691d158a9 Remove Gfx Driver Vertex and IndexBuffer size config 2026-09-06 15:58:09 +02:00
tobid7 57c376a822 Add Drawlist
- Add Pool iterator support
- Add Pool Expandability
- Add Pool::Push
- Add Lithium Maths API
- Remove InitPools
- update spirv-helper
2026-09-06 15:58:09 +02:00
tobid7 d72c447875 Replace spirv-helper stuff with a library that combines everything 2026-09-06 15:58:09 +02:00
tobid7 518015afb1 Add the shaders 2026-09-06 15:58:09 +02:00
tobid7 e6a60e90d1 Add pdsg (palladium spirv-generator)
- remove glslang from pd-system
- use spirv blobs instead of glsl 460
- Use Legacy shaders for OpenGL2 backend
- add devnotes
2026-09-06 15:58:09 +02:00
tobid7 9d63a17700 Add SpirvHelper (Shader cross compilation)
- Make OpenGL2 and OpenGL3 use the same base shaders (using SpirvHelper)
- Add Transpose func to Mat4
2026-09-06 15:58:09 +02:00
tobid7 fd498c5ea2 Add missing sources 2026-09-06 15:58:08 +02:00
tobid7 0cc886315d Full 3ds support and fix dx9 2026-09-06 15:58:08 +02:00
tobid7 1b9876f64b Work at 3ds support and backend upgrades
- Track textures (not sure if this is done tbh)
- Add lithium formatters and move TextureID, TextureFormat and TextureFilter to lithium
- Only include gl-helper if any glDriver is included
- Add Li::Rect for UV stuff
- Add Li::Texture as Info holder (still thinking of making them to ptrs
- Add Check if textures are still loaded on exit
2026-09-06 15:58:08 +02:00
tobid7 cd904ea544 Add backends
- Renamed GfxOpenGL to GfxOPenGL2
- Added GfxOpenGL3 backend for OpenGL 3.3+
- Added WIP DirectX9 backend
- Added structure for Citro3D
- Added linear Allocator
2026-09-06 15:58:08 +02:00
tobid7 e43cb41377 More work to drivers
- Add gfx_test
- add texture loading to GfxOpenGL
- add full submit code
- add debug logging
- add construct and destroy functionality to Pool
- add command functionality
- add vertex and index pools to lithium (static and not threadsafe yet)
- Update GfxDriver Matrix with SetViewPort
- Add glfw (only dependency of gfx_test) maybe later required for input driver
2026-09-06 15:58:08 +02:00
tobid7 b2d3d203a2 - Update pool to use template allocator directly instead of std::vector
- Add a GfxDriver config Template to be able to modify settings like allocators / Types for specific Drivers
- Add glad
2026-09-06 15:58:04 +02:00
tobid7 f1a63fe383 0.7.0 rewrite dev
- remove everyting
- keep core
-rename bit_utils to bits
- add formatter for  color
- add float getters to color
- start with new drivers api
2026-09-06 15:57:14 +02:00
tobid7 0501a4f87c Make UI7::IO::CurrentViewPort a Reference (finally) 2026-03-18 21:33:35 +01:00
tobid7 3d8b57ead6 add .gitattributes file 2026-03-16 20:28:30 +01:00
tobid7 ac37ce9e12 Fix test 2026-03-14 21:15:40 +01:00
42 changed files with 867 additions and 470 deletions
+1
View File
@@ -52,6 +52,7 @@ set(PD_SOURCES
source/lithium/drawlist.cpp source/lithium/drawlist.cpp
source/lithium/font.cpp source/lithium/font.cpp
source/lithium/math.cpp source/lithium/math.cpp
source/lithium/pools.cpp
# UI7 # UI7
source/ui7/io.cpp source/ui7/io.cpp
+4
View File
@@ -9,6 +9,7 @@ option(PD_ENABLE_CITRO3D "Enable Citro3D Support (3DS)" OFF)
option(PD_ENABLE_VULKAN "Not implemented yet" OFF) option(PD_ENABLE_VULKAN "Not implemented yet" OFF)
option(PD_ENABLE_HID_GLFW "Enable GLFW Input Driver" ON) option(PD_ENABLE_HID_GLFW "Enable GLFW Input Driver" ON)
option(PD_ENABLE_HID_NX "Enable NX Input Driver" OFF) option(PD_ENABLE_HID_NX "Enable NX Input Driver" OFF)
option(PD_ENABLE_HID3DS "Enable 3ds Input Driver" OFF)
if(NOT WIN32) # cause we are not on windows... if(NOT WIN32) # cause we are not on windows...
set(PD_ENABLE_DIRECTX9 OFF) set(PD_ENABLE_DIRECTX9 OFF)
@@ -21,6 +22,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
set(PD_ENABLE_CITRO3D ON) set(PD_ENABLE_CITRO3D ON)
set(PD_ENABLE_HID_GLFW OFF) set(PD_ENABLE_HID_GLFW OFF)
set(PD_ENABLE_HID_NX OFF) set(PD_ENABLE_HID_NX OFF)
set(PD_ENABLE_HID3DS ON)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "NintendoSwitch") elseif(${CMAKE_SYSTEM_NAME} STREQUAL "NintendoSwitch")
set(PD_ENABLE_OPENGL2 OFF) set(PD_ENABLE_OPENGL2 OFF)
set(PD_ENABLE_OPENGL3 ON) set(PD_ENABLE_OPENGL3 ON)
@@ -36,6 +38,7 @@ add_library(pd-system STATIC
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl3.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/hid_3ds.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/hid_glfw.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/hid_glfw.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/hid_nx.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/hid_nx.cpp
) )
@@ -64,6 +67,7 @@ target_compile_definitions(pd-system
$<$<BOOL:${PD_ENABLE_CITRO3D}>:PD_ENABLE_CITRO3D> $<$<BOOL:${PD_ENABLE_CITRO3D}>:PD_ENABLE_CITRO3D>
$<$<BOOL:${PD_ENABLE_HID_GLFW}>:PD_ENABLE_HID_GLFW> $<$<BOOL:${PD_ENABLE_HID_GLFW}>:PD_ENABLE_HID_GLFW>
$<$<BOOL:${PD_ENABLE_HID_NX}>:PD_ENABLE_HID_NX> $<$<BOOL:${PD_ENABLE_HID_NX}>:PD_ENABLE_HID_NX>
$<$<BOOL:${PD_ENABLE_HID3DS}>:PD_ENABLE_HID3DS>
) )
# Palladium # Palladium
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include <pd/drivers/hid.hpp>
namespace PD {
class Hid3DS : public HidDriver {
public:
Hid3DS();
~Hid3DS();
void Update() override;
private:
struct Impl;
Impl* impl;
};
} // namespace PD
+1
View File
@@ -7,4 +7,5 @@
#include <pd_system/gfx_opengl3.hpp> #include <pd_system/gfx_opengl3.hpp>
// Hid // Hid
#include <pd_system/hid_3ds.hpp>
#include <pd_system/hid_glfw.hpp> #include <pd_system/hid_glfw.hpp>
+11 -7
View File
@@ -175,6 +175,10 @@ void GfxDirectX9::SysReset() {
impl->Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); impl->Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
impl->Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); impl->Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
impl->Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); impl->Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
impl->Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
impl->Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
impl->Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
} }
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w, Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
@@ -257,27 +261,27 @@ void GfxDirectX9::UploadPools() {
if (!impl->VBO || impl->VertexBufferSize != GetVertexPoolSize()) { if (!impl->VBO || impl->VertexBufferSize != GetVertexPoolSize()) {
if (impl->VBO) impl->VBO->Release(); if (impl->VBO) impl->VBO->Release();
impl->Device->CreateVertexBuffer(GetVertexPoolSize() * sizeof(Li::Vertex), impl->Device->CreateVertexBuffer(GetVertexPoolSize() * sizeof(Li::Vertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED,
D3DPOOL_DEFAULT, &impl->VBO, nullptr); &impl->VBO, nullptr);
impl->VertexBufferSize = GetVertexPoolSize(); impl->VertexBufferSize = GetVertexPoolSize();
} }
if (!impl->IBO || impl->IndexBufferSize != GetIndexPoolSize()) { if (!impl->IBO || impl->IndexBufferSize != GetIndexPoolSize()) {
if (impl->IBO) impl->IBO->Release(); if (impl->IBO) impl->IBO->Release();
impl->Device->CreateIndexBuffer( impl->Device->CreateIndexBuffer(GetIndexPoolSize() * sizeof(u16),
GetIndexPoolSize() * sizeof(u16), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
D3DFMT_INDEX16, D3DPOOL_DEFAULT, &impl->IBO, nullptr); D3DPOOL_MANAGED, &impl->IBO, nullptr);
impl->IndexBufferSize = GetIndexPoolSize(); impl->IndexBufferSize = GetIndexPoolSize();
} }
void* vptr; void* vptr;
impl->VBO->Lock(0, 0, &vptr, D3DLOCK_DISCARD); impl->VBO->Lock(0, 0, &vptr, 0);
memcpy(vptr, GetVertexBufPtr(0), memcpy(vptr, GetVertexBufPtr(0),
GetVertexPoolSize() * sizeof(PD::Li::Vertex)); GetVertexPoolSize() * sizeof(PD::Li::Vertex));
impl->VBO->Unlock(); impl->VBO->Unlock();
void* iptr; void* iptr;
impl->IBO->Lock(0, 0, &iptr, D3DLOCK_DISCARD); impl->IBO->Lock(0, 0, &iptr, 0);
memcpy(iptr, GetIndexBufPtr(0), GetIndexPoolSize() * sizeof(u16)); memcpy(iptr, GetIndexBufPtr(0), GetIndexPoolSize() * sizeof(u16));
impl->IBO->Unlock(); impl->IBO->Unlock();
} }
+82
View File
@@ -0,0 +1,82 @@
#include <pd_system/hid_3ds.hpp>
#if defined(PD_ENABLE_HID3DS) && defined(__3DS__)
#include <3ds.h>
namespace PD {
struct Hid3DS::Impl {
std::string* Text;
bool InTextMode = false;
};
Hid3DS::Hid3DS() : HidDriver("Hid3DS") {
impl = new Impl;
pFlags |= PDHidBackendFlags_HasGamepad;
pFlags |= PDHidBackendFlags_HasTouch;
pGamepad[KEY_A] = HidInternal::Gamepad::A;
pGamepad[KEY_B] = HidInternal::Gamepad::B;
pGamepad[KEY_X] = HidInternal::Gamepad::X;
pGamepad[KEY_Y] = HidInternal::Gamepad::Y;
pGamepad[KEY_START] = HidInternal::Gamepad::Start;
pGamepad[KEY_SELECT] = HidInternal::Gamepad::Select;
pGamepad[KEY_L] = HidInternal::Gamepad::L;
pGamepad[KEY_R] = HidInternal::Gamepad::R;
pGamepad[KEY_DUP] = HidInternal::Gamepad::DUp;
pGamepad[KEY_DDOWN] = HidInternal::Gamepad::DDown;
pGamepad[KEY_DLEFT] = HidInternal::Gamepad::DLeft;
pGamepad[KEY_DRIGHT] = HidInternal::Gamepad::DRight;
pGamepad[KEY_CPAD_UP] = HidInternal::Gamepad::CPUp;
pGamepad[KEY_CPAD_DOWN] = HidInternal::Gamepad::CPDown;
pGamepad[KEY_CPAD_LEFT] = HidInternal::Gamepad::CPLeft;
pGamepad[KEY_CPAD_RIGHT] = HidInternal::Gamepad::CPRight;
pGamepad[KEY_CSTICK_UP] = HidInternal::Gamepad::CSUp;
pGamepad[KEY_CSTICK_DOWN] = HidInternal::Gamepad::CSDown;
pGamepad[KEY_CSTICK_LEFT] = HidInternal::Gamepad::CSLeft;
pGamepad[KEY_CSTICK_RIGHT] = HidInternal::Gamepad::CSRight;
pGamepad[KEY_ZL] = HidInternal::Gamepad::ZL;
pGamepad[KEY_ZR] = HidInternal::Gamepad::ZR;
pGamepad[KEY_TOUCH] = HidInternal::Gamepad::Touch;
}
Hid3DS::~Hid3DS() { delete impl; }
void Hid3DS::Update() {
HidDriver::Update(); // clear stats
hidScanInput();
u32 kd = hidKeysDown();
u32 kh = hidKeysHeld();
u32 ku = hidKeysUp();
for (const auto& b : pGamepad) {
if (b.first & kd) {
pGamepadEvents[0][Event::Down] |= b.second;
}
if (b.first & kh) {
pGamepadEvents[0][Event::Held] |= b.second;
}
if (b.first & ku) {
pGamepadEvents[0][Event::Up] |= b.second;
}
}
/*if (pLocked) {
SwapTab();
}*/
touchPosition t;
hidTouchRead(&t);
pMouse[0] = fvec2(t.px, t.py);
}
} // namespace PD
#else
struct GLFWgamepadstate {};
namespace PD {
Hid3DS::Hid3DS() : HidDriver("Hid3DS") {}
Hid3DS::~Hid3DS() {}
void Hid3DS::Update() {
HidDriver::Update(); // clear stats
}
} // namespace PD
#endif
+1 -1
View File
@@ -65,7 +65,7 @@ HidGlfw::HidGlfw(GLFWwindow* win) : HidDriver("HidGlfw") {
} }
} }
HidGlfw::~HidGlfw() {} HidGlfw::~HidGlfw() { delete impl; }
void HidGlfw::Update() { void HidGlfw::Update() {
HidDriver::Update(); // clear stats HidDriver::Update(); // clear stats
+1 -1
View File
@@ -11,7 +11,7 @@ struct HidNX::Impl {
HidNX::HidNX() : HidDriver("HidNX") { impl = new Impl; } HidNX::HidNX() : HidDriver("HidNX") { impl = new Impl; }
HidNX::~HidNX() {} HidNX::~HidNX() { delete impl; }
void HidNX::Update() { void HidNX::Update() {
HidDriver::Update(); // clear stats HidDriver::Update(); // clear stats
+48 -9
View File
@@ -2,7 +2,8 @@
#include <pd/core/mat.hpp> #include <pd/core/mat.hpp>
#include <pd/drivers/interface.hpp> #include <pd/drivers/interface.hpp>
#include <pd/lithium/command.hpp> #include <pd/lithium/drawlist.hpp>
#include <pd/lithium/pools.hpp>
#include <pd/lithium/texture.hpp> #include <pd/lithium/texture.hpp>
using PDGfxBackendFlags = PD::u32; using PDGfxBackendFlags = PD::u32;
@@ -37,7 +38,7 @@ class PD_API GfxDriver : public DriverInterface {
return Li::Texture(); return Li::Texture();
} }
virtual void DeleteTexture(const Li::Texture& tex) {} virtual void DeleteTexture(const Li::Texture& tex) {}
virtual void Draw(const Pool<Li::Command>& commands) {} virtual void Draw(const Li::Drawlist& commands) {}
Li::Texture::Ptr GetWhiteTexture() { return &pWhite; } Li::Texture::Ptr GetWhiteTexture() { return &pWhite; }
PDGfxBackendFlags GetFlags() { return Flags; } PDGfxBackendFlags GetFlags() { return Flags; }
@@ -110,17 +111,54 @@ class GfxDriverBase : public GfxDriver {
pWhite = LoadTexture(img, 16, 16); pWhite = LoadTexture(img, 16, 16);
} }
void Draw(const Pool<Li::Command>& commands) override { void Draw(const Li::Drawlist& dl) override {
const auto& commands = dl.Data();
if (commands.size() == 0) return;
pCountCommands += commands.size(); pCountCommands += commands.size();
size_t index = 0;
size_t vtotal = dl.GetNumVertices();
size_t itotal = dl.GetNumIndices();
size_t start_vtx = pVtxPool.size();
pVtxPool.Allocate(vtotal);
CurrentVertex += vtotal;
size_t start_idx = pIdxPool.size();
pIdxPool.Allocate(itotal);
CurrentIndex += itotal;
size_t current_vtx = start_vtx;
size_t current_idx = start_idx;
const auto& vpool = Li::GetVertexPool();
const auto& ipool = Li::GetIndexPool();
/** Build Pools */
for (size_t i = 0; i < commands.size(); i++) {
const auto& cmd = commands[i];
if (cmd.VertexCount > 0) {
std::memcpy(pVtxPool.begin() + current_vtx,
vpool.begin() + cmd.FirstVertex,
cmd.VertexCount * sizeof(Li::Vertex));
}
for (size_t idx = 0; idx < cmd.IndexCount; idx++) {
u16 local_idx = ipool[cmd.FirstIndex + idx];
pIdxPool[current_idx + idx] = static_cast<u16>(current_vtx + local_idx);
}
current_vtx += cmd.VertexCount;
current_idx += cmd.IndexCount;
}
UploadPools(); UploadPools();
size_t index = 0;
size_t ioff = start_idx;
while (index < commands.size()) { while (index < commands.size()) {
CurrentTex = commands[index].Tex; CurrentTex = commands[index].Tex;
CurrentTexIsSDF = commands[index].SDF; CurrentTexIsSDF = commands[index].SDF;
if (!CurrentTex) { if (!CurrentTex) {
CurrentTex = pWhite.GetID(); CurrentTex = pWhite.GetID();
} }
size_t startidx = commands[index].FirstIndex;
size_t num_indices = 0; size_t num_indices = 0;
while (index < commands.size() && while (index < commands.size() &&
CurrentTexIsSDF == commands[index].SDF && CurrentTexIsSDF == commands[index].SDF &&
@@ -129,10 +167,13 @@ class GfxDriverBase : public GfxDriver {
num_indices += commands[index].IndexCount; num_indices += commands[index].IndexCount;
index++; index++;
} }
Submit(num_indices, startidx); if (num_indices > 0) {
Submit(num_indices, ioff);
ioff += num_indices;
pCountDrawcalls++; pCountDrawcalls++;
} }
} }
}
size_t AllocateVertices(size_t count, PD::ptr accessor) override { size_t AllocateVertices(size_t count, PD::ptr accessor) override {
pVertexAccessor = accessor; pVertexAccessor = accessor;
@@ -210,9 +251,7 @@ class PD_API Gfx {
static void SetViewPort(const ivec2& vp) { driver->SetViewPort(vp); } static void SetViewPort(const ivec2& vp) { driver->SetViewPort(vp); }
static void SetViewPort(int w, int h) { driver->SetViewPort(w, h); } static void SetViewPort(int w, int h) { driver->SetViewPort(w, h); }
static void Reset() { driver->Reset(); } static void Reset() { driver->Reset(); }
static void Draw(const Pool<Li::Command>& commands) { static void Draw(const Li::Drawlist& dl) { driver->Draw(dl); }
driver->Draw(commands);
}
static Li::Texture LoadTexture(const std::vector<PD::u8>& pixels, int w, static Li::Texture LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, int h,
TextureFormat type = TextureFormat::RGBA32, TextureFormat type = TextureFormat::RGBA32,
+17
View File
@@ -42,6 +42,22 @@ class PD_API Drawlist {
void Copy(Drawlist& other); void Copy(Drawlist& other);
void Optimize(); void Optimize();
void Clear(); void Clear();
void SetLayer(int layer) { pCurrentLayer = layer; }
void LayerUp() { pCurrentLayer++; }
void LayerDown() { pCurrentLayer--; }
int GetLayer() const { return pCurrentLayer; }
size_t GetNumVertices() const {
size_t count = 0;
for (const auto& cmd : pCommands) count += cmd.VertexCount;
return count;
}
size_t GetNumIndices() const {
size_t count = 0;
for (const auto& cmd : pCommands) count += cmd.IndexCount;
return count;
}
/** Command Allocation */ /** Command Allocation */
Command& NewCommand(); Command& NewCommand();
@@ -114,6 +130,7 @@ class PD_API Drawlist {
private: private:
Texture pCurrentTexture; Texture pCurrentTexture;
int pCurrentLayer = 0;
Pool<Command> pCommands; Pool<Command> pCommands;
Pool<fvec2> pPath; Pool<fvec2> pPath;
Pool<Vertex> pVertices; Pool<Vertex> pVertices;
+1
View File
@@ -4,4 +4,5 @@
#include <pd/lithium/drawlist.hpp> #include <pd/lithium/drawlist.hpp>
#include <pd/lithium/font.hpp> #include <pd/lithium/font.hpp>
#include <pd/lithium/math.hpp> #include <pd/lithium/math.hpp>
#include <pd/lithium/pools.hpp>
#include <pd/lithium/vertex.hpp> #include <pd/lithium/vertex.hpp>
+12
View File
@@ -0,0 +1,12 @@
#pragma once
#include <pd/core/core.hpp>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace Li {
PD_API PD::Pool<Vertex>& GetVertexPool();
PD_API PD::Pool<u16>& GetIndexPool();
PD_API void ResetPools();
} // namespace Li
} // namespace PD
+4 -2
View File
@@ -47,7 +47,9 @@ class PD_API ColorEdit : public Container {
this->initial_color = *color; this->initial_color = *color;
this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale); this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale);
} }
~ColorEdit() = default; ~ColorEdit() {
if (layout) delete layout;
}
/** /**
* Override for the Input Handler * Override for the Input Handler
@@ -68,7 +70,7 @@ class PD_API ColorEdit : public Container {
u32* color_ref = nullptr; ///< Color Reference u32* color_ref = nullptr; ///< Color Reference
u32 initial_color; ///< Initial Color u32 initial_color; ///< Initial Color
std::string label; ///< Label of the Button std::string label; ///< Label of the Button
Layout* layout; ///< Layout to open Layout* layout = nullptr; ///< Layout to open
bool is_shown = false; ///< AHow Layout Editor bool is_shown = false; ///< AHow Layout Editor
}; };
} // namespace UI7 } // namespace UI7
+25 -3
View File
@@ -59,6 +59,7 @@ class PD_API Container {
void Init(UI7::IO* io, Li::Drawlist* l) { void Init(UI7::IO* io, Li::Drawlist* l) {
list = l; list = l;
this->io = io; this->io = io;
pFont = io->Font;
// this->screen = io->Ren->CurrentScreen(); // this->screen = io->Ren->CurrentScreen();
} }
@@ -75,6 +76,7 @@ class PD_API Container {
fvec2 GetPos() { return pos; } fvec2 GetPos() { return pos; }
/** Getter for Size */ /** Getter for Size */
fvec2 GetSize() { return size; } fvec2 GetSize() { return size; }
Li::Font* GetFont() { return pFont; }
/** /**
* Get the Containers Final Position * Get the Containers Final Position
* for Rendering and Input (if it has a parent Object) * for Rendering and Input (if it has a parent Object)
@@ -111,6 +113,25 @@ class PD_API Container {
virtual void Draw() {} virtual void Draw() {}
/** Template function to update internal data (if needed) */ /** Template function to update internal data (if needed) */
virtual void Update() {} virtual void Update() {}
/** Template as well as base func for Pool based Containers */
virtual void Reset() {
pos = 0;
size = 0;
parent = nullptr;
id = 0;
pFlags = 0;
skippable = false;
rem = false;
inp_done = false;
pSelected = false;
pPressed = false;
pPressedTwice = false;
pCLipRectUsed = false;
pClipRect = 0;
io = nullptr;
list = nullptr;
last_use = 0;
}
/** Internal function */ /** Internal function */
void PreDraw(); void PreDraw();
@@ -155,11 +176,11 @@ class PD_API Container {
/** Container Size*/ /** Container Size*/
fvec2 size; fvec2 size;
/** Reference to the Drawlist to Draw to*/ /** Reference to the Drawlist to Draw to*/
Li::Drawlist* list; Li::Drawlist* list = nullptr;
/** IO Reference for Renderer and Theme */ /** IO Reference for Renderer and Theme */
UI7::IO* io; UI7::IO* io = nullptr;
/** Reference to the parent container*/ /** Reference to the parent container*/
Container* parent; Container* parent = nullptr;
/** Object ID (0 if unused)*/ /** Object ID (0 if unused)*/
u32 id = 0; u32 id = 0;
/** Internal Flags */ /** Internal Flags */
@@ -174,6 +195,7 @@ class PD_API Container {
fvec4 pClipRect; fvec4 pClipRect;
/** Clip Rect used */ /** Clip Rect used */
bool pCLipRectUsed = false; bool pCLipRectUsed = false;
Li::Font* pFont = nullptr;
}; };
} // namespace UI7 } // namespace UI7
} // namespace PD } // namespace PD
+10 -1
View File
@@ -23,9 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <functional>
#include <pd/ui7/container/container.hpp> #include <pd/ui7/container/container.hpp>
#include <pd/ui7/io.hpp> #include <pd/ui7/io.hpp>
#include <functional>
namespace PD { namespace PD {
namespace UI7 { namespace UI7 {
@@ -38,6 +38,7 @@ namespace UI7 {
*/ */
class PD_API DynObj : public Container { class PD_API DynObj : public Container {
public: public:
DynObj() {}
/** /**
* Button Object constructor * Button Object constructor
* @param label Label of the Button * @param label Label of the Button
@@ -69,6 +70,14 @@ class PD_API DynObj : public Container {
/** Function to Update Size if framepadding changes */ /** Function to Update Size if framepadding changes */
void Update() override; void Update() override;
void Reset() override {
Container::Reset();
color = UI7Color_Button;
pressed = false;
pRenFun = nullptr;
pInp = nullptr;
}
private: private:
UI7Color color = UI7Color_Button; ///< current button color UI7Color color = UI7Color_Button; ///< current button color
bool pressed = false; ///< ispressed value bool pressed = false; ///< ispressed value
+8
View File
@@ -32,6 +32,7 @@ namespace UI7 {
*/ */
class PD_API Image : public Container { class PD_API Image : public Container {
public: public:
Image() {}
/** /**
* Constructor for the Image Object * Constructor for the Image Object
* @param img Image Texture Reference * @param img Image Texture Reference
@@ -57,6 +58,13 @@ class PD_API Image : public Container {
* */ * */
void Draw() override; void Draw() override;
void Reset() override {
Container::Reset();
img = Li::Texture();
newsize = 0.f;
cuv = Li::Rect();
}
private: private:
Li::Texture img; ///< Texture Li::Texture img; ///< Texture
fvec2 newsize = 0.f; ///< New Size fvec2 newsize = 0.f; ///< New Size
+8
View File
@@ -32,6 +32,7 @@ namespace UI7 {
*/ */
class PD_API Label : public Container { class PD_API Label : public Container {
public: public:
Label() {}
/** /**
* Constructor for Label Object * Constructor for Label Object
* @param label Label [Text] to Draw * @param label Label [Text] to Draw
@@ -54,6 +55,13 @@ class PD_API Label : public Container {
*/ */
void Update() override; void Update() override;
void Reset() override {
Container::Reset();
tdim = 0;
color = UI7Color_Text;
label.clear();
}
private: private:
fvec2 tdim; ///< Text Size fvec2 tdim; ///< Text Size
UI7Color color = UI7Color_Text; ///< Color UI7Color color = UI7Color_Text; ///< Color
+2
View File
@@ -58,6 +58,8 @@ enum UI7MenuFlags_ {
enum UI7LayoutFlags_ { enum UI7LayoutFlags_ {
UI7LayoutFlags_None = 0, ///< No Flags used UI7LayoutFlags_None = 0, ///< No Flags used
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
UI7LayoutFlags_HzScrolling = 1 << 1, ///< Scrolling Horizontal
UI7LayoutFlags_VtScrolling = 1 << 2, ///< Scrolling Vertical
}; };
/** UI7 Context Flags */ /** UI7 Context Flags */
+23 -7
View File
@@ -31,16 +31,14 @@ SOFTWARE.
#include <pd/ui7/viewport.hpp> #include <pd/ui7/viewport.hpp>
namespace PD { namespace PD {
class Context;
namespace UI7 { namespace UI7 {
class Label;
class Image;
class DynObj;
class PD_API IO { class PD_API IO {
public: public:
IO() : DeltaStats(60), CurrentViewPort("", 0) { IO();
/** Probably not the best solution i guess */ ~IO();
// CurrentViewPort =
// ViewPort::New("Default", ivec4(ivec2(0, 0), pCtx.Gfx()->ViewPort));
}
~IO() {}
/** /**
* IO Update Internal Variables * IO Update Internal Variables
@@ -83,6 +81,12 @@ class PD_API IO {
u32 NumVertices = 0; ///< Debug Vertices Num u32 NumVertices = 0; ///< Debug Vertices Num
u32 NumIndices = 0; ///< Debug Indices Num u32 NumIndices = 0; ///< Debug Indices Num
std::vector<u32> MenuOrder; std::vector<u32> MenuOrder;
std::vector<Li::Font*> FontStack;
// Pools
PD::Pool<UI7::Label> LabelPool;
PD::Pool<UI7::Image> ImagePool;
PD::Pool<UI7::DynObj> DynObjPool;
// DrawlistApi // DrawlistApi
void RegisterDrawlist(const UI7::ID& id, Li::Drawlist* v) { void RegisterDrawlist(const UI7::ID& id, Li::Drawlist* v) {
@@ -104,6 +108,18 @@ class PD_API IO {
return ViewPorts[id.RawID()]; return ViewPorts[id.RawID()];
} }
void PushFont(Li::Font* f) {
FontStack.push_back(Font);
Font = f;
}
void PopFont() {
if (!FontStack.empty()) {
Font = FontStack.back();
FontStack.pop_back();
}
}
UI7::InputHandler InputHandler; UI7::InputHandler InputHandler;
}; };
} // namespace UI7 } // namespace UI7
+5 -1
View File
@@ -47,7 +47,7 @@ class PD_API Layout {
Size = 0; Size = 0;
WorkRect = fvec4(IO.MenuPadding, Size - (fvec2(2) * IO.MenuPadding)); WorkRect = fvec4(IO.MenuPadding, Size - (fvec2(2) * IO.MenuPadding));
} }
~Layout() = default; ~Layout();
/** SECTION CONTAINERS */ /** SECTION CONTAINERS */
/** /**
@@ -127,6 +127,8 @@ class PD_API Layout {
void CursorInit(); void CursorInit();
void SameLine(); void SameLine();
void CursorMove(const fvec2& size); void CursorMove(const fvec2& size);
void PushFont(Li::Font* f) { IO.PushFont(f); }
void PopFont() { IO.PopFont(); }
bool ObjectWorkPos(fvec2& movpos); bool ObjectWorkPos(fvec2& movpos);
@@ -163,6 +165,8 @@ class PD_API Layout {
void SetAlign(UI7Align a) { Alignment = a; } void SetAlign(UI7Align a) { Alignment = a; }
void NextAlign(UI7Align a) { TempAlign = a; } void NextAlign(UI7Align a) { TempAlign = a; }
void HandleScrolling();
void Update(); void Update();
fvec2 DbgScrollOffset() { return ScrollOffset; } fvec2 DbgScrollOffset() { return ScrollOffset; }
+3 -1
View File
@@ -110,7 +110,6 @@ class PD_API Menu {
void EndTreeNode(); void EndTreeNode();
void HandleFocus(); void HandleFocus();
void HandleScrolling();
void HandleTitlebarActions(); void HandleTitlebarActions();
void DrawBaseLayout(); void DrawBaseLayout();
@@ -120,6 +119,9 @@ class PD_API Menu {
} }
Container* FindObject(u32 id) { return pLayout.FindObject(id); } Container* FindObject(u32 id) { return pLayout.FindObject(id); }
void PushFont(Li::Font* f) { pIO.PushFont(f); }
void PopFont() { pIO.PopFont(); }
void Update(); void Update();
void SetSize(PD::fvec2 size) { pLayout.SetSize(size); } void SetSize(PD::fvec2 size) { pLayout.SetSize(size); }
+1 -2
View File
@@ -56,8 +56,7 @@ class PD_API Context {
void AddViewPort(const ID& id, const ivec4& vp); void AddViewPort(const ID& id, const ivec4& vp);
void UseViewPort(const ID& id); void UseViewPort(const ID& id);
void Update(); void Update();
Menu* BeginMenu(const ID& id, UI7MenuFlags flags = 0, Menu* BeginMenu(const ID& id, UI7MenuFlags flags = 0, bool* pShow = nullptr);
bool* pShow = nullptr);
Menu* CurrentMenu() { return pCurrent; } Menu* CurrentMenu() { return pCurrent; }
void EndMenu(); void EndMenu();
void AboutMenu(bool* show = nullptr); void AboutMenu(bool* show = nullptr);
+40 -12
View File
@@ -1,23 +1,48 @@
#include <pd/drivers/gfx.hpp> #include <pd/drivers/gfx.hpp>
#include <pd/lithium/command.hpp> #include <pd/lithium/command.hpp>
#include <pd/lithium/pools.hpp>
namespace PD { namespace PD {
namespace Li { namespace Li {
void Command::Reserve(size_t vtx, size_t idx) { void Command::Reserve(size_t vtx, size_t idx) {
auto& vpool = GetVertexPool();
auto& ipool = GetIndexPool();
if (VertexCountMax == 0) { if (VertexCountMax == 0) {
FirstVertex = Gfx::AllocateVertices(vtx, (PD::ptr)this); FirstVertex = vpool.size();
vpool.Allocate(vtx);
VertexCountMax = vtx; VertexCountMax = vtx;
} else { } else {
Gfx::ExpandVertices(vtx, (PD::ptr)this); if (vpool.size() == FirstVertex + VertexCountMax) {
vpool.Allocate(vtx);
VertexCountMax += vtx;
} else {
size_t tmp = FirstVertex;
FirstVertex = vpool.size();
vpool.Allocate(VertexCountMax + vtx);
for (size_t i = 0; i < VertexCount; i++) {
vpool[FirstVertex + i] = vpool[tmp + i];
}
VertexCountMax += vtx; VertexCountMax += vtx;
} }
}
if (IndexCountMax == 0) { if (IndexCountMax == 0) {
FirstIndex = Gfx::AllocateIndices(idx, (PD::ptr)this); FirstIndex = ipool.size();
ipool.Allocate(idx);
IndexCountMax = idx; IndexCountMax = idx;
} else { } else {
Gfx::ExpandIndices(idx, (PD::ptr)this); if (ipool.size() == FirstIndex + IndexCountMax) {
ipool.Allocate(idx);
IndexCountMax += idx; IndexCountMax += idx;
} else {
size_t tmp = FirstIndex;
FirstIndex = ipool.size();
ipool.Allocate(IndexCountMax + idx);
for (size_t i = 0; i < IndexCount; i++) {
ipool[FirstIndex + i] = ipool[tmp + i];
}
IndexCountMax += idx;
}
} }
} }
@@ -34,22 +59,25 @@ void Command::Reset() {
} }
Command& Command::Add(const Vertex& vtx) { Command& Command::Add(const Vertex& vtx) {
if (VertexCount <= VertexCountMax) if (VertexCount < VertexCountMax) {
Gfx::PutVertex(FirstVertex + VertexCount++, vtx, (PD::ptr)this); GetVertexPool()[FirstVertex + VertexCount++] = vtx;
}
return *this; return *this;
} }
Command& Command::Add(u16 idx) { Command& Command::Add(u16 idx) {
if (IndexCount <= IndexCountMax) if (IndexCount < IndexCountMax) {
Gfx::PutIndex(FirstIndex + IndexCount++, FirstVertex + VertexCount + idx, GetIndexPool()[FirstIndex + IndexCount++] =
(PD::ptr)this); static_cast<u16>(VertexCount + idx);
}
return *this; return *this;
} }
Command& Command::Add(u16 a, u16 b, u16 c) { Command& Command::Add(u16 a, u16 b, u16 c) {
if (IndexCount + 3 <= IndexCountMax) { if (IndexCount + 3 <= IndexCountMax) {
auto& ip = GetIndexPool();
size_t idx = FirstIndex + IndexCount; size_t idx = FirstIndex + IndexCount;
Gfx::PutIndex(idx + 0, FirstVertex + VertexCount + a, (PD::ptr)this); ip[idx + 0] = static_cast<u16>(VertexCount + a);
Gfx::PutIndex(idx + 1, FirstVertex + VertexCount + b, (PD::ptr)this); ip[idx + 1] = static_cast<u16>(VertexCount + b);
Gfx::PutIndex(idx + 2, FirstVertex + VertexCount + c, (PD::ptr)this); ip[idx + 2] = static_cast<u16>(VertexCount + c);
IndexCount += 3; IndexCount += 3;
} }
return *this; return *this;
+22 -4
View File
@@ -1,3 +1,4 @@
#include <algorithm>
#include <iostream> #include <iostream>
#include <pd/drivers/gfx.hpp> #include <pd/drivers/gfx.hpp>
#include <pd/lithium/drawlist.hpp> #include <pd/lithium/drawlist.hpp>
@@ -11,27 +12,44 @@ PD_API Drawlist::Drawlist() { Clear(); }
PD_API Drawlist::~Drawlist() { Clear(); } PD_API Drawlist::~Drawlist() { Clear(); }
PD_API void Drawlist::Merge(Drawlist& other) { PD_API void Drawlist::Merge(Drawlist& other) {
size_t start = pCommands.size();
pCommands.AppendMove(other.pCommands); pCommands.AppendMove(other.pCommands);
for (size_t i = start; i < pCommands.size(); i++) {
pCommands[i].Layer += this->pCurrentLayer;
}
other.Clear(); other.Clear();
} }
PD_API void Drawlist::Copy(Drawlist& other) { PD_API void Drawlist::Copy(Drawlist& other) {
int start = pCommands.size();
pCommands.AppendCopy(other.pCommands); pCommands.AppendCopy(other.pCommands);
for (size_t i = start; i < pCommands.size(); i++) {
pCommands[i].Layer += this->pCurrentLayer;
}
} }
PD_API void Drawlist::Optimize() {} PD_API void Drawlist::Optimize() {
if (pCommands.size() <= 1) return;
std::stable_sort(pCommands.begin(), pCommands.end(),
[](const Command& a, const Command& b) {
if (a.Layer != b.Layer) return a.Layer < b.Layer;
if (a.SDF != b.SDF) return a.SDF < b.SDF;
return a.Tex < b.Tex;
});
}
PD_API void Drawlist::Clear() { PD_API void Drawlist::Clear() {
UnbindTexture(); UnbindTexture();
pPath.ResetFast(); pPath.ResetFast();
pVertices.ResetFast(); pCommands.NoReset();
pIndices.ResetFast(); pCurrentLayer = 0;
pCommands.ResetFast();
} }
/** Command Allocation */ /** Command Allocation */
PD_API Command& Drawlist::NewCommand() { PD_API Command& Drawlist::NewCommand() {
auto cmd = pCommands.Allocate(1); auto cmd = pCommands.Allocate(1);
cmd->Reset();
cmd->Layer = pCurrentLayer;
cmd->Tex = pCurrentTexture.GetID(); cmd->Tex = pCurrentTexture.GetID();
return *cmd; return *cmd;
} }
+2 -1
View File
@@ -288,7 +288,8 @@ PD_API void Font::CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color,
} }
if (cp.Size.x > 0 && cp.Size.y > 0) { if (cp.Size.x > 0 && cp.Size.y > 0) {
if (cmd == nullptr || cmd->Tex != Textures[cp.Tex]) { if (cmd == nullptr || cmd->Tex != Textures[cp.Tex] ||
cmd->Layer != dl.GetLayer()) {
if (cp.Tex >= Textures.size()) continue; if (cp.Tex >= Textures.size()) continue;
cmd = &dl.NewCommand(); cmd = &dl.NewCommand();
cmd->Tex = Textures[cp.Tex]; cmd->Tex = Textures[cp.Tex];
+16
View File
@@ -0,0 +1,16 @@
#include <pd/lithium/pools.hpp>
namespace PD {
namespace Li {
static PD::Pool<Vertex> gVertexPool;
static PD::Pool<u16> gIndexPool;
PD_API PD::Pool<Vertex>& GetVertexPool() { return gVertexPool; }
PD_API PD::Pool<u16>& GetIndexPool() { return gIndexPool; }
PD_API void ResetPools() {
gVertexPool.NoReset();
gIndexPool.NoReset();
}
} // namespace Li
} // namespace PD
+3 -2
View File
@@ -49,12 +49,13 @@ PD_API void Button::HandleInput() {
PD_API void Button::Draw() { PD_API void Button::Draw() {
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?"); // Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
// io->Ren->OnScreen(screen); // io->Ren->OnScreen(screen);
list->SetFont(GetFont());
list->PathRect(FinalPos(), FinalPos() + size, io->FrameRounding); list->PathRect(FinalPos(), FinalPos() + size, io->FrameRounding);
list->PathFill(io->Theme.Get(color)); list->PathFill(io->Theme.Get(color));
// list->LayerUp(); list->LayerUp();
list->DrawText(FinalPos() + size * 0.5 - tdim * 0.5, label.c_str(), list->DrawText(FinalPos() + size * 0.5 - tdim * 0.5, label.c_str(),
io->Theme.Get(UI7Color_Text)); io->Theme.Get(UI7Color_Text));
// list->LayerDown(); list->LayerDown();
} }
PD_API void Button::Update() { PD_API void Button::Update() {
+1
View File
@@ -48,6 +48,7 @@ PD_API void Checkbox::HandleInput() {
PD_API void Checkbox::Draw() { PD_API void Checkbox::Draw() {
// Assert(list.get() && io.get(), "Did you run Container::Init correctly?"); // Assert(list.get() && io.get(), "Did you run Container::Init correctly?");
// io->Ren->OnScreen(screen); // io->Ren->OnScreen(screen);
list->SetFont(GetFont());
list->PathRect(FinalPos(), FinalPos() + cbs, io->FrameRounding); list->PathRect(FinalPos(), FinalPos() + cbs, io->FrameRounding);
list->PathFill(io->Theme.Get(color)); list->PathFill(io->Theme.Get(color));
if (usr_ref) { if (usr_ref) {
+16 -11
View File
@@ -33,8 +33,7 @@ PD_API void ColorEdit::HandleInput() {
} }
// Assert(screen.get(), "Screen is not set up!"); // Assert(screen.get(), "Screen is not set up!");
// if (screen->ScreenType() == Screen::Bottom) { // if (screen->ScreenType() == Screen::Bottom) {
if (io->InputHandler.DragObject(this->GetID() + 2, if (io->InputHandler.DragObject(this->GetID() + 2, fvec4(FinalPos(), size))) {
fvec4(FinalPos(), size))) {
if (io->InputHandler.DragReleasedAW) { if (io->InputHandler.DragReleasedAW) {
is_shown = !is_shown; is_shown = !is_shown;
} }
@@ -45,6 +44,7 @@ PD_API void ColorEdit::HandleInput() {
PD_API void ColorEdit::Draw() { PD_API void ColorEdit::Draw() {
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?"); // Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
// io->Ren->OnScreen(screen); // io->Ren->OnScreen(screen);
list->SetFont(GetFont());
list->PathRect(FinalPos(), FinalPos() + io->ItemRowHeight, io->FrameRounding); list->PathRect(FinalPos(), FinalPos() + io->ItemRowHeight, io->FrameRounding);
list->PathFill(*color_ref); list->PathFill(*color_ref);
list->DrawText(FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0), list->DrawText(FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
@@ -54,18 +54,21 @@ PD_API void ColorEdit::Draw() {
layout = new UI7::Layout(GetID(), *io); layout = new UI7::Layout(GetID(), *io);
} }
layout->SetPosition(FinalPos()); layout->SetPosition(FinalPos());
layout->AddObjectEx( DynObj* r = io->DynObjPool.Allocate();
new DynObj( *r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
[=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) { list->SetFont(thiz->GetFont());
thiz->SetSize(layout->GetSize()); thiz->SetSize(layout->GetSize());
// l->Layer(30); // l->Layer(30);
l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(), l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(),
io->FrameRounding); io->FrameRounding);
l->PathFill(io->Theme.Get(UI7Color_FrameBackground)); l->PathFill(io->Theme.Get(UI7Color_FrameBackground));
}), l->SetLayer(0);
UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate | UI7LytAdd_NoScrollHandle); });
auto obj = new DynObj( layout->AddObjectEx(r, UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate |
[=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) { UI7LytAdd_NoScrollHandle);
r = io->DynObjPool.Allocate();
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
list->SetFont(thiz->GetFont());
l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight, l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight,
io->FrameRounding); io->FrameRounding);
l->PathFill(*color_ref); l->PathFill(*color_ref);
@@ -73,8 +76,8 @@ PD_API void ColorEdit::Draw() {
thiz->FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0), thiz->FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
label.c_str(), io->Theme.Get(UI7Color_Text)); label.c_str(), io->Theme.Get(UI7Color_Text));
}); });
obj->SetSize(PD::fvec2(200, io->ItemRowHeight)); r->SetSize(PD::fvec2(200, io->ItemRowHeight));
layout->AddObject(obj); layout->AddObject(r);
layout->Label("RGBA: ({}, {}, {}, {})", *((u8*)color_ref), layout->Label("RGBA: ({}, {}, {}, {})", *((u8*)color_ref),
*(((u8*)color_ref) + 1), *(((u8*)color_ref) + 2), *(((u8*)color_ref) + 1), *(((u8*)color_ref) + 2),
*(((u8*)color_ref) + 3)); *(((u8*)color_ref) + 3));
@@ -85,7 +88,9 @@ PD_API void ColorEdit::Draw() {
layout->Slider<u8>("B", ((u8*)color_ref) + 2); layout->Slider<u8>("B", ((u8*)color_ref) + 2);
layout->Slider<u8>("A", ((u8*)color_ref) + 3); layout->Slider<u8>("A", ((u8*)color_ref) + 3);
layout->Update(); layout->Update();
list->SetLayer(50);
list->Merge(layout->GetDrawList()); list->Merge(layout->GetDrawList());
list->SetLayer(0);
// io->RegisterDrawList(GetID(), layout->GetDrawList()); // io->RegisterDrawList(GetID(), layout->GetDrawList());
} }
} }
+2 -2
View File
@@ -31,8 +31,8 @@ PD_API void Container::HandleScrolling(fvec2 scrolling, fvec4 viewport) {
} }
last_use = PD::Os::GetTime(); last_use = PD::Os::GetTime();
pos -= fvec2(0, scrolling.y); pos -= fvec2(0, scrolling.y);
skippable = !Li::Math::InBounds( skippable =
pos, size, !Li::Math::InBounds(pos, size,
fvec4(viewport.x, viewport.y, viewport.x + viewport.z, fvec4(viewport.x, viewport.y, viewport.x + viewport.z,
viewport.y + viewport.w)); viewport.y + viewport.w));
} }
+6 -4
View File
@@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <algorithm>
#include <pd/ui7/container/dragdata.hpp> #include <pd/ui7/container/dragdata.hpp>
#include <pd/ui7/container/label.hpp> #include <pd/ui7/container/label.hpp>
#include <type_traits> #include <type_traits>
@@ -85,21 +86,22 @@ PD_API void DragData<T>::Draw() {
FinalPos() + fvec2(off_x, 0) + td + io->FramePadding, FinalPos() + fvec2(off_x, 0) + td + io->FramePadding,
io->FrameRounding); io->FrameRounding);
list->PathFill(io->Theme.Get(UI7Color_Button)); list->PathFill(io->Theme.Get(UI7Color_Button));
// list->LayerUp(); list->LayerUp();
list->DrawTextEx(FinalPos() + fvec2(off_x, 0), p.c_str(), list->DrawTextEx(FinalPos() + fvec2(off_x, 0), p.c_str(),
io->Theme.Get(UI7Color_Text), LiTextFlags_AlignMid, io->Theme.Get(UI7Color_Text), LiTextFlags_AlignMid,
td + io->FramePadding); td + io->FramePadding);
// list->LayerDown(); list->LayerDown();
off_x += td.x + io->ItemSpace.x + io->FramePadding.x; off_x += td.x + io->ItemSpace.x + io->FramePadding.x;
} }
list->DrawText(FinalPos() + fvec2(off_x, io->FramePadding.y * 0.5), label.c_str(), list->DrawText(FinalPos() + fvec2(off_x, io->FramePadding.y * 0.5),
io->Theme.Get(UI7Color_Text)); label.c_str(), io->Theme.Get(UI7Color_Text));
} }
template <typename T> template <typename T>
PD_API void DragData<T>::Update() { PD_API void DragData<T>::Update() {
// Assert(io.get(), "Did you run Container::Init correctly?"); // Assert(io.get(), "Did you run Container::Init correctly?");
// Probably need to find a faster solution (caching sizes calculated here) // Probably need to find a faster solution (caching sizes calculated here)
list->SetFont(GetFont());
float off_x = 0; float off_x = 0;
for (size_t i = 0; i < elm_count; i++) { for (size_t i = 0; i < elm_count; i++) {
std::string p; std::string p;
+2 -2
View File
@@ -29,11 +29,11 @@ PD_API void Image::Draw() {
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?"); // Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
// Assert(img.get(), "Image is nullptr!"); // Assert(img.get(), "Image is nullptr!");
// io->Ren->OnScreen(screen); // io->Ren->OnScreen(screen);
// list->LayerUp(); list->LayerUp();
list->BindTexture(img); list->BindTexture(img);
list->DrawRectFilled(FinalPos(), newsize, 0xffffffff); list->DrawRectFilled(FinalPos(), newsize, 0xffffffff);
list->UnbindTexture(); list->UnbindTexture();
//list->LayerDown(); list->LayerDown();
} }
} // namespace UI7 } // namespace UI7
} // namespace PD } // namespace PD
+1
View File
@@ -28,6 +28,7 @@ namespace UI7 {
PD_API void Label::Draw() { PD_API void Label::Draw() {
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?"); // Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
// io->Ren->OnScreen(screen); // io->Ren->OnScreen(screen);
list->SetFont(GetFont());
list->DrawTextEx(FinalPos(), label.c_str(), io->Theme.Get(UI7Color_Text), list->DrawTextEx(FinalPos(), label.c_str(), io->Theme.Get(UI7Color_Text),
LiTextFlags_NoOOS, LiTextFlags_NoOOS,
PD::fvec2(0, io->CurrentViewPort.pSize.w)); PD::fvec2(0, io->CurrentViewPort.pSize.w));
+6 -4
View File
@@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <algorithm>
#include <pd/ui7/container/label.hpp> #include <pd/ui7/container/label.hpp>
#include <pd/ui7/container/slider.hpp> #include <pd/ui7/container/slider.hpp>
#include <type_traits> #include <type_traits>
@@ -56,8 +57,8 @@ PD_API void Slider<T>::HandleInput() {
fvec4(FinalPos() + fvec2(2, 0), fvec2(width, GetSize().y)))) { fvec4(FinalPos() + fvec2(2, 0), fvec2(width, GetSize().y)))) {
if (!io->InputHandler.DragReleasedAW) { if (!io->InputHandler.DragReleasedAW) {
*data = std::clamp( *data = std::clamp(
T(max * (std::clamp(io->InputHandler.DragLastPosition.x - xps, 0.f, T(max *
width) / (std::clamp(io->InputHandler.DragLastPosition.x - xps, 0.f, width) /
width)), width)),
this->min, this->max); this->min, this->max);
} }
@@ -69,6 +70,7 @@ template <typename T>
PD_API void Slider<T>::Draw() { PD_API void Slider<T>::Draw() {
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?"); // Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
// io->Ren->OnScreen(screen); // io->Ren->OnScreen(screen);
list->SetFont(GetFont());
std::string p; std::string p;
if constexpr (std::is_floating_point_v<T>) { if constexpr (std::is_floating_point_v<T>) {
p = std::format("{:.{}f}", *data, precision); p = std::format("{:.{}f}", *data, precision);
@@ -83,10 +85,10 @@ PD_API void Slider<T>::Draw() {
FinalPos() + fvec2(slp + slw - 2, td.y - 2) + io->FramePadding, FinalPos() + fvec2(slp + slw - 2, td.y - 2) + io->FramePadding,
io->FrameRounding); io->FrameRounding);
list->PathFill(io->Theme.Get(UI7Color_ButtonActive)); list->PathFill(io->Theme.Get(UI7Color_ButtonActive));
// list->LayerUp(); list->LayerUp();
list->DrawTextEx(FinalPos(), p.c_str(), io->Theme.Get(UI7Color_Text), list->DrawTextEx(FinalPos(), p.c_str(), io->Theme.Get(UI7Color_Text),
LiTextFlags_AlignMid, fvec2(width, td.y) + io->FramePadding); LiTextFlags_AlignMid, fvec2(width, td.y) + io->FramePadding);
// list->LayerDown(); list->LayerDown();
list->DrawText(FinalPos() + fvec2(width + io->FramePadding.x * 2.f, list->DrawText(FinalPos() + fvec2(width + io->FramePadding.x * 2.f,
io->FramePadding.y * 0.5), io->FramePadding.y * 0.5),
label.c_str(), io->Theme.Get(UI7Color_Text)); label.c_str(), io->Theme.Get(UI7Color_Text));
+19 -3
View File
@@ -22,10 +22,23 @@ SOFTWARE.
*/ */
#include <pd/core/core.hpp> #include <pd/core/core.hpp>
#include <pd/ui7/io.hpp>
#include <pd/drivers/drivers.hpp> #include <pd/drivers/drivers.hpp>
#include <pd/ui7/containers.hpp>
#include <pd/ui7/io.hpp>
namespace PD { namespace PD {
PD_API UI7::IO::IO() : DeltaStats(60), CurrentViewPort("", 0) {
/** Probably not the best solution i guess */
// CurrentViewPort =
// ViewPort::New("Default", ivec4(ivec2(0, 0), pCtx.Gfx()->ViewPort));
// Start a little larger on these
LabelPool.Init(512);
DynObjPool.Init(512);
}
PD_API UI7::IO::~IO() {}
PD_API void UI7::IO::Update() { PD_API void UI7::IO::Update() {
/** Todo: find out if we even still use the Drawlist regestry */ /** Todo: find out if we even still use the Drawlist regestry */
u64 current = PD::Os::GetTimeNano(); u64 current = PD::Os::GetTimeNano();
@@ -39,7 +52,10 @@ PD_API void UI7::IO::Update() {
DrawlistRegestry.push_front(std::make_pair("CtxBackList", &Back)); DrawlistRegestry.push_front(std::make_pair("CtxBackList", &Back));
if (Font) ItemRowHeight = FontScale * Font->PixelHeight; if (Font) ItemRowHeight = FontScale * Font->PixelHeight;
// RegisterDrawList("CtxBackList", Back); // RegisterDrawList("CtxBackList", Back);
NumIndices = 0;//FDL.pNumIndices; NumIndices = FDL.GetNumIndices();
NumVertices = 0;//FDL.pNumVertices; NumVertices = FDL.GetNumVertices();
LabelPool.ResetFast();
DynObjPool.ResetFast();
ImagePool.ResetFast();
} }
} // namespace PD } // namespace PD
+52 -2
View File
@@ -21,11 +21,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <algorithm>
#include <pd/ui7/containers.hpp> #include <pd/ui7/containers.hpp>
#include <pd/ui7/layout.hpp> #include <pd/ui7/layout.hpp>
namespace PD { namespace PD {
namespace UI7 { namespace UI7 {
PD_API Layout::~Layout() {
// We all love managing memory i guess
for (Container* obj : IDObjects) {
delete obj;
}
IDObjects.clear();
}
PD_API void Layout::CursorInit() { Cursor = fvec2(WorkRect.x, WorkRect.y); } PD_API void Layout::CursorInit() { Cursor = fvec2(WorkRect.x, WorkRect.y); }
PD_API void Layout::SameLine() { PD_API void Layout::SameLine() {
@@ -113,6 +123,42 @@ PD_API fvec2 Layout::AlignPosition(fvec2 pos, fvec2 size, fvec4 area,
return p; return p;
} }
PD_API void Layout::HandleScrolling() {
if (Flags & UI7LayoutFlags_VtScrolling) {
bool allowed = MaxPosition.y > WorkRect.w;
if (allowed) {
if (PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Gamepad::Touch) ||
PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Keyboard::MouseLeft)) {
ScrollStart = ScrollOffset;
}
if (IO.InputHandler.DragObject(UI7::ID("sbg" + ID.GetName()),
fvec4(Pos, fvec2(0.f)) + WorkRect)) {
if (!IO.InputHandler.DragReleasedAW) {
ScrollOffset.y =
std::clamp(ScrollStart.y + IO.InputHandler.DragSourcePos.y -
IO.InputHandler.DragPosition.y,
-20.f, MaxPosition.y - WorkRect.w + 20.f);
}
}
} else {
ScrollOffset.y = 0.f;
}
if (ScrollOffset.y > MaxPosition.y - WorkRect.w) {
ScrollOffset.y -= 1.5f;
if (ScrollOffset.y < MaxPosition.y - WorkRect.w) {
ScrollOffset.y = MaxPosition.y - WorkRect.w;
}
}
if (ScrollOffset.y < 0) {
ScrollOffset.y += 1.5f;
if (ScrollOffset.y > 0) {
ScrollOffset.y = 0;
}
}
}
}
PD_API void Layout::Update() { PD_API void Layout::Update() {
if (Size == fvec2(0.f)) { if (Size == fvec2(0.f)) {
Size = fvec2(MaxPosition) + IO.MenuPadding * 2; Size = fvec2(MaxPosition) + IO.MenuPadding * 2;
@@ -136,6 +182,7 @@ PD_API void Layout::Update() {
for (auto it = IDObjects.begin(); it != IDObjects.end();) { for (auto it = IDObjects.begin(); it != IDObjects.end();) {
if ((*it)->Removable()) { if ((*it)->Removable()) {
delete *it;
it = IDObjects.erase(it); it = IDObjects.erase(it);
} else { } else {
it++; it++;
@@ -145,13 +192,15 @@ PD_API void Layout::Update() {
Objects.clear(); Objects.clear();
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO.MenuPadding); WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO.MenuPadding);
CursorInit(); CursorInit();
HandleScrolling();
} }
/** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */ /** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */
PD_API void Layout::Label(const std::string& label) { PD_API void Layout::Label(const std::string& label) {
// Layout API // Layout API
auto r = new UI7::Label(label, IO); auto r = IO.LabelPool.Allocate();
*r = UI7::Label(label, IO);
r->SetClipRect(fvec4(GetPosition(), GetPosition() + GetSize())); r->SetClipRect(fvec4(GetPosition(), GetPosition() + GetSize()));
AddObject(r); AddObject(r);
} }
@@ -182,7 +231,8 @@ PD_API void Layout::Checkbox(const std::string& label, bool& v) {
} }
PD_API void Layout::Image(Li::Texture img, fvec2 size, Li::Rect uv) { PD_API void Layout::Image(Li::Texture img, fvec2 size, Li::Rect uv) {
Container* r = new UI7::Image(img, size, uv); auto r = IO.ImagePool.Allocate();
*r = UI7::Image(img, size, uv);
AddObject(r); AddObject(r);
} }
+37 -62
View File
@@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <algorithm>
#include <pd/ui7/containers.hpp> #include <pd/ui7/containers.hpp>
#include <pd/ui7/menu.hpp> #include <pd/ui7/menu.hpp>
@@ -35,7 +36,8 @@ Menu::Menu(const ID& id, IO& io) : pIO(io), pID(id), pLayout(id, io) {
PD_API void Menu::Label(const std::string& label) { PD_API void Menu::Label(const std::string& label) {
// Layout API // Layout API
auto r = new UI7::Label(label, pIO); auto r = pIO.LabelPool.Allocate();
*r = UI7::Label(label, pIO);
pLayout.AddObject(r); pLayout.AddObject(r);
} }
@@ -67,7 +69,8 @@ PD_API void Menu::Checkbox(const std::string& label, bool& v) {
} }
PD_API void Menu::Image(Li::Texture img, fvec2 size, Li::Rect uv) { PD_API void Menu::Image(Li::Texture img, fvec2 size, Li::Rect uv) {
Container* r = new UI7::Image(img, size, uv); auto r = pIO.ImagePool.Allocate();
*r = UI7::Image(img, size, uv);
pLayout.AddObject(r); pLayout.AddObject(r);
} }
@@ -83,7 +86,8 @@ PD_API void Menu::ColorEdit(const std::string& label, u32& clr) {
PD_API void Menu::Separator() { PD_API void Menu::Separator() {
// Dynamic Objects are very simple... // Dynamic Objects are very simple...
Container* r = new DynObj( DynObj* r = pIO.DynObjPool.Allocate();
*r = UI7::DynObj(
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) { [=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
l->DrawRectFilled(self->FinalPos(), self->GetSize(), l->DrawRectFilled(self->FinalPos(), self->GetSize(),
pIO.Theme.Get(UI7Color_TextDead)); pIO.Theme.Get(UI7Color_TextDead));
@@ -97,8 +101,10 @@ PD_API void Menu::Separator() {
PD_API void Menu::SeparatorText(const std::string& label) { PD_API void Menu::SeparatorText(const std::string& label) {
// Also note to use [=] instead of [&] to not undefined access label // Also note to use [=] instead of [&] to not undefined access label
Container* r = new DynObj([=, this](UI7::IO* io, Li::Drawlist* l, DynObj* r = pIO.DynObjPool.Allocate();
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
UI7::Container* self) { UI7::Container* self) {
l->SetFont(self->GetFont());
fvec2 size = self->GetSize(); fvec2 size = self->GetSize();
fvec2 tdim = io->Font->GetTextBounds(label.c_str(), io->FontScale); fvec2 tdim = io->Font->GetTextBounds(label.c_str(), io->FontScale);
fvec2 pos = self->FinalPos(); fvec2 pos = self->FinalPos();
@@ -142,45 +148,6 @@ PD_API void Menu::HandleFocus() {
} }
} }
/** Todo: (func name is self describing) */
PD_API void Menu::HandleScrolling() {
if (Flags & UI7MenuFlags_VtScrolling) {
bool allowed =
pLayout.MaxPosition.y > (pLayout.WorkRect.w - pLayout.WorkRect.y);
if (allowed) {
if (PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Gamepad::Touch)) {
pLayout.ScrollStart = pLayout.ScrollOffset;
}
if (pIO.InputHandler.DragObject(
"sbg" + pID.GetName(),
fvec4(pLayout.Pos, fvec2(0.f)) + pLayout.WorkRect)) {
if (pIO.InputHandler.DragReleasedAW) {
} else {
pLayout.ScrollOffset.y = std::clamp(
pLayout.ScrollStart.y + pIO.InputHandler.DragSourcePos.y -
pIO.InputHandler.DragPosition.y,
-20.f, pLayout.MaxPosition.y - 220);
}
}
} else {
pLayout.ScrollOffset.y = 0.f;
}
if (pLayout.ScrollOffset.y > pLayout.MaxPosition.y - 240) {
pLayout.ScrollOffset.y -= 1.5;
if (pLayout.ScrollOffset.y < pLayout.MaxPosition.y - 240) {
pLayout.ScrollOffset.y = pLayout.MaxPosition.y - 240;
}
}
if (pLayout.ScrollOffset.y < 0) {
pLayout.ScrollOffset.y += 1.5;
if (pLayout.ScrollOffset.y > 0) {
pLayout.ScrollOffset.y = 0;
}
}
}
}
PD_API void Menu::HandleTitlebarActions() { PD_API void Menu::HandleTitlebarActions() {
// Collapse // Collapse
if (!(Flags & UI7MenuFlags_NoCollapse)) { if (!(Flags & UI7MenuFlags_NoCollapse)) {
@@ -250,13 +217,14 @@ PD_API void Menu::DrawBaseLayout() {
if (pIsOpen) { if (pIsOpen) {
/** Resize Sym (Render on Top of Everything) */ /** Resize Sym (Render on Top of Everything) */
if (!(Flags & UI7MenuFlags_NoResize)) { if (!(Flags & UI7MenuFlags_NoResize)) {
Container* r = DynObj* r = pIO.DynObjPool.Allocate();
new DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) { *r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
// //l->Layer(1); l->SetLayer(1);
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20)); l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20));
l->PathAdd(self->FinalPos() + self->GetSize()); l->PathAdd(self->FinalPos() + self->GetSize());
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(20, 0)); l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(20, 0));
l->PathFill(io->Theme.Get(UI7Color_Button)); l->PathFill(io->Theme.Get(UI7Color_Button));
l->SetLayer(0);
}); });
r->SetSize( r->SetSize(
fvec2(pLayout.GetSize().x, pLayout.GetSize().y - TitleBarHeight)); fvec2(pLayout.GetSize().x, pLayout.GetSize().y - TitleBarHeight));
@@ -266,9 +234,9 @@ PD_API void Menu::DrawBaseLayout() {
} }
/** Background */ /** Background */
Container* r = new DynObj([](IO* io, Li::Drawlist* l, DynObj* r = pIO.DynObjPool.Allocate();
UI7::Container* self) { *r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
//l->Layer(0); l->SetLayer(0);
l->PathRectEx(self->FinalPos(), self->FinalPos() + self->GetSize(), 10.f, l->PathRectEx(self->FinalPos(), self->FinalPos() + self->GetSize(), 10.f,
LiPathRectFlags_KeepTop | LiPathRectFlags_KeepBot); LiPathRectFlags_KeepTop | LiPathRectFlags_KeepBot);
l->PathFill(io->Theme.Get(UI7Color_Background)); l->PathFill(io->Theme.Get(UI7Color_Background));
@@ -283,13 +251,15 @@ PD_API void Menu::DrawBaseLayout() {
UI7LytAdd_Front); UI7LytAdd_Front);
} }
if (!(Flags & UI7MenuFlags_NoTitlebar)) { if (!(Flags & UI7MenuFlags_NoTitlebar)) {
Container* r = new DynObj( DynObj* r = pIO.DynObjPool.Allocate();
*r = UI7::DynObj(
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) { [=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
//l->Layer(20); l->SetFont(self->GetFont());
l->SetLayer(20);
/** Header Bar */ /** Header Bar */
l->DrawRectFilled(self->FinalPos(), self->GetSize(), l->DrawRectFilled(self->FinalPos(), self->GetSize(),
io->Theme.Get(UI7Color_Header)); io->Theme.Get(UI7Color_Header));
//l->Layer(21); l->SetLayer(21);
/** Inline if statement to shift the Text if collapse sym is shown */ /** Inline if statement to shift the Text if collapse sym is shown */
/** What the hell is this code btw (didn't found a better way) */ /** What the hell is this code btw (didn't found a better way) */
l->DrawText(self->FinalPos() + l->DrawText(self->FinalPos() +
@@ -299,6 +269,7 @@ PD_API void Menu::DrawBaseLayout() {
(io->FramePadding.x * 2)), (io->FramePadding.x * 2)),
2), 2),
pID.GetName().c_str(), io->Theme.Get(UI7Color_Text)); pID.GetName().c_str(), io->Theme.Get(UI7Color_Text));
l->SetLayer(0);
}); });
r->SetSize(fvec2(pLayout.GetSize().x, TitleBarHeight)); r->SetSize(fvec2(pLayout.GetSize().x, TitleBarHeight));
r->SetPos(0); r->SetPos(0);
@@ -306,10 +277,11 @@ PD_API void Menu::DrawBaseLayout() {
/** Collapse Sym */ /** Collapse Sym */
if (!(Flags & UI7MenuFlags_NoCollapse)) { if (!(Flags & UI7MenuFlags_NoCollapse)) {
r = new DynObj([=, this](UI7::IO* io, Li::Drawlist* l, DynObj* r = pIO.DynObjPool.Allocate();
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
UI7::Container* self) { UI7::Container* self) {
/** This sym actually requires layer 21 (i dont know why) */ /** This sym actually requires layer 21 (i dont know why) */
//l->Layer(21); l->SetLayer(21);
/** /**
* Symbol (Position Swapping set by pIsOpen ? openpos : closepos;) * Symbol (Position Swapping set by pIsOpen ? openpos : closepos;)
*/ */
@@ -320,6 +292,7 @@ PD_API void Menu::DrawBaseLayout() {
self->FinalPos() + self->FinalPos() +
fvec2(pIsOpen ? self->GetSize().x * 0.5 : 0, self->GetSize().y), fvec2(pIsOpen ? self->GetSize().x * 0.5 : 0, self->GetSize().y),
io->Theme.Get(UI7Color_FrameBackground)); io->Theme.Get(UI7Color_FrameBackground));
l->SetLayer(0);
}); });
r->SetSize(TitleBarHeight - pIO.FramePadding.y * 2); r->SetSize(TitleBarHeight - pIO.FramePadding.y * 2);
r->SetPos(pIO.FramePadding); r->SetPos(pIO.FramePadding);
@@ -351,6 +324,10 @@ PD_API void Menu::Update() {
if (pLayout.Size == fvec2(0.f) || Flags & UI7MenuFlags_AlwaysAutoSize) { if (pLayout.Size == fvec2(0.f) || Flags & UI7MenuFlags_AlwaysAutoSize) {
pLayout.Size = fvec2(pLayout.MaxPosition) + pIO.MenuPadding * 2; pLayout.Size = fvec2(pLayout.MaxPosition) + pIO.MenuPadding * 2;
} }
if (Flags & UI7MenuFlags_VtScrolling)
pLayout.Flags |= UI7LayoutFlags_VtScrolling;
if (Flags & UI7MenuFlags_HzScrolling)
pLayout.Flags |= UI7LayoutFlags_HzScrolling;
if (!(Flags & UI7MenuFlags_NoTitlebar)) { if (!(Flags & UI7MenuFlags_NoTitlebar)) {
TitleBarHeight = pIO.FontScale * pIO.Font->PixelHeight + pIO.MenuPadding.y; TitleBarHeight = pIO.FontScale * pIO.Font->PixelHeight + pIO.MenuPadding.y;
pLayout.WorkRect.y = 5.f + TitleBarHeight; pLayout.WorkRect.y = 5.f + TitleBarHeight;
@@ -361,9 +338,6 @@ PD_API void Menu::Update() {
} }
DrawBaseLayout(); DrawBaseLayout();
pLayout.Update(); pLayout.Update();
if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) {
HandleScrolling();
}
} }
PD_API bool Menu::BeginTreeNode(const ID& id) { PD_API bool Menu::BeginTreeNode(const ID& id) {
@@ -382,7 +356,9 @@ PD_API bool Menu::BeginTreeNode(const ID& id) {
} }
// Object // Object
auto r = new DynObj([=, this](IO* io, Li::Drawlist* l, Container* self) { DynObj* r = pIO.DynObjPool.Allocate();
*r = UI7::DynObj([=, this](IO* io, Li::Drawlist* l, Container* self) {
l->SetFont(self->GetFont());
fvec2 ts = self->FinalPos() + fvec2(0, 7); fvec2 ts = self->FinalPos() + fvec2(0, 7);
fvec2 pl[2] = {fvec2(10, 5), fvec2(0, 10)}; fvec2 pl[2] = {fvec2(10, 5), fvec2(0, 10)};
if (n->second) { if (n->second) {
@@ -393,13 +369,12 @@ PD_API bool Menu::BeginTreeNode(const ID& id) {
l->DrawTriangleFilled(ts, ts + pl[0], ts + pl[1], l->DrawTriangleFilled(ts, ts + pl[0], ts + pl[1],
io->Theme.Get(UI7Color_FrameBackground)); io->Theme.Get(UI7Color_FrameBackground));
l->DrawText(self->FinalPos() + fvec2(10 + io->ItemSpace.x, 0), id.GetName().c_str(), l->DrawText(self->FinalPos() + fvec2(10 + io->ItemSpace.x, 0),
io->Theme.Get(UI7Color_Text)); id.GetName().c_str(), io->Theme.Get(UI7Color_Text));
}); });
/** Yes this new function handler was created for tree nodes */ /** Yes this new function handler was created for tree nodes */
r->AddInputHandler([=, this](IO* io, Container* self) { r->AddInputHandler([=, this](IO* io, Container* self) {
if (io->InputHandler.DragObject( if (io->InputHandler.DragObject(ID(pID.GetName() + id.GetName()),
ID(pID.GetName() + id.GetName()),
fvec4(self->FinalPos(), self->GetSize()))) { fvec4(self->FinalPos(), self->GetSize()))) {
if (io->InputHandler.DragReleased) { if (io->InputHandler.DragReleased) {
n->second = !n->second; n->second = !n->second;
+5 -4
View File
@@ -51,8 +51,7 @@ PD_API void Context::UseViewPort(const ID& id) {
pIO.CurrentViewPort = pIO.ViewPorts[id.RawID()]; pIO.CurrentViewPort = pIO.ViewPorts[id.RawID()];
} }
PD_API Menu* Context::BeginMenu(const ID& id, UI7MenuFlags flags, PD_API Menu* Context::BeginMenu(const ID& id, UI7MenuFlags flags, bool* pShow) {
bool* pShow) {
if (pCurrent) { if (pCurrent) {
PDERR("UI7: You are already in {} Menu!", pCurrent->pID.GetName()); PDERR("UI7: You are already in {} Menu!", pCurrent->pID.GetName());
return nullptr; return nullptr;
@@ -144,8 +143,11 @@ PD_API void Context::Update() {
pMenus[it]->Update(); /** Render */ pMenus[it]->Update(); /** Render */
this->pIO.InputHandler.CurrentMenu = 0; this->pIO.InputHandler.CurrentMenu = 0;
} }
int base_layer = 0;
for (int i = (int)FinalList.size() - 1; i >= 0; i--) { for (int i = (int)FinalList.size() - 1; i >= 0; i--) {
pIO.FDL.SetLayer(base_layer);
pIO.FDL.Merge(pMenus[FinalList[i]]->pLayout.GetDrawList()); pIO.FDL.Merge(pMenus[FinalList[i]]->pLayout.GetDrawList());
base_layer += 100;
} }
pCurrentMenus.clear(); pCurrentMenus.clear();
pIO.Update(); pIO.Update();
@@ -256,8 +258,7 @@ PD_API void Context::MetricsMenu(bool* show) {
m->Label(std::format("Cursor: {}", pMenus[it]->pLayout.Cursor)); m->Label(std::format("Cursor: {}", pMenus[it]->pLayout.Cursor));
if (m->BeginTreeNode( if (m->BeginTreeNode(
"ID Objects (" + "ID Objects (" +
std::to_string(pMenus[it]->pLayout.IDObjects.size()) + std::to_string(pMenus[it]->pLayout.IDObjects.size()) + ")")) {
")")) {
for (auto& jt : pMenus[it]->pLayout.IDObjects) { for (auto& jt : pMenus[it]->pLayout.IDObjects) {
m->Label(std::format("{:08X}", jt->GetID())); m->Label(std::format("{:08X}", jt->GetID()));
} }
+26 -6
View File
@@ -211,16 +211,15 @@ int main(int argc, char** argv) {
ui7.AddViewPort("Default", PD::ivec4(0, 0, 1280, 720)); ui7.AddViewPort("Default", PD::ivec4(0, 0, 1280, 720));
ui7.UseViewPort("Default"); ui7.UseViewPort("Default");
while (pOs->Mainloop()) { while (pOs->Mainloop()) {
PD::TT::End("OSCTX::MainLoop");
pOs->ClearViewPort();
PD::TT::Scope __st("MainLoop"); PD::TT::Scope __st("MainLoop");
PD::TT::Beg("MainRaw");
PD::Hid::Update(); PD::Hid::Update();
PD::Gfx::NewFrame(); PD::Gfx::NewFrame();
pOs->ClearViewPort(); PD::Li::ResetPools();
// app.Update(pOs->GetViewport(), pList); // app.Update(pOs->GetViewport(), pList);
pList.SetFontscale(0.7); pList.SetFontscale(0.7);
if (auto m = ui7.BeginMenu("Test")) {
m->Label("Hello World!");
ui7.EndMenu();
}
if (PD::Hid::IsEvent(PD::Hid::Event::Down, PD::Hid::Gamepad::CPLeft | if (PD::Hid::IsEvent(PD::Hid::Event::Down, PD::Hid::Gamepad::CPLeft |
PD::Hid::Gamepad::CPRight)) { PD::Hid::Gamepad::CPRight)) {
LeftStick.pPos.x += PD::Hid::GetLeftStick().x * 15; LeftStick.pPos.x += PD::Hid::GetLeftStick().x * 15;
@@ -299,19 +298,40 @@ int main(int argc, char** argv) {
"#ff00ff"); "#ff00ff");
} }
pList.SetFont(&font); pList.SetFont(&font);
PD::TT::Beg("BuildUI7Menus");
if (auto m = ui7.BeginMenu("Test")) {
m->Label("Hello World!");
ui7.EndMenu();
}
if (auto m = ui7.BeginMenu("LI DBG INFO")) {
m->PushFont(&debug_font);
m->Label("Gfx Driver: {}", PD::Gfx::GetDriverName());
m->Separator();
m->Label("LI Draw Comamnds: {}", PD::Gfx::GetNumCommands());
m->Label("GFX Draw Calls: {}", PD::Gfx::GetNumDrawcalls());
m->Label("GFX Vertices: {}", PD::Gfx::GetNumVertices());
m->Label("GFX Triangles: {}", PD::Gfx::GetNumVertices() / 3);
m->Label("GFX Indices: {}", PD::Gfx::GetNumIndices());
m->PopFont();
ui7.EndMenu();
}
ui7.MetricsMenu(); ui7.MetricsMenu();
PD::TT::End("BuildUI7Menus");
PD::TT::Beg("UI7::Context::Update"); PD::TT::Beg("UI7::Context::Update");
ui7.Update(); ui7.Update();
PD::TT::End("UI7::Context::Update"); PD::TT::End("UI7::Context::Update");
PD::Gfx::Reset(); PD::Gfx::Reset();
PD::TT::Beg("PD::Gfx::Draw"); PD::TT::Beg("PD::Gfx::Draw");
PD::Gfx::Draw(pList);
PD::Gfx::Draw(ui7.GetDrawData()); PD::Gfx::Draw(ui7.GetDrawData());
PD::Gfx::Draw(pList);
PD::TT::End("PD::Gfx::Draw"); PD::TT::End("PD::Gfx::Draw");
pList.Clear(); pList.Clear();
PD::TT::End("MainRaw");
pOs->SwapBuffers(); pOs->SwapBuffers();
PD::TT::Beg("OSCTX::MainLoop");
} }
font.Delete(); font.Delete();
debug_font.Delete();
PD::Gfx::DeleteTexture(pTex); PD::Gfx::DeleteTexture(pTex);
PD::Gfx::Deinit(); PD::Gfx::Deinit();
pOs->Deinit(); pOs->Deinit();
+21 -10
View File
@@ -18,6 +18,7 @@ struct DesktopOS::Impl {
#if WIN32 #if WIN32
IDirect3D9* d3d = nullptr; IDirect3D9* d3d = nullptr;
IDirect3DDevice9* dx9_device = nullptr; IDirect3DDevice9* dx9_device = nullptr;
D3DPRESENT_PARAMETERS d3dpp = {};
#endif #endif
}; };
@@ -56,17 +57,18 @@ void DesktopOS::Init() {
if (pDriver == Driver::DirectX9) { if (pDriver == Driver::DirectX9) {
impl->d3d = Direct3DCreate9(D3D_SDK_VERSION); impl->d3d = Direct3DCreate9(D3D_SDK_VERSION);
auto hwnd = glfwGetWin32Window(impl->win); auto hwnd = glfwGetWin32Window(impl->win);
D3DPRESENT_PARAMETERS d3dpp = {};
d3dpp.Windowed = TRUE; impl->d3dpp = D3DPRESENT_PARAMETERS{};
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; impl->d3dpp.Windowed = TRUE;
d3dpp.hDeviceWindow = hwnd; impl->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; impl->d3dpp.hDeviceWindow = hwnd;
d3dpp.EnableAutoDepthStencil = TRUE; impl->d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16; impl->d3dpp.EnableAutoDepthStencil = TRUE;
impl->d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
HRESULT hr = impl->d3d->CreateDevice( HRESULT hr = impl->d3d->CreateDevice(
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &impl->dx9_device); D3DCREATE_HARDWARE_VERTEXPROCESSING, &impl->d3dpp, &impl->dx9_device);
if (FAILED(hr)) { if (FAILED(hr)) {
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK); MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
std::abort(); std::abort();
@@ -100,7 +102,15 @@ void DesktopOS::ClearViewPort() {
glViewport(0, 0, pViewPort.x, pViewPort.y); glViewport(0, 0, pViewPort.x, pViewPort.y);
} else if (pDriver == Driver::DirectX9) { } else if (pDriver == Driver::DirectX9) {
#ifdef _WIN32 #ifdef _WIN32
if (impl->dx9_device) { // Resize the swapchain to match the window size
if (impl->dx9_device && pViewPort.x > 0 && pViewPort.y > 0) {
if (impl->d3dpp.BackBufferWidth != (UINT)pViewPort.x ||
impl->d3dpp.BackBufferHeight != (UINT)pViewPort.y) {
impl->d3dpp.BackBufferWidth = pViewPort.x;
impl->d3dpp.BackBufferHeight = pViewPort.y;
impl->dx9_device->Reset(&impl->d3dpp);
}
impl->dx9_device->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, impl->dx9_device->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(25, 25, 25), 1.0f, 0); D3DCOLOR_XRGB(25, 25, 25), 1.0f, 0);
impl->dx9_device->BeginScene(); impl->dx9_device->BeginScene();
@@ -112,7 +122,8 @@ void DesktopOS::ClearViewPort() {
void DesktopOS::SwapBuffers() { void DesktopOS::SwapBuffers() {
if (pDriver == Driver::DirectX9) { if (pDriver == Driver::DirectX9) {
#ifdef _WIN32 #ifdef _WIN32
if (impl->dx9_device) { // yes we schould use some safetey checks
if (impl->dx9_device && pViewPort.x > 0 && pViewPort.y > 0) {
impl->dx9_device->EndScene(); impl->dx9_device->EndScene();
impl->dx9_device->Present(nullptr, nullptr, nullptr, nullptr); impl->dx9_device->Present(nullptr, nullptr, nullptr, nullptr);
} }
+3 -4
View File
@@ -33,7 +33,7 @@ void HorizonCtr::Init() {
romfsInit(); romfsInit();
osSetSpeedupEnable(true); osSetSpeedupEnable(true);
gfxInitDefault(); gfxInitDefault();
consoleInit(GFX_BOTTOM, nullptr); // consoleInit(GFX_BOTTOM, nullptr);
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
impl->Top = impl->Top =
C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
@@ -43,7 +43,7 @@ void HorizonCtr::Init() {
C3D_RenderTargetSetOutput(impl->Bottom, GFX_BOTTOM, GFX_LEFT, C3D_RenderTargetSetOutput(impl->Bottom, GFX_BOTTOM, GFX_LEFT,
DisplayTransferFlags); DisplayTransferFlags);
PD::Gfx::UseDriver<PD::GfxCitro3D>(); PD::Gfx::UseDriver<PD::GfxCitro3D>();
PD::Hid::UseDriver<PD::HidDriver>(); PD::Hid::UseDriver<PD::Hid3DS>();
} }
void HorizonCtr::Deinit() { void HorizonCtr::Deinit() {
@@ -61,14 +61,13 @@ void HorizonCtr::Deinit() {
bool HorizonCtr::Mainloop() { bool HorizonCtr::Mainloop() {
pViewPort = ivec2(400, 240); pViewPort = ivec2(400, 240);
hidScanInput();
bool _kill = hidKeysUp() & KEY_START; bool _kill = hidKeysUp() & KEY_START;
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
return aptMainLoop() && !_kill; return aptMainLoop() && !_kill;
} }
void HorizonCtr::ClearViewPort() { void HorizonCtr::ClearViewPort() {
PD::Gfx::SetViewPort(pViewPort); PD::Gfx::SetViewPort(pViewPort);
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C3D_FrameDrawOn(impl->Top); C3D_FrameDrawOn(impl->Top);
C3D_RenderTargetClear(impl->Top, C3D_CLEAR_ALL, PD::Color(25, 25, 25, 25), 0); C3D_RenderTargetClear(impl->Top, C3D_CLEAR_ALL, PD::Color(25, 25, 25, 25), 0);
} }