Make Timer SmartCtor
ClangFormat
Reactivate Graphical Error Screen
Fix Logger
Fix Image Rendering
This commit is contained in:
tobid7 2024-06-15 15:12:06 +02:00
parent f7c0c83ac2
commit ec8743417d
17 changed files with 287 additions and 234 deletions

View File

@ -29,7 +29,7 @@
namespace RenderD7 { namespace RenderD7 {
class Image { class Image {
public: public:
Image(); Image() = default;
~Image() = default; ~Image() = default;
RD7_SMART_CTOR(Image) RD7_SMART_CTOR(Image)
void Load(const std::string& path); void Load(const std::string& path);

View File

@ -64,6 +64,7 @@ class R2Base {
// Text Specific // Text Specific
RD7TextFlags flags; // Text Flags RD7TextFlags flags; // Text Flags
std::string text; // Text std::string text; // Text
RD7_SMART_CTOR(R2Cmd)
}; };
R2Base(); R2Base();
~R2Base() = default; ~R2Base() = default;
@ -83,7 +84,7 @@ class R2Base {
// Processing // Processing
void Process(); void Process();
R7Vec2 GetTextDimensions(const std::string& text); R7Vec2 GetTextDimensions(const std::string& text);
std::string WrapText(const std ::string& in, int maxlen);
// Draw Functions // Draw Functions
void AddRect(R7Vec2 pos, R7Vec2 size, RD7Color clr); void AddRect(R7Vec2 pos, R7Vec2 size, RD7Color clr);
void AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr); void AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr);
@ -103,7 +104,7 @@ class R2Base {
std::map<std::string, float> ts; std::map<std::string, float> ts;
std::map<std::string, int> mln; std::map<std::string, int> mln;
bool next_lined = false; bool next_lined = false;
std::vector<R2Cmd> commands; std::vector<R2Cmd::Ref> commands;
R2Screen current_screen = R2Screen_Bottom; R2Screen current_screen = R2Screen_Bottom;
}; };
} // namespace RenderD7 } // namespace RenderD7

View File

