Skip to content

Commit a2c32c2

Browse files
committed
Updated wrapping
1 parent fd738c9 commit a2c32c2

File tree

9 files changed

+100
-69
lines changed

9 files changed

+100
-69
lines changed

inc/gfx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace gfx
1515
void frameStartBot();
1616

1717
void drawText(const std::string& str, const int& x, const int& y, const uint32_t& clr);
18+
void drawTextWrap(const std::string& str, const int& x, int y, const int& maxWidth, const uint32_t& clr);
1819
void drawU16Text(const std::u16string& str, const int& x, const int& y, const uint32_t& clr);
1920
size_t getTextWidth(const std::string& str);
2021
}

inc/ui/menu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ namespace ui
1010
{
1111
public:
1212
void addOpt(const std::string& add, int maxWidth);
13+
void editOpt(int ind, const std::string& ch){ opt[ind] = ch; }
1314
void multiSet(const bool& s);
1415
bool multiIsSet(int ind){ return multiSel[ind]; }
1516
void reset();
17+
void adjust();
1618
void setSelected(const int& newSel);
1719

1820
void handleInput(const uint32_t& down, const uint32_t& held);

src/fs.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ namespace fs
410410
}
411411

412412
uint8_t *buff = new uint8_t[buff_size];
413-
std::string copyString = "Copying " + util::toUtf8(from) + "...";
414-
//copyString = util::getWrappedString(copyString, 224);
413+
std::string copyString = "Copying '" + util::toUtf8(from) + "'...";
415414
ui::progressBar prog((uint32_t)in.getSize());
416415
do
417416
{
@@ -492,8 +491,7 @@ namespace fs
492491
}
493492

