9 Commits
24 changed files with 325 additions and 204 deletions
+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();
} }
+2 -1
View File
@@ -125,7 +125,8 @@ class GfxDriverBase : public GfxDriver {
while (index < commands.size() && while (index < commands.size() &&
CurrentTexIsSDF == commands[index].SDF && CurrentTexIsSDF == commands[index].SDF &&
(CurrentTex == commands[index].Tex || (CurrentTex == commands[index].Tex ||
(CurrentTex == pWhite.GetID() && commands[index].Tex == 0))) { (CurrentTex == pWhite.GetID() && commands[index].Tex == 0)) &&
commands[index].FirstIndex == startidx + num_indices) {
num_indices += commands[index].IndexCount; num_indices += commands[index].IndexCount;
index++; index++;
} }
+12
View File
@@ -43,6 +43,18 @@ class PD_API Drawlist {
void Optimize(); void Optimize();
void Clear(); void Clear();
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();
bool HasCommands() { return pCommands.size() > 0; } bool HasCommands() { return pCommands.size() > 0; }
+76 -74
View File
@@ -1,75 +1,77 @@
#pragma once #pragma once
/* /*
MIT License MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7) Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <pd/ui7/container/container.hpp> #include <pd/ui7/container/container.hpp>
#include <pd/ui7/io.hpp> #include <pd/ui7/io.hpp>
#include <pd/ui7/layout.hpp> #include <pd/ui7/layout.hpp>
namespace PD { namespace PD {
namespace UI7 { namespace UI7 {
/** /**
* Color Editor (Creating a PopUP when clicking) * Color Editor (Creating a PopUP when clicking)
*/ */
class PD_API ColorEdit : public Container { class PD_API ColorEdit : public Container {
public: public:
/** /**
* Constructor * Constructor
* @param label Label of the Button * @param label Label of the Button
* @param pos Base Position * @param pos Base Position
* @param lr Reference to the Renderer * @param lr Reference to the Renderer
*/ */
ColorEdit(const std::string& label, u32* color, UI7::IO& io) { ColorEdit(const std::string& label, u32* color, UI7::IO& io) {
// PD::Assert(color != nullptr, "Input Color Address is null!"); // PD::Assert(color != nullptr, "Input Color Address is null!");
this->label = label; this->label = label;
this->color_ref = color; this->color_ref = color;
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
* @note This function is usally called by Menu::Update /**
*/ * Override for the Input Handler
void HandleInput() override; * @note This function is usally called by Menu::Update
/** */
* Override for the Rendering Handler void HandleInput() override;
* @note This function is usally called by Menu::Update /**
* */ * Override for the Rendering Handler
void Draw() override; * @note This function is usally called by Menu::Update
* */
/** Function to Update Size if framepadding changes */ void Draw() override;
void Update() override;
/** Function to Update Size if framepadding changes */
private: void Update() override;
fvec2 tdim; ///< Text size
u32* color_ref = nullptr; ///< Color Reference private:
u32 initial_color; ///< Initial Color fvec2 tdim; ///< Text size
std::string label; ///< Label of the Button u32* color_ref = nullptr; ///< Color Reference
Layout* layout; ///< Layout to open u32 initial_color; ///< Initial Color
bool is_shown = false; ///< AHow Layout Editor std::string label; ///< Label of the Button
}; Layout* layout = nullptr; ///< Layout to open
} // namespace UI7 bool is_shown = false; ///< AHow Layout Editor
};
} // namespace UI7
} // namespace PD } // namespace PD
+22 -3
View File
@@ -111,6 +111,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 +174,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 */
+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
+10 -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
@@ -84,6 +82,11 @@ class PD_API IO {
u32 NumIndices = 0; ///< Debug Indices Num u32 NumIndices = 0; ///< Debug Indices Num
std::vector<u32> MenuOrder; std::vector<u32> MenuOrder;
// 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) {
DrawlistRegestry.push_back(std::make_pair(id, v)); DrawlistRegestry.push_back(std::make_pair(id, v));
+1 -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 */
/** /**
+1 -1
View File
@@ -82,7 +82,7 @@ class PD_API Menu {
Container* r = pLayout.FindObject(id); Container* r = pLayout.FindObject(id);
if (!r) { if (!r) {
r = new UI7::DragData<T>(label, data, num_elms, pIO, min, max, step, r = new UI7::DragData<T>(label, data, num_elms, pIO, min, max, step,
precision); precision);
// Isnt This exactly the same line??? // Isnt This exactly the same line???
// r = UI7::DragData<T>::New(label, data, num_elms, pIO, min, max, step, // r = UI7::DragData<T>::New(label, data, num_elms, pIO, min, max, step,
// precision); // precision);
+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);
+1 -1
View File
@@ -51,7 +51,7 @@ PD_API void Button::Draw() {
// io->Ren->OnScreen(screen); // io->Ren->OnScreen(screen);
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();
+22 -23
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;
} }
@@ -54,27 +53,27 @@ 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) { 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)); });
}), layout->AddObjectEx(r, UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate |
UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate | UI7LytAdd_NoScrollHandle); UI7LytAdd_NoScrollHandle);
auto obj = new DynObj( r = io->DynObjPool.Allocate();
[=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) { *r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
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);
l->DrawText( l->DrawText(
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));
+4 -4
View File
@@ -31,10 +31,10 @@ 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));
} }
PD_API void Container::HandleInternalInput() { PD_API void Container::HandleInternalInput() {
+3 -2
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>
@@ -92,8 +93,8 @@ PD_API void DragData<T>::Draw() {
// 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>
+1 -1
View File
@@ -33,7 +33,7 @@ PD_API void Image::Draw() {
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
+4 -3
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,9 +57,9 @@ 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);
} }
} }
+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
+14 -2
View File
@@ -26,6 +26,15 @@ SOFTWARE.
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() {
@@ -136,6 +145,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++;
@@ -151,7 +161,8 @@ PD_API void Layout::Update() {
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 +193,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);
} }
+42 -35
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,9 @@ 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();
UI7::Container* self) { *r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
UI7::Container* self) {
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();
@@ -134,7 +139,7 @@ PD_API void Menu::HandleFocus() {
PD::Hid::IsEvent(Hid::Event::Down, Hid::Keyboard::MouseLeft)) && PD::Hid::IsEvent(Hid::Event::Down, Hid::Keyboard::MouseLeft)) &&
Li::Math::InBounds(PD::Hid::MousePos(), newarea) && Li::Math::InBounds(PD::Hid::MousePos(), newarea) &&
!Li::Math::InBounds(PD::Hid::MousePos(), !Li::Math::InBounds(PD::Hid::MousePos(),
pIO.InputHandler.FocusedMenuRect)) { pIO.InputHandler.FocusedMenuRect)) {
pIO.InputHandler.FocusedMenu = pID; pIO.InputHandler.FocusedMenu = pID;
} }
if (pIO.InputHandler.FocusedMenu == pID) { if (pIO.InputHandler.FocusedMenu == pID) {
@@ -187,7 +192,7 @@ PD_API void Menu::HandleTitlebarActions() {
vec2 cpos = pLayout.Pos + pIO.FramePadding; vec2 cpos = pLayout.Pos + pIO.FramePadding;
// clr_collapse_tri = UI7Color_FrameBackground; // clr_collapse_tri = UI7Color_FrameBackground;
if (pIO.InputHandler.DragObject(UI7::ID(pID.GetName() + "clbse"), if (pIO.InputHandler.DragObject(UI7::ID(pID.GetName() + "clbse"),
fvec4(cpos, fvec2(18, TitleBarHeight)))) { fvec4(cpos, fvec2(18, TitleBarHeight)))) {
if (pIO.InputHandler.DragReleased) { if (pIO.InputHandler.DragReleased) {
pIsOpen = !pIsOpen; pIsOpen = !pIsOpen;
} }
@@ -203,7 +208,7 @@ PD_API void Menu::HandleTitlebarActions() {
// clr_close_btn = UI7Color_FrameBackground; // clr_close_btn = UI7Color_FrameBackground;
if (pIO.InputHandler.DragObject(UI7::ID(pID.GetName() + "clse"), if (pIO.InputHandler.DragObject(UI7::ID(pID.GetName() + "clse"),
fvec4(cpos, size))) { fvec4(cpos, size))) {
if (pIO.InputHandler.DragReleased) { if (pIO.InputHandler.DragReleased) {
*pIsShown = !(*pIsShown); *pIsShown = !(*pIsShown);
} }
@@ -216,7 +221,7 @@ PD_API void Menu::HandleTitlebarActions() {
// clr_close_btn = UI7Color_FrameBackground; // clr_close_btn = UI7Color_FrameBackground;
if (pIO.InputHandler.DragObject(UI7::ID(pID.GetName() + "rszs"), if (pIO.InputHandler.DragObject(UI7::ID(pID.GetName() + "rszs"),
fvec4(cpos, fvec2(20)))) { fvec4(cpos, fvec2(20)))) {
fvec2 szs = pLayout.Size + (pIO.InputHandler.DragPosition - fvec2 szs = pLayout.Size + (pIO.InputHandler.DragPosition -
pIO.InputHandler.DragLastPosition); pIO.InputHandler.DragLastPosition);
if (szs.x < 30) szs.x = 30; if (szs.x < 30) szs.x = 30;
@@ -250,14 +255,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->Layer(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));
}); });
r->SetSize( r->SetSize(
fvec2(pLayout.GetSize().x, pLayout.GetSize().y - TitleBarHeight)); fvec2(pLayout.GetSize().x, pLayout.GetSize().y - TitleBarHeight));
r->SetPos(fvec2(0, TitleBarHeight)); r->SetPos(fvec2(0, TitleBarHeight));
@@ -266,9 +271,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->Layer(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 +288,14 @@ 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->Layer(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->Layer(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() +
@@ -306,10 +312,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();
UI7::Container* self) { *r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
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->Layer(21);
/** /**
* Symbol (Position Swapping set by pIsOpen ? openpos : closepos;) * Symbol (Position Swapping set by pIsOpen ? openpos : closepos;)
*/ */
@@ -338,10 +345,10 @@ PD_API void Menu::DrawBaseLayout() {
fvec2(pLayout.Pos.x + pLayout.Size.x - size.x - pIO.FramePadding.x, fvec2(pLayout.Pos.x + pLayout.Size.x - size.x - pIO.FramePadding.x,
pLayout.Pos.y + pIO.FramePadding.y); pLayout.Pos.y + pIO.FramePadding.y);
pLayout.DrawList.DrawLine(cpos, cpos + size, pLayout.DrawList.DrawLine(cpos, cpos + size,
pIO.Theme.Get(UI7Color_FrameBackground), 2); pIO.Theme.Get(UI7Color_FrameBackground), 2);
pLayout.DrawList.DrawLine(cpos + fvec2(0, size.y), pLayout.DrawList.DrawLine(cpos + fvec2(0, size.y),
cpos + fvec2(size.x, 0), cpos + fvec2(size.x, 0),
pIO.Theme.Get(UI7Color_FrameBackground), 2); pIO.Theme.Get(UI7Color_FrameBackground), 2);
} }
} }
} }
@@ -382,7 +389,8 @@ 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) {
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,14 +401,13 @@ 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;
} }
+16 -18
View File
@@ -51,15 +51,14 @@ 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;
} }
if (std::find(pCurrentMenus.begin(), pCurrentMenus.end(), (u32)id) != if (std::find(pCurrentMenus.begin(), pCurrentMenus.end(), (u32)id) !=
pCurrentMenus.end()) { pCurrentMenus.end()) {
PDERR("UI7: Menu {} already exists!", id.GetName()); PDERR("UI7: Menu {} already exists!", id.GetName());
return nullptr; return nullptr;
} }
pCurrent = pGetOrCreateMenu(id); pCurrent = pGetOrCreateMenu(id);
@@ -208,18 +207,18 @@ PD_API void Context::MetricsMenu(bool* show) {
m->Label("Renderer: {}", PD::Gfx::GetDriverName()); m->Label("Renderer: {}", PD::Gfx::GetDriverName());
if (m->BeginTreeNode( if (m->BeginTreeNode(
std::string(std::string("Input: ") + PD::Hid::GetDriverName()))) { std::string(std::string("Input: ") + PD::Hid::GetDriverName()))) {
/* if (pIO.pCtx.Hid()->Flags & PD::HidDriver::Flags_HasKeyboard) { /* if (pIO.pCtx.Hid()->Flags & PD::HidDriver::Flags_HasKeyboard) {
m->Label("- Keyboard Supported"); m->Label("- Keyboard Supported");
} }
if (pIO.pCtx.Hid()->Flags & PD::HidDriver::Flags_HasMouse) { if (pIO.pCtx.Hid()->Flags & PD::HidDriver::Flags_HasMouse) {
m->Label("- Mouse Supported"); m->Label("- Mouse Supported");
} }
if (pIO.pCtx.Hid()->Flags & PD::HidDriver::Flags_HasTouch) { if (pIO.pCtx.Hid()->Flags & PD::HidDriver::Flags_HasTouch) {
m->Label("- Touch Supported"); m->Label("- Touch Supported");
} }
if (pIO.pCtx.Hid()->Flags & PD::HidDriver::FLags_HasGamepad) { if (pIO.pCtx.Hid()->Flags & PD::HidDriver::FLags_HasGamepad) {
m->Label("- Gamepad Supported"); m->Label("- Gamepad Supported");
}*/ }*/
m->EndTreeNode(); m->EndTreeNode();
} }
/** Section IO */ /** Section IO */
@@ -256,8 +255,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()));
} }
@@ -321,7 +319,7 @@ PD_API void UI7::Context::StyleEditor(bool* show) {
} }
/// Small trick to print without prefix /// Small trick to print without prefix
#define ts(x) m->ColorEdit(std::string(#x).substr(9), pIO.Theme.GetRef(x)); #define ts(x) m->ColorEdit(std::string(#x).substr(9), pIO.Theme.GetRef(x));
#define ts2(x) \ #define ts2(x) \
m->DragData(std::string(#x).substr(9), (u8*)&pIO.Theme.GetRef(x), 4, (u8)0, \ m->DragData(std::string(#x).substr(9), (u8*)&pIO.Theme.GetRef(x), 4, (u8)0, \
(u8)255); (u8)255);
ts(UI7Color_Background); ts(UI7Color_Background);
+16 -5
View File
@@ -198,9 +198,9 @@ int main(int argc, char** argv) {
auto pTex = PD::Gfx::LoadTexture(img, img.Width(), img.Height()); auto pTex = PD::Gfx::LoadTexture(img, img.Width(), img.Height());
PD::Li::Font font; PD::Li::Font font;
PD::Li::Font debug_font; PD::Li::Font debug_font;
font.LoadTTF(ResourcePath("default.ttf"), 32, LiFontFlags_SDF); font.LoadTTF(ResourcePath("default.ttf"), 32, LiFontFlags_SDF);
debug_font.LoadTTF(ResourcePath("JetBrainsMono-Medium.ttf"), 32, debug_font.LoadTTF(ResourcePath("JetBrainsMono-Medium.ttf"), 32,
LiFontFlags_SDF | LiFontFlags_Monospace); LiFontFlags_SDF | LiFontFlags_Monospace);
pList.SetFont(&font); pList.SetFont(&font);
App app(font); App app(font);
Cursor LeftStick; Cursor LeftStick;
@@ -297,18 +297,28 @@ int main(int argc, char** argv) {
"#ff00ff"); "#ff00ff");
} }
pList.SetFont(&font); pList.SetFont(&font);
#ifndef __3DS__ #ifndef __3DS__
PD::TT::Beg("BuildUI7Menus"); PD::TT::Beg("BuildUI7Menus");
if (auto m = ui7.BeginMenu("Test")) { if (auto m = ui7.BeginMenu("Test")) {
m->Label("Hello World!"); m->Label("Hello World!");
ui7.EndMenu(); ui7.EndMenu();
} }
if (auto m = ui7.BeginMenu("LI DBG INFO")) {
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());
ui7.EndMenu();
}
ui7.MetricsMenu(); ui7.MetricsMenu();
PD::TT::End("BuildUI7Menus"); 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");
#endif #endif
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(pList);
@@ -320,6 +330,7 @@ int main(int argc, char** argv) {
PD::TT::Beg("OSCTX::MainLoop"); 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);
} }