# Stage 1.8

- Renderer now vould use more screen Objects
- Register default Top and Bottom Screens (for Overlays and UI7)
- Make ToHex an Inline header func
- Add GetCompilerVersion
- Add Library Compile And Version Info to common
- Remove z of vertex object and shader in position
- Add Container base and SubContainers to UI7
- Add abillity to Join Multiple Objects in Same Line and Center them
- Fix LayerOrder Bug for updating texts in DrawList
This commit is contained in:
2025-02-02 20:32:07 +01:00
parent 055588ce8b
commit f87c103d8d
32 changed files with 619 additions and 293 deletions

View File

@ -66,6 +66,10 @@ class App {
Hid::Ref Input() { return input_mgr; }
float GetFps() const { return fps; }
protected:
Screen::Ref Top;
Screen::Ref Bottom;
private:
void PreInit();
void PostDeinit();

View File

@ -69,4 +69,12 @@ using u64 = unsigned long long;
using u32 = unsigned int;
using u16 = unsigned short;
using u8 = unsigned char;
namespace LibInfo {
const std::string CompiledWith();
const std::string CxxVersion();
const std::string BuildTime();
const std::string Version();
const std::string Commit();
} // namespace LibInfo
} // namespace PD

View File

@ -37,7 +37,30 @@ const std::string GetFileName(const std::string& path,
const std::string& saperators = "/\\");
const std::string PathRemoveExtension(const std::string& path);
template <typename T>
const std::string ToHex(const T& v);
inline const std::string ToHex(const T& v) {
std::stringstream s;
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
return s.str();
}
u32 FastHash(const std::string& s);
inline const std::string GetCompilerVersion() {
/// As the function looks like this Project is meant to
/// Be ported to other systems as well
std::stringstream res;
#ifdef __GNUC__
res << "GCC: " << __GNUC__;
res << "." << __GNUC_MINOR__ << ".";
res << __GNUC_PATCHLEVEL__;
#elif __clang__
res << "Clang: " << __clang_major__ << ".";
res << __clang_minor__ << ".";
res << __clang_patchlevel__;
#elif _MSC_VER
res << "MSVC: " << _MSC_VER;
#else
res << "Unknown Compiler";
#endif
return res.str();
}
} // namespace Strings
} // namespace PD

View File