494493
uint8_t *buff = new uint8_t[buff_size];
495-
std::string copyString = "Copying " + util::toUtf8(from) + "...";
496-
//copyString = util::getWrappedString(copyString, 224);
494+
std::string copyString = "Copying '" + util::toUtf8(from) + "'...";
497495
ui::progressBar prog(in.getSize());
498496
do
499497
{
@@ -561,7 +559,7 @@ namespace fs
561559
ui::progressBar prog(data::titles.size());
562560
for(unsigned i = 0; i < data::titles.size(); i++)
563561
{
564-
std::string copyStr = "Working on \"" + util::toUtf8(data::titles[i].getTitle()) + "\"...";
562+
std::string copyStr = "Working on '" + util::toUtf8(data::titles[i].getTitle()) + "'...";
565563
prog.update(i);
566564

567565
//Sue me

src/gfx.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,55 @@ namespace gfx
5757
void drawText(const std::string& str, const int& x, const int& y, const uint32_t& clr)
5858
{
5959
C2D_Text tmpTxt;
60-
C2D_TextBuf tmpBuf = C2D_TextBufNew(1024);
60+
C2D_TextBuf tmpBuf = C2D_TextBufNew(512);
6161

6262
C2D_TextParse(&tmpTxt, tmpBuf, str.c_str());
6363
C2D_TextOptimize(&tmpTxt);
64-
C2D_DrawText(&tmpTxt, C2D_WithColor, (float)x, (float) y, 0.5f, 0.5f, 0.5f, clr);
64+
C2D_DrawText(&tmpTxt, C2D_WithColor, (float)x, (float)y, 0.5f, 0.5f, 0.5f, clr);
65+
C2D_TextBufDelete(tmpBuf);
66+
}
67+
68+
void drawTextWrap(const std::string& str, const int& x, int y, const int& maxWidth, const uint32_t& clr)
69+
{
70+
C2D_Text tmpTxt;
71+
C2D_TextBuf tmpBuf = C2D_TextBufNew(512);
72+
73+
int tmpX = x;
74+
for(int i = 0; i < (int)str.length(); )
75+
{
76+
size_t nextBreak = str.find_first_of(" /", i, 2);
77+
if(nextBreak == str.npos)
78+
{
79+
C2D_TextParse(&tmpTxt, tmpBuf, str.substr(i, str.length() - i).c_str());
80+
C2D_TextOptimize(&tmpTxt);
81+
C2D_DrawText(&tmpTxt, C2D_WithColor, (float)tmpX, (float)y, 0.5f, 0.5f, 0.5f, clr);
82+
break;
83+
}
84+
else
85+
{
86+
std::string temp = str.substr(i, (nextBreak + 1) - i);
87+
size_t width = getTextWidth(temp);
88+
if((int)(tmpX + width) >= maxWidth)
89+
{
90+
tmpX = x;
91+
y += 12;
92+
}
93+
94+
C2D_TextParse(&tmpTxt, tmpBuf, temp.c_str());
95+
96+
C2D_TextOptimize(&tmpTxt);
97+
C2D_DrawText(&tmpTxt, C2D_WithColor, (float)tmpX, (float)y, 0.5f, 0.5f, 0.5f, clr);
98+
tmpX += width;
99+
i += temp.length();
100+
}
101+
}
65102
C2D_TextBufDelete(tmpBuf);
66103
}
67104

68105
void drawU16Text(const std::u16string& str, const int& x, const int& y, const uint32_t& clr)
69106
{
70107
C2D_Text tmpTxt;
71-
C2D_TextBuf tmpBuf = C2D_TextBufNew(1024);
108+
C2D_TextBuf tmpBuf = C2D_TextBufNew(512);
72109

73110
std::string tmp = util::toUtf8(str);
74111

@@ -82,10 +119,9 @@ namespace gfx
82119
{
83120
float ret = 0;
84121
C2D_Text tmpTxt;
85-
C2D_TextBuf tmpBuf = C2D_TextBufNew(1024);
122+
C2D_TextBuf tmpBuf = C2D_TextBufNew(512);
86123

87124
C2D_TextParse(&tmpTxt, tmpBuf, str.c_str());
88-
C2D_TextOptimize(&tmpTxt);
89125

90126
C2D_TextGetDimensions(&tmpTxt, 0.5f, 0.5f, &ret, NULL);
91127
C2D_TextBufDelete(tmpBuf);

src/ui.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace ui
2424
titleMenu.multiSet(true);
2525
for(unsigned i = 0; i < data::titles.size(); i++)
2626
titleMenu.addOpt(util::toUtf8(data::titles[i].getTitle()), 320);
27+
28+
titleMenu.adjust();
2729
}
2830

2931
void loadNandMenu()
@@ -108,7 +110,7 @@ namespace ui
108110

109111
gfx::frameBegin();
110112
gfx::frameStartTop();
111-
drawTopBar("JKSM - 08/16/2018");
113+
drawTopBar("JKSM - 08/18/2018");
112114
mainMenu.draw(40, 82, 0xFFFFFFFF, 320);
113115
gfx::frameStartBot();
114116
gfx::frameEnd();
@@ -149,7 +151,7 @@ namespace ui
149151
}
150152
else if(down & KEY_X || bl.getEvent() == BUTTON_RELEASED)
151153
{
152-
std::string confString = "Are you sure you want to add " + util::toUtf8(data::titles[titleMenu.getSelected()].getTitle()) + " to the blacklist?";
154+
std::string confString = "Are you sure you want to add '" + util::toUtf8(data::titles[titleMenu.getSelected()].getTitle()) + "' to the blacklist?";
153155
if(confirm(confString))
154156
data::blacklistAdd(data::titles[titleMenu.getSelected()]);
155157
}
@@ -228,6 +230,8 @@ namespace ui
228230

229231
for(unsigned i = 0; i < bakDir.getCount(); i++)
230232
folderMenu.addOpt(util::toUtf8(bakDir.getItem(i)), 320);
233+
234+
folderMenu.adjust();
231235
}
232236

233237
void stateBackupMenu(const uint32_t& down, const uint32_t& held)
@@ -269,7 +273,7 @@ namespace ui
269273

270274
case 3:
271275
{
272-
std::string confStr = "Are you 100% sure you want to delete the currently saved Extra Data for \"" + util::toUtf8(data::curData.getTitle()) + "\"?";
276+
std::string confStr = "Are you 100% sure you want to delete the currently saved Extra Data for '" + util::toUtf8(data::curData.getTitle()) + "'?";
273277
if(confirm(confStr))
274278
{
275279
FS_ExtSaveDataInfo del = { MEDIATYPE_SD, 0, 0, data::curData.getExtData(), 0 };
@@ -409,7 +413,7 @@ namespace ui
409413
sel--;
410414

411415
fs::dirList titleDir(fs::getSDMCArch(), util::createPath(data::curData, fs::getSaveMode()));
412-
std::string confStr = "Are you sure you want to overwrite \"" + util::toUtf8(titleDir.getItem(sel)) + "\"?";
416+
std::string confStr = "Are you sure you want to overwrite '" + util::toUtf8(titleDir.getItem(sel)) + "'?";
413417
if(ui::confirm(confStr))
414418
{
415419
std::u16string fullPath = util::createPath(data::curData, fs::getSaveMode()) + titleDir.getItem(sel);
@@ -429,7 +433,7 @@ namespace ui
429433
{
430434
sel--;
431435
fs::dirList titleDir(fs::getSDMCArch(), util::createPath(data::curData, fs::getSaveMode()));
432-
std::string confStr = "Are you sure you want to restore \"" + util::toUtf8(titleDir.getItem(sel)) + "\"?";
436+
std::string confStr = "Are you sure you want to restore '" + util::toUtf8(titleDir.getItem(sel)) + "'?";
433437
if(confirm(confStr))
434438
{
435439
std::u16string restPath = util::createPath(data::curData, fs::getSaveMode()) + titleDir.getItem(sel) + util::toUtf16("/");
@@ -445,7 +449,7 @@ namespace ui
445449
{
446450
sel--;
447451
fs::dirList titleDir(fs::getSDMCArch(), util::createPath(data::curData, fs::getSaveMode()));
448-
std::string confStr = "Are you sure you want to delete \"" + util::toUtf8(titleDir.getItem(sel)) + "\"?";
452+
std::string confStr = "Are you sure you want to delete '" + util::toUtf8(titleDir.getItem(sel)) + "'?";
449453
if(confirm(confStr))
450454
{
451455
std::u16string delPath = util::createPath(data::curData, fs::getSaveMode()) + titleDir.getItem(sel);
@@ -563,7 +567,6 @@ namespace ui
563567

564568
void showMessage(const std::string& mess)
565569
{
566-
std::string disp = util::getWrappedString(mess, 224);
567570
while(1)
568571
{
569572
hidScanInput();
@@ -576,7 +579,7 @@ namespace ui
576579
gfx::frameBegin();
577580
gfx::frameStartBot();
578581
C2D_DrawRectSolid(8, 8, 0.5f, 304, 224, 0xFFE7E7E7);
579-
gfx::drawText(disp, 16, 16,0xFF000000);
582+
gfx::drawTextWrap(mess, 16, 16, 224, 0xFF000000);
580583
gfx::frameEnd();
581584
}
582585
}
@@ -599,13 +602,11 @@ namespace ui
599602
C2D_DrawRectSolid(8, 8, 0.5f, 304, 224, 0xFFE7E7E7);
600603
C2D_DrawRectSolid(16, 200, 0.5f, 288, 16, 0xFF000000);
601604
C2D_DrawRectSolid(16, 200, 0.5f, width, 16, 0xFF00FF00);
602-
gfx::drawText(text, 16, 16, 0xFF000000);
605+
gfx::drawTextWrap(text, 16, 16, 224, 0xFF000000);
603606
}
604607

605608
bool confirm(const std::string& mess)
606609
{
607-
std::string wrapped = util::getWrappedString(mess, 288);
608-
609610
button yes("Yes (A)", 16, 192, 128, 32);
610611
button no("No (B)", 176, 192, 128, 32);
611612

@@ -629,7 +630,7 @@ namespace ui
629630
gfx::frameBegin();
630631
gfx::frameStartBot();
631632
C2D_DrawRectSolid(8, 8, 0.5f, 304, 224, 0xFFF4F4F4);
632-
gfx::drawText(wrapped, 16, 16, 0xFF000000);
633+
gfx::drawTextWrap(mess, 16, 16, 224, 0xFF000000);
633634
yes.draw();
634635
no.draw();
635636
gfx::frameEnd();

src/ui/adv.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool confirmTransfer(const std::u16string& from, const std::u16string& to, int w
3939
break;
4040
}
4141

42-
std::string conf = "Are you sure you want to copy \"" + fromDrive + util::toUtf8(from) + "\" to \"" + toDrive + util::toUtf8(to) + "\"?";
42+
std::string conf = "Are you sure you want to copy '" + fromDrive + util::toUtf8(from) + "' to '" + toDrive + util::toUtf8(to) + "'?";
4343

4444
return ui::confirm(conf);
4545
}
@@ -58,7 +58,7 @@ bool confirmDelete(const std::u16string& del, int way)
5858
break;
5959
}
6060

61-
std::string conf = "Are you sure you want to delete \"" + drive + util::toUtf8(del) + "\"?";
61+
std::string conf = "Are you sure you want to delete '" + drive + util::toUtf8(del) + "'?";
6262
return ui::confirm(conf);
6363
}
6464

@@ -109,7 +109,10 @@ void performCopyOps()
109109
if(sdMenu.getSelected() == 0)
110110
{
111111
if(confirmTransfer(sdPath, savePath, SD_TO_ARCH))
112+
{
112113
fs::copyDirToArch(fs::getSaveArch(), sdPath, savePath);
114+
fs::commitData(fs::getSaveMode());
115+
}
113116
}
114117
else if(sdMenu.getSelected() > 1)
115118
{
@@ -134,6 +137,7 @@ void performCopyOps()
134137
if(confirmTransfer(fromPath, toPath, SD_TO_ARCH))
135138
fs::copyFileToArch(fs::getSaveArch(), fromPath, toPath);
136139
}
140+
fs::commitData(fs::getSaveMode());
137141
}
138142
}
139143
break;
@@ -220,6 +224,8 @@ void performCopyOps()
220224
FSUSER_RenameDirectory(fs::getSaveArch(), fsMakePath(PATH_UTF16, oldPath.data()), fs::getSaveArch(), fsMakePath(PATH_UTF16, newPath.data()));
221225
else
222226
FSUSER_RenameFile(fs::getSaveArch(), fsMakePath(PATH_UTF16, oldPath.data()), fs::getSaveArch(), fsMakePath(PATH_UTF16, newPath.data()));
227+
228+
fs::commitData(fs::getSaveMode());
223229
}
224230
}
225231
break;
@@ -256,6 +262,7 @@ void performCopyOps()
256262
{
257263
std::u16string crPath = savePath + newDir;
258264
FSUSER_CreateDirectory(fs::getSaveArch(), fsMakePath(PATH_UTF16, crPath.data()), 0);
265+
fs::commitData(fs::getSaveMode());
259266
}
260267
break;
261268

@@ -350,6 +357,7 @@ namespace ui
350357

351358
saveList.reassign(fs::getSaveArch(), savePath);
352359
util::copyDirlistToMenu(saveList, saveMenu);
360+
saveMenu.setSelected(0);
353361
}
354362
else if(saveSel > 1 && saveList.isDir(saveSel - 2))
355363
{
@@ -358,6 +366,7 @@ namespace ui
358366

359367
saveList.reassign(fs::getSaveArch(), savePath);
360368
util::copyDirlistToMenu(saveList, saveMenu);
369+
saveMenu.setSelected(0);
361370
}
362371
}
363372
break;
@@ -372,6 +381,7 @@ namespace ui
372381

