UI Tweaking

This commit is contained in:
J-D-K 2018-12-16 20:44:24 -05:00
parent cc8f91dee3
commit edff6f7dac
11 changed files with 161 additions and 40 deletions

View File

@ -38,7 +38,7 @@ INCLUDES := inc
EXEFS_SRC := exefs_src
APP_TITLE := JKSV
APP_AUTHOR := JK
APP_VERSION := 12/03/2018
APP_VERSION := 12/16/2018
ROMFS := romfs
#---------------------------------------------------------------------------------

View File

@ -15,6 +15,9 @@ enum menuTouch
namespace ui
{
void menuPrepGfx();
void menuDestGfx();
class menu
{
public:
@ -41,6 +44,9 @@ namespace ui
//Clears and resets menu
void reset();
//Resets selected + start
void resetSel(){ selected = 0; start = 0; }
//Adjusts things after changes are made
void adjust();

View File

@ -31,7 +31,7 @@ namespace ui
void update(const uint64_t& _prog);
//Draws with text at top
void draw(const std::string& text);
void draw(const std::string& text, const std::string& head);
private:
uint64_t max, prog;
@ -80,7 +80,7 @@ namespace ui
};
//General use
void showMessage(const std::string& mess);
void showMessage(const std::string& mess, const std::string& head);
void showError(const std::string& mess, const Result& r);
bool confirm(const std::string& q);
bool confirmTransfer(const std::string& f, const std::string& t);

BIN
romfs/img/mnu/msel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

View File

@ -198,7 +198,6 @@ namespace fs
uint8_t *buff = new uint8_t[BUFF_SIZE];
ui::progBar prog(fileSize);
std::string copyString = "Copying " + from + "...";
for(unsigned i = 0; i < fileSize; )
{
f.read((char *)buff, BUFF_SIZE);
@ -207,7 +206,7 @@ namespace fs
i += f.gcount();
prog.update(i);
prog.draw(copyString);
prog.draw(from, "Copying File:");
gfxHandleBuffs();
}
@ -237,7 +236,6 @@ namespace fs
uint8_t *buff = new uint8_t[BUFF_SIZE];
ui::progBar prog(fileSize);
std::string copyString = "Copying " + from + "...";
for(unsigned i = 0; i < fileSize; )
{
f.read((char *)buff, BUFF_SIZE);
@ -246,7 +244,7 @@ namespace fs
i += f.gcount();
prog.update(i);
prog.draw(copyString);
prog.draw(from, "Copying File:");
gfxHandleBuffs();
}
@ -257,7 +255,7 @@ namespace fs
t.close();
if(R_FAILED(fsdevCommitDevice(dev.c_str())))
ui::showMessage("Error committing file to device!");
ui::showMessage("Error committing file to device!", "*ERROR*");
}
void copyDirToDir(const std::string& from, const std::string& to)

View File

