Make text work the way I want

This commit is contained in:
J-D-K
2018-07-10 18:38:23 -04:00
parent 570ee8884e
commit 0a932dc042
16 changed files with 95 additions and 131 deletions

View File

@@ -38,7 +38,7 @@ INCLUDES := inc
EXEFS_SRC := exefs_src
APP_TITLE := JKSV
APP_AUTHOR := JK_
APP_VERSION := 07/08/2018
APP_VERSION := 07/10/2018
ROMFS := romfs
#---------------------------------------------------------------------------------

View File

@@ -10,35 +10,30 @@
namespace data
{
extern bool sysSave, forceMountable, smoothIcns;
extern bool sysSave;
//Loads user + title info
void loadDataInfo();
void exit();
//Class to help not load the same icons over and over
class icn
class icn : gfx::tex
{
public:
//Loads jpeg icon from jpegData
void load(const uint64_t& _id, const uint8_t *jpegData, const size_t& jpegSize);
//For loading default icon
void load(const uint64_t & _id, const std::string& _png);
//Sets icon from image already loaded. Only used for default
void setIcon(const uint64_t& _id, const gfx::tex& _set);
void draw(unsigned x, unsigned y) { gfx::tex::draw(x, y); }
void drawHalf(unsigned x, unsigned y) { gfx::tex::drawNoBlendSkipSmooth(x, y); }
//Draw
void draw(unsigned x, unsigned y);
uint64_t getTitleID() { return titleID; }
//Draws skipping pixels for half size
void drawHalf(unsigned x, unsigned y);
uint64_t getTitleID() { return titleID;}
void deleteData();
void deleteData() { gfx::tex::deleteData(); }
private:
uint64_t titleID;
gfx::tex iconTex;
};
//Class to store title info
@@ -53,15 +48,15 @@ namespace data
//Returns title + title without forbidden chars
std::string getTitle() { return title;}
std::string getTitleSafe() { return titleSafe;}
std::string getTitleSafe() { return titleSafe; }
//Returns ID
uint64_t getID() {return id;}
uint64_t getID() { return id; }
//Game icon
icn icon;
FsSaveDataType getType() { return type;}
FsSaveDataType getType() { return type; }
private:
FsSaveDataType type;
@@ -81,11 +76,11 @@ namespace data
bool initNoChk(const u128& _id);
//Returns user ID
u128 getUID() {return userID;}
u128 getUID() { return userID; }
//Returns username
std::string getUsername() {return username;}
std::string getUsernameSafe() {return userSafe;}
std::string getUsername() { return username; }
std::string getUsernameSafe() { return userSafe; }
//Vector for storing save data info for user
std::vector<titledata> titles;

View File

@@ -27,7 +27,6 @@ namespace gfx
uint8_t rgb[4];
};
//Old 3DS code for loading raw RGBA8 data
class tex
{
public:
@@ -41,9 +40,9 @@ namespace gfx
void loadJpegFile(const std::string& path);
//Frees memory used by data
void deleteData();
uint16_t getWidth() { return width;}
uint16_t getHeight() {return height;}
const uint32_t *getDataPointer() {return data;}
uint16_t getWidth() { return width; }
uint16_t getHeight() { return height; }
uint32_t *getDataPointer() { return data; }
void draw(uint32_t x, uint32_t y);
void drawInvert(uint32_t x, uint32_t y);
@@ -61,7 +60,7 @@ namespace gfx
void drawRepeatVert(uint32_t x, uint32_t y, uint32_t h);
void drawRepeatVertNoBlend(uint32_t x, uint32_t y, uint32_t h);
private:
protected:
uint32_t sz;
uint16_t width, height;
uint32_t *data = NULL;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -74,7 +74,7 @@ namespace ui
{
util::makeTitleDir(data::curUser, data::curData);
folderMenuPrepare(data::curUser, data::curData);
folderMenuInfo = util::getWrappedString(util::getInfoString(data::curUser, data::curData), 38, 256);
folderMenuInfo = util::getWrappedString(util::getInfoString(data::curUser, data::curData), 18, 256);
mstate = 2; //FLD_SEL
}

View File

@@ -38,26 +38,19 @@ static int getUserIndex(const u128& id)
return -1;
}
//Default icon if one isn't found. For system saves
gfx::tex defIcn;
namespace data
{
titledata curData;
user curUser;
std::vector<icn> icons;
std::vector<user> users;
bool sysSave = false, forceMountable = true, smoothIcns = false;
bool sysSave = false;
void loadDataInfo()
{
//Load default icon
defIcn.loadPNGFile("romfs:/img/icn/icnDefault.png");
//Create icon for it
icn defIcnIcon;
defIcnIcon.setIcon((uint64_t)0, defIcn);
icons.push_back(defIcnIcon);
icn defIcon;
defIcon.load(0, "romfs:/img/icn/icnDefault.png");
icons.push_back(defIcon);
for(unsigned i = 0; i < users.size(); i++)
users[i].titles.clear();
@@ -94,7 +87,7 @@ namespace data
u = getUserIndex(info.userID);
titledata newData;
if(newData.init(info) && (!forceMountable || newData.isMountable(newUser.getUID())))
if(newData.init(info) && newData.isMountable(newUser.getUID()))
{
users[u].titles.push_back(newData);
}
@@ -103,7 +96,7 @@ namespace data
else
{
titledata newData;
if(newData.init(info) && (!forceMountable || newData.isMountable(users[u].getUID())))
if(newData.init(info) && newData.isMountable(users[u].getUID()))
{
users[u].titles.push_back(newData);
}
@@ -124,37 +117,20 @@ namespace data
for(unsigned i = 0; i < users.size(); i++)
users[i].icn.deleteData();
for(unsigned i = 1; i < icons.size(); i++)
for(unsigned i = 0; i < icons.size(); i++)
icons[i].deleteData();
}
void icn::load(const uint64_t& _id, const uint8_t *jpegData, const size_t& jpegSize)
{
titleID = _id;
iconTex.loadJpegMem(jpegData, jpegSize);
gfx::tex::loadJpegMem(jpegData, jpegSize);
}
void icn::setIcon(const uint64_t& _id, const gfx::tex& _set)
void icn::load(const uint64_t& _id, const std::string& _png)
{
titleID = _id;
iconTex = _set;
}
void icn::draw(unsigned x, unsigned y)
{
iconTex.drawNoBlend(x, y);
}
void icn::drawHalf(unsigned x, unsigned y)
{
iconTex.drawNoBlendSkipSmooth(x, y);
}
void icn::deleteData()
{
iconTex.deleteData();
gfx::tex::loadPNGFile(_png);
}
int findIcnIndex(const uint64_t& titleID)
@@ -305,7 +281,8 @@ namespace data
{
username = "Unknown";
userSafe = "Unknown";
icn = defIcn;
//This shouldn't happen too much
icn.loadPNGFile("romfs:/img/icn/icnDefault.png");
}
return true;

View File

@@ -3,6 +3,7 @@
#include <switch.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include "file.h"
#include "util.h"
@@ -121,7 +122,7 @@ namespace fs
ui::progBar prog(fileSize);
std::string copyString = "Copying " + from + "...";
copyString = util::getWrappedString(copyString, 64, 1136);
copyString = util::getWrappedString(copyString, 24, 1136);
for(unsigned i = 0; i < fileSize; )
{
f.read((char *)buff, BUFF_SIZE);
@@ -154,7 +155,7 @@ namespace fs
ui::progBar prog(fileSize);
std::string copyString = "Copying " + from + "...";
copyString = util::getWrappedString(copyString, 64, 1136);
copyString = util::getWrappedString(copyString, 24, 1136);
for(unsigned i = 0; i < fileSize; )
{
f.read((char *)buff, BUFF_SIZE);

View File

@@ -117,9 +117,9 @@ namespace gfx
uint32_t tmpChr;
ssize_t unitCount = 0;
y += 27;
FT_Set_Char_Size(face, 0, 8 * sz, 300, 300);
//Set's font height to size. Easier to work with
FT_Set_Char_Size(face, 0, sz * 64, 90, 90);
unsigned height = sz;
uint32_t *fb = (uint32_t *)gfxGetFramebuffer(&fbw, NULL);
@@ -136,7 +136,7 @@ namespace gfx
if(tmpChr == '\n')
{
tmpX = x;
y += face->size->metrics.height / sz;
y += height + 8;
continue;
}
@@ -145,7 +145,9 @@ namespace gfx
if(ret)
return;
drawGlyph(slot->bitmap, fb, tmpX + slot->bitmap_left, y - slot->bitmap_top, textColor);
unsigned drawY = y + (height - slot->bitmap_top);
drawGlyph(slot->bitmap, fb, tmpX + slot->bitmap_left, drawY, textColor);
tmpX += slot->advance.x >> 6;
}
}
@@ -159,7 +161,7 @@ namespace gfx
FT_GlyphSlot slot = face->glyph;
FT_Error ret = 0;
FT_Set_Char_Size(face, 0, 8 * sz, 300, 300);
FT_Set_Char_Size(face, 0, 64 * sz, 90, 90);
for(unsigned i = 0; i < str.length(); )
{
@@ -183,17 +185,8 @@ namespace gfx
unsigned getTextHeight(const uint32_t& sz)
{
FT_UInt glyphIndex = 0;
FT_Error error = 0;
uint32_t tChar = 'A';
FT_Set_Char_Size(face, 0, 8 * sz, 300, 300);
glyphIndex = FT_Get_Char_Index(face, tChar);
error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_RENDER);
if(error)
return 0;
return face->size->metrics.height / sz;
//Pointless now, but keep
return sz;
}
void clearBufferColor(const uint32_t& clr)
@@ -307,9 +300,8 @@ namespace gfx
delete[] rows;
png_destroy_read_struct(&png, &pngInfo, NULL);
fclose(pngIn);
}
fclose(pngIn);
}
void tex::loadJpegMem(const uint8_t *txData, const size_t& jpegSz)
@@ -402,11 +394,11 @@ namespace gfx
jpeg_finish_decompress(&jpegInfo);
jpeg_destroy_decompress(&jpegInfo);
fclose(jpegFile);
delete row[0];
delete[] row;
}
fclose(jpegFile);
}
void tex::deleteData()