373382
sdList.reassign(fs::getSDMCArch(), sdPath);
374383
util::copyDirlistToMenu(sdList, sdMenu);
384+
sdMenu.setSelected(0);
375385
}
376386
else if(sdSel > 1 && sdList.isDir(sdSel - 2))
377387
{
@@ -380,6 +390,7 @@ namespace ui
380390

381391
sdList.reassign(fs::getSDMCArch(), sdPath);
382392
util::copyDirlistToMenu(sdList, sdMenu);
393+
sdMenu.setSelected(0);
383394
}
384395
}
385396
break;
@@ -398,6 +409,7 @@ namespace ui
398409

399410
saveList.reassign(fs::getSaveArch(), savePath);
400411
util::copyDirlistToMenu(saveList, saveMenu);
412+
saveMenu.setSelected(0);
401413
}
402414
else if(advMenuCtrl == 1 && sdPath != util::toUtf16("/"))
403415
{
@@ -406,6 +418,7 @@ namespace ui
406418

407419
sdList.reassign(fs::getSDMCArch(), sdPath);
408420
util::copyDirlistToMenu(sdList, sdMenu);
421+
sdMenu.setSelected(0);
409422
}
410423
else if(advMenuCtrl == 2)
411424
advMenuCtrl = advPrev;
@@ -427,16 +440,20 @@ namespace ui
427440
gfx::frameBegin();
428441
gfx::frameStartTop();
429442
ui::drawTopBar("Adv. Mode");
443+
gfx::drawU16Text(util::toUtf16("sv:") + savePath, 0, 20, 0xFFFFFFFF);
430444
saveMenu.draw(40, 32, 0xFFFFFFFF, 320);
431445
if(advMenuCtrl == 2 && advPrev == 0)
432446
{
447+
copyMenu.editOpt(0, "Copy to SD");
433448
C2D_DrawRectSolid(144, 78, 0.5f, 112, 88, 0xFFCCCCCC);
434449
copyMenu.draw(152, 86, 0xFF000000, 96);
435450
}
436451
gfx::frameStartBot();
452+
gfx::drawU16Text(util::toUtf16("sd:") + sdPath, 0, 0, 0xFFFFFFFF);
437453
sdMenu.draw(0, 24, 0xFFFFFFFF, 320);
438454
if(advMenuCtrl == 2 && advPrev == 1)
439455
{
456+
copyMenu.editOpt(0, "Copy to Save");
440457
C2D_DrawRectSolid(100, 78, 0.5f, 112, 88, 0xFFCCCCCC);
441458
copyMenu.draw(108, 86, 0xFF000000, 96);
442459
}

