From 4433a23609c5b0fd834053eb5d5c66c08bf5fa98 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Sun, 17 Jun 2018 00:51:39 -0400 Subject: [PATCH] Text wrap works now? --- Makefile | 4 ++-- inc/file.h | 1 + inc/gfx.h | 2 +- src/file.cpp | 14 ++++++++++++++ src/main.cpp | 2 +- src/ui.cpp | 12 +++++++----- src/util.cpp | 10 ++++++---- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index ab8e84c..6f56653 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ INCLUDES := inc EXEFS_SRC := exefs_src APP_TITLE := JKSV APP_AUTHOR := JK_ -APP_VERSION := 06/15/2018 +APP_VERSION := 06/17/2018 ROMFS := romfs #--------------------------------------------------------------------------------- @@ -46,7 +46,7 @@ ROMFS := romfs #--------------------------------------------------------------------------------- ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -CFLAGS := -g -Wall -O3 -ffunction-sections \ +CFLAGS := -g -Wall -O2 -ffunction-sections \ $(ARCH) $(DEFINES) CFLAGS += $(INCLUDE) -D__SWITCH__ `freetype-config --cflags` diff --git a/inc/file.h b/inc/file.h index cfcc079..f671fa6 100644 --- a/inc/file.h +++ b/inc/file.h @@ -27,6 +27,7 @@ namespace fs { public: dirList(const std::string& _path); + void reassign(const std::string& _path); void rescan(); std::string getItem(int index); diff --git a/inc/gfx.h b/inc/gfx.h index 7141adb..9bcdd06 100644 --- a/inc/gfx.h +++ b/inc/gfx.h @@ -20,7 +20,7 @@ namespace gfx //Blends two pixels. Clr is the color to be drawn. FB should be the framebuffer pixel uint32_t blend(const uint32_t& clr, const uint32_t& fb); - //Draws text using shared font. No alpha blending yet. + //Draws text using shared font. void drawText(const std::string& str, unsigned x, unsigned y, const uint32_t& sz, const uint32_t& clr); //Returns width of str diff --git a/src/file.cpp b/src/file.cpp index 6990f40..745f5fc 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -55,6 +55,20 @@ namespace fs closedir(d); } + void dirList::reassign(const std::string& _path) + { + path = _path; + + d = opendir(path.c_str()); + + while((ent = readdir(d))) + { + item.push_back(ent->d_name); + } + + closedir(d); + } + void dirList::rescan() { item.clear(); diff --git a/src/main.cpp b/src/main.cpp index 24405aa..7eff942 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,7 @@ int main(int argc, const char *argv[]) break; gfx::clearBufferColor(0x3B3B3BFF); - gfx::drawText("JKSV - 6/15/2018", 16, 16, 64, 0xFFFFFFFF); + gfx::drawText("JKSV - 6/17/2018", 16, 16, 64, 0xFFFFFFFF); gfx::drawRectangle(16, 64, 1248, 1, 0xFFFFFFFF); gfx::drawRectangle(448, 64, 1, 592, 0xFFFFFFFF); gfx::drawRectangle(16, 656, 1248, 1, 0xFFFFFFFF); diff --git a/src/ui.cpp b/src/ui.cpp index 3a5e728..3b7f491 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -687,8 +687,6 @@ namespace ui { if(folderMenu.getSelected() > 0) { - fs::delDir("sv:/"); - std::string scanPath = util::getTitleDir(data::curUser, data::curData); fs::dirList list(scanPath); @@ -703,7 +701,7 @@ namespace ui } } else - ui::showMessage("NEIN! NEIN! NEIN!"); + ui::showMessage("Writing data to system save data is not allowed currently. It CAN brick your system."); } else if(down & KEY_X) { @@ -800,6 +798,7 @@ namespace ui void showMessage(const std::string& mess) { button ok("OK (A)", 480, 464, 320, 96); + std::string wrapMess = util::getWrappedString(mess, 48, 752); while(true) { hidScanInput(); @@ -812,7 +811,7 @@ namespace ui break; gfx::drawRectangle(256, 128, 768, 464, 0xC0C0C0FF); - gfx::drawText(mess, 272, 144, 48, 0x000000FF); + gfx::drawText(wrapMess, 272, 144, 48, 0x000000FF); ok.draw(); gfx::handleBuffs(); @@ -823,6 +822,7 @@ namespace ui { button ok("OK (A)", 480, 464, 320, 96); char tmp[512]; + std::string wrapMess = util::getWrappedString(mess, 48, 752); sprintf(tmp, "%s\n0x%08X", mess.c_str(), (unsigned)r); while(true) @@ -851,6 +851,8 @@ namespace ui button yes("Yes (A)", 288, 464, 320, 96); button no("No (B)", 672, 464, 320, 96); + std::string wrapMess = util::getWrappedString(mess, 48, 752); + while(true) { hidScanInput(); @@ -871,7 +873,7 @@ namespace ui } gfx::drawRectangle(256, 128, 768, 464, 0xC0C0C0FF); - gfx::drawText(mess, 272, 144, 48, 0x000000FF); + gfx::drawText(wrapMess, 272, 144, 48, 0x000000FF); yes.draw(); no.draw(); diff --git a/src/util.cpp b/src/util.cpp index 0f5418c..96e4206 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -56,14 +56,16 @@ namespace util { tmp.assign(s, first, lastSpace - first); - first = lastSpace + 1; ret += tmp + "\n"; - tmp.assign(s, first, i); + first = lastSpace + 1; + i = lastSpace; + + tmp.clear(); } - else if(i == s.length() - 1 && gfx::getTextWidth(tmp, sz) < maxWidth) - ret += tmp; } + if(!tmp.empty()) + ret += tmp; return ret; }