From ce7c59a162435f84e4d1b59267528c38b206a45b Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sun, 25 Feb 2024 14:26:35 +0100 Subject: [PATCH] Auto Offset Grid --- CHANGELOG.md | 4 ++-- include/renderd7/UI7.hpp | 4 ++-- rd7tf/source/main.cpp | 22 -------------------- rd7tf/source/scene.cpp | 13 +++++------- source/UI7.cpp | 44 +++++++++++++++++++--------------------- 5 files changed, 30 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c802f4..c37a00e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,11 +14,10 @@ - Removed Old Font/Text Handlers - Added UI7 (New UI Api) - Remove Old UI Api -- Added Music Player (MP3, Vorbis) - Rewrite of RenderD7::Image - Internal Debugger/Database (IDB) - Removed BitmapPrinter -- Added nimg and nimg_engine +- Added nimg and swr(render2nimg | SoftwareRender) - Removed Old Error/Message Handler - GetTextSize (extra buffer) + New TextShorter - Require specific FLAG for Music/MemTrack @@ -27,6 +26,7 @@ - Remove INI reader - Python based clangformat script - Move some Init code into functions to not use twice +- Added Font class ## 0.9.4 - Implement new Security System To prevent from crashes - Implement Functiontrace for better Timing Tests diff --git a/include/renderd7/UI7.hpp b/include/renderd7/UI7.hpp index b435bf9..4c59a3c 100644 --- a/include/renderd7/UI7.hpp +++ b/include/renderd7/UI7.hpp @@ -46,8 +46,8 @@ void InputText(const std::string &label, std::string &text, bool BeginMenu(const std::string &title, R7Vec2 size = R7Vec2(0, 0), UI7MenuFlags flags = 0); void EndMenu(); -void Grid(const std::string &name, const R7Vec2 &size, - R7Vec2 (*display_func)(void *, R7Vec2), void **data_array, +void Grid(const std::string &name, const R7Vec2 &size, const R7Vec2 &entry_size, + void (*display_func)(void *, R7Vec2), void **data_array, size_t num_entrys); bool BeginTree(const std::string &text); void EndTree(); diff --git a/rd7tf/source/main.cpp b/rd7tf/source/main.cpp index 220f0ac..03a172a 100644 --- a/rd7tf/source/main.cpp +++ b/rd7tf/source/main.cpp @@ -1,26 +1,5 @@ #include "scene.hpp" -void ColorThemeSample() { - RD7::ColorNew(RD7Color_Text, RD7::Color::Hex("#000000", 255)); - RD7::ColorNew(RD7Color_TextDisabled, RD7::Color::Hex("#212121", 200)); - RD7::ColorNew(RD7Color_Text2, RD7::Color::Hex("#ffffff", 255)); - RD7::ColorNew(RD7Color_Background, RD7::Color::Hex("#eeeeee", 170)); - RD7::ColorNew(RD7Color_Header, RD7::Color::Hex("#222222", 190)); - RD7::ColorNew(RD7Color_Selector, RD7::Color::Hex("#4444dd", 200)); - RD7::ColorNew(RD7Color_SelectorFade, RD7::Color::Hex("#7777dd", 200)); - RD7::ColorNew(RD7Color_List0, RD7::Color::Hex("#555555", 130)); - RD7::ColorNew(RD7Color_List1, RD7::Color::Hex("#777777", 130)); - RD7::ColorNew(RD7Color_MessageBackground, RD7::Color::Hex("#222222", 180)); - RD7::ColorNew(RD7Color_Button, RD7::Color::Hex("#4444dd", 150)); - RD7::ColorNew(RD7Color_ButtonHovered, RD7::Color::Hex("#6666dd", 150)); - RD7::ColorNew(RD7Color_ButtonDisabled, RD7::Color::Hex("#2222dd", 150)); - RD7::ColorNew(RD7Color_ButtonActive, RD7::Color::Hex("#7777dd", 150)); - RD7::ColorNew(RD7Color_Checkmark, RD7::Color::Hex("#4444dd", 130)); - RD7::ColorNew(RD7Color_FrameBg, RD7::Color::Hex("#555555", 160)); - RD7::ColorNew(RD7Color_FrameBgHovered, RD7::Color::Hex("#777777", 160)); - RD7::ColorNew(RD7Color_Progressbar, RD7::Color::Hex("#4444dd", 200)); -} - extern void IdbServer(); int main() { @@ -30,7 +9,6 @@ int main() { RD7::Init::Main("rd7tf"); RD7::FadeIn(); // IdbServer(); - ColorThemeSample(); RD7::Init::NdspFirm(); RD7::Scene::Load(std::make_unique()); RD7::Ftrace::End("app", "app_init"); diff --git a/rd7tf/source/scene.cpp b/rd7tf/source/scene.cpp index db6395d..b8efa47 100644 --- a/rd7tf/source/scene.cpp +++ b/rd7tf/source/scene.cpp @@ -51,10 +51,7 @@ void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) { R7Vec2 testv2 = R7Vec2(48, 48); std::vector img; -R7Vec2 display_icon(void* v, R7Vec2 p) { - DV2::RFS(p, testv2, 0xff00ffff); - return testv2; -} +void display_icon(void* v, R7Vec2 p) { DV2::RFS(p, testv2, 0xff00ffff); } Sample::Sample() { auto t = RD7::FileSystem::GetDirContent("sdmc:/music/"); @@ -98,8 +95,8 @@ void Sample::Draw() const { UI7::RestoreCursor(); if (state == State_Menu) { UI7::Label("SZS: " + std::to_string(img.size())); - UI7::Grid("Images", R7Vec2(390, 180), display_icon, (void**)&img[0], - img.size()); + UI7::Grid("Images", R7Vec2(390, 180), testv2, display_icon, + (void**)&img[0], img.size()); } UI7::EndMenu(); } @@ -124,9 +121,9 @@ void Sample::Draw() const { UI7::SameLine(); if (UI7::Button("def")) txt_size = 0.5; UI7::Label("GridControl: "); - if(UI7::Button("icn++")) testv2 += R7Vec2(1, 1); + if (UI7::Button("icn++")) testv2 += R7Vec2(1, 1); UI7::SameLine(); - if(UI7::Button("icn--")) testv2 -= R7Vec2(1, 1); + if (UI7::Button("icn--")) testv2 -= R7Vec2(1, 1); } UI7::EndMenu(); } diff --git a/source/UI7.cpp b/source/UI7.cpp index c1d3f5b..b05d753 100644 --- a/source/UI7.cpp +++ b/source/UI7.cpp @@ -123,7 +123,6 @@ struct UI7_Ctx { bool in_menu; bool debugging; UI7ID current_menu; - std::map grid_mapping; std::unordered_map ids; std::vector objects; }; @@ -476,44 +475,43 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) { void EndMenu() { UI7CtxEndMenu(); } -void Grid(const std::string &name, const R7Vec2 &size, - R7Vec2 (*display_func)(void *, R7Vec2), void **data_array, +void Grid(const std::string &name, const R7Vec2 &size, const R7Vec2 &entry_size, + void (*display_func)(void *, R7Vec2), void **data_array, size_t num_entrys) { if (!UI7CtxValidate()) return; if (num_entrys <= 0) return; if (data_array == nullptr) return; - if (ui7_ctx->grid_mapping.find(UI7ID(name).real_id) == - ui7_ctx->grid_mapping.end()) - ui7_ctx->grid_mapping[UI7ID(name).real_id] = - R7Vec2(); // Register id not exist R7Vec2 pos = GetCursorPos(); R7Vec2 cpos(pos); UI7CtxRegObj(UI7OBJ(R7Vec4(pos, size), 1)); + int neh = std::floor(size.x / (entry_size.x + 4)); + int nev = std::floor(size.y / (entry_size.y + 4)); + // Inside Grid Offset + R7Vec2 igoff = R7Vec2(); + if (neh >= 2 && nev >= 2) { + igoff = R7Vec2( + ((size.x) / 2 - (((neh - 1) * (entry_size.x + 4)) + entry_size.x) / 2), + ((size.y) / 2 - ((nev - 1) * ((entry_size.y + 4)) + entry_size.y) / 2)); + } // Y-Offset int yoff = 0; - pos += ui7_ctx->grid_mapping[UI7ID(name).real_id]; + pos += igoff; for (size_t i = 0; i < num_entrys; i++) { - R7Vec2 szs = display_func(data_array[i], pos); - UI7CtxRegObj(UI7OBJ(R7Vec4(pos, szs), 2)); - if(ui7_ctx->debugging) RenderD7::Draw2::Text(pos + R7Vec2(4, 4), std::to_string(i)); - if (pos.x + (szs.x * 2) > (cpos.x + size.x) && - pos.y + (szs.y*2) > cpos.y + size.y) { - if (ui7_ctx->grid_mapping[UI7ID(name).real_id].y == 0) - ui7_ctx->grid_mapping[UI7ID(name).real_id].y = - (cpos.y + size.y) / 2 - ((yoff+2) * (szs.y + 4)) / 2; + display_func(data_array[i], pos); + UI7CtxRegObj(UI7OBJ(R7Vec4(pos, entry_size), 2)); + if (ui7_ctx->debugging) + RenderD7::Draw2::Text(pos + R7Vec2(4, 4), std::to_string(i)); + if (pos.x + (entry_size.x * 2) > (cpos.x + size.x) && + pos.y + (entry_size.y * 2) > cpos.y + size.y) { break; - } else if (pos.x + (szs.x * 2) > (cpos.x + size.x)) { - if (ui7_ctx->grid_mapping[UI7ID(name).real_id].x == 0) - ui7_ctx->grid_mapping[UI7ID(name).real_id].x = - (cpos.x + size.x) / 2 - ((i + 1) * (szs.x + 4)) / 2; - pos = R7Vec2(5 + ui7_ctx->grid_mapping[UI7ID(name).real_id].x, - pos.y + szs.y + 4); + } else if (pos.x + (entry_size.x * 2) > (cpos.x + size.x)) { + pos = R7Vec2(5 + igoff.x, pos.y + entry_size.y + 4); yoff++; } else { - pos += R7Vec2(szs.x + 4, 0); + pos += R7Vec2(entry_size.x + 4, 0); } }