From ec8743417d8bfec9c1c577c154ae7b52067e591a Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sat, 15 Jun 2024 15:12:06 +0200 Subject: [PATCH] Changes: Make Timer SmartCtor ClangFormat Reactivate Graphical Error Screen Fix Logger Fix Image Rendering --- include/renderd7/Image.hpp | 2 +- include/renderd7/Render2.hpp | 5 +- include/renderd7/Sheet.hpp | 5 +- include/renderd7/Timer.hpp | 17 ++- include/renderd7/UI7.hpp | 6 + include/renderd7/renderd7_logo.hpp | 32 ++-- rd7tf/source/main.cpp | 5 +- rd7tf/source/scene.cpp | 20 +-- source/Error.cpp | 39 ++--- source/Image.cpp | 77 +++++----- source/Logger.cpp | 4 +- source/Overlays.cpp | 12 +- source/Render2.cpp | 231 ++++++++++++++++------------- source/Timer.cpp | 14 +- source/UI7.cpp | 18 +++ source/renderd7.cpp | 2 +- source/renderd7_logo.cpp | 32 ++-- 17 files changed, 287 insertions(+), 234 deletions(-) diff --git a/include/renderd7/Image.hpp b/include/renderd7/Image.hpp index 8ee22e4..25b332f 100644 --- a/include/renderd7/Image.hpp +++ b/include/renderd7/Image.hpp @@ -29,7 +29,7 @@ namespace RenderD7 { class Image { public: - Image(); + Image() = default; ~Image() = default; RD7_SMART_CTOR(Image) void Load(const std::string& path); diff --git a/include/renderd7/Render2.hpp b/include/renderd7/Render2.hpp index 95d70a8..f13d261 100644 --- a/include/renderd7/Render2.hpp +++ b/include/renderd7/Render2.hpp @@ -64,6 +64,7 @@ class R2Base { // Text Specific RD7TextFlags flags; // Text Flags std::string text; // Text + RD7_SMART_CTOR(R2Cmd) }; R2Base(); ~R2Base() = default; @@ -83,7 +84,7 @@ class R2Base { // Processing void Process(); R7Vec2 GetTextDimensions(const std::string& text); - + std::string WrapText(const std ::string& in, int maxlen); // Draw Functions void AddRect(R7Vec2 pos, R7Vec2 size, RD7Color clr); void AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr); @@ -103,7 +104,7 @@ class R2Base { std::map ts; std::map mln; bool next_lined = false; - std::vector commands; + std::vector commands; R2Screen current_screen = R2Screen_Bottom; }; } // namespace RenderD7 \ No newline at end of file diff --git a/include/renderd7/Sheet.hpp b/include/renderd7/Sheet.hpp index afc8689..eaf6492 100644 --- a/include/renderd7/Sheet.hpp +++ b/include/renderd7/Sheet.hpp @@ -21,8 +21,8 @@ #include #include -#include #include +#include #include namespace RenderD7 { @@ -44,7 +44,8 @@ class Sheet { void Free(); Image::Ref GetImage(int idx); C2D_SpriteSheet Get() { return this->spritesheet; } - private: + + private: /// \param spritesheet The Sheet C2D_SpriteSheet spritesheet; }; diff --git a/include/renderd7/Timer.hpp b/include/renderd7/Timer.hpp index d4d92a6..b637291 100644 --- a/include/renderd7/Timer.hpp +++ b/include/renderd7/Timer.hpp @@ -20,18 +20,21 @@ #include <3ds.h> +#include + namespace RenderD7 { class Timer { public: Timer(bool autostart = true); ~Timer() {} - void reset(); - void tick(); - void pause(); - void resume(); - float get(); - float get_live(); - bool running(); + RD7_SMART_CTOR(Timer) + void Reset(); + void Tick(); + void Pause(); + void Resume(); + float Get(); + float GetLive(); + bool Running(); private: uint64_t last = 0; diff --git a/include/renderd7/UI7.hpp b/include/renderd7/UI7.hpp index b90988f..0963cd0 100644 --- a/include/renderd7/UI7.hpp +++ b/include/renderd7/UI7.hpp @@ -102,6 +102,12 @@ void SetCursorPos(R7Vec2 cp); void RestoreCursor(); void SameLine(); float GetScrollingOffset(); +namespace Menu { + // All of them return the Main BG DrawList if Menu is null + UI7DrawList::Ref GetBackgroundList(); + UI7DrawList::Ref GetList(); + UI7DrawList::Ref GetForegroundList(); +} // DrawLists UI7DrawList::Ref GetForegroundList(); UI7DrawList::Ref GetBackgroundList(); diff --git a/include/renderd7/renderd7_logo.hpp b/include/renderd7/renderd7_logo.hpp index ce03c67..1da6df3 100644 --- a/include/renderd7/renderd7_logo.hpp +++ b/include/renderd7/renderd7_logo.hpp @@ -1,20 +1,20 @@ /** -* This file is part of RenderD7 -* Copyright (C) 2021-2024 NPI-D7, tobid7 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * This file is part of RenderD7 + * Copyright (C) 2021-2024 NPI-D7, tobid7 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ // THIS FILE WAS GENERATED BY generate_assets.py!!! diff --git a/rd7tf/source/main.cpp b/rd7tf/source/main.cpp index 718aec5..4adb75d 100644 --- a/rd7tf/source/main.cpp +++ b/rd7tf/source/main.cpp @@ -26,12 +26,9 @@ int main() { RD7::FadeIn(); // RD7::Init::NdspFirm(); RD7::Scene::Load(std::make_unique()); - auto img = RD7::Image::New(); - img->Load("romfs:/icons/icon.png"); RD7::Ftrace::End("app", "app_init"); while (RD7::MainLoop()) { - RD7::R2()->OnScreen(R2Screen_Top); - UI7::GetForegroundList()->AddImage(R7Vec2(), img); + RD7::R2()->OnScreen(R2Screen_Bottom); RD7::Ftrace::Beg("app", "app_mainloop"); if (d7_hDown & KEY_START) { RD7::FadeOut(); diff --git a/rd7tf/source/scene.cpp b/rd7tf/source/scene.cpp index 5ffbbf7..60dc070 100644 --- a/rd7tf/source/scene.cpp +++ b/rd7tf/source/scene.cpp @@ -41,14 +41,14 @@ static void Wave(int index, R7Vec2 position, R7Vec2 size, float time, } // Just to make sure... y_position = std::min(y_position, position.y + size.y - (90 - shrink)); - - RD7::R2()->AddTriangle( - R7Vec2(x_position, y_position), - R7Vec2(x_position + 300, y_position + (90 - shrink)), - R7Vec2(x_position - 300, y_position + (90 - shrink)), - RD7::Color::RGBA(.94f - .17f * color_effect, .61f - .25f * color_effect, - .36f + .38f * color_effect) - .toRGBA()); + + RD7::R2()->AddTriangle( + R7Vec2(x_position, y_position), + R7Vec2(x_position + 300, y_position + (90 - shrink)), + R7Vec2(x_position - 300, y_position + (90 - shrink)), + RD7::Color::RGBA(.94f - .17f * color_effect, .61f - .25f * color_effect, + .36f + .38f * color_effect) + .toRGBA()); } void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) { @@ -60,7 +60,9 @@ void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) { R7Vec2 testv2 = R7Vec2(48, 48); std::vector img; -void display_icon(void* v, R7Vec2 p) { RD7::R2()->AddRect(p, testv2, 0xff00ffff); } +void display_icon(void* v, R7Vec2 p) { + UI7::Menu::GetList()->AddRectangle(p, testv2, 0xff00ffff); +} Sample::Sample() { auto ti = new int; diff --git a/source/Error.cpp b/source/Error.cpp index 5477434..a07708b 100644 --- a/source/Error.cpp +++ b/source/Error.cpp @@ -37,39 +37,40 @@ void rd7i_save_report(const std::string& msg) { namespace RenderD7 { void Error(const std::string& msg) { rd7i_save_report(msg); - /*if (rd7i_graphics_on) { - C3D_FrameEnd(0); + if (rd7i_graphics_on) { while (aptMainLoop()) { hidScanInput(); if (hidKeysDown() & KEY_START) break; C3D_FrameBegin(C3D_FRAME_SYNCDRAW); RenderD7::ClearTextBufs(); - C2D_TargetClear(Top, 0x00000000); - C2D_TargetClear(Bottom, 0x00000000); - RenderD7::OnScreen(Top); + C2D_TargetClear(rd7_top, 0x00000000); + C2D_TargetClear(rd7_bottom, 0x00000000); + RenderD7::R2()->OnScreen(R2Screen_Top); if (UI7::BeginMenu("RenderD7 - Error Manager", R7Vec2(), UI7MenuFlags_TitleMid)) { UI7::Label(msg, RD7TextFlags_Wrap); UI7::Label("Press Start to Exit!"); UI7::EndMenu(); } - RenderD7::OnScreen(Bottom); + RenderD7::R2()->OnScreen(R2Screen_Bottom); + UI7::Update(); + RenderD7::R2()->Process(); C3D_FrameEnd(0); } exit(0); - } else {*/ - gfxInitDefault(); - consoleInit(GFX_TOP, NULL); - printf("RENDERD7 - ERROR MANAGER\n\n%s\n", msg.c_str()); - printf("Report Saved in\nsdmc:/RenderD7/Reports\n"); - printf("Press Start to Exit\n"); - while (aptMainLoop()) { - hidScanInput(); - if (hidKeysDown() & KEY_START) break; - gfxSwapBuffers(); + } else { + gfxInitDefault(); + consoleInit(GFX_TOP, NULL); + printf("RENDERD7 - ERROR MANAGER\n\n%s\n", msg.c_str()); + printf("Report Saved in\nsdmc:/RenderD7/Reports\n"); + printf("Press Start to Exit\n"); + while (aptMainLoop()) { + hidScanInput(); + if (hidKeysDown() & KEY_START) break; + gfxSwapBuffers(); + } + gfxExit(); + exit(0); } - gfxExit(); - exit(0); - // } } } // namespace RenderD7 \ No newline at end of file diff --git a/source/Image.cpp b/source/Image.cpp index 44da0e8..e1b19df 100644 --- a/source/Image.cpp +++ b/source/Image.cpp @@ -19,9 +19,8 @@ #include #include -#include - #include +#include static u32 __rd7i_gp2o__(u32 v) { v--; @@ -50,30 +49,30 @@ static void __rd7i_r24r32(std::vector &out, } } -static void __rd7i_maketex__(C3D_Tex* tex, Tex3DS_SubTexture* sub, std::vector& buf, int w, int h) { - if(!tex || !sub) - { +static void __rd7i_maketex__(C3D_Tex *tex, Tex3DS_SubTexture *sub, + std::vector &buf, int w, int h) { + if (!tex || !sub) { _rd7i_logger()->Write("Invalid Inpit (objects have no adress!)"); return; } // RGBA -> Abgr - for(int y = 0; y < h; y++) { - for(int x = 0; x < w; x++) { - int pos = (x+y*w)*4; - auto r = buf[pos+0]; - auto g = buf[pos+1]; - auto b = buf[pos+2]; - auto a = buf[pos+3]; - buf[pos+0] = a; - buf[pos+1] = b; - buf[pos+2] = g; - buf[pos+3] = r; + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + int pos = (x + y * w) * 4; + auto r = buf[pos + 0]; + auto g = buf[pos + 1]; + auto b = buf[pos + 2]; + auto a = buf[pos + 3]; + buf[pos + 0] = a; + buf[pos + 1] = b; + buf[pos + 2] = g; + buf[pos + 3] = r; } } // Pow2 - int wp2 = __rd7i_gp2o__(w); - int hp2 = __rd7i_gp2o__(h); + int wp2 = __rd7i_gp2o__((unsigned int)w); + int hp2 = __rd7i_gp2o__((unsigned int)h); sub->width = (u16)w; sub->height = (u16)h; @@ -106,10 +105,6 @@ static void __rd7i_maketex__(C3D_Tex* tex, Tex3DS_SubTexture* sub, std::vectorWrite("Failed to Load Image: " + path); + //_rd7i_logger()->Write("Failed to Load Image: " + path); return; } // Size/Fmt Check if (w > 1024 || h > 1024) { // Reason: Image to Large - _rd7i_logger()->Write("Image too Large!"); + //_rd7i_logger()->Write("Image too Large!"); stbi_image_free(image); return; } std::vector wimg; if (c == 3) { - _rd7i_logger()->Write("Convert Image to RGBA"); + //_rd7i_logger()->Write("Convert Image to RGBA"); stbi_image_free(image); image = stbi_load(path.c_str(), &w, &h, &c, 3); - wimg.resize(w*h*4); - __rd7i_r24r32(wimg, std::vector(image, image + (w * h * 3)), w, h); + wimg.resize(w * h * 4); + __rd7i_r24r32(wimg, std::vector(image, image + (w * h * 3)), + w, h); } else { - wimg.assign(&image[0], &image[(w*h*4)-1]); + wimg.assign(&image[0], &image[(w * h * 4) - 1]); stbi_image_free(image); } // Create C2D_Image - C3D_Tex *tex = new C3D_Tex; - Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture; + C3D_Tex* tex = new C3D_Tex; + Tex3DS_SubTexture* subtex = new Tex3DS_SubTexture; __rd7i_maketex__(tex, subtex, wimg, w, h); - img.tex = tex; - img.subtex = subtex; + _rd7i_logger()->Write(RenderD7::FormatString("Created Texture (%d, %d)", + tex->width, tex->height)); + img = {tex, subtex}; } void Image::From_NIMG(const nimg &image) { // Make sure to cleanup Delete(); if (image.width > 1024 || image.height > 1024) return; - C3D_Tex *tex = new C3D_Tex; - Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture; + C3D_Tex* tex = new C3D_Tex; + Tex3DS_SubTexture* subtex = new Tex3DS_SubTexture; std::vector mdpb = image.pixel_buffer; __rd7i_maketex__(tex, subtex, mdpb, image.width, image.height); - img.tex = tex; - img.subtex = subtex; + img = {tex, subtex}; } -C2D_Image Image::Get() { - if(!Loadet()) { +C2D_Image Image::Get() { + if (!Loadet()) { _rd7i_logger()->Write("Image not Loadet!"); } return img; } C2D_Image &Image::GetRef() { - if(!Loadet()) { + if (!Loadet()) { _rd7i_logger()->Write("Image not Loadet!"); } return img; @@ -188,7 +184,8 @@ void Image::Delete() { delete img.subtex; img.subtex = nullptr; } - if (img.tex != nullptr) { + if (img.tex != nullptr) { + C3D_TexDelete(img.tex); delete img.tex; img.tex = nullptr; } diff --git a/source/Logger.cpp b/source/Logger.cpp index ba20051..d358522 100644 --- a/source/Logger.cpp +++ b/source/Logger.cpp @@ -51,10 +51,10 @@ void LoggerBase::Write(const std::string& debug_text, int lvl) { if (this->_log.is_open() && lvl <= writelvl) { this->_log << msg << std::endl; } - while (msg.find_first_of('\n') != 0) { + /*while (msg.find_first_of('\n') != 0) { lines.push_back(msg.substr(0, msg.find_first_of('\n'))); msg = msg.substr(msg.find_first_of('\n')); - } + }*/ lines.push_back(msg); } diff --git a/source/Overlays.cpp b/source/Overlays.cpp index 1fa8eb9..dfcd267 100644 --- a/source/Overlays.cpp +++ b/source/Overlays.cpp @@ -434,16 +434,16 @@ void Ovl_Keyboard::Draw(void) const { R2()->AddText(R7Vec2(5, 114), "> " + *typed_text, RenderD7::ThemeActive()->AutoText(RD7Color_Header)); for (auto const& it : key_table) { + R7Vec2 szs = it.size; + R7Vec2 pos = it.pos; R7Vec2 txtdim = R2()->GetTextDimensions(it.disp); - R7Vec2 txtpos = R7Vec2(it.pos.x + it.size.x * 0.5 - txtdim.x * 0.5, - it.pos.y + it.size.y * 0.5 - txtdim.y * 0.5); RD7Color btn = RD7Color_Button; if (RenderD7::Hid::IsEvent("cancel", RenderD7::Hid::Up)) { RenderD7::Hid::Clear(); shared_data[0x05] = 1; } if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Up) && - UI7_InBox(RenderD7::Hid::GetLastTouchPosition(), it.pos, it.size)) { + UI7_InBox(RenderD7::Hid::GetLastTouchPosition(), pos, szs)) { if (mode == 2) // Request Disable Shift shared_data[0x02] = 1; @@ -468,8 +468,12 @@ void Ovl_Keyboard::Draw(void) const { } else if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held) && UI7_InBox(RenderD7::Hid::GetTouchPosition(), it.pos, it.size)) { btn = RD7Color_ButtonHovered; + pos -= R7Vec2(1, 1); + szs += R7Vec2(2, 2); } - R2()->AddRect(it.pos, it.size, btn); + R7Vec2 txtpos = R7Vec2(pos.x + szs.x * 0.5 - txtdim.x * 0.5, + pos.y + szs.y * 0.5 - txtdim.y * 0.5); + R2()->AddRect(pos, szs, btn); R2()->AddText(txtpos, it.disp, RenderD7::ThemeActive()->AutoText(btn)); } if (ft3 > 5) RenderD7::Hid::Lock(); diff --git a/source/Render2.cpp b/source/Render2.cpp index 926dbb9..7ef34bc 100644 --- a/source/Render2.cpp +++ b/source/Render2.cpp @@ -57,73 +57,96 @@ R7Vec2 R2Base::GetTextDimensions(const std::string& text) { return R7Vec2(w, h); } +std::string R2Base::WrapText(const std ::string& in, int maxlen) { + std::string out; + std::string line; + int line_x = 0; + std::istringstream istream(in); + std::string temp; + + while (istream >> temp) { + R7Vec2 dim = this->GetTextDimensions(line + temp); + if (line_x + dim.x <= maxlen) { + line += temp + ' '; + line_x += dim.x; + } else { + out += line + '\n'; + line = temp + ' '; + line_x = dim.x; + } + } + out += line; + return out; +} + // Main Processing of Draw Calls void R2Base::Process() { for (auto& it : this->commands) { - if (it.type <= 0 || it.type > 3) { + if (it->type <= 0 || it->type > 5) { // Skip continue; } - C2D_SceneBegin(it.Screen ? rd7_top : rd7_bottom); - if (it.type == 1) { + C2D_SceneBegin(it->Screen ? rd7_top : rd7_bottom); + if (it->type == 1) { // Rect - if (it.lined) { - C2D_DrawLine(it.pos.x, it.pos.y, it.clr, it.pos.x + it.pszs.x, it.pos.y, - it.clr, 1.f, 0.5f); - C2D_DrawLine(it.pos.x, it.pos.y, it.clr, it.pos.x, it.pos.y + it.pszs.y, - it.clr, 1.f, 0.5f); - C2D_DrawLine(it.pos.x + it.pszs.x, it.pos.y, it.clr, - it.pos.x + it.pszs.x, it.pos.y + it.pszs.y, it.clr, 1.f, + if (it->lined) { + C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pos.x + it->pszs.x, it->pos.y, + it->clr, 1.f, 0.5f); + C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pos.x, it->pos.y + it->pszs.y, + it->clr, 1.f, 0.5f); + C2D_DrawLine(it->pos.x + it->pszs.x, it->pos.y, it->clr, + it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr, 1.f, 0.5f); - C2D_DrawLine(it.pos.x, it.pos.y + it.pszs.y, it.clr, - it.pos.x + it.pszs.x, it.pos.y + it.pszs.y, it.clr, 1.f, + C2D_DrawLine(it->pos.x, it->pos.y + it->pszs.y, it->clr, + it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr, 1.f, 0.5f); } else { - C2D_DrawRectSolid(it.pos.x, it.pos.y, 0.5, it.pszs.x, it.pszs.y, - it.clr); + C2D_DrawRectSolid(it->pos.x, it->pos.y, 0.5, it->pszs.x, it->pszs.y, + it->clr); } - } else if (it.type == 2) { + } else if (it->type == 2) { // Triangle - if (it.lined) { - C2D_DrawLine(it.pos.x, it.pos.y, it.clr, it.pszs.x, it.pszs.y, it.clr, + if (it->lined) { + C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y, it->clr, 1, 0.5f); - C2D_DrawLine(it.pos.x, it.pos.y, it.clr, it.ap.x, it.ap.y, it.clr, 1, + C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->ap.x, it->ap.y, it->clr, 1, 0.5f); - C2D_DrawLine(it.pszs.x, it.pszs.y, it.clr, it.ap.x, it.ap.y, it.clr, 1, + C2D_DrawLine(it->pszs.x, it->pszs.y, it->clr, it->ap.x, it->ap.y, it->clr, 1, 0.5f); } else { - C2D_DrawTriangle(it.pos.x, it.pos.y, it.clr, it.pszs.x, it.pszs.y, - it.clr, it.ap.x, it.ap.y, it.clr, 0.5); + C2D_DrawTriangle(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y, + it->clr, it->ap.x, it->ap.y, it->clr, 0.5); } - } else if (it.type == 3) { + } else if (it->type == 3) { // Text // little patch for a freeze - if (it.text.length() < 1) continue; - if (it.pszs.x == 0.0f) { - it.pszs.x = it.Screen == R2Screen_Top ? 400 : 320; + if (it->text.length() < 1) continue; + if (it->pszs.x == 0.0f) { + it->pszs.x = it->Screen == R2Screen_Top ? 400 : 320; } - if (it.pszs.y == 0.0f) { - it.pszs.y = 240; + if (it->pszs.y == 0.0f) { + it->pszs.y = 240; } - std::string edit_text = it.text; - if (edit_text.substr(it.text.length() - 1) != "\n") + std::string edit_text = it->text; + if (edit_text.substr(it->text.length() - 1) != "\n") edit_text.append("\n"); // Add \n to end if not exist int line = 0; - // if (it.flags & RD7TextFlags_Wrap) - // edit_text = WrapText(text, rd7i_d7_mwh.x - pos.x); + if (it->flags & RD7TextFlags_Wrap) { + edit_text = WrapText(it->text, it->pszs.x - it->pos.x); + } while (edit_text.find('\n') != edit_text.npos) { std::string current_line = edit_text.substr(0, edit_text.find('\n')); - // if (it.flags & RD7TextFlags_Short) - // current_line = GetShortedText(current_line, it.pszs.x - it.pos.x); - R7Vec2 newpos = it.pos; + // if (it->flags & RD7TextFlags_Short) + // current_line = GetShortedText(current_line, it->pszs.x - it->pos.x); + R7Vec2 newpos = it->pos; // Check Flags R7Vec2 dim = this->GetTextDimensions(current_line); - if (it.flags & RD7TextFlags_AlignRight) newpos.x = newpos.x - dim.x; - if (it.flags & RD7TextFlags_AlignMid) // Offset by inpos - newpos.x = (it.pszs.x * 0.5) - (dim.x * 0.5) + it.pos.x; - if (it.flags & RD7TextFlags_Scroll) { // Scroll Text + if (it->flags & RD7TextFlags_AlignRight) newpos.x = newpos.x - dim.x; + if (it->flags & RD7TextFlags_AlignMid) // Offset by inpos + newpos.x = (it->pszs.x * 0.5) - (dim.x * 0.5) + it->pos.x; + if (it->flags & RD7TextFlags_Scroll) { // Scroll Text // Look into Old Draw2 Code // TODO: Create Code for this } @@ -136,73 +159,73 @@ void R2Base::Process() { current_line.c_str()); C2D_TextOptimize(&c2dtext); - if (it.flags & RD7TextFlags_Shaddow) // performance Killer xd + if (it->flags & RD7TextFlags_Shaddow) // performance Killer xd C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x + 1 + (dim.y * line), newpos.y + 1, 0.5, this->text_size, this->text_size, RenderD7::ThemeActive()->Get(RD7Color_TextDisabled)); C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x, newpos.y + (dim.y * line), 0.5, this->text_size, - this->text_size, it.clr); + this->text_size, it->clr); edit_text = edit_text.substr(edit_text.find('\n') + 1); line++; } - } else if (it.type == 4) { - if(it.img->Loadet()) { - C2D_DrawImageAt(it.img->Get(), it.pos.x, it.pos.y, 0.5f); + } else if (it->type == 4) { + if (it->img->Loadet()) { + C2D_DrawImageAt(it->img->Get(), it->pos.x, it->pos.y, 0.5f); } - } else if (it.type == 5) { + } else if (it->type == 5) { // TODO: Move the Draw Func into this API - it.spr->Draw(); + it->spr->Draw(); } } this->commands.clear(); } void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, RD7Color clr) { - R2Cmd cmd; - cmd.pos = pos; - cmd.pszs = size; - cmd.clr = RenderD7::ThemeActive()->Get(clr); - cmd.type = 1; // Rect + auto cmd = R2Cmd::New(); + cmd->pos = pos; + cmd->pszs = size; + cmd->clr = RenderD7::ThemeActive()->Get(clr); + cmd->type = 1; // Rect // Just assign current screen as bottom is 0 (false) // and Top and TopRight are !0 (true) - cmd.Screen = current_screen; + cmd->Screen = current_screen; if (this->next_lined) { - cmd.lined = true; + cmd->lined = true; this->next_lined = false; } this->commands.push_back(cmd); } void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr) { - R2Cmd cmd; - cmd.pos = pos; - cmd.pszs = size; - cmd.clr = clr; - cmd.type = 1; // Rect + auto cmd = R2Cmd::New(); + cmd->pos = pos; + cmd->pszs = size; + cmd->clr = clr; + cmd->type = 1; // Rect // Just assign current screen as bottom is 0 (false) // and Top and TopRight are !0 (true) - cmd.Screen = current_screen; + cmd->Screen = current_screen; if (this->next_lined) { - cmd.lined = true; + cmd->lined = true; this->next_lined = false; } this->commands.push_back(cmd); } void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, RD7Color clr) { - R2Cmd cmd; - cmd.pos = pos0; - cmd.pszs = pos1; - cmd.ap = pos2; - cmd.clr = RenderD7::ThemeActive()->Get(clr); - cmd.type = 2; // Triangle + auto cmd = R2Cmd::New(); + cmd->pos = pos0; + cmd->pszs = pos1; + cmd->ap = pos2; + cmd->clr = RenderD7::ThemeActive()->Get(clr); + cmd->type = 2; // Triangle // Just assign current screen as bottom is 0 (false) // and Top and TopRight are !0 (true) - cmd.Screen = current_screen; + cmd->Screen = current_screen; if (this->next_lined) { - cmd.lined = true; + cmd->lined = true; this->next_lined = false; } this->commands.push_back(cmd); @@ -210,17 +233,17 @@ void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, RD7Color clr) { void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, unsigned int clr) { - R2Cmd cmd; - cmd.pos = pos0; - cmd.pszs = pos1; - cmd.ap = pos2; - cmd.clr = clr; - cmd.type = 2; // Triangle + auto cmd = R2Cmd::New(); + cmd->pos = pos0; + cmd->pszs = pos1; + cmd->ap = pos2; + cmd->clr = clr; + cmd->type = 2; // Triangle // Just assign current screen as bottom is 0 (false) // and Top and TopRight are !0 (true) - cmd.Screen = current_screen; + cmd->Screen = current_screen; if (this->next_lined) { - cmd.lined = true; + cmd->lined = true; this->next_lined = false; } this->commands.push_back(cmd); @@ -228,18 +251,18 @@ void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, void R2Base::AddText(R7Vec2 pos, const std::string& text, RD7Color clr, RD7TextFlags flags, R7Vec2 tmb) { - R2Cmd cmd; - cmd.pos = pos; - cmd.pszs = tmb; - cmd.clr = RenderD7::ThemeActive()->Get(clr); - cmd.flags = flags; - cmd.text = text; - cmd.type = 3; // Text + auto cmd = R2Cmd::New(); + cmd->pos = pos; + cmd->pszs = tmb; + cmd->clr = RenderD7::ThemeActive()->Get(clr); + cmd->flags = flags; + cmd->text = text; + cmd->type = 3; // Text // Just assign current screen as bottom is 0 (false) // and Top and TopRight are !0 (true) - cmd.Screen = current_screen; + cmd->Screen = current_screen; if (this->next_lined) { - cmd.lined = true; + cmd->lined = true; this->next_lined = false; } this->commands.push_back(cmd); @@ -247,47 +270,47 @@ void R2Base::AddText(R7Vec2 pos, const std::string& text, RD7Color clr, void R2Base::AddText(R7Vec2 pos, const std::string& text, unsigned int clr, RD7TextFlags flags, R7Vec2 tmb) { - R2Cmd cmd; - cmd.pos = pos; - cmd.pszs = tmb; - cmd.clr = clr; - cmd.flags = flags; - cmd.text = text; - cmd.type = 3; // Text + auto cmd = R2Cmd::New(); + cmd->pos = pos; + cmd->pszs = tmb; + cmd->clr = clr; + cmd->flags = flags; + cmd->text = text; + cmd->type = 3; // Text // Just assign current screen as bottom is 0 (false) // and Top and TopRight are !0 (true) - cmd.Screen = current_screen; + cmd->Screen = current_screen; if (this->next_lined) { - cmd.lined = true; + cmd->lined = true; this->next_lined = false; } this->commands.push_back(cmd); } void R2Base::AddImage(R7Vec2 pos, Image::Ref img) { - R2Cmd cmd; - cmd.pos = pos; - cmd.img = img; - cmd.type = 4; // Image + auto cmd = R2Cmd::New(); + cmd->pos = pos; + cmd->img = img; + cmd->type = 4; // Image // Just assign current screen as bottom is 0 (false) // and Top and TopRight are !0 (true) - cmd.Screen = current_screen; + cmd->Screen = current_screen; if (this->next_lined) { - cmd.lined = true; + cmd->lined = true; this->next_lined = false; } this->commands.push_back(cmd); } void R2Base::AddSprite(Sprite::Ref spr) { - R2Cmd cmd; - cmd.spr = spr; - cmd.type = 5; // Sprite + auto cmd = R2Cmd::New(); + cmd->spr = spr; + cmd->type = 5; // Sprite // Just assign current screen as bottom is 0 (false) // and Top and TopRight are !0 (true) - cmd.Screen = current_screen; + cmd->Screen = current_screen; if (this->next_lined) { - cmd.lined = true; + cmd->lined = true; this->next_lined = false; } this->commands.push_back(cmd); diff --git a/source/Timer.cpp b/source/Timer.cpp index be490cb..8e63918 100644 --- a/source/Timer.cpp +++ b/source/Timer.cpp @@ -28,22 +28,22 @@ Timer::Timer(bool autostart) { current = last; } -void Timer::reset() { +void Timer::Reset() { last = svcGetSystemTick(); current = last; } -void Timer::tick() { +void Timer::Tick() { if (is_running) current = svcGetSystemTick(); } -void Timer::pause() { is_running = false; } +void Timer::Pause() { is_running = false; } -void Timer::resume() { is_running = true; } +void Timer::Resume() { is_running = true; } -bool Timer::running() { return is_running; } +bool Timer::Running() { return is_running; } -float Timer::get() { return (float)((current - last) / TPMS); } +float Timer::Get() { return (float)((current - last) / TPMS); } -float Timer::get_live() { return (float)((svcGetSystemTick() - last) / TPMS); } +float Timer::GetLive() { return (float)((svcGetSystemTick() - last) / TPMS); } } // namespace RenderD7 \ No newline at end of file diff --git a/source/UI7.cpp b/source/UI7.cpp index cacb574..094e8da 100644 --- a/source/UI7.cpp +++ b/source/UI7.cpp @@ -1181,4 +1181,22 @@ UI7DrawList::Ref GetBackgroundList() { if (!UI7CtxValidate()) return nullptr; return ui7_ctx->bdl; } + +UI7DrawList::Ref Menu::GetBackgroundList() { + if (!UI7CtxValidate()) return nullptr; + if(!UI7CtxInMenu()) return ui7_ctx->bdl; + return ui7_ctx->cm->background; +} + +UI7DrawList::Ref Menu::GetList() { + if (!UI7CtxValidate()) return nullptr; + if(!UI7CtxInMenu()) return ui7_ctx->bdl; + return ui7_ctx->cm->main; +} + +UI7DrawList::Ref Menu::GetForegroundList() { + if (!UI7CtxValidate()) return nullptr; + if(!UI7CtxInMenu()) return ui7_ctx->bdl; + return ui7_ctx->cm->front; +} } // namespace UI7 \ No newline at end of file diff --git a/source/renderd7.cpp b/source/renderd7.cpp index a1047f3..b321d1c 100644 --- a/source/renderd7.cpp +++ b/source/renderd7.cpp @@ -808,7 +808,7 @@ void RenderD7::RSettings::Draw(void) const { RenderD7::R2()->OnScreen(R2Screen_Bottom); if (UI7::BeginMenu("Press \uE001 to go back!", R7Vec2(), UI7MenuFlags_Scrolling)) { - for (auto &it : rd7i_logger->Lines()) UI7::Label(it); + for (auto &it : rd7i_logger->Lines()) UI7::Label(it, RD7TextFlags_Wrap); UI7::EndMenu(); } } diff --git a/source/renderd7_logo.cpp b/source/renderd7_logo.cpp index 73363c1..09ad4ff 100644 --- a/source/renderd7_logo.cpp +++ b/source/renderd7_logo.cpp @@ -1,20 +1,20 @@ /** -* This file is part of RenderD7 -* Copyright (C) 2021-2024 NPI-D7, tobid7 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * This file is part of RenderD7 + * Copyright (C) 2021-2024 NPI-D7, tobid7 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ // THIS FILE WAS GENERATED BY generate_assets.py!!!