@ -113,21 +113,13 @@ class Vertex {
Vertex(const vec2& p, const vec2& u, u32 c) {
pos[0] = p[0];
pos[1] = p[1];
pos[2] = 0.f;
uv = u;
color = c;
}
~Vertex() {}
Vertex& Pos(const vec3& v) {
pos = v;
return *this;
}
// Lets support that as well
Vertex& Pos(const vec2& v) {
pos[0] = v[0];
pos[1] = v[1];
pos[2] = 0.f;
pos = v;
return *this;
}
Vertex& Uv(const vec2& v) {
@ -140,7 +132,7 @@ class Vertex {
}
// private:
vec3 pos;
vec2 pos;
vec2 uv;
u32 color;
};
@ -270,7 +262,7 @@ class StaticObject : public SmartCtor<StaticObject> {
void MoveIt(vec2 off) {
for (auto& it : cpy) {
for (auto& jt : it->VertexList()) {
jt.pos += vec3(off, 0);
jt.pos += off;
}
}
}
@ -354,27 +346,24 @@ class Renderer : public SmartCtor<Renderer> {
StaticObject::Ref text;
};
void Render();
void PrepareRender();
void Render(Screen::Ref s);
void FinalizeRender();
void OnScreen(Screen::Screen_ screen) {
if (screen == Screen::Top) {
bottom = false;
area_size = top->GetSize();
} else if (screen == Screen::Bottom) {
bottom = true;
area_size = bot->GetSize();
} else {
void RegisterScreen(bool bottom, Screen::Ref s) { screens[bottom] = s; }
void OnScreen(Screen::Ref s) {
if (!s) {
return;
}
this->screen = s;
area_size = screen->GetSize();
}
void OnScreen(bool bottom) {
bottom = bottom;
area_size = bottom ? bot->GetSize() : top->GetSize();
}
Screen::Screen_ CurrentScreen() const {
return bottom ? Screen::Bottom : Screen::Top;
Screen::Ref CurrentScreen() const { return screen; }
Screen::Ref GetScreen(bool bottom) {
auto res = screens[bottom];
Assert(res.get(), "Screen is not registered!");
return res;
}
void Rotation(float v) { rot = v; }
@ -458,13 +447,17 @@ class Renderer : public SmartCtor<Renderer> {
static bool InBox(const vec2& pos, const vec4& rect);
static bool InBox(const vec2& alpha, const vec2& bravo, const vec2& charlie,
const vec4& rect);
/// @brief Get The Address of a Screen
/// @note IMPORTANT: THIS IS FOR 32Bit System
/// Should find a better way to do this for porting this lib
static u32 Screen32(Screen::Ref s) { return (u32)s.get(); }
static void OptiCommandList(std::vector<Command::Ref>& list);
/// @brief Returns Viewport with xy
vec4 GetViewport();
/// @brief Push a Self Created command
void PushCommand(Command::Ref cmd) {
cmd->Index(cmd_idx++); // Indexing
draw_list[bottom].push_back(cmd);
draw_list[Screen32(screen)].push_back(cmd);
}
/// @brief Automatically sets up a command
void SetupCommand(Command::Ref cmd);
@ -487,17 +480,16 @@ class Renderer : public SmartCtor<Renderer> {
private:
/// Helper Funcitons ///
void RenderOn(bool bottom);
void UpdateRenderMode(const RenderMode& mode);
/// @brief Screens ///
Screen::Ref top;
Screen::Ref bot;
/// One Screen Only... ///
Screen::Ref screen;
/// Reference Screens ///
Screen::Ref screens[2];
/// Context Related ///
RenderFlags flags = RenderFlags_Default;
vec2 area_size;
bool bottom = false;
int current_layer = 0;
Texture::Ref current_tex = nullptr;
Texture::Ref white = nullptr; // Single color
@ -516,7 +508,7 @@ class Renderer : public SmartCtor<Renderer> {
float rot = 0.f;
/// Rendering ///
// Use dual drawlist
std::vector<Command::Ref> draw_list[2];
std::unordered_map<u32, std::vector<Command::Ref>> draw_list;
std::vector<Vertex, LinearAllocator<Vertex>> vertex_buf;
std::vector<u16, LinearAllocator<u16>> index_buf;
u32 vertex_idx = 0;

View File

@ -33,7 +33,7 @@ namespace PD {
class Screen : public SmartCtor<Screen> {
public:
enum Screen_ { Top, Bottom, TopRight };
Screen(Screen_ screen) {
Screen(Screen_ screen) : type(screen) {
if (screen == Top) {
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
GPU_RB_DEPTH24_STENCIL8);
@ -60,10 +60,13 @@ class Screen : public SmartCtor<Screen> {
return vec2(target->frameBuf.height, target->frameBuf.width);
}
Screen_ ScreenType() const { return type; }
C3D_RenderTarget* Get() const { return target; }
operator C3D_RenderTarget*() const { return target; }
private:
Screen_ type;
const u32 DisplayTransferFlags =
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |

View File

@ -0,0 +1,30 @@
#pragma once
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
class Button : public Container {
public:
Button(const std::string& label, vec2 pos, LI::Renderer::Ref lr) {
this->screen = lr->CurrentScreen();
this->label = label;
this->SetPos(pos);
this->tdim = lr->GetTextDimensions(label);
color = UI7Color_Button;
this->SetSize(tdim + vec2(8, 4));
}
~Button() {}
bool IsPressed() { return pressed; }
void HandleInput(Hid::Ref inp) override;
void Draw() override;
private:
vec2 tdim;
UI7Color color;
std::string label;
bool pressed = false;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,32 @@
#pragma once
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
class Checkbox : public Container {
public:
Checkbox(const std::string& label, vec2 pos, bool& usr_ref,
LI::Renderer::Ref lr)
: usr_ref(usr_ref) {
this->screen = lr->CurrentScreen();
this->label = label;
this->SetPos(pos);
this->tdim = lr->GetTextDimensions(label);
color = UI7Color_FrameBackground;
this->SetSize(cbs + vec2(tdim.x() + 5, 0));
}
~Checkbox() {}
void HandleInput(Hid::Ref inp) override;
void Draw() override;
private:
vec2 tdim;
vec2 cbs = vec2(18);
UI7Color color;
std::string label;
bool& usr_ref;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,54 @@
#pragma once
#include <pd/common/common.hpp>
#include <pd/common/strings.hpp>
#include <pd/controls/hid.hpp>
#include <pd/maths/vec.hpp>
#include <pd/ui7/drawlist.hpp>
namespace PD {
namespace UI7 {
class Container : public SmartCtor<Container> {
public:
Container() {}
Container(const vec2& pos, const vec2& size) : pos(pos), size(size) {}
Container(const vec4& box) : pos(box.xy()), size(box.zw()) {}
~Container() {}
void Init(LI::Renderer::Ref r, UI7::DrawList::Ref l, UI7::Theme* lt) {
list = l;
linked_theme = lt;
ren = r;
}
void SetPos(const vec2& pos) { this->pos = pos; }
void SetSize(const vec2& size) { this->size = size; }
vec2 GetPos() { return pos; }
vec2 GetSize() { return size; }
bool Skippable() const { return skippable; }
void HandleScrolling(vec2 scrolling, vec4 viewport);
virtual void HandleInput(Hid::Ref inp) {}
virtual void Draw() {}
void UnlockInput() { inp_done = false; }
u32 GetID() const { return id; }
void SetID(u32 id) { this->id = id; }
protected:
/// used to skip Input/Render preocessing ot not
bool skippable = false;
bool inp_done = false;
Screen::Ref screen;
vec2 pos;
vec2 size;
UI7::DrawList::Ref list;
UI7::Theme* linked_theme;
LI::Renderer::Ref ren;
u32 id = 0;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,27 @@
#pragma once
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
class Image : public Container {
public:
Image(Texture::Ref img, vec2 pos, LI::Renderer::Ref lr, vec2 size = 0.f) {
this->screen = lr->CurrentScreen();
this->img = img;
this->SetPos(pos);
if (size.x() != 0 || size.y() != 0) {
this->SetSize(size);
} else {
this->SetSize(img->GetSize());
}
}
~Image() {}
void Draw() override;
private:
Texture::Ref img;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,27 @@
#pragma once
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
class Label : public Container {
public:
Label(const std::string& label, vec2 pos, LI::Renderer::Ref lr) {
this->screen = lr->CurrentScreen();
this->label = label;
this->SetPos(pos);
this->tdim = lr->GetTextDimensions(label);
color = UI7Color_Text;
this->SetSize(tdim);
}
~Label() {}
void Draw() override;
private:
vec2 tdim;
UI7Color color;
std::string label;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,6 @@
#pragma once
#include <pd/ui7/container/button.hpp>
#include <pd/ui7/container/checkbox.hpp>
#include <pd/ui7/container/image.hpp>
#include <pd/ui7/container/label.hpp>

View File

@ -24,6 +24,7 @@ SOFTWARE.
*/
#include <pd/controls/hid.hpp>
#include <pd/ui7/containers.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
@ -56,6 +57,10 @@ class Menu : public SmartCtor<Menu> {
void SameLine();
void Separator();
void SeparatorText(const std::string& label);
void Join();
/// @brief Horizontal Center Joined objects
void JoinOpHzCenter();
void AfterAlignCenter();
/// API for Custom Objects
bool HandleScrolling(vec2& pos, const vec2& size);
@ -106,6 +111,10 @@ class Menu : public SmartCtor<Menu> {
/// Internal Processing
void Update(float delta);
/// Objects API
Container::Ref ObjectPush(Container::Ref obj);
Container::Ref FindIDObj(u32 id);
/// This ability is crazy useful
friend class Context;
@ -127,6 +136,11 @@ class Menu : public SmartCtor<Menu> {
Menu::Ref submenu;
/// Objects API
std::vector<Container::Ref> objects;
std::vector<Container::Ref> idobjs;
std::vector<Container*> join;
// DrawLists
DrawList::Ref back;
DrawList::Ref main;