@ -21,8 +21,8 @@
#include <citro2d.h> #include <citro2d.h>
#include <citro3d.h> #include <citro3d.h>
#include <renderd7/smart_ctor.hpp>
#include <renderd7/Image.hpp> #include <renderd7/Image.hpp>
#include <renderd7/smart_ctor.hpp>
#include <string> #include <string>
namespace RenderD7 { namespace RenderD7 {
@ -44,7 +44,8 @@ class Sheet {
void Free(); void Free();
Image::Ref GetImage(int idx); Image::Ref GetImage(int idx);
C2D_SpriteSheet Get() { return this->spritesheet; } C2D_SpriteSheet Get() { return this->spritesheet; }
private:
private:
/// \param spritesheet The Sheet /// \param spritesheet The Sheet
C2D_SpriteSheet spritesheet; C2D_SpriteSheet spritesheet;
}; };

View File

@ -20,18 +20,21 @@
#include <3ds.h> #include <3ds.h>
#include <renderd7/smart_ctor.hpp>
namespace RenderD7 { namespace RenderD7 {
class Timer { class Timer {
public: public:
Timer(bool autostart = true); Timer(bool autostart = true);
~Timer() {} ~Timer() {}
void reset(); RD7_SMART_CTOR(Timer)
void tick(); void Reset();
void pause(); void Tick();
void resume(); void Pause();
float get(); void Resume();
float get_live(); float Get();
bool running(); float GetLive();
bool Running();
private: private:
uint64_t last = 0; uint64_t last = 0;

View File

@ -102,6 +102,12 @@ void SetCursorPos(R7Vec2 cp);
void RestoreCursor(); void RestoreCursor();
void SameLine(); void SameLine();
float GetScrollingOffset(); 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 // DrawLists
UI7DrawList::Ref GetForegroundList(); UI7DrawList::Ref GetForegroundList();
UI7DrawList::Ref GetBackgroundList(); UI7DrawList::Ref GetBackgroundList();

View File

@ -1,20 +1,20 @@
/** /**
* This file is part of RenderD7 * This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7 * Copyright (C) 2021-2024 NPI-D7, tobid7
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// THIS FILE WAS GENERATED BY generate_assets.py!!! // THIS FILE WAS GENERATED BY generate_assets.py!!!

View File

@ -26,12 +26,9 @@ int main() {
RD7::FadeIn(); RD7::FadeIn();
// RD7::Init::NdspFirm(); // RD7::Init::NdspFirm();
RD7::Scene::Load(std::make_unique<Sample>()); RD7::Scene::Load(std::make_unique<Sample>());
auto img = RD7::Image::New();
img->Load("romfs:/icons/icon.png");
RD7::Ftrace::End("app", "app_init"); RD7::Ftrace::End("app", "app_init");
while (RD7::MainLoop()) { while (RD7::MainLoop()) {
RD7::R2()->OnScreen(R2Screen_Top); RD7::R2()->OnScreen(R2Screen_Bottom);
UI7::GetForegroundList()->AddImage(R7Vec2(), img);
RD7::Ftrace::Beg("app", "app_mainloop"); RD7::Ftrace::Beg("app", "app_mainloop");
if (d7_hDown & KEY_START) { if (d7_hDown & KEY_START) {
RD7::FadeOut(); RD7::FadeOut();

View File

@ -41,14 +41,14 @@ static void Wave(int index, R7Vec2 position, R7Vec2 size, float time,
} }
// Just to make sure... // Just to make sure...
y_position = std::min(y_position, position.y + size.y - (90 - shrink)); y_position = std::min(y_position, position.y + size.y - (90 - shrink));
RD7::R2()->AddTriangle( RD7::R2()->AddTriangle(
R7Vec2(x_position, y_position), R7Vec2(x_position, y_position),
R7Vec2(x_position + 300, y_position + (90 - shrink)), R7Vec2(x_position + 300, y_position + (90 - shrink)),
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, RD7::Color::RGBA(.94f - .17f * color_effect, .61f - .25f * color_effect,
.36f + .38f * color_effect) .36f + .38f * color_effect)
.toRGBA()); .toRGBA());
} }
void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) { 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); R7Vec2 testv2 = R7Vec2(48, 48);
std::vector<int*> img; std::vector<int*> 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() { Sample::Sample() {
auto ti = new int; auto ti = new int;

View File

@ -37,39 +37,40 @@ void rd7i_save_report(const std::string& msg) {
namespace RenderD7 { namespace RenderD7 {
void Error(const std::string& msg) { void Error(const std::string& msg) {
rd7i_save_report(msg); rd7i_save_report(msg);
/*if (rd7i_graphics_on) { if (rd7i_graphics_on) {
C3D_FrameEnd(0);
while (aptMainLoop()) { while (aptMainLoop()) {
hidScanInput(); hidScanInput();
if (hidKeysDown() & KEY_START) break; if (hidKeysDown() & KEY_START) break;
C3D_FrameBegin(C3D_FRAME_SYNCDRAW); C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
RenderD7::ClearTextBufs(); RenderD7::ClearTextBufs();
C2D_TargetClear(Top, 0x00000000); C2D_TargetClear(rd7_top, 0x00000000);
C2D_TargetClear(Bottom, 0x00000000); C2D_TargetClear(rd7_bottom, 0x00000000);
RenderD7::OnScreen(Top); RenderD7::R2()->OnScreen(R2Screen_Top);
if (UI7::BeginMenu("RenderD7 - Error Manager", R7Vec2(), if (UI7::BeginMenu("RenderD7 - Error Manager", R7Vec2(),
UI7MenuFlags_TitleMid)) { UI7MenuFlags_TitleMid)) {
UI7::Label(msg, RD7TextFlags_Wrap); UI7::Label(msg, RD7TextFlags_Wrap);
UI7::Label("Press Start to Exit!"); UI7::Label("Press Start to Exit!");
UI7::EndMenu(); UI7::EndMenu();
} }
RenderD7::OnScreen(Bottom); RenderD7::R2()->OnScreen(R2Screen_Bottom);
UI7::Update();
RenderD7::R2()->Process();
C3D_FrameEnd(0); C3D_FrameEnd(0);
} }
exit(0); exit(0);
} else {*/ } else {
gfxInitDefault(); gfxInitDefault();
consoleInit(GFX_TOP, NULL); consoleInit(GFX_TOP, NULL);
printf("RENDERD7 - ERROR MANAGER\n\n%s\n", msg.c_str()); printf("RENDERD7 - ERROR MANAGER\n\n%s\n", msg.c_str());
printf("Report Saved in\nsdmc:/RenderD7/Reports\n"); printf("Report Saved in\nsdmc:/RenderD7/Reports\n");
printf("Press Start to Exit\n"); printf("Press Start to Exit\n");
while (aptMainLoop()) { while (aptMainLoop()) {
hidScanInput(); hidScanInput();
if (hidKeysDown() & KEY_START) break; if (hidKeysDown() & KEY_START) break;
gfxSwapBuffers(); gfxSwapBuffers();
}
gfxExit();
exit(0);
} }
gfxExit();
exit(0);
// }
} }
} // namespace RenderD7 } // namespace RenderD7

View File

@ -19,9 +19,8 @@
#include <renderd7/external/stb_image.h> #include <renderd7/external/stb_image.h>
#include <renderd7/Image.hpp> #include <renderd7/Image.hpp>
#include <vector>
#include <renderd7/internal_db.hpp> #include <renderd7/internal_db.hpp>
#include <vector>
static u32 __rd7i_gp2o__(u32 v) { static u32 __rd7i_gp2o__(u32 v) {
v--; v--;
@ -50,30 +49,30 @@ static void __rd7i_r24r32(std::vector<uint8_t> &out,
} }
} }
static void __rd7i_maketex__(C3D_Tex* tex, Tex3DS_SubTexture* sub, std::vector<unsigned char>& buf, int w, int h) { static void __rd7i_maketex__(C3D_Tex *tex, Tex3DS_SubTexture *sub,
if(!tex || !sub) std::vector<unsigned char> &buf, int w, int h) {
{ if (!tex || !sub) {
_rd7i_logger()->Write("Invalid Inpit (objects have no adress!)"); _rd7i_logger()->Write("Invalid Inpit (objects have no adress!)");
return; return;
} }
// RGBA -> Abgr // RGBA -> Abgr
for(int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
int pos = (x+y*w)*4; int pos = (x + y * w) * 4;
auto r = buf[pos+0]; auto r = buf[pos + 0];
auto g = buf[pos+1]; auto g = buf[pos + 1];
auto b = buf[pos+2]; auto b = buf[pos + 2];
auto a = buf[pos+3]; auto a = buf[pos + 3];
buf[pos+0] = a; buf[pos + 0] = a;
buf[pos+1] = b; buf[pos + 1] = b;
buf[pos+2] = g; buf[pos + 2] = g;
buf[pos+3] = r; buf[pos + 3] = r;
} }
} }
// Pow2 // Pow2
int wp2 = __rd7i_gp2o__(w); int wp2 = __rd7i_gp2o__((unsigned int)w);
int hp2 = __rd7i_gp2o__(h); int hp2 = __rd7i_gp2o__((unsigned int)h);
sub->width = (u16)w; sub->width = (u16)w;
sub->height = (u16)h; sub->height = (u16)h;
@ -106,10 +105,6 @@ static void __rd7i_maketex__(C3D_Tex* tex, Tex3DS_SubTexture* sub, std::vector<u
} }
namespace RenderD7 { namespace RenderD7 {
Image::Image() {
img.tex = nullptr;
img.subtex = nullptr;
}
void Image::Load(const std::string &path) { void Image::Load(const std::string &path) {
// Make sure to cleanup // Make sure to cleanup
@ -118,56 +113,57 @@ void Image::Load(const std::string &path) {
int w, h, c = 0; int w, h, c = 0;
unsigned char *image = stbi_load(path.c_str(), &w, &h, &c, 4); unsigned char *image = stbi_load(path.c_str(), &w, &h, &c, 4);
if (image == nullptr) { if (image == nullptr) {
_rd7i_logger()->Write("Failed to Load Image: " + path); //_rd7i_logger()->Write("Failed to Load Image: " + path);
return; return;
} }
// Size/Fmt Check // Size/Fmt Check
if (w > 1024 || h > 1024) { if (w > 1024 || h > 1024) {
// Reason: Image to Large // Reason: Image to Large
_rd7i_logger()->Write("Image too Large!"); //_rd7i_logger()->Write("Image too Large!");
stbi_image_free(image); stbi_image_free(image);
return; return;
} }
std::vector<unsigned char> wimg; std::vector<unsigned char> wimg;
if (c == 3) { if (c == 3) {
_rd7i_logger()->Write("Convert Image to RGBA"); //_rd7i_logger()->Write("Convert Image to RGBA");
stbi_image_free(image); stbi_image_free(image);
image = stbi_load(path.c_str(), &w, &h, &c, 3); image = stbi_load(path.c_str(), &w, &h, &c, 3);
wimg.resize(w*h*4); wimg.resize(w * h * 4);
__rd7i_r24r32(wimg, std::vector<unsigned char>(image, image + (w * h * 3)), w, h); __rd7i_r24r32(wimg, std::vector<unsigned char>(image, image + (w * h * 3)),
w, h);
} else { } else {
wimg.assign(&image[0], &image[(w*h*4)-1]); wimg.assign(&image[0], &image[(w * h * 4) - 1]);
stbi_image_free(image); stbi_image_free(image);
} }
// Create C2D_Image // Create C2D_Image
C3D_Tex *tex = new C3D_Tex; C3D_Tex* tex = new C3D_Tex;
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture; Tex3DS_SubTexture* subtex = new Tex3DS_SubTexture;
__rd7i_maketex__(tex, subtex, wimg, w, h); __rd7i_maketex__(tex, subtex, wimg, w, h);
img.tex = tex; _rd7i_logger()->Write(RenderD7::FormatString("Created Texture (%d, %d)",
img.subtex = subtex; tex->width, tex->height));
img = {tex, subtex};
} }
void Image::From_NIMG(const nimg &image) { void Image::From_NIMG(const nimg &image) {
// Make sure to cleanup // Make sure to cleanup
Delete(); Delete();
if (image.width > 1024 || image.height > 1024) return; if (image.width > 1024 || image.height > 1024) return;
C3D_Tex *tex = new C3D_Tex; C3D_Tex* tex = new C3D_Tex;
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture; Tex3DS_SubTexture* subtex = new Tex3DS_SubTexture;
std::vector<unsigned char> mdpb = image.pixel_buffer; std::vector<unsigned char> mdpb = image.pixel_buffer;
__rd7i_maketex__(tex, subtex, mdpb, image.width, image.height); __rd7i_maketex__(tex, subtex, mdpb, image.width, image.height);
img.tex = tex; img = {tex, subtex};
img.subtex = subtex;
} }
C2D_Image Image::Get() { C2D_Image Image::Get() {
if(!Loadet()) { if (!Loadet()) {
_rd7i_logger()->Write("Image not Loadet!"); _rd7i_logger()->Write("Image not Loadet!");
} }
return img; return img;
} }
C2D_Image &Image::GetRef() { C2D_Image &Image::GetRef() {
if(!Loadet()) { if (!Loadet()) {
_rd7i_logger()->Write("Image not Loadet!"); _rd7i_logger()->Write("Image not Loadet!");
} }
return img; return img;
@ -188,7 +184,8 @@ void Image::Delete() {
delete img.subtex; delete img.subtex;
img.subtex = nullptr; img.subtex = nullptr;
} }
if (img.tex != nullptr) { if (img.tex != nullptr) {
C3D_TexDelete(img.tex);
delete img.tex; delete img.tex;
img.tex = nullptr; img.tex = nullptr;
} }

View File

@ -51,10 +51,10 @@ void LoggerBase::Write(const std::string& debug_text, int lvl) {
if (this->_log.is_open() && lvl <= writelvl) { if (this->_log.is_open() && lvl <= writelvl) {
this->_log << msg << std::endl; 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'))); lines.push_back(msg.substr(0, msg.find_first_of('\n')));
msg = msg.substr(msg.find_first_of('\n')); msg = msg.substr(msg.find_first_of('\n'));
} }*/
lines.push_back(msg); lines.push_back(msg);
} }

View File

@ -434,16 +434,16 @@ void Ovl_Keyboard::Draw(void) const {
R2()->AddText(R7Vec2(5, 114), "> " + *typed_text, R2()->AddText(R7Vec2(5, 114), "> " + *typed_text,
RenderD7::ThemeActive()->AutoText(RD7Color_Header)); RenderD7::ThemeActive()->AutoText(RD7Color_Header));
for (auto const& it : key_table) { for (auto const& it : key_table) {
R7Vec2 szs = it.size;
R7Vec2 pos = it.pos;
R7Vec2 txtdim = R2()->GetTextDimensions(it.disp); 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; RD7Color btn = RD7Color_Button;
if (RenderD7::Hid::IsEvent("cancel", RenderD7::Hid::Up)) { if (RenderD7::Hid::IsEvent("cancel", RenderD7::Hid::Up)) {
RenderD7::Hid::Clear(); RenderD7::Hid::Clear();
shared_data[0x05] = 1; shared_data[0x05] = 1;
} }
if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Up) && 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 if (mode == 2) // Request Disable Shift
shared_data[0x02] = 1; shared_data[0x02] = 1;
@ -468,8 +468,12 @@ void Ovl_Keyboard::Draw(void) const {
} else if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held) && } else if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held) &&
UI7_InBox(RenderD7::Hid::GetTouchPosition(), it.pos, it.size)) { UI7_InBox(RenderD7::Hid::GetTouchPosition(), it.pos, it.size)) {
btn = RD7Color_ButtonHovered; 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)); R2()->AddText(txtpos, it.disp, RenderD7::ThemeActive()->AutoText(btn));
} }
if (ft3 > 5) RenderD7::Hid::Lock(); if (ft3 > 5) RenderD7::Hid::Lock();