@ -8,6 +8,7 @@
#include "gfx.h"
tex *frameBuffer;
clr textClr;
static inline uint32_t blend(const clr px, const clr fb)
{
@ -71,7 +72,7 @@ void gfxHandleBuffs()
gfxWaitForVsync();
}
static void drawGlyph(const FT_Bitmap *bmp, tex *target, int _x, int _y, const clr c)
static void drawGlyph(const FT_Bitmap *bmp, tex *target, int _x, int _y)
{
if(bmp->pixel_mode != FT_PIXEL_MODE_GRAY)
return;
@ -90,7 +91,7 @@ static void drawGlyph(const FT_Bitmap *bmp, tex *target, int _x, int _y, const c
if(*bmpPtr > 0)
{
clr txClr = clrCreateRGBA(c.r, c.g, c.b, *bmpPtr);
clr txClr = clrCreateRGBA(textClr.r, textClr.g, textClr.b, *bmpPtr);
clr tgtClr = clrCreateU32(*rowPtr);
*rowPtr = blend(txClr, tgtClr);
@ -135,6 +136,7 @@ void drawText(const char *str, tex *target, const font *f, int x, int y, int sz,
int tmpX = x;
uint32_t tmpChr = 0;
ssize_t unitCnt = 0;
textClr = c;
resizeFont(f, sz);
@ -146,18 +148,37 @@ void drawText(const char *str, tex *target, const font *f, int x, int y, int sz,
break;
i += unitCnt;
if(tmpChr == '\n')
switch(tmpChr)
{
tmpX = x;
y += sz + 8;
continue;
case '\n':
tmpX = x;
y += sz + 8;
continue;
break;
case '"':
case '#':
if(clrGetColor(textClr) == 0xFFEE9900)
textClr = c;
else
textClr = clrCreateU32(0xFFEE9900);
continue;
break;
case '*':
if(clrGetColor(textClr) == 0xFF0000FF)
textClr = c;
else
textClr = clrCreateU32(0xFF0000FF);
continue;
break;
}
FT_GlyphSlot slot = loadGlyph(tmpChr, f, FT_LOAD_RENDER);
if(slot != NULL)
{
int drawY = y + (sz - slot->bitmap_top);
drawGlyph(&slot->bitmap, target, tmpX + slot->bitmap_left, drawY, c);
drawGlyph(&slot->bitmap, target, tmpX + slot->bitmap_left, drawY);
tmpX += slot->advance.x >> 6;
}
@ -194,18 +215,37 @@ void drawTextWrap(const char *str, tex *target, const font *f, int x, int y, int
break;
j += unitCnt;
if(tmpChr == '\n')
switch(tmpChr)
{
tmpX = x;
y += sz + 8;
continue;
case '\n':
tmpX = x;
y += sz + 8;
continue;
break;
case '"':
case '#':
if(clrGetColor(textClr) == 0xFFEE9900)
textClr = c;
else
textClr = clrCreateU32(0xFFEE9900);
continue;
break;
case '*':
if(clrGetColor(textClr) == 0xFF0000FF)
textClr = c;
else
textClr = clrCreateU32(0xFF0000FF);
continue;
break;
}
FT_GlyphSlot slot = loadGlyph(tmpChr, f, FT_LOAD_RENDER);
if(slot != NULL)
{
int drawY = y + (sz - slot->bitmap_top);
drawGlyph(&slot->bitmap, target, tmpX + slot->bitmap_left, drawY, c);
drawGlyph(&slot->bitmap, target, tmpX + slot->bitmap_left, drawY);
tmpX += slot->advance.x >> 6;
}

View File

@ -11,7 +11,7 @@
#include "util.h"
#include "file.h"
#define VER_STRING "v. 12/03/2018"
#define VER_STRING "v. 12/16/2018"
//background that can be drawn from "/JKSV/back.jpg"
//txtSide and fldSide are to fake alpha blending so the framerate doesn't suffer
@ -136,6 +136,7 @@ namespace ui
txtSide = texCreateFromPart(background, 30, 88, 448, 560);
drawRectAlpha(txtSide, 0, 0, 448, 560, tempRect);
}
menuPrepGfx();
advCopyMenuPrep();
}
@ -155,6 +156,8 @@ namespace ui
texDestroy(selBox);
menuDestGfx();
if(background != NULL)
texDestroy(background);
if(fldSide != NULL)
@ -239,7 +242,7 @@ namespace ui
break;
case ADV_MDE:
drawRect(frameBuffer, 640, 87, 1, 560, divClr);
drawRect(frameBuffer, 640, 87, 1, 561, divClr);
break;
case CLS_TTL:

View File

@ -274,7 +274,7 @@ void performCopyMenuOps()
std::string fullPath = savePath + saveList.getItem(sel);
std::string props = fs::getFileProps(fullPath);
if(!props.empty())
ui::showMessage(props);
ui::showMessage(props, "File Properties:");
}
}
break;
@ -287,7 +287,7 @@ void performCopyMenuOps()
std::string fullPath = sdPath + sdList.getItem(sel);
std::string props = fs::getFileProps(fullPath);
if(!props.empty())
ui::showMessage(props);
ui::showMessage(props, "File Properties:");
}
}
break;
@ -459,6 +459,10 @@ namespace ui
advMenuCtrl = 0;
}
}
else if(down & KEY_L)
{
data::curData.setType(FsSaveDataType_SaveData);
}
else if(down & KEY_MINUS)
{
if(prevState == EX_MNU)

View File

@ -77,6 +77,12 @@ namespace ui
clsMode = false;
mstate = USR_SEL;
}
else if(down & KEY_MINUS || usrNav[3].getEvent() == BUTTON_RELEASED)
{
fsdevUnmountDevice("sv");
ui::exMenuPrep();
ui::mstate = EX_MNU;
}
}
void classicTitleMenuUpdate(const uint64_t& down, const uint64_t& held, const touchPosition& p)
@ -195,7 +201,7 @@ namespace ui
}
}
else
ui::showMessage("Writing data to system save data is not allowed currently. It CAN brick your system.");
ui::showMessage("Writing data to system save data is not allowed currently. It CAN brick your system.", "Sorry, bro:");
}
else if(down & KEY_X || fldNav[2].getEvent() == BUTTON_RELEASED)
{
@ -331,12 +337,12 @@ namespace ui
}
else
{
ui::showMessage("Something went wrong while dumping your NAND.");
ui::showMessage("Something went wrong while dumping your NAND.", "*ERROR*");
break;
}
nandProg.update(offset);
nandProg.draw("Backing up NAND...");
nandProg.draw("", "Copying NAND");
gfxHandleBuffs();
}
@ -385,12 +391,12 @@ namespace ui
}
else
{
ui::showMessage("Something went wrong while dumping your NAND.");
ui::showMessage("Something went wrong while dumping your NAND.", "*ERROR*");
break;
}
nandProg.update(offset);
nandProg.draw("Backing up NAND...");
nandProg.draw("", "Copying NAND");
gfxHandleBuffs();
}
@ -433,7 +439,7 @@ namespace ui
uint64_t termID = std::strtoull(idStr.c_str(), NULL, 16);
pmshellInitialize();
if(R_SUCCEEDED(pmshellTerminateProcessByTitleId(termID)))
ui::showMessage("Process " + idStr + " successfully shutdown.");
ui::showMessage("Process " + idStr + " successfully shutdown.", "FUCK YES");
pmshellExit();
}
}