src/ui/button.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ namespace ui
6060
void button::draw()
6161
{
6262
if(pressed)
63-
C2D_DrawRectSolid(x, y, 0.5f, w, h, 0xFFDBDBDB);
63+
C2D_DrawRectSolid(x, y, 0.5f, w, h, 0xFFBBBBBB);
6464
else
65-
C2D_DrawRectSolid(x, y, 0.5f, w, h, 0xFFEBEBEB);
65+
C2D_DrawRectSolid(x, y, 0.5f, w, h, 0xFFDBDBDB);
6666

6767
gfx::drawText(text, tx, ty, 0xFF000000);
6868
}

src/ui/menu.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@ namespace ui
3737
{
3838
opt.clear();
3939
multiSel.clear();
40-
41-
selected = 0;
42-
start = 0;
4340
multi = false;
4441
}
4542

43+
void menu::adjust()
44+
{
45+
if(selected > (int)opt.size() - 1)
46+
selected = opt.size() - 1;
47+
48+
if(opt.size() < 16)
49+
start = 0;
50+
else if(opt.size() > 16 && start + 16 > (int)opt.size() - 1)
51+
start--;
52+
}
53+
4654
void menu::setSelected(const int& newSel)
4755
{
4856
if(newSel < start || newSel > start + 16)

0 commit comments

Comments
 (0)