From 968c2576b90d5515e612c802bd4b54b1577ce7f7 Mon Sep 17 00:00:00 2001 From: Tobi-D7 Date: Wed, 21 Feb 2024 12:48:56 +0100 Subject: [PATCH] - Add RD7 and DV2 namespace - Restructer Default Theme System - Rename NIMG_Engine to swr (SoftwareRender) - Begin Adding Debug Lines to UI7 - Remove GUI ErrorSystem --- .vscode/launch.json | 7 ++ .vscode/tasks.json | 23 ++++++ README.md | 5 +- include/rd7.hpp | 5 +- include/renderd7/Color.hpp | 2 +- include/renderd7/R7Vec.hpp | 62 ++++++++++++++++ include/renderd7/UI7.hpp | 3 + include/renderd7/{nimg_engine.hpp => swr.hpp} | 11 +-- rd7tf/source/main.cpp | 72 +++++++++---------- rd7tf/source/scene.cpp | 48 ++++++------- rd7tf/source/scene.hpp | 2 +- source/Color.cpp | 31 ++------ source/Error.cpp | 26 +++---- source/UI7.cpp | 58 ++++++++++++++- source/nimg.cpp | 6 +- source/renderd7.cpp | 5 +- source/{nimg_engine.cpp => swr.cpp} | 35 +++++---- 17 files changed, 269 insertions(+), 132 deletions(-) create mode 100644 .vscode/tasks.json rename include/renderd7/{nimg_engine.hpp => swr.hpp} (70%) rename source/{nimg_engine.cpp => swr.cpp} (69%) diff --git a/.vscode/launch.json b/.vscode/launch.json index 45e7983..77e326e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,6 +1,13 @@ { "version": "0.2.0", "configurations": [ + { + "name": "Format Code", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/clang-format.py", + "cwd": "${workspaceFolder}" + }, { "name": "(gdb) Launch", "type": "cppdbg", diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..1b669bb --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build", + "command": "make", + "type": "shell", + "options": { + "cwd": "${workspaceFolder}/rd7tf/" + }, + "presentation": { + "reveal": "always", + "panel": "new", + "focus": true + }, + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 1340429..7cab15e 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ RENDERD7_SRC := RenderD7/source RenderD7/external RENDERD7_INC := RenderD7/include # Libraries used for RenderD7 # if you already use -lm, -lctru etc place a # before -lm -RENDERD7_LIBS := -lmpg123 -lvorbisidec -logg -lcurl -lm -lcitro2dd -lcitro3d -lctru -RENDERD7_FLAGS := -DRENDERD7_MUSICDEC=1 -DRENDERD7_MEMTRACK=1 +RENDERD7_LIBS := -lcurl -lm -lcitro2dd -lcitro3d -lctru +RENDERD7_FLAGS := -DRENDERD7_MEMTRACK=1 ``` Now you need to add it to your sources and includes ``` @@ -22,7 +22,6 @@ INCLUDES := source $(RENDERD7_INC) Finally append `$(RENDERD7_FLAGS)` to your `CFLAGS` Example from rd7tf -Keep in mind that -DRENDERD7_MUSICDEC=1 requires `-lmpg123 -lvorbisidec -logg` ### Installation (0.8.0-0.9.4) (OUTDATED) Download a Package From Releses Page `https://github.com/NPI-D7/RenderD7/releases/download/v0.9.4/renderd7.tar.bz2 -o renderd7.tar.bz2` diff --git a/include/rd7.hpp b/include/rd7.hpp index 9507227..50812c5 100644 --- a/include/rd7.hpp +++ b/include/rd7.hpp @@ -10,6 +10,9 @@ #include #include #include -#include #include #include +#include + +namespace RD7 = RenderD7; +namespace DV2 = RenderD7::Draw2; \ No newline at end of file diff --git a/include/renderd7/Color.hpp b/include/renderd7/Color.hpp index 104e685..5677225 100644 --- a/include/renderd7/Color.hpp +++ b/include/renderd7/Color.hpp @@ -12,7 +12,7 @@ #define UNPACK_BGRA(col) (uint8_t)(col >> 8), (col >> 16), (col >> 24), (col) inline uint32_t RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) { -#define ISIMPLEPAK(x, y) (((x)&0xff) << y) +#define ISIMPLEPAK(x, y) (((x) & 0xff) << y) return (ISIMPLEPAK(r, 0) | ISIMPLEPAK(g, 8) | ISIMPLEPAK(b, 16) | ISIMPLEPAK(a, 24)); } diff --git a/include/renderd7/R7Vec.hpp b/include/renderd7/R7Vec.hpp index 3cc0d8d..ec205d6 100644 --- a/include/renderd7/R7Vec.hpp +++ b/include/renderd7/R7Vec.hpp @@ -39,4 +39,66 @@ struct R7Vec2 { // Internal Values float x; float y; +}; + +struct R7Vec4 { + // Init Funcs + R7Vec4() : x(0), y(0), z(0), w(0) {} + R7Vec4(float i0, float i1, float i2, float i3) : x(i0), y(i1), z(i2), w(i3) {} + R7Vec4(const R7Vec4 &i) { + x = i.x; + y = i.y; + z = i.z; + w = i.w; + } + + R7Vec4(const R7Vec2 &i0, const R7Vec2 &i1) { + x = i0.x; + y = i0.y; + z = i1.x; + w = i1.y; + } + + // Operators + // Add + R7Vec4 &operator+=(const R7Vec4 &i) { + x += i.x; + y += i.y; + z += i.z; + w += i.w; + return *this; + } + + R7Vec4 operator+(const R7Vec4 &i) const { + return R7Vec4(x + i.x, y + i.y, z + i.z, w + i.w); + } + + // Sub + R7Vec4 &operator-=(const R7Vec4 &i) { + x -= i.x; + y -= i.y; + z -= i.z; + w -= i.w; + return *this; + } + + R7Vec4 operator-(const R7Vec4 &i) const { + return R7Vec4(x - i.x, y - i.y, z - i.z, w - i.w); + } + + // Compare + bool operator==(const R7Vec4 &in) const { + return x == in.x && y == in.y && z == in.z && w == in.w; + } + + bool operator!=(const R7Vec4 &in) const { + // use the first comparefuncs result + // and swap it lol + return !(*this == in); + } + // Internal Values + float x; + float y; + float z; + float w; }; \ No newline at end of file diff --git a/include/renderd7/UI7.hpp b/include/renderd7/UI7.hpp index 256f980..fb6220c 100644 --- a/include/renderd7/UI7.hpp +++ b/include/renderd7/UI7.hpp @@ -26,6 +26,9 @@ void Deinit(); void Update(); float GetTime(); float GetDeltaTime(); +// Internal Function +// Should not be used +void Debug(); bool Button(const std::string &label, R7Vec2 size = R7Vec2(0, 0)); void Checkbox(const std::string &label, bool &c); diff --git a/include/renderd7/nimg_engine.hpp b/include/renderd7/swr.hpp similarity index 70% rename from include/renderd7/nimg_engine.hpp rename to include/renderd7/swr.hpp index 9fe8a88..0677d20 100644 --- a/include/renderd7/nimg_engine.hpp +++ b/include/renderd7/swr.hpp @@ -3,12 +3,12 @@ #include namespace RenderD7 { -class NIMG_Engine { +class swr { public: - NIMG_Engine(int w, int h); - NIMG_Engine(); - ~NIMG_Engine(); - nimg& GetImage() { return image; } + swr(int w, int h); + swr(); + ~swr(); + nimg& get_image() { return image; } void load_file(const std::string& path); void load_nimg(const std::string& path); @@ -16,6 +16,7 @@ class NIMG_Engine { void draw_pixel(int x, int y, unsigned int color); void draw_rect(int x, int y, int w, int h, unsigned int color, int t = 1); void draw_rect_solid(int x, int y, int w, int h, unsigned int color); + void draw_line(int x1, int y1, int x2, int y2, unsigned int color, int t = 1); void flip(bool h, bool v); private: diff --git a/rd7tf/source/main.cpp b/rd7tf/source/main.cpp index 6541803..220f0ac 100644 --- a/rd7tf/source/main.cpp +++ b/rd7tf/source/main.cpp @@ -1,32 +1,24 @@ #include "scene.hpp" void ColorThemeSample() { - RenderD7::ColorNew(RD7Color_Text, RenderD7::Color::Hex("#000000", 255)); - RenderD7::ColorNew(RD7Color_TextDisabled, - RenderD7::Color::Hex("#212121", 200)); - RenderD7::ColorNew(RD7Color_Text2, RenderD7::Color::Hex("#ffffff", 255)); - RenderD7::ColorNew(RD7Color_Background, RenderD7::Color::Hex("#eeeeee", 170)); - RenderD7::ColorNew(RD7Color_Header, RenderD7::Color::Hex("#222222", 190)); - RenderD7::ColorNew(RD7Color_Selector, RenderD7::Color::Hex("#4444dd", 200)); - RenderD7::ColorNew(RD7Color_SelectorFade, - RenderD7::Color::Hex("#7777dd", 200)); - RenderD7::ColorNew(RD7Color_List0, RenderD7::Color::Hex("#555555", 130)); - RenderD7::ColorNew(RD7Color_List1, RenderD7::Color::Hex("#777777", 130)); - RenderD7::ColorNew(RD7Color_MessageBackground, - RenderD7::Color::Hex("#222222", 180)); - RenderD7::ColorNew(RD7Color_Button, RenderD7::Color::Hex("#4444dd", 150)); - RenderD7::ColorNew(RD7Color_ButtonHovered, - RenderD7::Color::Hex("#6666dd", 150)); - RenderD7::ColorNew(RD7Color_ButtonDisabled, - RenderD7::Color::Hex("#2222dd", 150)); - RenderD7::ColorNew(RD7Color_ButtonActive, - RenderD7::Color::Hex("#7777dd", 150)); - RenderD7::ColorNew(RD7Color_Checkmark, RenderD7::Color::Hex("#4444dd", 130)); - RenderD7::ColorNew(RD7Color_FrameBg, RenderD7::Color::Hex("#555555", 160)); - RenderD7::ColorNew(RD7Color_FrameBgHovered, - RenderD7::Color::Hex("#777777", 160)); - RenderD7::ColorNew(RD7Color_Progressbar, - RenderD7::Color::Hex("#4444dd", 200)); + 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(); @@ -34,24 +26,24 @@ extern void IdbServer(); int main() { rd7_enable_memtrack = true; rd7_do_splash = true; - RenderD7::Ftrace::Beg("app", "app_init"); - RenderD7::Init::Main("rd7tf"); - RenderD7::FadeIn(); + RD7::Ftrace::Beg("app", "app_init"); + RD7::Init::Main("rd7tf"); + RD7::FadeIn(); // IdbServer(); ColorThemeSample(); - RenderD7::Init::NdspFirm(); - RenderD7::Scene::Load(std::make_unique()); - RenderD7::Ftrace::End("app", "app_init"); - while (RenderD7::MainLoop()) { - RenderD7::OnScreen(Top); - RenderD7::Ftrace::Beg("app", "app_mainloop"); + RD7::Init::NdspFirm(); + RD7::Scene::Load(std::make_unique()); + RD7::Ftrace::End("app", "app_init"); + while (RD7::MainLoop()) { + RD7::OnScreen(Top); + RD7::Ftrace::Beg("app", "app_mainloop"); if (d7_hDown & KEY_START) { - RenderD7::FadeOut(); - RenderD7::ExitApp(); + RD7::FadeOut(); + RD7::ExitApp(); } - RenderD7::OnScreen(Top); - RenderD7::FrameEnd(); - RenderD7::Ftrace::End("app", "app_mainloop"); + RD7::OnScreen(Top); + RD7::FrameEnd(); + RD7::Ftrace::End("app", "app_mainloop"); } return 0; diff --git a/rd7tf/source/scene.cpp b/rd7tf/source/scene.cpp index 243ffb6..fa5c028 100644 --- a/rd7tf/source/scene.cpp +++ b/rd7tf/source/scene.cpp @@ -25,27 +25,25 @@ static void Wave(int index, R7Vec2 position, R7Vec2 size, float time, y_position = std::min(y_position, position.y + size.y - (90 - shrink)); if (dbg) - RenderD7::Draw2::TriangleLined( + DV2::TriangleLined( R7Vec2(x_position, y_position), R7Vec2(x_position + 300, y_position + (90 - shrink)), R7Vec2(x_position - 300, y_position + (90 - shrink)), - RenderD7::Color::RGBA(.94f - .17f * color_effect, - .61f - .25f * color_effect, - .36f + .38f * color_effect) + RD7::Color::RGBA(.94f - .17f * color_effect, .61f - .25f * color_effect, + .36f + .38f * color_effect) .toRGBA()); else - RenderD7::Draw2::TriangleSolid( + DV2::TriangleSolid( R7Vec2(x_position, y_position), R7Vec2(x_position + 300, y_position + (90 - shrink)), R7Vec2(x_position - 300, y_position + (90 - shrink)), - RenderD7::Color::RGBA(.94f - .17f * color_effect, - .61f - .25f * color_effect, - .36f + .38f * color_effect) + 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) { - RenderD7::Draw2::RectFilledSolid(position, size, 0xff64c9fd); + DV2::RectFilledSolid(position, size, 0xff64c9fd); int i = 0; for (; i < 44; i++) Wave(i, position, size, time, dbg); } @@ -53,7 +51,7 @@ void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) { R7Vec2 testv2 = R7Vec2(48, 48); Sample::Sample() { - auto t = RenderD7::FileSystem::GetDirContent("sdmc:/music/"); + auto t = RD7::FileSystem::GetDirContent("sdmc:/music/"); for (const auto& it : t) { names.push_back(it.name); files.push_back(it.path); @@ -67,32 +65,32 @@ Sample::~Sample() { void Sample::Draw() const { // Draw Things to Screen: // Step 1 -> Select Screen - RenderD7::OnScreen(Top); + RD7::OnScreen(Top); // Step 2 -> Draw Things // The hbloader Triangle Wave - DrawWave(R7Vec2(0, 0), R7Vec2(400, 240), RenderD7::GetTime(), - debug_background); + DrawWave(R7Vec2(0, 0), R7Vec2(400, 240), RD7::GetTime(), debug_background); // For Example A Rect with Draw2 and StyleColorApi // And the RFS Wrapper for RectFilledSolid lol - /*RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(400, 20), - RenderD7::StyleColor(RD7Color_Header)); + /*DV2::RFS(R7Vec2(0, 0), R7Vec2(400, 20), + RD7::StyleColor(RD7Color_Header)); // As the Top bar is Dark you need TextColor2 - RenderD7::RedirectColor(RD7Color_Text, RD7Color_Text2); - RenderD7::Draw2::Text(R7Vec2(5, 2), "RenderD7 - Test Framework"); - RenderD7::Draw2::Text(R7Vec2(395, 2), RENDERD7VSTRING, + RD7::RedirectColor(RD7Color_Text, RD7Color_Text2); + DV2::Text(R7Vec2(5, 2), "RenderD7 - Test Framework"); + DV2::Text(R7Vec2(395, 2), RENDERD7VSTRING, RD7TextFlags_AlignRight); - RenderD7::UndoColorEdit(RD7Color_Text);*/ + RD7::UndoColorEdit(RD7Color_Text);*/ if (UI7::BeginMenu("RenderD7 Test Framework")) { UI7::SetCursorPos(R7Vec2(395, 2)); - UI7::Label(RenderD7::FormatBytes(RenderD7::Memory::GetCurrent()), + UI7::Label(RD7::FormatBytes(RD7::Memory::GetCurrent()), RD7TextFlags_AlignRight); UI7::RestoreCursor(); if (state == State_Menu) { UI7::Label("Test App"); + UI7::BrowserList(names, sel); } UI7::EndMenu(); } - RenderD7::OnScreen(Bottom); + RD7::OnScreen(Bottom); if (UI7::BeginMenu("Control Center")) { if (state == State_Menu) { if (UI7::Button("RenderD7 Settings")) @@ -116,14 +114,14 @@ void Sample::Draw() const { } void Sample::Logic() { - RenderD7::CustomTextSize(txt_size); + RD7::CustomTextSize(txt_size); for (const auto& it : shared_requests) { if (it.first == 1U) { - if (it.second) RenderD7::LoadSettings(); + if (it.second) RD7::LoadSettings(); } else if (it.first == 2U) { if (it.second) - RenderD7::PushMessage(RenderD7::Message( - "Test Message", "Button Bressed\nBest Msg Handler...")); + RD7::PushMessage(RD7::Message("Test Message", + "Button Bressed\nBest Msg Handler...")); } else if (it.first == 3U) { state = (State)it.second; } diff --git a/rd7tf/source/scene.hpp b/rd7tf/source/scene.hpp index 921fa13..c010a67 100644 --- a/rd7tf/source/scene.hpp +++ b/rd7tf/source/scene.hpp @@ -2,7 +2,7 @@ #include -class Sample : public RenderD7::Scene { +class Sample : public RD7::Scene { public: enum State { State_Menu, diff --git a/source/Color.cpp b/source/Color.cpp index 8f5732a..b62e908 100644 --- a/source/Color.cpp +++ b/source/Color.cpp @@ -5,10 +5,8 @@ #include #include -// This is btw the default theme setup -// RenderD7 StyleColor Api -// not const cause const = error lol -std::map rd7i_color_map = { +// Default Theme +const std::map rd7i_default_theme = { {RD7Color_Text, RGBA8(0, 0, 0, 255)}, {RD7Color_Text2, RGBA8(255, 255, 255, 255)}, // For Background change or so {RD7Color_TextDisabled, RGBA8(170, 170, 170, 255)}, @@ -29,6 +27,10 @@ std::map rd7i_color_map = { {RD7Color_Progressbar, RGBA8(0, 255, 0, 255)}, }; +// RenderD7 StyleColor Api +// not const cause const = error lol +std::map rd7i_color_map = rd7i_default_theme; + std::map rd7i_color_swap_map; unsigned int RenderD7::StyleColor(RD7Color color) { @@ -175,26 +177,7 @@ void RenderD7::ThemeSave(const std::string& path) { file.close(); } -void RenderD7::ThemeDefault() { - rd7i_color_map[RD7Color_Text] = RGBA8(0, 0, 0, 255); - rd7i_color_map[RD7Color_Text2] = RGBA8(255, 255, 255, 255); - rd7i_color_map[RD7Color_TextDisabled] = RGBA8(170, 170, 170, 255); - rd7i_color_map[RD7Color_Background] = RGBA8(238, 238, 238, 255); - rd7i_color_map[RD7Color_Header] = RGBA8(17, 17, 17, 255); - rd7i_color_map[RD7Color_Selector] = RGBA8(34, 34, 34, 255); - rd7i_color_map[RD7Color_SelectorFade] = RGBA8(90, 90, 90, 255); - rd7i_color_map[RD7Color_List0] = RGBA8(204, 204, 204, 255); - rd7i_color_map[RD7Color_List1] = RGBA8(187, 187, 187, 255); - rd7i_color_map[RD7Color_MessageBackground] = RGBA8(51, 51, 51, 255); - rd7i_color_map[RD7Color_Button] = RGBA8(17, 17, 17, 255); - rd7i_color_map[RD7Color_ButtonHovered] = RGBA8(34, 34, 34, 255); - rd7i_color_map[RD7Color_ButtonDisabled] = RGBA8(8, 8, 8, 255); - rd7i_color_map[RD7Color_ButtonActive] = RGBA8(42, 42, 42, 255); - rd7i_color_map[RD7Color_Checkmark] = RGBA8(42, 42, 42, 255); - rd7i_color_map[RD7Color_FrameBg] = RGBA8(85, 85, 85, 255); - rd7i_color_map[RD7Color_FrameBgHovered] = RGBA8(119, 119, 119, 255); - rd7i_color_map[RD7Color_Progressbar] = RGBA8(0, 255, 0, 255); -} +void RenderD7::ThemeDefault() { rd7i_color_map = rd7i_default_theme; } uint32_t RenderD7::Color::Hex(const std::string& color, uint8_t a) { if (color.length() < 7 || diff --git a/source/Error.cpp b/source/Error.cpp index 9ffc6b4..c80d131 100644 --- a/source/Error.cpp +++ b/source/Error.cpp @@ -7,7 +7,7 @@ namespace RenderD7 { void Error(const std::string& msg) { - if (rd7i_graphics_on) { + /*if (rd7i_graphics_on) { C3D_FrameEnd(0); while (aptMainLoop()) { hidScanInput(); @@ -27,18 +27,18 @@ void Error(const std::string& msg) { C3D_FrameEnd(0); } exit(0); - } else { - gfxInitDefault(); - consoleInit(GFX_TOP, NULL); - printf("RENDERD7 - ERROR MANAGER\n\n%s\n", msg.c_str()); - printf("Press Start to Exit\n"); - while (aptMainLoop()) { - hidScanInput(); - if (hidKeysDown() & KEY_START) break; - gfxSwapBuffers(); - } - gfxExit(); - exit(0); + } else {*/ + gfxInitDefault(); + consoleInit(GFX_TOP, NULL); + printf("RENDERD7 - ERROR MANAGER\n\n%s\n", msg.c_str()); + printf("Press Start to Exit\n"); + while (aptMainLoop()) { + hidScanInput(); + if (hidKeysDown() & KEY_START) break; + gfxSwapBuffers(); } + gfxExit(); + exit(0); + // } } } // namespace RenderD7 \ No newline at end of file diff --git a/source/UI7.cpp b/source/UI7.cpp index 920d489..99f69db 100644 --- a/source/UI7.cpp +++ b/source/UI7.cpp @@ -65,6 +65,31 @@ struct UI7ID { int lt; }; +struct UI7OBJ { + UI7OBJ() {} + UI7OBJ(const R7Vec4 &i0, const int &i1) { + box = i0; + type = i1; + s = rd7i_current_screen; + } + void Debug() { + RenderD7::OnScreen(s ? Top : Bottom); + RenderD7::Draw2::TriangleLined(R7Vec2(box.x, box.y), + R7Vec2(box.x + box.z, box.y), + R7Vec2(box.x, box.y + box.w), 0xff0000ff); + RenderD7::Draw2::TriangleLined( + R7Vec2(box.x, box.y + box.w), R7Vec2(box.x + box.z, box.y), + R7Vec2(box.x + box.z, box.y + box.w), 0xff0000ff); + } + R7Vec4 box; + int type; + bool s = false; +}; + +std::vector ui7i_debug_colors{ + 0x00000000, +}; + struct UI7_Ctx { UI7_Ctx() { delta = 0.0f; @@ -76,6 +101,7 @@ struct UI7_Ctx { cbackup = R7Vec2(); in_menu = false; current_menu = UI7ID(""); + debugging = true; } float delta; float time; @@ -85,9 +111,11 @@ struct UI7_Ctx { R7Vec2 cbackup; R7Vec2 slc; bool in_menu; + bool debugging; UI7ID current_menu; std::map grid_mapping; std::unordered_map ids; + std::vector objects; }; UI7_Ctx *ui7_ctx; @@ -127,6 +155,12 @@ void UI7CtxCursorMove(R7Vec2 size) { ui7_ctx->slc += R7Vec2(size.x, 0); } +void UI7CtxRegObj(const UI7OBJ &obj) { + if (!UI7CtxValidate()) return; + if (!ui7_ctx->debugging) return; + ui7_ctx->objects.push_back(obj); +} + UI7ID *UI7CtxNewID(const std::string &i) { std::string t = i; std::transform(t.begin(), t.end(), t.begin(), @@ -195,6 +229,7 @@ void Update() { ui7_ctx->time += ui7_ctx->delta; ui7_ctx->cursor = R7Vec2(); UI7CtxClearIDs(); + if (ui7_ctx->debugging) ui7_ctx->objects.clear(); } float GetTime() { @@ -219,8 +254,7 @@ bool Button(const std::string &label, R7Vec2 size) { } RD7Color btn = RD7Color_Button; R7Vec2 pos = GetCursorPos(); - - UI7CtxCursorMove(size); + UI7CtxRegObj(UI7OBJ(R7Vec4(pos, size), 0)); if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Up) && InBox(RenderD7::Hid::GetLastTouchPosition(), pos, size)) { @@ -237,6 +271,7 @@ bool Button(const std::string &label, R7Vec2 size) { RenderD7::TextColorByBg(btn); RenderD7::Draw2::Text(pos, label); RenderD7::UndoColorEdit(RD7Color_Text); + UI7CtxCursorMove(size); return ret; } @@ -265,8 +300,11 @@ void Checkbox(const std::string &label, bool &c) { if (c == true) { RenderD7::Draw2::RFS(pos + R7Vec2(2, 2), cbs - R7Vec2(4, 4), RenderD7::StyleColor(RD7Color_Checkmark)); + UI7CtxRegObj(UI7OBJ(R7Vec4(pos + R7Vec2(2, 2), cbs - R7Vec2(4, 4)), 2)); } RenderD7::Draw2::Text(pos + R7Vec2(cbs.x + 5, 1), label); + UI7CtxRegObj(UI7OBJ(R7Vec4(pos, cbs + R7Vec2(txtdim.x + 5, 0)), 0)); + UI7CtxRegObj(UI7OBJ(R7Vec4(pos, cbs), 1)); } void Label(const std::string &label, RD7TextFlags flags) { @@ -274,6 +312,11 @@ void Label(const std::string &label, RD7TextFlags flags) { R7Vec2 textdim = RenderD7::GetTextDimensions(label); R7Vec2 pos = GetCursorPos(); float tbh = RenderD7::TextGetSize() * 40; + if (flags & RD7TextFlags_AlignRight) { + UI7CtxRegObj(UI7OBJ(R7Vec4(pos - R7Vec2(textdim.x, 0), textdim), 0)); + } else { + UI7CtxRegObj(UI7OBJ(R7Vec4(pos, textdim), 0)); + } // Remove some y offset cause texts have some offset UI7CtxCursorMove(textdim - R7Vec2(0, 4)); RenderD7::TextColorByBg( @@ -301,6 +344,7 @@ void Image(RenderD7::Image *img) { if (!UI7CtxValidate()) return; R7Vec2 pos = GetCursorPos(); UI7CtxCursorMove(R7Vec2(img->get_size().x, img->get_size().y)); + UI7CtxRegObj(UI7OBJ(R7Vec4(pos, img->get_size()), 0)); RenderD7::Draw2::Image(img, pos); } @@ -414,6 +458,7 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) { } SetCursorPos(R7Vec2(5, tbh + 5)); + return UI7CtxBeginMenu(title); } @@ -488,4 +533,13 @@ void SameLine() { ui7_ctx->cursor = ui7_ctx->slc; } +void Debug() { + if (!UI7CtxValidate()) return; + if (ui7_ctx->debugging) { + for (size_t i = 0; i < ui7_ctx->objects.size(); i++) { + ui7_ctx->objects[i].Debug(); + } + } +} + } // namespace UI7 \ No newline at end of file diff --git a/source/nimg.cpp b/source/nimg.cpp index fd46b72..2bdfdc1 100644 --- a/source/nimg.cpp +++ b/source/nimg.cpp @@ -7,9 +7,9 @@ // Use an Npi simplifier cause I am lazy #define reca_cc(x) reinterpret_cast(x) #define reca_c(x) reinterpret_cast(x) -#define pak32(q, w, e, r) \ - ((((q)&0xff) << 0) | (((w)&0xff) << 8) | (((e)&0xff) << 16) | \ - (((r)&0xff) << 24)) +#define pak32(q, w, e, r) \ + ((((q) & 0xff) << 0) | (((w) & 0xff) << 8) | (((e) & 0xff) << 16) | \ + (((r) & 0xff) << 24)) // Stupid RLE Algorithm void npi_compress(std::vector& ret, diff --git a/source/renderd7.cpp b/source/renderd7.cpp index 2894855..0c59ccd 100644 --- a/source/renderd7.cpp +++ b/source/renderd7.cpp @@ -448,6 +448,7 @@ void RenderD7::FrameEnd() { RenderD7::Ftrace::Beg("rd7oh", f2s(OvlHandler)); OvlHandler(); RenderD7::Ftrace::End("rd7oh", f2s(OvlHandler)); + UI7::Debug(); Npifade(); RenderD7::Ftrace::End("rd7-core", "frame"); C3D_FrameEnd(0); @@ -593,10 +594,10 @@ void RenderD7::RSettings::Draw(void) const { // List Bg for (int i = 0; i < 12; i++) { if ((i % 2 == 0)) - RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i)*15), R7Vec2(400, 15), + RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i) * 15), R7Vec2(400, 15), RenderD7::StyleColor(RD7Color_List0)); else - RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i)*15), R7Vec2(400, 15), + RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i) * 15), R7Vec2(400, 15), RenderD7::StyleColor(RD7Color_List1)); } diff --git a/source/nimg_engine.cpp b/source/swr.cpp similarity index 69% rename from source/nimg_engine.cpp rename to source/swr.cpp index 28f7159..223fa80 100644 --- a/source/nimg_engine.cpp +++ b/source/swr.cpp @@ -1,17 +1,17 @@ #include #include -#include +#include namespace RenderD7 { -NIMG_Engine::NIMG_Engine(int w, int h) { image = RenderD7::nimg(w, h); } -NIMG_Engine::NIMG_Engine() { image = RenderD7::nimg(1, 1); } +swr::swr(int w, int h) { image = RenderD7::nimg(w, h); } +swr::swr() { image = RenderD7::nimg(1, 1); } -NIMG_Engine::~NIMG_Engine() { +swr::~swr() { // Do nothing } -void NIMG_Engine::load_file(const std::string& path) { +void swr::load_file(const std::string& path) { int w, h, c; uint8_t* dat = stbi_load(path.c_str(), &w, &h, &c, 4); image = nimg(w, h); @@ -27,11 +27,11 @@ void NIMG_Engine::load_file(const std::string& path) { stbi_image_free(dat); } -void NIMG_Engine::load_nimg(const std::string& path) { +void swr::load_nimg(const std::string& path) { image = RenderD7::NIMG_Load(path); } -void NIMG_Engine::draw_pixel(int x, int y, unsigned int color) { +void swr::draw_pixel(int x, int y, unsigned int color) { if (x > image.width || x < 0 || y > image.height || y < 0) return; RenderD7::Color::RGBA splitter(color); image.pixel_buffer[((y * image.width + x) * 4) + 0] = splitter.m_r; @@ -40,11 +40,14 @@ void NIMG_Engine::draw_pixel(int x, int y, unsigned int color) { image.pixel_buffer[((y * image.width + x) * 4) + 3] = splitter.m_a; } -void NIMG_Engine::draw_rect(int x, int y, int w, int h, unsigned int color, - int t) {} +void swr::draw_rect(int x, int y, int w, int h, unsigned int color, int t) { + draw_line(x, y, x + w, y, color, t); + draw_line(x, y, x, y + h, color, t); + draw_line(x, y + h, x + w, y + h, color, t); + draw_line(x + w, y + h, x + w, y + h, color, t); +} -void NIMG_Engine::draw_rect_solid(int x, int y, int w, int h, - unsigned int color) { +void swr::draw_rect_solid(int x, int y, int w, int h, unsigned int color) { for (int ix = x; ix < x + w; ix++) { for (int iy = y; iy < y + h; iy++) { draw_pixel(ix, iy, color); @@ -52,7 +55,15 @@ void NIMG_Engine::draw_rect_solid(int x, int y, int w, int h, } } -void NIMG_Engine::flip(bool h, bool v) { +void swr::draw_line(int x1, int y1, int x2, int y2, unsigned int color, int t) { + for (int ix = x1; ix < x2 * t; ix++) { + for (int iy = y1; iy < y2 * t; iy++) { + draw_pixel(ix, iy, color); + } + } +} + +void swr::flip(bool h, bool v) { const nimg _bak = image; if (h) { for (int x = 0; x < image.width; x++) {