View File

@ -6,8 +6,57 @@
#include "ui.h"
#include "miscui.h"
static tex *mnuTopLeft, *mnuTopRight, *mnuBotLeft, *mnuBotRight;
static void drawBoundBox(int x, int y, int w, int h, int clrSh)
{
clr rectClr = clrCreateRGBA(0x00, 0x60 + clrSh, 0xBB + clrSh, 0xFF);
texSwapColors(mnuTopLeft, clrCreateRGBA(0x00, 0x60, 0xBB, 0xFF), rectClr);
texSwapColors(mnuTopRight, clrCreateRGBA(0x00, 0x60, 0xBB, 0xFF), rectClr);
texSwapColors(mnuBotLeft, clrCreateRGBA(0x00, 0x60, 0xBB, 0xFF), rectClr);
texSwapColors(mnuBotRight, clrCreateRGBA(0x00, 0x60, 0xBB, 0xFF), rectClr);
//top
texDraw(mnuTopLeft, frameBuffer, x, y);
drawRect(frameBuffer, x + 8, y, w - 16, 2, rectClr);
texDraw(mnuTopRight, frameBuffer, (x + w) - 8, y);
//mid
drawRect(frameBuffer, x, y + 8, 2, h - 16, rectClr);
drawRect(frameBuffer, (x + w) - 2, y + 8, 2, h - 16, rectClr);
//bottom
texDraw(mnuBotLeft, frameBuffer, x, (y + h) - 8);
drawRect(frameBuffer, x + 8, (y + h) - 2, w - 16, 2, rectClr);
texDraw(mnuBotRight, frameBuffer, (x + w) - 8, (y + h) - 8);
texSwapColors(mnuTopLeft, rectClr, clrCreateRGBA(0x00, 0x60, 0xBB, 0xFF));
texSwapColors(mnuTopRight, rectClr, clrCreateRGBA(0x00, 0x60, 0xBB, 0xFF));
texSwapColors(mnuBotLeft, rectClr, clrCreateRGBA(0x00, 0x60, 0xBB, 0xFF));
texSwapColors(mnuBotRight, rectClr, clrCreateRGBA(0x00, 0x60, 0xBB, 0xFF));
}
namespace ui
{
void menuPrepGfx()
{
tex *temp = texLoadPNGFile("romfs:/img/mnu/msel.png");
mnuTopLeft = texCreateFromPart(temp, 0, 0, 8, 8);
mnuTopRight = texCreateFromPart(temp, 8, 0, 8, 8);
mnuBotLeft = texCreateFromPart(temp, 0, 8, 8, 8);
mnuBotRight = texCreateFromPart(temp, 8, 8, 8, 8);
texDestroy(temp);
}
void menuDestGfx()
{
texDestroy(mnuTopLeft);
texDestroy(mnuTopRight);
texDestroy(mnuBotLeft);
texDestroy(mnuBotRight);
}
void menu::setParams(const unsigned& _x, const unsigned& _y, const unsigned& _rW)
{
x = _x;
@ -164,12 +213,10 @@ namespace ui
else
length = start + 15;
clr rectClr = clrCreateRGBA(0x00, 0x60 + clrSh, 0xBB + clrSh, 0xFF);
for(int i = start; i < length; i++)
{
if(i == selected)
drawRect(frameBuffer, x, y + ((i - start) * 36), rW, 32, rectClr);
drawBoundBox(x, y + ((i - start) * 36), rW, 36, clrSh);
drawText(opt[i].c_str(), frameBuffer, shared, x + 8, (y + 8) + ((i - start) * 36), 18, textClr);
}

View File

@ -20,9 +20,13 @@ namespace ui
width = (float)(((float)prog / (float)max) * 1088);
}
void progBar::draw(const std::string& text)
void progBar::draw(const std::string& text, const std::string& head)
{
size_t headWidth = textGetWidth(head.c_str(), ui::shared, 24);
unsigned headX = (1280 / 2) - (headWidth / 2);
ui::drawTextbox(64, 240, 1152, 240);
drawRect(frameBuffer, 64, 296, 1152, 2, clrCreateU32(0xFF6D6D6D));
drawRect(frameBuffer, 96, 400, 1088, 64, clrCreateU32(0xFF000000));
drawRect(frameBuffer, 96, 400, (unsigned)width, 64, clrCreateU32(0xFF00CC00));
@ -30,7 +34,8 @@ namespace ui
sprintf(tmp, "%lu KB/%lu KB", prog / 1024, max / 1024);
int szX = 640 - (textGetWidth(tmp, shared, 24) / 2);
drawTextWrap(text.c_str(), frameBuffer, ui::shared, 80, 256, 18, txtClr, 752);
drawText(head.c_str(), frameBuffer, ui::shared, headX, 256, 24, txtClr);
drawTextWrap(text.c_str(), frameBuffer, ui::shared, 80, 312, 18, txtClr, 752);
drawText(tmp, frameBuffer, shared, szX, 416, 24, clrCreateU32(0xFFFFFFFF));
}
@ -142,9 +147,14 @@ namespace ui
}
void showMessage(const std::string& mess)
void showMessage(const std::string& mess, const std::string& head)
{
button ok("OK", 256, 496, 768, 96);
//center head text width
size_t headWidth = textGetWidth(head.c_str(), ui::shared, 24);
unsigned headX = (1280 / 2) - (headWidth / 2);
while(true)
{
hidScanInput();
@ -159,7 +169,9 @@ namespace ui
break;
ui::drawTextbox(256, 128, 768, 464);
drawTextWrap(mess.c_str(), frameBuffer, ui::shared, 272, 144, 24, txtClr, 752);
drawText(head.c_str(), frameBuffer, ui::shared, headX, 144, 24, txtClr);
drawRect(frameBuffer, 256, 184, 768, 2, clrCreateU32(0xFF6D6D6D));
drawTextWrap(mess.c_str(), frameBuffer, ui::shared, 272, 200, 24, txtClr, 752);
ok.draw();
texDrawInvert(ui::buttonA, frameBuffer, ok.getTx() + 56, ok.getTy() - 4);
@ -200,6 +212,9 @@ namespace ui
button yes("Yes ", 256, 496, 384, 96);
button no("No ", 640, 496, 384, 96);
size_t headWidth = textGetWidth("Confirm", ui::shared, 24);
unsigned headX = (1280 / 2) - (headWidth / 2);
while(true)
{
hidScanInput();
@ -223,7 +238,9 @@ namespace ui
}
ui::drawTextbox(256, 128, 768, 464);
drawTextWrap(mess.c_str(), frameBuffer, ui::shared, 272, 144, 24, txtClr, 752);
drawText("Confirm", frameBuffer, ui::shared, headX, 144, 24, txtClr);
drawRect(frameBuffer, 256, 184, 768, 2, clrCreateU32(0xFF6D6D6D));
drawTextWrap(mess.c_str(), frameBuffer, ui::shared, 272, 200, 24, txtClr, 752);
yes.draw();
texDrawInvert(ui::buttonA, frameBuffer, yes.getTx() + 64, yes.getTy() - 4);
no.draw();
@ -237,14 +254,14 @@ namespace ui
bool confirmTransfer(const std::string& f, const std::string& t)
{
std::string confMess = "Are you sure you want to copy \"" + f + "\" to \"" + t +"\"?";
std::string confMess = "Are you sure you want to copy #" + f + "# to #" + t +"#?";
return confirm(confMess);
}
bool confirmDelete(const std::string& p)
{
std::string confMess = "Are you 100% sure you want to delete \"" + p + "\"? This is permanent!";
std::string confMess = "Are you 100% sure you want to delete #" + p + "#? *This is permanent*!";
return confirm(confMess);
}