View File

@ -57,73 +57,96 @@ R7Vec2 R2Base::GetTextDimensions(const std::string& text) {
return R7Vec2(w, h); 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 // Main Processing of Draw Calls
void R2Base::Process() { void R2Base::Process() {
for (auto& it : this->commands) { for (auto& it : this->commands) {
if (it.type <= 0 || it.type > 3) { if (it->type <= 0 || it->type > 5) {
// Skip // Skip
continue; continue;
} }
C2D_SceneBegin(it.Screen ? rd7_top : rd7_bottom); C2D_SceneBegin(it->Screen ? rd7_top : rd7_bottom);
if (it.type == 1) { if (it->type == 1) {
// Rect // Rect
if (it.lined) { if (it->lined) {
C2D_DrawLine(it.pos.x, it.pos.y, it.clr, it.pos.x + it.pszs.x, it.pos.y, 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); 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, 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); it->clr, 1.f, 0.5f);
C2D_DrawLine(it.pos.x + it.pszs.x, it.pos.y, it.clr, 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, it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr, 1.f,
0.5f); 0.5f);
C2D_DrawLine(it.pos.x, it.pos.y + it.pszs.y, it.clr, 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, it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr, 1.f,
0.5f); 0.5f);
} else { } else {
C2D_DrawRectSolid(it.pos.x, it.pos.y, 0.5, it.pszs.x, it.pszs.y, C2D_DrawRectSolid(it->pos.x, it->pos.y, 0.5, it->pszs.x, it->pszs.y,
it.clr); it->clr);
} }
} else if (it.type == 2) { } else if (it->type == 2) {
// Triangle // Triangle
if (it.lined) { if (it->lined) {
C2D_DrawLine(it.pos.x, it.pos.y, it.clr, it.pszs.x, it.pszs.y, it.clr, C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y, it->clr,
1, 0.5f); 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); 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); 0.5f);
} else { } else {
C2D_DrawTriangle(it.pos.x, it.pos.y, it.clr, it.pszs.x, it.pszs.y, 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); it->clr, it->ap.x, it->ap.y, it->clr, 0.5);
} }
} else if (it.type == 3) { } else if (it->type == 3) {
// Text // Text
// little patch for a freeze // little patch for a freeze
if (it.text.length() < 1) continue; if (it->text.length() < 1) continue;
if (it.pszs.x == 0.0f) { if (it->pszs.x == 0.0f) {
it.pszs.x = it.Screen == R2Screen_Top ? 400 : 320; it->pszs.x = it->Screen == R2Screen_Top ? 400 : 320;
} }
if (it.pszs.y == 0.0f) { if (it->pszs.y == 0.0f) {
it.pszs.y = 240; it->pszs.y = 240;
} }
std::string edit_text = it.text; std::string edit_text = it->text;
if (edit_text.substr(it.text.length() - 1) != "\n") if (edit_text.substr(it->text.length() - 1) != "\n")
edit_text.append("\n"); // Add \n to end if not exist edit_text.append("\n"); // Add \n to end if not exist
int line = 0; int line = 0;
// if (it.flags & RD7TextFlags_Wrap) if (it->flags & RD7TextFlags_Wrap) {
// edit_text = WrapText(text, rd7i_d7_mwh.x - pos.x); edit_text = WrapText(it->text, it->pszs.x - it->pos.x);
}
while (edit_text.find('\n') != edit_text.npos) { while (edit_text.find('\n') != edit_text.npos) {
std::string current_line = edit_text.substr(0, edit_text.find('\n')); std::string current_line = edit_text.substr(0, edit_text.find('\n'));
// if (it.flags & RD7TextFlags_Short) // if (it->flags & RD7TextFlags_Short)
// current_line = GetShortedText(current_line, it.pszs.x - it.pos.x); // current_line = GetShortedText(current_line, it->pszs.x - it->pos.x);
R7Vec2 newpos = it.pos; R7Vec2 newpos = it->pos;
// Check Flags // Check Flags
R7Vec2 dim = this->GetTextDimensions(current_line); R7Vec2 dim = this->GetTextDimensions(current_line);
if (it.flags & RD7TextFlags_AlignRight) newpos.x = newpos.x - dim.x; if (it->flags & RD7TextFlags_AlignRight) newpos.x = newpos.x - dim.x;
if (it.flags & RD7TextFlags_AlignMid) // Offset by inpos if (it->flags & RD7TextFlags_AlignMid) // Offset by inpos
newpos.x = (it.pszs.x * 0.5) - (dim.x * 0.5) + it.pos.x; 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_Scroll) { // Scroll Text
// Look into Old Draw2 Code // Look into Old Draw2 Code
// TODO: Create Code for this // TODO: Create Code for this
} }
@ -136,73 +159,73 @@ void R2Base::Process() {
current_line.c_str()); current_line.c_str());
C2D_TextOptimize(&c2dtext); 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), C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x + 1 + (dim.y * line),
newpos.y + 1, 0.5, this->text_size, this->text_size, newpos.y + 1, 0.5, this->text_size, this->text_size,
RenderD7::ThemeActive()->Get(RD7Color_TextDisabled)); RenderD7::ThemeActive()->Get(RD7Color_TextDisabled));
C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x, C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x,
newpos.y + (dim.y * line), 0.5, this->text_size, 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); edit_text = edit_text.substr(edit_text.find('\n') + 1);
line++; line++;
} }
} else if (it.type == 4) { } else if (it->type == 4) {
if(it.img->Loadet()) { if (it->img->Loadet()) {
C2D_DrawImageAt(it.img->Get(), it.pos.x, it.pos.y, 0.5f); 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 // TODO: Move the Draw Func into this API
it.spr->Draw(); it->spr->Draw();
} }
} }
this->commands.clear(); this->commands.clear();
} }
void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, RD7Color clr) { void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, RD7Color clr) {
R2Cmd cmd; auto cmd = R2Cmd::New();
cmd.pos = pos; cmd->pos = pos;
cmd.pszs = size; cmd->pszs = size;
cmd.clr = RenderD7::ThemeActive()->Get(clr); cmd->clr = RenderD7::ThemeActive()->Get(clr);
cmd.type = 1; // Rect cmd->type = 1; // Rect
// Just assign current screen as bottom is 0 (false) // Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true) // and Top and TopRight are !0 (true)
cmd.Screen = current_screen; cmd->Screen = current_screen;
if (this->next_lined) { if (this->next_lined) {
cmd.lined = true; cmd->lined = true;
this->next_lined = false; this->next_lined = false;
} }
this->commands.push_back(cmd); this->commands.push_back(cmd);
} }
void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr) { void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr) {
R2Cmd cmd; auto cmd = R2Cmd::New();
cmd.pos = pos; cmd->pos = pos;
cmd.pszs = size; cmd->pszs = size;
cmd.clr = clr; cmd->clr = clr;
cmd.type = 1; // Rect cmd->type = 1; // Rect
// Just assign current screen as bottom is 0 (false) // Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true) // and Top and TopRight are !0 (true)
cmd.Screen = current_screen; cmd->Screen = current_screen;
if (this->next_lined) { if (this->next_lined) {
cmd.lined = true; cmd->lined = true;
this->next_lined = false; this->next_lined = false;
} }
this->commands.push_back(cmd); this->commands.push_back(cmd);
} }
void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, RD7Color clr) { void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, RD7Color clr) {
R2Cmd cmd; auto cmd = R2Cmd::New();
cmd.pos = pos0; cmd->pos = pos0;
cmd.pszs = pos1; cmd->pszs = pos1;
cmd.ap = pos2; cmd->ap = pos2;
cmd.clr = RenderD7::ThemeActive()->Get(clr); cmd->clr = RenderD7::ThemeActive()->Get(clr);
cmd.type = 2; // Triangle cmd->type = 2; // Triangle
// Just assign current screen as bottom is 0 (false) // Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true) // and Top and TopRight are !0 (true)
cmd.Screen = current_screen; cmd->Screen = current_screen;
if (this->next_lined) { if (this->next_lined) {
cmd.lined = true; cmd->lined = true;
this->next_lined = false; this->next_lined = false;
} }
this->commands.push_back(cmd); 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, void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2,
unsigned int clr) { unsigned int clr) {
R2Cmd cmd; auto cmd = R2Cmd::New();
cmd.pos = pos0; cmd->pos = pos0;
cmd.pszs = pos1; cmd->pszs = pos1;
cmd.ap = pos2; cmd->ap = pos2;
cmd.clr = clr; cmd->clr = clr;
cmd.type = 2; // Triangle cmd->type = 2; // Triangle
// Just assign current screen as bottom is 0 (false) // Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true) // and Top and TopRight are !0 (true)
cmd.Screen = current_screen; cmd->Screen = current_screen;
if (this->next_lined) { if (this->next_lined) {
cmd.lined = true; cmd->lined = true;
this->next_lined = false; this->next_lined = false;
} }
this->commands.push_back(cmd); 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, void R2Base::AddText(R7Vec2 pos, const std::string& text, RD7Color clr,
RD7TextFlags flags, R7Vec2 tmb) { RD7TextFlags flags, R7Vec2 tmb) {
R2Cmd cmd; auto cmd = R2Cmd::New();
cmd.pos = pos; cmd->pos = pos;
cmd.pszs = tmb; cmd->pszs = tmb;
cmd.clr = RenderD7::ThemeActive()->Get(clr); cmd->clr = RenderD7::ThemeActive()->Get(clr);
cmd.flags = flags; cmd->flags = flags;
cmd.text = text; cmd->text = text;
cmd.type = 3; // Text cmd->type = 3; // Text
// Just assign current screen as bottom is 0 (false) // Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true) // and Top and TopRight are !0 (true)
cmd.Screen = current_screen; cmd->Screen = current_screen;
if (this->next_lined) { if (this->next_lined) {
cmd.lined = true; cmd->lined = true;
this->next_lined = false; this->next_lined = false;
} }
this->commands.push_back(cmd); 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, void R2Base::AddText(R7Vec2 pos, const std::string& text, unsigned int clr,
RD7TextFlags flags, R7Vec2 tmb) { RD7TextFlags flags, R7Vec2 tmb) {
R2Cmd cmd; auto cmd = R2Cmd::New();
cmd.pos = pos; cmd->pos = pos;
cmd.pszs = tmb; cmd->pszs = tmb;
cmd.clr = clr; cmd->clr = clr;
cmd.flags = flags; cmd->flags = flags;
cmd.text = text; cmd->text = text;
cmd.type = 3; // Text cmd->type = 3; // Text
// Just assign current screen as bottom is 0 (false) // Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true) // and Top and TopRight are !0 (true)
cmd.Screen = current_screen; cmd->Screen = current_screen;
if (this->next_lined) { if (this->next_lined) {
cmd.lined = true; cmd->lined = true;
this->next_lined = false; this->next_lined = false;
} }
this->commands.push_back(cmd); this->commands.push_back(cmd);
} }
void R2Base::AddImage(R7Vec2 pos, Image::Ref img) { void R2Base::AddImage(R7Vec2 pos, Image::Ref img) {
R2Cmd cmd; auto cmd = R2Cmd::New();
cmd.pos = pos; cmd->pos = pos;
cmd.img = img; cmd->img = img;
cmd.type = 4; // Image cmd->type = 4; // Image
// Just assign current screen as bottom is 0 (false) // Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true) // and Top and TopRight are !0 (true)
cmd.Screen = current_screen; cmd->Screen = current_screen;
if (this->next_lined) { if (this->next_lined) {
cmd.lined = true; cmd->lined = true;
this->next_lined = false; this->next_lined = false;
} }
this->commands.push_back(cmd); this->commands.push_back(cmd);
} }
void R2Base::AddSprite(Sprite::Ref spr) { void R2Base::AddSprite(Sprite::Ref spr) {
R2Cmd cmd; auto cmd = R2Cmd::New();
cmd.spr = spr; cmd->spr = spr;
cmd.type = 5; // Sprite cmd->type = 5; // Sprite
// Just assign current screen as bottom is 0 (false) // Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true) // and Top and TopRight are !0 (true)
cmd.Screen = current_screen; cmd->Screen = current_screen;
if (this->next_lined) { if (this->next_lined) {
cmd.lined = true; cmd->lined = true;
this->next_lined = false; this->next_lined = false;
} }
this->commands.push_back(cmd); this->commands.push_back(cmd);

View File

@ -28,22 +28,22 @@ Timer::Timer(bool autostart) {
current = last; current = last;
} }
void Timer::reset() { void Timer::Reset() {
last = svcGetSystemTick(); last = svcGetSystemTick();
current = last; current = last;
} }
void Timer::tick() { void Timer::Tick() {
if (is_running) current = svcGetSystemTick(); 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 } // namespace RenderD7

View File

@ -1181,4 +1181,22 @@ UI7DrawList::Ref GetBackgroundList() {
if (!UI7CtxValidate()) return nullptr; if (!UI7CtxValidate()) return nullptr;
return ui7_ctx->bdl; 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 } // namespace UI7

View File

@ -808,7 +808,7 @@ void RenderD7::RSettings::Draw(void) const {
RenderD7::R2()->OnScreen(R2Screen_Bottom); RenderD7::R2()->OnScreen(R2Screen_Bottom);
if (UI7::BeginMenu("Press \uE001 to go back!", R7Vec2(), if (UI7::BeginMenu("Press \uE001 to go back!", R7Vec2(),
UI7MenuFlags_Scrolling)) { UI7MenuFlags_Scrolling)) {
for (auto &it : rd7i_logger->Lines()) UI7::Label(it); for (auto &it : rd7i_logger->Lines()) UI7::Label(it, RD7TextFlags_Wrap);
UI7::EndMenu(); UI7::EndMenu();
} }
} }

View File

@ -1,20 +1,20 @@
/** /**
* This file is part of RenderD7 * This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7 * Copyright (C) 2021-2024 NPI-D7, tobid7
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// THIS FILE WAS GENERATED BY generate_assets.py!!! // THIS FILE WAS GENERATED BY generate_assets.py!!!