diff --git a/clang-format.py b/clang-format.py index 7289ec1..34f8879 100644 --- a/clang-format.py +++ b/clang-format.py @@ -18,12 +18,10 @@ def fmt_dir(path): print('Formatting...') fmt_dir('source') -fmt_dir('source/music') fmt_dir('include') fmt_dir('include/renderd7') -fmt_dir('include/renderd7/music') # Format LE and TF as well fmt_dir('rd7tf/source') -fmt_dir('rd7le/source') +#fmt_dir('rd7le/source') print('Done') \ No newline at end of file diff --git a/include/renderd7/Hardware.hpp b/include/renderd7/Hardware.hpp index b7b3b41..b0c896e 100644 --- a/include/renderd7/Hardware.hpp +++ b/include/renderd7/Hardware.hpp @@ -29,13 +29,16 @@ bool IsHeadphones(); /// @return true if System gets Charged bool IsCharging(); /// @brief Check the Battery Percentage -/// @return Persentage as float -float GetBatteryPercentage(); +/// @return Persentage as int +int GetBatteryPercentage(); /// @brief Get current State of 3d Slider /// @return current 3dslider poition float Get3dSliderLevel(); /// @brief Get Current state of Sound Slider /// @return current SoundSlider state float GetSoundSliderLevel(); +/// @brief Get Current Wifi Level +/// @return current wifi level +int GetWifiLevel(); } // namespace Hardware } // namespace RenderD7 \ No newline at end of file diff --git a/include/renderd7/Image.hpp b/include/renderd7/Image.hpp index 25b332f..b017bdb 100644 --- a/include/renderd7/Image.hpp +++ b/include/renderd7/Image.hpp @@ -30,6 +30,8 @@ namespace RenderD7 { class Image { public: Image() = default; + Image(C2D_Image img) { this->img = img; } + Image(const std::string& path) { this->Load(path); } ~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 f13d261..2b0ef31 100644 --- a/include/renderd7/Render2.hpp +++ b/include/renderd7/Render2.hpp @@ -80,7 +80,7 @@ class R2Base { void SetTextSize(float szs); void DefaultTextSize(); float GetTextSize(); - + R7Vec2 GetCurrentScreenSize(); // Processing void Process(); R7Vec2 GetTextDimensions(const std::string& text); diff --git a/include/renderd7/Sheet.hpp b/include/renderd7/Sheet.hpp index eaf6492..8027db6 100644 --- a/include/renderd7/Sheet.hpp +++ b/include/renderd7/Sheet.hpp @@ -31,6 +31,7 @@ class Sheet { public: /// @brief Constructor Sheet() = default; + Sheet(const std::string& path) { this->Load(path); } /// @brief Deconstructor ~Sheet() { if (spritesheet) Free(); @@ -42,7 +43,7 @@ class Sheet { Result Load(const std::string& path); /// @brief Unload the Sheet void Free(); - Image::Ref GetImage(int idx); + C2D_Image GetImage(int idx); C2D_SpriteSheet Get() { return this->spritesheet; } private: diff --git a/include/renderd7/UI7.hpp b/include/renderd7/UI7.hpp index 0963cd0..c1668fb 100644 --- a/include/renderd7/UI7.hpp +++ b/include/renderd7/UI7.hpp @@ -103,11 +103,11 @@ 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(); -} +// All of them return the Main BG DrawList if Menu is null +UI7DrawList::Ref GetBackgroundList(); +UI7DrawList::Ref GetList(); +UI7DrawList::Ref GetForegroundList(); +} // namespace Menu // DrawLists UI7DrawList::Ref GetForegroundList(); UI7DrawList::Ref GetBackgroundList(); diff --git a/source/Hardware.cpp b/source/Hardware.cpp index b4011c0..c6c9f51 100644 --- a/source/Hardware.cpp +++ b/source/Hardware.cpp @@ -48,10 +48,10 @@ bool RenderD7::Hardware::IsCharging() { return (var == 0x01 ? true : false); } -float RenderD7::Hardware::GetBatteryPercentage() { - uint8_t percentLevel; - PTMU_GetBatteryLevel(&percentLevel); - return (float)percentLevel / 100; +int RenderD7::Hardware::GetBatteryPercentage() { + uint8_t percentLevel = 0; + MCUHWC_GetBatteryLevel(&percentLevel); + return percentLevel; } float RenderD7::Hardware::Get3dSliderLevel() { return osGet3DSliderState(); } @@ -60,4 +60,6 @@ float RenderD7::Hardware::GetSoundSliderLevel() { uint8_t percentLevel; MCUHWC_GetSoundSliderLevel(&percentLevel); return (float)percentLevel / 100; -} \ No newline at end of file +} + +int RenderD7::Hardware::GetWifiLevel() { return osGetWifiStrength(); } \ No newline at end of file diff --git a/source/Image.cpp b/source/Image.cpp index e1b19df..6b8ef37 100644 --- a/source/Image.cpp +++ b/source/Image.cpp @@ -137,8 +137,8 @@ void Image::Load(const std::string &path) { 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); _rd7i_logger()->Write(RenderD7::FormatString("Created Texture (%d, %d)", tex->width, tex->height)); @@ -149,8 +149,8 @@ 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, subtex}; diff --git a/source/Overlays.cpp b/source/Overlays.cpp index dfcd267..b6e9932 100644 --- a/source/Overlays.cpp +++ b/source/Overlays.cpp @@ -57,7 +57,7 @@ std::vector keyboard_layout_num{ {"0", R7Vec2(5, 213), R7Vec2(74, 24), 0}, {".", R7Vec2(81, 213), R7Vec2(36, 24), 0}, // additional actions - {"bksp", R7Vec2(119, 135), R7Vec2(74, 24), 2}, + {"<---", R7Vec2(119, 135), R7Vec2(74, 24), 2}, //{"", R7Vec2(119, 161), R7Vec2(74, 24), 0}, {"Confirm", R7Vec2(119, 187), R7Vec2(74, 24), 5}, {"Cancel", R7Vec2(119, 213), R7Vec2(74, 24), 4}, @@ -78,7 +78,7 @@ std::vector keyboard_layout = { {"0", R7Vec2(205, 137), R7Vec2(18, 18), 0}, {"-", R7Vec2(225, 137), R7Vec2(18, 18), 0}, {"=", R7Vec2(245, 137), R7Vec2(18, 18), 0}, - {"Bksp", R7Vec2(265, 137), R7Vec2(50, 18), 2}, + {"<---", R7Vec2(265, 137), R7Vec2(50, 18), 2}, // 2nd row {"Tab", R7Vec2(5, 157), R7Vec2(40, 18), 6}, {"q", R7Vec2(47, 157), R7Vec2(18, 18), 0}, @@ -148,7 +148,7 @@ std::vector keyboard_layout_caps = { {"0", R7Vec2(205, 137), R7Vec2(18, 18), 0}, {"-", R7Vec2(225, 137), R7Vec2(18, 18), 0}, {"=", R7Vec2(245, 137), R7Vec2(18, 18), 0}, - {"Bksp", R7Vec2(265, 137), R7Vec2(50, 18), 2}, + {"<---", R7Vec2(265, 137), R7Vec2(50, 18), 2}, // 2nd row {"Tab", R7Vec2(5, 157), R7Vec2(40, 18), 6}, {"Q", R7Vec2(47, 157), R7Vec2(18, 18), 0}, @@ -218,7 +218,7 @@ std::vector keyboard_layout_shift = { {")", R7Vec2(205, 137), R7Vec2(18, 18), 0}, {"_", R7Vec2(225, 137), R7Vec2(18, 18), 0}, {"+", R7Vec2(245, 137), R7Vec2(18, 18), 0}, - {"Bksp", R7Vec2(265, 137), R7Vec2(50, 18), 2}, + {"<---", R7Vec2(265, 137), R7Vec2(50, 18), 2}, // 2nd row {"Tab", R7Vec2(5, 157), R7Vec2(40, 18), 6}, {"Q", R7Vec2(47, 157), R7Vec2(18, 18), 0}, diff --git a/source/Render2.cpp b/source/Render2.cpp index 7ef34bc..a777b91 100644 --- a/source/Render2.cpp +++ b/source/Render2.cpp @@ -79,6 +79,10 @@ std::string R2Base::WrapText(const std ::string& in, int maxlen) { return out; } +R7Vec2 R2Base::GetCurrentScreenSize() { + return R7Vec2(this->current_screen == R2Screen_Bottom ? 320 : 400, 240); +} + // Main Processing of Draw Calls void R2Base::Process() { for (auto& it : this->commands) { @@ -90,16 +94,16 @@ void R2Base::Process() { 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->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); + 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, - 0.5f); + 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); @@ -107,12 +111,12 @@ void R2Base::Process() { } 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, + 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, 0.5f); - 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, - 0.5f); + 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); diff --git a/source/Sheet.cpp b/source/Sheet.cpp index 5e4c926..3ce6928 100644 --- a/source/Sheet.cpp +++ b/source/Sheet.cpp @@ -34,9 +34,7 @@ void RenderD7::Sheet::Free() { this->spritesheet = nullptr; } -RenderD7::Image::Ref RenderD7::Sheet::GetImage(int idx) { - if (!this->spritesheet) return nullptr; - Image::Ref img = Image::New(); - img->GetRef() = C2D_SpriteSheetGetImage(this->spritesheet, idx); - return img; +C2D_Image RenderD7::Sheet::GetImage(int idx) { + if (!this->spritesheet) return {nullptr, nullptr}; + return C2D_SpriteSheetGetImage(this->spritesheet, idx); } \ No newline at end of file diff --git a/source/UI7.cpp b/source/UI7.cpp index 094e8da..d1cca0f 100644 --- a/source/UI7.cpp +++ b/source/UI7.cpp @@ -179,6 +179,7 @@ class DrawCmd { R7Vec2(rect.x + szs.x, rect.y), R7Vec2(rect.x, rect.y + szs.y), 0xff00ffff); } else if (stype == DrawCmdType_Image) { + if (!img) return; rect.z = img->GetSize().x; rect.w = img->GetSize().y; RenderD7::R2()->DrawNextLined(); @@ -324,6 +325,7 @@ void UI7DrawList::AddDebugCall(std::shared_ptr cmd) { dcmd->text = cmd->text; dcmd->text_box = cmd->text_box; dcmd->text_flags = cmd->text_flags; + dcmd->img = cmd->img; dcmd->type = DrawCmdType_Debug; dcmd->screen = RenderD7::R2()->GetCurrentScreen(); UI7CtxPushDebugCmd(dcmd); @@ -351,9 +353,11 @@ struct UI7Menu { UI7DrawList::Ref main; UI7DrawList::Ref front; - R7Vec2 ms; // Max Size - R7Vec2 msr; // Max Size Real (Slider) - R7Vec2 mdp; // Mouse/Touch Initial pos + R7Vec2 ms; // Max Size + R7Vec2 msr; // Max Size Real (Slider) + R7Vec2 mdp; // Mouse/Touch Initial pos + R7Vec2 bslp; // Before SameLine Pos + R7Vec2 lszs; // Last Size // For Smart Pointer RD7_SMART_CTOR(UI7Menu) }; @@ -426,13 +430,22 @@ void UI7CtxEndMenu() { ui7_ctx->cm->show_scroolbar = (ui7_ctx->cm->ms.y < 235 ? false : true); if (ui7_ctx->cm->show_scroolbar) { - int sw = (RenderD7::R2()->GetCurrentScreen() ? 400 : 320); + // Screen Width + int sw = RenderD7::R2()->GetCurrentScreenSize().x; + // Top Start Pos int tsp = 5 + ui7_ctx->cm->tbh; + // Slider Width + int slider_w = 4; + // Height of Slider int szs = 240 - tsp - 5; + // Lowest Height of Slider Obj int lszs = 20; // Lowest Slider size + // Calculate Slider Height float slider_h = (szs - 4) * (static_cast(szs - 4) / static_cast(ui7_ctx->cm->msr.y)); + // Create Real Slider Height int slider_rh = d7min(d7max(slider_h, (float)lszs), (float)(szs - 4)); + // Calculate Slider Position int slider_pos = d7min( static_cast(tsp + szs - slider_rh - 4), d7max(static_cast(tsp), @@ -441,7 +454,7 @@ void UI7CtxEndMenu() { (szs) * (static_cast(ui7_ctx->cm->scrolling_offset) / static_cast(ui7_ctx->cm->msr.y))))); - int slider_w = 4; + // Render Slider ui7_ctx->cm->front->AddRectangle( R7Vec2(sw - 12, tsp), R7Vec2(slider_w * 2, szs), RD7Color_List0); ui7_ctx->cm->front->AddRectangle(R7Vec2(sw - 10, slider_pos + 2), @@ -457,9 +470,15 @@ void UI7CtxEndMenu() { void UI7CtxCursorMove(R7Vec2 size) { if (!UI7CtxValidate()) return; if (!UI7CtxInMenu()) return; + ui7_ctx->cm->lszs = size; ui7_ctx->cm->slc = ui7_ctx->cm->cursor + R7Vec2(size.x + 5, 0); ui7_ctx->cm->cursor.x = 5; - ui7_ctx->cm->cursor += R7Vec2(0, size.y + 5); + if (ui7_ctx->cm->bslp.y) { + ui7_ctx->cm->cursor += R7Vec2(0, ui7_ctx->cm->bslp.y + 5); + ui7_ctx->cm->bslp = R7Vec2(); + } else { + ui7_ctx->cm->cursor += R7Vec2(0, size.y + 5); + } ui7_ctx->cm->ms = R7Vec2(ui7_ctx->cm->slc.x, ui7_ctx->cm->cursor.y); // TODO: Correct that calculation ui7_ctx->cm->msr = R7Vec2(ui7_ctx->cm->slc.x, ui7_ctx->cm->slc.y - 10); @@ -637,8 +656,8 @@ void Label(const std::string &label, RD7TextFlags flags) { void Progressbar(float value) { if (!UI7CtxValidate()) return; R7Vec2 pos = GetCursorPos(); - R7Vec2 size = R7Vec2( - (RenderD7::R2()->GetCurrentScreen() ? 400 : 320) - (pos.x * 2), 20); + R7Vec2 size = + R7Vec2(RenderD7::R2()->GetCurrentScreenSize().x - (pos.x * 2), 20); if (ui7_ctx->cm->show_scroolbar && ui7_ctx->cm->enable_scrolling) size.x -= 16; UI7CtxCursorMove(size); @@ -688,7 +707,7 @@ void BrowserList(const std::vector &entrys, int &selection, R7Vec2 pos = GetCursorPos(); if (pos.y + 15 * max_entrys > 230) max_entrys = (int)((230 - pos.y) / 15); if (size.x == 0) - size.x = (RenderD7::R2()->GetCurrentScreen() ? 400 : 320) - (pos.x * 2); + size.x = RenderD7::R2()->GetCurrentScreenSize().x - (pos.x * 2); if (size.y == 0) size.y = (max_entrys * 15); UI7CtxCursorMove(size); ui7_ctx->cm->ctrl->AddObj(); @@ -1146,6 +1165,7 @@ void SameLine() { if (!UI7CtxValidate()) return; if (!UI7CtxInMenu()) return; ui7_ctx->cm->ctrl->NewRow(); + ui7_ctx->cm->bslp = ui7_ctx->cm->lszs; ui7_ctx->cm->cursor = ui7_ctx->cm->slc; } @@ -1184,19 +1204,19 @@ UI7DrawList::Ref GetBackgroundList() { UI7DrawList::Ref Menu::GetBackgroundList() { if (!UI7CtxValidate()) return nullptr; - if(!UI7CtxInMenu()) return ui7_ctx->bdl; + 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; + 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; + 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 b321d1c..609fc12 100644 --- a/source/renderd7.cpp +++ b/source/renderd7.cpp @@ -387,6 +387,8 @@ Result RenderD7::Init::Main(std::string app_name) { rd7i_is_am_init = true; } + Hardware::Initialisize(); + C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); atexit(C3D_Fini); C2D_Init((size_t)rd7_max_objects); @@ -442,6 +444,8 @@ Result RenderD7::Init::Minimal(std::string app_name) { rd7i_is_am_init = true; } + Hardware::Initialisize(); + osSetSpeedupEnable(true); C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); atexit(C3D_Fini);