From cee671c6825aa8a673a1465647982dcd116a5fbd Mon Sep 17 00:00:00 2001 From: J-D-K Date: Sun, 5 Aug 2018 17:40:25 -0400 Subject: [PATCH] Tweak Nav buttons --- inc/data.h | 3 +++ inc/util.h | 2 +- src/data.cpp | 29 +++++++++++++++++++++++++---- src/gfx.c | 4 ++-- src/ui.cpp | 22 +++++++++++----------- src/ui/clsui.cpp | 4 ++++ src/ui/fldrsel.cpp | 4 ++++ src/ui/kb.cpp | 2 +- src/util.cpp | 10 +++------- 9 files changed, 54 insertions(+), 26 deletions(-) diff --git a/inc/data.h b/inc/data.h index 81d62e1..699f771 100644 --- a/inc/data.h +++ b/inc/data.h @@ -51,6 +51,9 @@ namespace data std::string getTitle() { return title;} std::string getTitleSafe() { return titleSafe; } + //Just for testing to make sure only ASCII folders + void debugCreate(const uint64_t& _id, const std::string& t); + //Returns ID uint64_t getID() { return id; } diff --git a/inc/util.h b/inc/util.h index 3cf6dd0..92cc55b 100644 --- a/inc/util.h +++ b/inc/util.h @@ -29,6 +29,6 @@ namespace util std::string getInfoString(data::user& u, data::titledata& d); - void debugPrintf(const char *format, ...); + void debugPrintf(const char *out); } #endif // UTIL_H diff --git a/src/data.cpp b/src/data.cpp index 1ff15ef..b710e70 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -15,11 +15,17 @@ static struct { bool operator()(data::titledata& a, data::titledata& b) { - for(unsigned i = 0; i < a.getTitle().length(); i++) + uint32_t tmpA, tmpB; + for(unsigned i = 0; i < a.getTitle().length(); ) { - int charA = tolower(a.getTitle().c_str()[i]), charB = tolower(b.getTitle().c_str()[i]); - if(charA != charB) - return charA < charB; + ssize_t uCnt = decode_utf8(&tmpA, (const uint8_t *)&a.getTitle().data()[i]); + decode_utf8(&tmpB, (const uint8_t *)&b.getTitle().data()[i]); + tmpA = tolower(tmpA); + tmpB = tolower(tmpB); + if(tmpA != tmpB) + return tmpA < tmpB; + + i += uCnt; } return false; @@ -228,6 +234,21 @@ namespace data return false; } + //ASCII Testing + void titledata::debugCreate(const uint64_t& _id, const std::string& t) + { + id = _id; + title = t; + + titleSafe = util::safeString(t); + if(titleSafe.empty()) + { + char tmp[18]; + sprintf(tmp, "%016lX", id); + titleSafe.assign(tmp); + } + } + bool user::init(const u128& _id) { Result res = 0; diff --git a/src/gfx.c b/src/gfx.c index c32135d..50938be 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -116,7 +116,7 @@ void drawText(const char *str, tex *target, const font *f, int x, int y, int sz, size_t length = strlen(str); for(unsigned i = 0; i < length; ) { - unitCnt = decode_utf8(&tmpChr, (uint8_t *)&str[i]); + unitCnt = decode_utf8(&tmpChr, (const uint8_t *)&str[i]); if(unitCnt <= 0) break; @@ -152,7 +152,7 @@ size_t textGetWidth(const char *str, const font *f, int sz) size_t length = strlen(str); for(unsigned i = 0; i < length; ) { - untCnt = decode_utf8(&tmpChr, (uint8_t *)&str[i]); + untCnt = decode_utf8(&tmpChr, (const uint8_t *)&str[i]); if(untCnt <= 0) break; diff --git a/src/ui.cpp b/src/ui.cpp index 8e291f0..5dd4773 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -13,7 +13,7 @@ #define TITLE_TEXT "JKSV - 08/05/2018" -//Secret background that can be drawn from "/JKSV/back.jpg" +//background that can be drawn from "/JKSV/back.jpg" static tex *background = NULL; //Nav buttons @@ -164,28 +164,28 @@ namespace ui { //User Select int startX = 848; - ui::button sel("", startX, 672, 110, 32); - ui::button dmp("", startX += 110, 672, 110, 32); - ui::button cls("", startX += 110, 672, 110, 32); + ui::button sel("", startX, 656, 110, 64); + ui::button dmp("", startX += 110, 656, 110, 64); + ui::button cls("", startX += 110, 656, 110, 64); usrNav.push_back(sel); usrNav.push_back(dmp); usrNav.push_back(cls); //Title startX = 914; - ui::button ttlSel("", startX, 672, 110, 32); - ui::button ttlDmp("", startX += 110, 672, 110, 32); - ui::button ttlBck("", startX += 110, 672, 110, 32); + ui::button ttlSel("", startX, 656, 110, 64); + ui::button ttlDmp("", startX += 110, 656, 110, 64); + ui::button ttlBck("", startX += 110, 656, 110, 64); ttlNav.push_back(ttlSel); ttlNav.push_back(ttlDmp); ttlNav.push_back(ttlBck); //Folder. Skip adv since it can't be touch controlled startX = 800; - ui::button fldBackup("", startX, 672, 110, 32); - ui::button fldRestor("", startX += 110, 672, 110, 32); - ui::button fldDelete("", startX += 110, 672, 110, 32); - ui::button fldBack("", startX += 110, 672, 110, 32); + ui::button fldBackup("", startX, 656, 110, 64); + ui::button fldRestor("", startX += 110, 656, 110, 64); + ui::button fldDelete("", startX += 110, 656, 110, 64); + ui::button fldBack("", startX += 110, 672, 110, 64); fldNav.push_back(fldBackup); fldNav.push_back(fldRestor); fldNav.push_back(fldDelete); diff --git a/src/ui/clsui.cpp b/src/ui/clsui.cpp index 7d63117..d7d46d5 100644 --- a/src/ui/clsui.cpp +++ b/src/ui/clsui.cpp @@ -147,6 +147,10 @@ namespace ui if(confirm("Are you sure you want to overwrite \"" + folderName + "\"?")) { std::string toPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/"; + //Delete and recreate + fs::delDir(toPath); + mkdir(toPath.c_str(), 777); + std::string root = "sv:/"; fs::copyDirToDir(root, toPath); diff --git a/src/ui/fldrsel.cpp b/src/ui/fldrsel.cpp index e19f57c..fb2fa1d 100644 --- a/src/ui/fldrsel.cpp +++ b/src/ui/fldrsel.cpp @@ -74,6 +74,10 @@ namespace ui if(confirm("Are you sure you want to overwrite \"" + folderName + "\"?")) { std::string toPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/"; + //Delete and recreate + fs::delDir(toPath); + mkdir(toPath.c_str(), 777); + std::string root = "sv:/"; fs::copyDirToDir(root, toPath); diff --git a/src/ui/kb.cpp b/src/ui/kb.cpp index ae3b7f7..07ca2b8 100644 --- a/src/ui/kb.cpp +++ b/src/ui/kb.cpp @@ -159,7 +159,7 @@ namespace ui } } - for(unsigned i = 41; i < 44; i++) + for(unsigned i = 41; i < 45; i++) keys[i].update(p); //shift diff --git a/src/util.cpp b/src/util.cpp index b4a7615..81c3a41 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -55,7 +55,7 @@ namespace util if(textGetWidth(tmp.c_str(), ui::shared, sz) >= maxWidth) { - tmp.assign(s, first, lastSpace - first); + tmp.assign(s, first, (lastSpace + 1) - first); ret += tmp + "\n"; @@ -169,14 +169,10 @@ namespace util return ret; } - void debugPrintf(const char *format, ...) + void debugPrintf(const char *out) { #ifdef __debug__ - char buff[512]; - va_list args; - va_start(args, format); - vsnprintf(buff, 512, format, args); - va_end(args); + printf("%s", out); #endif } }