View File

@@ -103,7 +103,7 @@ namespace ui
for(unsigned i = 0; i < keys.size(); i++)
keys[i].draw();
gfx::drawText(str, 16, 192, 64, 0xFF000000);
gfx::drawText(str, 16, 192, 32, 0xFF000000);
}
std::string keyboard::getString(const std::string& def)

View File

@@ -41,7 +41,7 @@ int main(int argc, const char *argv[])
data::loadDataInfo();
ui::init();
appletSetScreenShotPermission(0);
appletSetScreenShotPermission(1);
bool run = true;
while(appletMainLoop() && run)
@@ -59,7 +59,6 @@ int main(int argc, const char *argv[])
if(ui::confirm("You are about to enable system save dumping and remove checks. Are you sure you want to continue?"))
{
data::sysSave = true;
data::forceMountable = false;
data::loadDataInfo();
//Just to be sure

View File

@@ -145,7 +145,7 @@ namespace ui
if(i == selected)
gfx::drawRectangle(x, y + ((i - start) * 36), rW, 32, rectClr);
gfx::drawText(opt[i], x, y + ((i - start) * 36), 38, textClr);
gfx::drawText(opt[i], x, (y + 8) + ((i - start) * 36), 16, textClr);
}
}

View File

@@ -29,7 +29,7 @@ namespace ui
//char tmp[64];
//sprintf(tmp, "%u / %u", (unsigned)prog, (unsigned)max);
gfx::drawText(text, 80, 256, 64, txtClr);
gfx::drawText(text, 80, 256, 24, txtClr);
//gfx::drawText(tmp, 80, 320, 64, 0x000000FF);
}
@@ -41,8 +41,8 @@ namespace ui
h = _h;
text = _txt;
unsigned tw = gfx::getTextWidth(text, 48);
unsigned th = gfx::getTextHeight(48);
unsigned tw = gfx::getTextWidth(text, 24);
unsigned th = gfx::getTextHeight(24);
tx = x + (w / 2) - (tw / 2);
ty = y + (h / 2) - (th / 2);
@@ -91,7 +91,7 @@ namespace ui
else
ui::drawTextbox(x, y, w, h);
gfx::drawText(text, tx, ty, 48, txtClr);
gfx::drawText(text, tx, ty, 24, txtClr);
}
void touchTrack::update(const touchPosition& p)
@@ -140,7 +140,7 @@ namespace ui
void showMessage(const std::string& mess)
{
button ok("OK", 256, 496, 768, 96);
std::string wrapMess = util::getWrappedString(mess, 48, 752);
std::string wrapMess = util::getWrappedString(mess, 24, 752);
while(true)
{
hidScanInput();
@@ -155,9 +155,9 @@ namespace ui
break;
ui::drawTextbox(256, 128, 768, 464);
gfx::drawText(wrapMess, 272, 144, 48, txtClr);
gfx::drawText(wrapMess, 272, 144, 24, txtClr);
ok.draw();
ui::buttonA.drawInvert(ok.getTx() + 48, ok.getTy());
ui::buttonA.drawInvert(ok.getTx() + 56, ok.getTy() - 4);
gfx::handleBuffs();
}
@@ -195,10 +195,10 @@ namespace ui
{
bool ret = false;
button yes("Yes ", 256, 496, 384, 96);
button no("No ", 640, 496, 384, 96);
button yes("Yes ", 256, 496, 384, 96);
button no("No ", 640, 496, 384, 96);
std::string wrapMess = util::getWrappedString(mess, 48, 752);
std::string wrapMess = util::getWrappedString(mess, 24, 752);
while(true)
{
@@ -223,11 +223,11 @@ namespace ui
}
ui::drawTextbox(256, 128, 768, 464);
gfx::drawText(wrapMess, 272, 144, 48, txtClr);
gfx::drawText(wrapMess, 272, 144, 24, txtClr);
yes.draw();
ui::buttonA.drawInvert(yes.getTx() + 56, yes.getTy());
ui::buttonA.drawInvert(yes.getTx() + 64, yes.getTy() - 4);
no.draw();
ui::buttonB.drawInvert(no.getTx() + 48, no.getTy());
ui::buttonB.drawInvert(no.getTx() + 56, no.getTy() - 4);
gfx::handleBuffs();
}

View File

@@ -3,6 +3,7 @@
#include <fstream>
#include <cstdio>
#include <cstring>
#include <sys/stat.h>
#include <switch.h>
#include "ui.h"
@@ -21,7 +22,7 @@ enum menuState
CLS_TTL
};
#define TITLE_TEXT "JKSV - 07/08/2018"
#define TITLE_TEXT "JKSV - 07/10/2018"
//Menu currently up
int mstate = USR_SEL;
@@ -207,7 +208,7 @@ namespace ui
else
background.drawNoBlend(0, 0);
gfx::drawText(TITLE_TEXT, 16, 16, 64, mnuTxt);
gfx::drawText(TITLE_TEXT, 16, 16, 32, mnuTxt);
switch(mstate)
{
@@ -263,11 +264,11 @@ namespace ui
//Input guide
unsigned startX = 848;
buttonA.draw(startX, 672);
gfx::drawText("Select", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Select", startX += 38, 680, 14, mnuTxt);
buttonY.draw(startX += 72, 672);
gfx::drawText("Dump All", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Dump All", startX += 38, 680, 14, mnuTxt);
buttonX.draw(startX += 96, 672);
gfx::drawText("Classic Mode", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Classic Mode", startX += 38, 680, 14, mnuTxt);
}
break;
@@ -276,11 +277,11 @@ namespace ui
{
unsigned startX = 914;
buttonA.draw(startX, 672);
gfx::drawText("Select", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Select", startX += 38, 680, 14, mnuTxt);
buttonY.draw(startX += 72, 672);
gfx::drawText("Dump All", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Dump All", startX += 38, 680, 14, mnuTxt);
buttonB.draw(startX += 96, 672);
gfx::drawText("Back", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Back", startX += 38, 680, 14, mnuTxt);
}
break;
@@ -290,15 +291,15 @@ namespace ui
//Input guide
unsigned startX = 690;
buttonMin.draw(startX, 672);
gfx::drawText("Adv. Mode", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Adv. Mode", startX += 38, 680, 14, mnuTxt);
buttonA.draw(startX += 100, 672);
gfx::drawText("Backup", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Backup", startX += 38, 680, 14, mnuTxt);
buttonY.draw(startX += 72, 672);
gfx::drawText("Restore", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Restore", startX += 38, 680, 14, mnuTxt);
buttonX.draw(startX += 72, 672);
gfx::drawText("Delete", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Delete", startX += 38, 680, 14, mnuTxt);
buttonB.draw(startX += 72, 672);
gfx::drawText("Back", startX += 38, 668, 32, mnuTxt);
gfx::drawText("Back", startX += 38, 680, 14, mnuTxt);
}
break;
@@ -306,8 +307,8 @@ namespace ui
saveMenu.draw(mnuTxt);
sdMenu.draw(mnuTxt);
gfx::drawText(saveWrap, 16, 652, 32, mnuTxt);
gfx::drawText(sdWrap, 656, 652, 32, mnuTxt);
gfx::drawText(saveWrap, 16, 668, 14, mnuTxt);
gfx::drawText(sdWrap, 656, 668, 14, mnuTxt);
break;
}
}
@@ -372,7 +373,7 @@ namespace ui
}
std::string username = data::users[selected].getUsername();
unsigned userWidth = gfx::getTextWidth(username, 32);
unsigned userWidth = gfx::getTextWidth(username, 16);
int userRectWidth = userWidth + 32, userRectX = (tX + 64) - (userRectWidth / 2);
if(userRectX < 16)
userRectX = 16;
@@ -381,7 +382,7 @@ namespace ui
userRectX = 1264 - userRectWidth;
drawTextbox(userRectX, y - 50, userRectWidth, 38);
gfx::drawText(username, userRectX + 16, y - 50, 32, txtClr);
gfx::drawText(username, userRectX + 16, y - 38, 16, txtClr);
}
data::users[i].icn.drawNoBlendSkipSmooth(tX, y);
}
@@ -534,7 +535,7 @@ namespace ui
}
std::string title = data::curUser.titles[selected].getTitle();
unsigned titleWidth = gfx::getTextWidth(title, 32);
unsigned titleWidth = gfx::getTextWidth(title, 16);
int rectWidth = titleWidth + 32, rectX = (tX + 64) - (rectWidth / 2);
if(rectX < 16)
rectX = 16;
@@ -543,7 +544,7 @@ namespace ui
rectX = 1264 - rectWidth;
drawTextbox(rectX, y - 50, rectWidth, 38);
gfx::drawText(title, rectX + 16, y - 50, 32, txtClr);
gfx::drawText(title, rectX + 16, y - 38, 16, txtClr);
}
data::curUser.titles[i].icon.drawHalf(tX, y);
}
@@ -564,7 +565,7 @@ namespace ui
{
util::makeTitleDir(data::curUser, data::curData);
folderMenuPrepare(data::curUser, data::curData);
folderMenuInfo = util::getWrappedString(util::getInfoString(data::curUser, data::curData), 38, 256);
folderMenuInfo = util::getWrappedString(util::getInfoString(data::curUser, data::curData), 18, 256);
mstate = FLD_SEL;
}
@@ -645,7 +646,7 @@ namespace ui
{
util::makeTitleDir(data::curUser, data::curData);
folderMenuPrepare(data::curUser, data::curData);
folderMenuInfo = util::getWrappedString(util::getInfoString(data::curUser, data::curData), 38, 256);
folderMenuInfo = util::getWrappedString(util::getInfoString(data::curUser, data::curData), 18, 256);
mstate = FLD_SEL;
}
@@ -670,7 +671,7 @@ namespace ui
folderMenu.handleInput(down, held, p);
data::curData.icon.draw(16, 88);
gfx::drawText(folderMenuInfo, 16, 344, 38, mnuTxt);
gfx::drawText(folderMenuInfo, 16, 360, 18, mnuTxt);
if(down & KEY_A || folderMenu.getTouchEvent() == MENU_DOUBLE_REL)
{
@@ -775,7 +776,7 @@ namespace ui
}
}
//Performs copy menu operations. To big to stuff into case IMO.
//Performs copy menu operations. To big to stuff into case IMO.
void performCopyMenuOps()
{
switch(copyMenu.getSelected())
@@ -1094,7 +1095,7 @@ namespace ui
if(saveSel == 1 && savePath != "sv:/")
{
util::removeLastFolderFromString(savePath);
saveWrap = util::getWrappedString(savePath, 32, 600);
saveWrap = util::getWrappedString(savePath, 14, 600);
saveList.reassign(savePath);
util::copyDirListToMenu(saveList, saveMenu);
@@ -1102,7 +1103,7 @@ namespace ui
else if(saveSel > 1 && saveList.isDir(saveSel - 2))
{
savePath += saveList.getItem(saveSel - 2) + "/";
saveWrap = util::getWrappedString(savePath, 32, 600);
saveWrap = util::getWrappedString(savePath, 14, 600);
saveList.reassign(savePath);
util::copyDirListToMenu(saveList, saveMenu);
@@ -1117,7 +1118,7 @@ namespace ui
if(sdSel == 1 && sdPath != "sdmc:/")
{
util::removeLastFolderFromString(sdPath);
sdWrap = util::getWrappedString(sdPath, 32, 600);
sdWrap = util::getWrappedString(sdPath, 14, 600);
sdList.reassign(sdPath);
util::copyDirListToMenu(sdList, sdMenu);
@@ -1125,7 +1126,7 @@ namespace ui
else if(sdSel > 1 && sdList.isDir(sdSel - 2))
{
sdPath += sdList.getItem(sdSel - 2) + "/";
sdWrap = util::getWrappedString(sdPath, 32, 600);
sdWrap = util::getWrappedString(sdPath, 14, 600);
sdList.reassign(sdPath);
util::copyDirListToMenu(sdList, sdMenu);
@@ -1145,7 +1146,7 @@ namespace ui
if(advMenuCtrl == 0 && savePath != "sv:/")
{
util::removeLastFolderFromString(savePath);
saveWrap = util::getWrappedString(savePath, 32, 600);
saveWrap = util::getWrappedString(savePath, 14, 600);
saveList.reassign(savePath);
util::copyDirListToMenu(saveList, saveMenu);
@@ -1154,7 +1155,7 @@ namespace ui
else if(advMenuCtrl == 1 && sdPath != "sdmc:/")
{
util::removeLastFolderFromString(sdPath);
sdWrap = util::getWrappedString(sdPath, 32, 600);
sdWrap = util::getWrappedString(sdPath, 14, 600);
sdList.reassign(sdPath);
util::copyDirListToMenu(sdList, sdMenu);
@@ -1195,11 +1196,11 @@ namespace ui
switch(advPrev)
{
case 0:
gfx::drawText("SAVE", 472, 242, 32,txtClr);
gfx::drawText("SAVE", 472, 250, 18,txtClr);
break;
case 1:
gfx::drawText("SDMC", 472, 242, 32, txtClr);
gfx::drawText("SDMC", 472, 250, 18, txtClr);
break;
}