# 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:
@ -53,7 +53,10 @@ void App::Run() {
|
||||
renderer->Layer(93);
|
||||
msg_mgr->Update(dt);
|
||||
PD::TT::End("Ovl_Update");
|
||||
renderer->Render();
|
||||
renderer->PrepareRender();
|
||||
renderer->Render(Top);
|
||||
renderer->Render(Bottom);
|
||||
renderer->FinalizeRender();
|
||||
}
|
||||
this->Deinit();
|
||||
this->PostDeinit();
|
||||
@ -64,8 +67,14 @@ void App::PreInit() {
|
||||
gfxInitDefault();
|
||||
cfguInit();
|
||||
romfsInit();
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||
input_mgr = Hid::New();
|
||||
Top = Screen::New(Screen::Top);
|
||||
Bottom = Screen::New(Screen::Bottom);
|
||||
renderer = LI::Renderer::New();
|
||||
renderer->RegisterScreen(false, Top);
|
||||
renderer->RegisterScreen(true, Bottom);
|
||||
renderer->OnScreen(Top);
|
||||
msg_mgr = MessageMgr::New(renderer);
|
||||
overlay_mgr = OverlayMgr::New(renderer, input_mgr);
|
||||
}
|
||||
@ -75,6 +84,7 @@ void App::PostDeinit() {
|
||||
msg_mgr = nullptr;
|
||||
overlay_mgr = nullptr;
|
||||
input_mgr = nullptr;
|
||||
C3D_Fini();
|
||||
gfxExit();
|
||||
cfguExit();
|
||||
romfsExit();
|
||||
|
@ -23,10 +23,21 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/common/strings.hpp>
|
||||
|
||||
#ifndef PALLADIUM_VERSION
|
||||
#define PALLADIUM_VERSION "unknown"
|
||||
#endif
|
||||
#ifndef PALLADIUM_GIT_COMMIT
|
||||
#define PALLADIUM_GIT_COMMIT "unknown"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const std::string PD::LibInfo::CompiledWith() {
|
||||
return Strings::GetCompilerVersion();
|
||||
}
|
||||
const std::string PD::LibInfo::CxxVersion() {
|
||||
return "CPP: " + std::to_string(__cplusplus);
|
||||
}
|
||||
const std::string PD::LibInfo::BuildTime() { return __DATE__ " - " __TIME__; }
|
||||
const std::string PD::LibInfo::Version() { return PALLADIUM_VERSION; }
|
||||
const std::string PD::LibInfo::Commit() { return PALLADIUM_GIT_COMMIT; }
|
@ -121,13 +121,6 @@ const std::string PathRemoveExtension(const std::string& path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
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) {
|
||||
u32 hash = 5381;
|
||||
for (auto& it : s) {
|
||||
|
@ -28,7 +28,7 @@ SOFTWARE.
|
||||
|
||||
// clang-format off
|
||||
unsigned char li7_shader[] = {
|
||||
0x44, 0x56, 0x4c, 0x42, 0x1, 0x0, 0x0, 0x0, 0xa4, 0x0, 0x0, 0x0, 0x44, 0x56, 0x4c, 0x50, 0x0, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0x98, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x1, 0xf0, 0x7, 0x4e, 0x2, 0x8, 0x2, 0x8, 0x3, 0x18, 0x2, 0x8, 0x4, 0x28, 0x2, 0x8, 0x5, 0x38, 0x2, 0x8, 0x6, 0x10, 0x40, 0x4c, 0x7, 0xf1, 0x27, 0x22, 0x8, 0x10, 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0x0, 0x54, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x54, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x6c, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x74, 0x0, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x2, 0x0, 0x5f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x1, 0x1, 0x37, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0, 0xf, 0x0, 0x0, 0x0, 0x3, 0x0, 0x2, 0x0, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x13, 0x0, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0, 0x0,
|
||||
};
|
||||
// clang-format on
|
||||
size_t li7_shader_size = 0x124;
|
@ -220,12 +220,6 @@ void Font::LoadSystemFont() {
|
||||
}
|
||||
|
||||
Renderer::Renderer(RenderFlags flags) {
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||
top = Screen::New(Screen::Top);
|
||||
bot = Screen::New(Screen::Bottom);
|
||||
top->Clear();
|
||||
bot->Clear();
|
||||
|
||||
vertex_buf.resize(4 * 4096, Vertex());
|
||||
index_buf.resize(6 * 4096, 0);
|
||||
|
||||
@ -237,7 +231,7 @@ Renderer::Renderer(RenderFlags flags) {
|
||||
shaderInstanceGetUniformLocation(shader.vertexShader, "projection");
|
||||
|
||||
AttrInfo_Init(&attr);
|
||||
AttrInfo_AddLoader(&attr, 0, GPU_FLOAT, 3);
|
||||
AttrInfo_AddLoader(&attr, 0, GPU_FLOAT, 2);
|
||||
AttrInfo_AddLoader(&attr, 1, GPU_FLOAT, 2);
|
||||
AttrInfo_AddLoader(&attr, 2, GPU_UNSIGNED_BYTE, 4);
|
||||
|
||||
@ -252,13 +246,10 @@ Renderer::Renderer(RenderFlags flags) {
|
||||
// Not Loading as Systemfont is freezing
|
||||
// font = Font::New();
|
||||
// font->LoadSystemFont();
|
||||
|
||||
area_size = top->GetSize();
|
||||
}
|
||||
Renderer::~Renderer() {
|
||||
shaderProgramFree(&shader);
|
||||
DVLB_Free(dvlb);
|
||||
C3D_Fini();
|
||||
}
|
||||
|
||||
void Renderer::StaticText::Setup(Renderer* ren, const vec2& pos, u32 clr,
|
||||
@ -475,10 +466,7 @@ void Renderer::TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos,
|
||||
}
|
||||
}
|
||||
|
||||
vec4 Renderer::GetViewport() {
|
||||
auto screen = bottom ? bot->GetSize() : top->GetSize();
|
||||
return vec4(0, 0, screen[0], screen[1]);
|
||||
}
|
||||
vec4 Renderer::GetViewport() { return vec4(vec2(), screen->GetSize()); }
|
||||
|
||||
vec2 Renderer::GetTextDimensions(const std::string& text) {
|
||||
if (!font) {
|
||||
@ -564,16 +552,68 @@ void Renderer::UpdateRenderMode(const RenderMode& mode) {
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::RenderOn(bool bot) {
|
||||
void Renderer::PrepareRender() {
|
||||
if (font_update) {
|
||||
tms.clear();
|
||||
font_update = false;
|
||||
}
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
TT::Beg("LI_RenderAll");
|
||||
vertex_idx = 0;
|
||||
index_idx = 0;
|
||||
vertices = 0;
|
||||
indices = 0;
|
||||
commands = 0;
|
||||
drawcalls = 0;
|
||||
C3D_BindProgram(&shader);
|
||||
C3D_SetAttrInfo(&attr);
|
||||
}
|
||||
|
||||
void Renderer::FinalizeRender() {
|
||||
C3D_FrameEnd(0);
|
||||
TT::End("LI_RenderAll");
|
||||
current_layer = 0;
|
||||
cmd_idx = 0;
|
||||
rot = 0.f;
|
||||
UseTex();
|
||||
if (flags & RenderFlags_TMS) {
|
||||
std::vector<std::string> rem;
|
||||
for (auto& it : tms) {
|
||||
if (Sys::GetTime() - it.second.TimeCreated() > 5) rem.push_back(it.first);
|
||||
}
|
||||
for (auto it : rem) tms.erase(it);
|
||||
} else {
|
||||
tms.clear();
|
||||
}
|
||||
if (flags & RenderFlags_AST) {
|
||||
std::vector<u32> rem;
|
||||
for (auto it : ast) {
|
||||
if (!it.second->Used()) {
|
||||
rem.push_back(it.first);
|
||||
}
|
||||
it.second->SetUnused();
|
||||
}
|
||||
for (auto& it : rem) {
|
||||
ast.erase(it);
|
||||
}
|
||||
} else {
|
||||
ast.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::Render(Screen::Ref s) {
|
||||
Assert(s.get(), "Expected Screen Address but got nullptr!");
|
||||
s->Clear();
|
||||
s->Use();
|
||||
bool bot = s->ScreenType() == Screen::Bottom;
|
||||
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection,
|
||||
(bot ? &bot_proj : &top_proj));
|
||||
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
|
||||
UpdateRenderMode(RenderMode_RGBA);
|
||||
int total_vertices = 0;
|
||||
int total_indices = 0;
|
||||
drawcalls = 0;
|
||||
auto& cmds = draw_list[bot];
|
||||
commands = cmds.size();
|
||||
auto& cmds = draw_list[Screen32(s)];
|
||||
commands += cmds.size();
|
||||
size_t index = 0;
|
||||
if (flags & RenderFlags_LRS) {
|
||||
OptiCommandList(cmds);
|
||||
@ -613,66 +653,8 @@ void Renderer::RenderOn(bool bot) {
|
||||
}
|
||||
cmds.clear();
|
||||
C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
|
||||
vertices = total_vertices;
|
||||
indices = total_indices;
|
||||
}
|
||||
|
||||
void Renderer::Render() {
|
||||
if (font_update) {
|
||||
tms.clear();
|
||||
font_update = false;
|
||||
}
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
TT::Beg("LI_RenderAll");
|
||||
top->Clear();
|
||||
bot->Clear();
|
||||
vertex_idx = 0;
|
||||
index_idx = 0;
|
||||
C3D_BindProgram(&shader);
|
||||
C3D_SetAttrInfo(&attr);
|
||||
top->Use();
|
||||
RenderOn(false);
|
||||
int dtc = commands;
|
||||
int dtd = drawcalls;
|
||||
int dtv = vertices;
|
||||
int dti = indices;
|
||||
bot->Use();
|
||||
RenderOn(true);
|
||||
TT::End("LI_RenderAll");
|
||||
C3D_FrameEnd(0);
|
||||
commands += dtc;
|
||||
drawcalls += dtd;
|
||||
vertices += dtv;
|
||||
indices += dti;
|
||||
current_layer = 0;
|
||||
cmd_idx = 0;
|
||||
area_size = top->GetSize();
|
||||
bottom = false;
|
||||
rot = 0.f;
|
||||
UseTex();
|
||||
if (flags & RenderFlags_TMS) {
|
||||
std::vector<std::string> rem;
|
||||
for (auto& it : tms) {
|
||||
if (Sys::GetTime() - it.second.TimeCreated() > 5) rem.push_back(it.first);
|
||||
}
|
||||
for (auto it : rem) tms.erase(it);
|
||||
} else {
|
||||
tms.clear();
|
||||
}
|
||||
if (flags & RenderFlags_AST) {
|
||||
std::vector<u32> rem;
|
||||
for (auto it : ast) {
|
||||
if (!it.second->Used()) {
|
||||
rem.push_back(it.first);
|
||||
}
|
||||
it.second->SetUnused();
|
||||
}
|
||||
for (auto& it : rem) {
|
||||
ast.erase(it);
|
||||
}
|
||||
} else {
|
||||
ast.clear();
|
||||
}
|
||||
vertices += total_vertices;
|
||||
indices += total_indices;
|
||||
}
|
||||
|
||||
void Renderer::DrawRect(const vec2& pos, const vec2& size, u32 color,
|
||||
@ -685,7 +667,7 @@ void Renderer::DrawRect(const vec2& pos, const vec2& size, u32 color,
|
||||
auto cmd = Command::New();
|
||||
SetupCommand(cmd);
|
||||
QuadCommand(cmd, rec, uv, color);
|
||||
draw_list[bottom].push_back(cmd);
|
||||
draw_list[Screen32(screen)].push_back(cmd);
|
||||
}
|
||||
|
||||
void Renderer::DrawRectSolid(const vec2& pos, const vec2& size, u32 color) {
|
||||
@ -702,7 +684,7 @@ void Renderer::DrawTriangle(const vec2& a, const vec2& b, const vec2& c,
|
||||
auto cmd = Command::New();
|
||||
SetupCommand(cmd);
|
||||
TriangleCommand(cmd, a, b, c, color);
|
||||
draw_list[bottom].push_back(cmd);
|
||||
draw_list[Screen32(screen)].push_back(cmd);
|
||||
}
|
||||
|
||||
void Renderer::DrawCircle(const vec2& center_pos, float r, u32 color,
|
||||
@ -725,7 +707,7 @@ void Renderer::DrawCircle(const vec2& center_pos, float r, u32 color,
|
||||
vec2(x, y), vec2((std::cos(a) + 1.f) / 2.f, (std::sin(a) + 1.f) / 2.f),
|
||||
color));
|
||||
}
|
||||
draw_list[bottom].push_back(cmd);
|
||||
draw_list[Screen32(screen)].push_back(cmd);
|
||||
}
|
||||
|
||||
void Renderer::DrawLine(const vec2& a, const vec2& b, u32 color, int t) {
|
||||
@ -735,7 +717,7 @@ void Renderer::DrawLine(const vec2& a, const vec2& b, u32 color, int t) {
|
||||
auto cmd = Command::New();
|
||||
SetupCommand(cmd);
|
||||
QuadCommand(cmd, line, vec4(0.f, 1.f, 1.f, 0.f), color);
|
||||
draw_list[bottom].push_back(cmd);
|
||||
draw_list[Screen32(screen)].push_back(cmd);
|
||||
}
|
||||
|
||||
void Renderer::DrawImage(const vec2& pos, Texture::Ref tex, const vec2& scale) {
|
||||
@ -760,7 +742,7 @@ void Renderer::DrawText(const vec2& pos, u32 color, const std::string& text,
|
||||
e->second->Draw();
|
||||
return;
|
||||
}
|
||||
TextCommand(draw_list[bottom], pos, color, text, flags, ap);
|
||||
TextCommand(draw_list[Screen32(screen)], pos, color, text, flags, ap);
|
||||
}
|
||||
|
||||
} // namespace PD::LI
|
@ -497,11 +497,11 @@ void Keyboard::Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) {
|
||||
fade.a(fade.a() * flymgr.Progress());
|
||||
}
|
||||
if (flags & Flags_BlendTop) {
|
||||
ren->OnScreen(Screen::Top);
|
||||
ren->OnScreen(ren->GetScreen(false));
|
||||
ren->DrawRectSolid(0, vec2(400, 240), fade);
|
||||
}
|
||||
if (flags & Flags_BlendBottom) {
|
||||
ren->OnScreen(Screen::Bottom);
|
||||
ren->OnScreen(ren->GetScreen(true));
|
||||
ren->DrawRectSolid(0, vec2(320, 240), fade);
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ void MessageMgr::Push(const std::string& title, const std::string& text) {
|
||||
}
|
||||
|
||||
void MessageMgr::Update(float delta) {
|
||||
ren->OnScreen(Screen::Top);
|
||||
ren->OnScreen(ren->GetScreen(false));
|
||||
for (size_t i = 0; i < msgs.size(); i++) {
|
||||
// Update the Animation Handlers and Move older
|
||||
// Messages up if a new one got pushed
|
||||
|
@ -9,7 +9,7 @@ void Performance::Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) {
|
||||
if (*skill) {
|
||||
Kill();
|
||||
}
|
||||
ren->OnScreen(Screen::Top);
|
||||
ren->OnScreen(ren->GetScreen(false));
|
||||
ren->TextScale(0.6);
|
||||
vec2 pos;
|
||||
Line(pos, std::format("{:.1f} FPS / {:.2f}ms", 1000.f / delta, delta), ren);
|
||||
|
36
source/ui7/container/button.cpp
Normal file
36
source/ui7/container/button.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <pd/ui7/container/button.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
void Button::HandleInput(Hid::Ref inp) {
|
||||
/// Ensure to only check input once
|
||||
if (inp_done) {
|
||||
return;
|
||||
}
|
||||
/// Ensure it gets sed to false and stays if not pressed
|
||||
pressed = false;
|
||||
color = UI7Color_Button;
|
||||
Assert(screen.get(), "Screen is not set up!");
|
||||
if (screen->ScreenType() == Screen::Bottom) {
|
||||
if (inp->IsHeld(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPos(), vec4(pos, size))) {
|
||||
color = UI7Color_ButtonHovered;
|
||||
}
|
||||
if (inp->IsUp(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPosLast(), vec4(pos, size))) {
|
||||
color = UI7Color_ButtonActive;
|
||||
pressed = true;
|
||||
}
|
||||
}
|
||||
inp_done = true;
|
||||
}
|
||||
void Button::Draw() {
|
||||
Assert(ren.get() && list.get() && linked_theme,
|
||||
"Did you run Container::Init correctly?");
|
||||
ren->OnScreen(screen);
|
||||
list->AddRectangle(pos, size, linked_theme->Get(color));
|
||||
list->AddText(pos + size * 0.5 - tdim * 0.5, label,
|
||||
linked_theme->Get(UI7Color_Text));
|
||||
}
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
38
source/ui7/container/checkbox.cpp
Normal file
38
source/ui7/container/checkbox.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <pd/ui7/container/checkbox.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
void Checkbox::HandleInput(Hid::Ref inp) {
|
||||
/// Ensure to only check input once
|
||||
if (inp_done) {
|
||||
return;
|
||||
}
|
||||
color = UI7Color_FrameBackground;
|
||||
/// Ensure it gets sed to false and stays if not pressed
|
||||
Assert(screen.get(), "Screen is not set up!");
|
||||
if (screen->ScreenType() == Screen::Bottom) {
|
||||
if (inp->IsHeld(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPos(), vec4(pos, size))) {
|
||||
color = UI7Color_FrameBackgroundHovered;
|
||||
}
|
||||
if (inp->IsUp(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPosLast(), vec4(pos, size))) {
|
||||
color = UI7Color_FrameBackgroundHovered;
|
||||
usr_ref = !usr_ref;
|
||||
}
|
||||
}
|
||||
inp_done = true;
|
||||
}
|
||||
void Checkbox::Draw() {
|
||||
Assert(ren.get() && list.get() && linked_theme,
|
||||
"Did you run Container::Init correctly?");
|
||||
ren->OnScreen(screen);
|
||||
list->AddRectangle(pos, cbs, linked_theme->Get(color));
|
||||
if (usr_ref) {
|
||||
list->AddRectangle(pos + 2, cbs - 4, linked_theme->Get(UI7Color_Checkmark));
|
||||
}
|
||||
list->AddText(pos + vec2(cbs.x() + 5, cbs.y() * 0.5 - tdim.y() * 0.5), label,
|
||||
linked_theme->Get(UI7Color_Text));
|
||||
}
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
12
source/ui7/container/container.cpp
Normal file
12
source/ui7/container/container.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
void Container::HandleScrolling(vec2 scrolling, vec4 viewport) {
|
||||
pos -= vec2(0, scrolling.y());
|
||||
if (!LI::Renderer::InBox(pos, size, viewport)) {
|
||||
skippable = true;
|
||||
}
|
||||
}
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
13
source/ui7/container/image.cpp
Normal file
13
source/ui7/container/image.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include <pd/ui7/container/image.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
void Image::Draw() {
|
||||
Assert(ren.get() && list.get() && linked_theme,
|
||||
"Did you run Container::Init correctly?");
|
||||
Assert(img.get(), "Image is nullptr!");
|
||||
ren->OnScreen(screen);
|
||||
list->AddImage(pos, img);
|
||||
}
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
12
source/ui7/container/label.cpp
Normal file
12
source/ui7/container/label.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <pd/ui7/container/label.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
void Label::Draw() {
|
||||
Assert(ren.get() && list.get() && linked_theme,
|
||||
"Did you run Container::Init correctly?");
|
||||
ren->OnScreen(screen);
|
||||
list->AddText(pos, label, linked_theme->Get(UI7Color_Text));
|
||||
}
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -34,10 +34,10 @@ void DrawList::AddRectangle(vec2 pos, vec2 szs, const UI7Color& clr) {
|
||||
auto cmd = LI::Command::New();
|
||||
ren->UseTex();
|
||||
ren->SetupCommand(cmd);
|
||||
cmd->Layer(layer);
|
||||
cmd->Layer(base + layer);
|
||||
ren->QuadCommand(cmd, rect, vec4(0.f, 1.f, 1.f, 0.f), clr);
|
||||
commands.push_back(
|
||||
std::make_pair(ren->CurrentScreen() == Screen::Bottom, cmd));
|
||||
commands.push_back(std::make_pair(
|
||||
ren->CurrentScreen()->ScreenType() == Screen::Bottom, cmd));
|
||||
}
|
||||
|
||||
void DrawList::AddTriangle(vec2 pos0, vec2 pos1, vec2 pos2,
|
||||
@ -48,10 +48,10 @@ void DrawList::AddTriangle(vec2 pos0, vec2 pos1, vec2 pos2,
|
||||
auto cmd = LI::Command::New();
|
||||
ren->UseTex();
|
||||
ren->SetupCommand(cmd);
|
||||
cmd->Layer(layer);
|
||||
cmd->Layer(base + layer);
|
||||
ren->TriangleCommand(cmd, pos0, pos1, pos2, clr);
|
||||
commands.push_back(
|
||||
std::make_pair(ren->CurrentScreen() == Screen::Bottom, cmd));
|
||||
commands.push_back(std::make_pair(
|
||||
ren->CurrentScreen()->ScreenType() == Screen::Bottom, cmd));
|
||||
}
|
||||
|
||||
void DrawList::AddText(vec2 pos, const std::string& text, const UI7Color& clr,
|
||||
@ -63,11 +63,14 @@ void DrawList::AddText(vec2 pos, const std::string& text, const UI7Color& clr,
|
||||
e = static_text.find(id);
|
||||
}
|
||||
if (!e->second->IsSetup()) {
|
||||
int l = ren->Layer();
|
||||
ren->Layer(base);
|
||||
e->second->Setup(&(*ren), pos, clr, text, flags, box);
|
||||
ren->Layer(l);
|
||||
}
|
||||
e->second->SetPos(pos);
|
||||
e->second->SetColor(clr);
|
||||
e->second->SetLayer(base + layer);
|
||||
e->second->SetLayer(layer);
|
||||
e->second->Draw();
|
||||
|
||||
////// STILL LEAVING THE OLD CODE BELOW AS IT IS MAYBE NEEDED //////
|
||||
@ -78,13 +81,14 @@ void DrawList::AddText(vec2 pos, const std::string& text, const UI7Color& clr,
|
||||
// Font uses multiple textures
|
||||
// Oh and Handle Layer management here as well
|
||||
// int l = ren->Layer();
|
||||
// ren->Layer(layer);
|
||||
// ren->Layer(base + layer);
|
||||
// std::vector<LI::Command::Ref> cmds;
|
||||
// ren->TextCommand(cmds, pos, clr, text, flags, box);
|
||||
// ren->Layer(l);
|
||||
// for (auto c : cmds) {
|
||||
// commands.push_back(
|
||||
// std::make_pair(ren->CurrentScreen() == Screen::Bottom, c));
|
||||
// std::make_pair(ren->CurrentScreen()->ScreenType() == Screen::Bottom,
|
||||
// c));
|
||||
// }
|
||||
}
|
||||
|
||||
@ -97,18 +101,17 @@ void DrawList::AddImage(vec2 pos, Texture::Ref img, vec2 size) {
|
||||
auto cmd = LI::Command::New();
|
||||
ren->UseTex(img);
|
||||
ren->SetupCommand(cmd);
|
||||
cmd->Layer(layer);
|
||||
cmd->Layer(base + layer);
|
||||
ren->QuadCommand(cmd, rect, img->GetUV(), 0xffffffff);
|
||||
commands.push_back(
|
||||
std::make_pair(ren->CurrentScreen() == Screen::Bottom, cmd));
|
||||
commands.push_back(std::make_pair(
|
||||
ren->CurrentScreen()->ScreenType() == Screen::Bottom, cmd));
|
||||
}
|
||||
|
||||
void DrawList::Clear() { commands.clear(); }
|
||||
|
||||
void DrawList::Process() {
|
||||
for (auto command : commands) {
|
||||
command.second->Layer(command.second->Layer() + base);
|
||||
ren->OnScreen(command.first ? Screen::Bottom : Screen::Top);
|
||||
ren->OnScreen(ren->GetScreen(command.first));
|
||||
ren->PushCommand(command.second);
|
||||
}
|
||||
commands.clear();
|
||||
|
@ -2,107 +2,57 @@
|
||||
#include <pd/common/timetrace.hpp>
|
||||
#include <pd/ui7/menu.hpp>
|
||||
|
||||
//////////////////////////////
|
||||
//////// OBJECT SETUP ////////
|
||||
////// Setup Variables ///////
|
||||
///////// Move Cursor ////////
|
||||
//// Check Scrolling State ///
|
||||
/////// Handle Controls //////
|
||||
////////// Render ////////////
|
||||
//////////////////////////////
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
void UI7::Menu::Label(const std::string& label) {
|
||||
vec2 size = this->back->GetRenderer()->GetTextDimensions(label);
|
||||
vec2 pos = Cursor();
|
||||
CursorMove(size - vec2(0, 4)); // Fix to make gap not to large
|
||||
|
||||
if (HandleScrolling(pos, size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/// To Draw a Label above the head bar you should
|
||||
/// use the m->GetFrontList() instead
|
||||
|
||||
main->AddText(pos, label, linked_theme->Get(UI7Color_Text), 0,
|
||||
vec2(view_area.z(), 20));
|
||||
Container::Ref r =
|
||||
ObjectPush(PD::New<UI7::Label>(label, Cursor(), this->back->ren));
|
||||
CursorMove(r->GetSize());
|
||||
r->Init(main->ren, main, linked_theme);
|
||||
r->HandleScrolling(scrolling_off, view_area);
|
||||
}
|
||||
|
||||
bool UI7::Menu::Button(const std::string& label) {
|
||||
bool ret = false;
|
||||
auto tszs = this->back->GetRenderer()->GetTextDimensions(label);
|
||||
vec2 size = tszs + vec2(8, 4);
|
||||
vec2 pos = Cursor();
|
||||
UI7Color clr = UI7Color_Button;
|
||||
CursorMove(size);
|
||||
/////// SCROLLING HANDLER HERE ////////
|
||||
if (HandleScrolling(pos, size)) {
|
||||
return false;
|
||||
u32 id = Strings::FastHash("btn" + label);
|
||||
Container::Ref r = FindIDObj(id);
|
||||
if (!r) {
|
||||
r = ObjectPush(PD::New<UI7::Button>(label, Cursor(), this->back->ren));
|
||||
r->SetID(id);
|
||||
r->Init(main->ren, main, linked_theme);
|
||||
} else {
|
||||
ObjectPush(r);
|
||||
r->SetPos(Cursor());
|
||||
}
|
||||
/// CONTROLS ///
|
||||
if (has_touch) {
|
||||
if (inp->IsHeld(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPos(), vec4(pos, size))) {
|
||||
clr = UI7Color_ButtonHovered;
|
||||
}
|
||||
if (inp->IsUp(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPosLast(), vec4(pos, size))) {
|
||||
clr = UI7Color_ButtonActive;
|
||||
ret = true;
|
||||
}
|
||||
CursorMove(r->GetSize());
|
||||
r->HandleScrolling(scrolling_off, view_area);
|
||||
if (!r->Skippable()) {
|
||||
ret = std::static_pointer_cast<UI7::Button>(r)->IsPressed();
|
||||
}
|
||||
/// Rendering ///
|
||||
main->AddRectangle(pos, size, linked_theme->Get(clr));
|
||||
main->AddText(pos + size * 0.5 - tszs * 0.5, label,
|
||||
linked_theme->Get(UI7Color_Text));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UI7::Menu::Checkbox(const std::string& label, bool& v) {
|
||||
vec2 pos = Cursor();
|
||||
vec2 tdim = front->ren->GetTextDimensions(label);
|
||||
vec2 cbs(18);
|
||||
vec2 size = cbs + vec2(tdim.x() + 5, 0);
|
||||
CursorMove(size);
|
||||
|
||||
if (HandleScrolling(pos, size)) {
|
||||
return;
|
||||
u32 id = Strings::FastHash("cbx" + label);
|
||||
Container::Ref r = FindIDObj(id);
|
||||
if (!r) {
|
||||
r = ObjectPush(PD::New<UI7::Checkbox>(label, Cursor(), v, this->back->ren));
|
||||
r->SetID(id);
|
||||
r->Init(main->ren, main, linked_theme);
|
||||
} else {
|
||||
ObjectPush(r);
|
||||
r->SetPos(Cursor());
|
||||
}
|
||||
|
||||
UI7Color cbbg = UI7Color_FrameBackground;
|
||||
|
||||
if (has_touch) {
|
||||
if (inp->IsHeld(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPos(), vec4(pos, size))) {
|
||||
cbbg = UI7Color_FrameBackgroundHovered;
|
||||
}
|
||||
if (inp->IsUp(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPosLast(), vec4(pos, size))) {
|
||||
cbbg = UI7Color_FrameBackgroundHovered;
|
||||
v = !v;
|
||||
}
|
||||
}
|
||||
|
||||
main->AddRectangle(pos, cbs, linked_theme->Get(cbbg));
|
||||
if (v) {
|
||||
main->AddRectangle(pos + 2, cbs - 4, linked_theme->Get(UI7Color_Checkmark));
|
||||
}
|
||||
main->AddText(pos + vec2(cbs.x() + 5, cbs.y() * 0.5 - tdim.y() * 0.5), label,
|
||||
linked_theme->Get(UI7Color_Text));
|
||||
CursorMove(r->GetSize());
|
||||
r->HandleScrolling(scrolling_off, view_area);
|
||||
}
|
||||
|
||||
void UI7::Menu::Image(Texture::Ref img, vec2 size) {
|
||||
/// Variable Setup Stage ///
|
||||
size = size == 0.f ? img->GetSize() : size;
|
||||
vec2 pos = Cursor();
|
||||
CursorMove(size);
|
||||
/// Scrolling Handler ///
|
||||
if (HandleScrolling(pos, size)) {
|
||||
return;
|
||||
}
|
||||
/// Rendering Stage ///
|
||||
main->AddImage(pos, img, size);
|
||||
Container::Ref r =
|
||||
ObjectPush(PD::New<UI7::Image>(img, Cursor(), this->back->ren, size));
|
||||
CursorMove(r->GetSize());
|
||||
r->Init(main->ren, main, linked_theme);
|
||||
r->HandleScrolling(scrolling_off, view_area);
|
||||
}
|
||||
|
||||
void UI7::Menu::DebugLabels() {
|
||||
@ -131,12 +81,21 @@ void UI7::Menu::DebugLabels() {
|
||||
|
||||
void UI7::Menu::Update(float delta) {
|
||||
TT::Scope st("MUPT_" + name);
|
||||
this->back->BaseLayer(30);
|
||||
for (auto& it : objects) {
|
||||
if (it->GetID() != 0 && !FindIDObj(it->GetID())) {
|
||||
idobjs.push_back(it);
|
||||
}
|
||||
if (!it->Skippable()) {
|
||||
it->HandleInput(inp);
|
||||
/// Unlock Input after to ensure nothing is checked twice
|
||||
it->UnlockInput();
|
||||
it->Draw();
|
||||
}
|
||||
}
|
||||
this->back->Process();
|
||||
this->main->BaseLayer(40);
|
||||
this->main->Process();
|
||||
this->front->BaseLayer(50);
|
||||
this->front->Process();
|
||||
this->objects.clear();
|
||||
}
|
||||
|
||||
void UI7::Menu::CursorMove(const vec2& size) {
|
||||
@ -154,13 +113,18 @@ void UI7::Menu::CursorMove(const vec2& size) {
|
||||
void UI7::Menu::PreHandler(UI7MenuFlags flags) {
|
||||
TT::Scope st("MPRE_" + name);
|
||||
TT::Beg("MUSR_" + name);
|
||||
this->back->BaseLayer(30);
|
||||
this->main->BaseLayer(40);
|
||||
this->front->BaseLayer(50);
|
||||
Cursor(vec2(5, 5));
|
||||
this->flags = flags;
|
||||
this->scrolling[0] = flags & UI7MenuFlags_HzScrolling;
|
||||
this->scrolling[1] = flags & UI7MenuFlags_VtScrolling;
|
||||
has_touch = main->GetRenderer()->CurrentScreen() == Screen::Bottom;
|
||||
has_touch =
|
||||
main->GetRenderer()->CurrentScreen()->ScreenType() == Screen::Bottom;
|
||||
if (!(flags & UI7MenuFlags_NoBackground)) {
|
||||
back->AddRectangle(0, view_area.zw(), UI7Color_Background);
|
||||
back->AddRectangle(0, view_area.zw(),
|
||||
linked_theme->Get(UI7Color_Background));
|
||||
}
|
||||
if (!(flags & UI7MenuFlags_NoTitlebar)) {
|
||||
tbh = front->GetRenderer()->TextScale() * 30.f;
|
||||
@ -327,5 +291,42 @@ bool UI7::Menu::HandleScrolling(vec2& pos, const vec2& size) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Container::Ref UI7::Menu::ObjectPush(Container::Ref obj) {
|
||||
this->objects.push_back(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
Container::Ref UI7::Menu::FindIDObj(u32 id) {
|
||||
for (auto& it : idobjs) {
|
||||
if (it->GetID() == id) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UI7::Menu::Join() {
|
||||
Assert(objects.size(), "Objects list is empty!");
|
||||
join.push_back(objects.back().get());
|
||||
}
|
||||
|
||||
void UI7::Menu::JoinOpHzCenter() {
|
||||
this->Join();
|
||||
float spos = join.front()->GetPos().x();
|
||||
float szs = join.back()->GetPos().x() + join.back()->GetSize().x() - spos;
|
||||
float off = (view_area.x() + view_area.z() * 0.5) - (spos + szs * 0.5);
|
||||
for (auto it : join) {
|
||||
it->SetPos(it->GetPos() + vec2(off, 0.f));
|
||||
}
|
||||
join.clear();
|
||||
}
|
||||
void UI7::Menu::AfterAlignCenter() {
|
||||
Container* ref = objects.back().get();
|
||||
vec2 p = ref->GetPos();
|
||||
vec2 s = ref->GetSize();
|
||||
float newx = (view_area.x() + view_area.z() * 0.5) - (p.x() + s.x() * 0.5);
|
||||
ref->SetPos(vec2(newx, p.y()));
|
||||
}
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -6,7 +6,7 @@ namespace UI7 {
|
||||
void Theme::Default(Theme& theme) {
|
||||
theme.Set(UI7Color_Text, Color("#FFFFFFFF"));
|
||||
theme.Set(UI7Color_TextDead, Color("#AAAAAAFF"));
|
||||
theme.Set(UI7Color_Background, Color("#EEEEEEFF"));
|
||||
theme.Set(UI7Color_Background, Color("#222222aa"));
|
||||
theme.Set(UI7Color_Button, Color("#111111FF"));
|
||||
theme.Set(UI7Color_ButtonDead, Color("#080808FF"));
|
||||
theme.Set(UI7Color_ButtonActive, Color("#2A2A2AFF"));
|
||||
|
Reference in New Issue
Block a user