-rewrote the font fix of r960 to hopefully fix issues for some people

-fixed two very minor bugs
This commit is contained in:
fix94.1 2013-09-01 22:31:46 +00:00
parent 66a2b21cee
commit 32946bef84
6 changed files with 54 additions and 70 deletions

View File

@ -192,8 +192,9 @@ void DEVO_SetOptions(const char *isopath, const char *gameID, bool memcard_emu,
stat(isopath, &st);
FILE *f = fopen(isopath, "rb");
gprintf("Devolution: ISO Header %s\n", isopath);
fread((u8*)0x80000000, 1, 32, f);
fread((u8*)Disc_ID, 1, 32, f);
fclose(f);
f = NULL;
// fill out the Devolution config struct
memset(DEVO_CONFIG, 0, sizeof(gconfig));
@ -227,8 +228,6 @@ void DEVO_SetOptions(const char *isopath, const char *gameID, bool memcard_emu,
f = fopen(iso2path, "rb");
}
}
}
if(f != NULL)
{
gprintf("Devolution: 2nd ISO File for Multi DVD Game %s\n", iso2path);
@ -236,6 +235,7 @@ void DEVO_SetOptions(const char *isopath, const char *gameID, bool memcard_emu,
DEVO_CONFIG->disc2_cluster = st.st_ino;
fclose(f);
}
}
// make sure these directories exist, they are required for Devolution to function correctly
fsop_MakeFolder(fmt("%s:/apps", DeviceName[currentPartition]));
@ -285,7 +285,7 @@ void DEVO_SetOptions(const char *isopath, const char *gameID, bool memcard_emu,
DEVO_CONFIG->memcard_cluster = st.st_ino;
// flush disc ID and Devolution config out to memory
DCFlushRange((void*)0x80000000, 64);
DCFlushRange((void*)Disc_ID, 64);
DeviceHandle.UnMountDevolution();
}

View File

@ -164,11 +164,11 @@ void SFont::ClearData(void)
dataSize = 0;
}
bool SFont::fromBuffer(const u8 *buffer, const u32 bufferSize, u32 size, u32 lspacing, u32 w, u32 idx, const char *)
bool SFont::fromBuffer(const u8 *buffer, const u32 bufferSize, u32 size, u32 lspacing, u32 w, u32 idx, const char *fontname)
{
if(buffer == NULL)
return false;
size = min(max(6u, size), 1000u);
fSize = min(max(6u, size), 1000u);
lineSpacing = min(max(6u, lspacing), 1000u);
weight = min(w, 32u);
index = idx;
@ -182,14 +182,15 @@ bool SFont::fromBuffer(const u8 *buffer, const u32 bufferSize, u32 size, u32 lsp
memcpy(data, buffer, bufferSize);
DCFlushRange(data, dataSize);
memcpy(name, fontname, 127);
font = new FreeTypeGX();
font->loadFont(data, dataSize, size, weight, index, false);
font->loadFont(data, dataSize, fSize, weight, index, false);
return true;
}
bool SFont::fromFile(const char *filename, u32 size, u32 lspacing, u32 w, u32 idx)
bool SFont::fromFile(const char *path, u32 size, u32 lspacing, u32 w, u32 idx, const char *fontname)
{
size = min(max(6u, size), 1000u);
fSize = min(max(6u, size), 1000u);
weight = min(w, 32u);
index = idx = 0;
@ -197,14 +198,15 @@ bool SFont::fromFile(const char *filename, u32 size, u32 lspacing, u32 w, u32 id
if(data != NULL)
free(data);
data = fsop_ReadFile(filename, &dataSize);
data = fsop_ReadFile(path, &dataSize);
if(data == NULL)
return false;
DCFlushRange(data, dataSize);
memcpy(name, fontname, 127);
font = new FreeTypeGX();
font->loadFont(data, dataSize, size, weight, index, false);
font->loadFont(data, dataSize, fSize, weight, index, false);
return true;
}

View File

@ -15,15 +15,17 @@ using namespace std;
class SFont
{
public:
SFont(void) : font(NULL), lineSpacing(0), weight(0), index(0), data(NULL), dataSize(0) { }
SFont(void) : font(NULL), fSize(0), lineSpacing(0), weight(0), index(0), data(NULL), dataSize(0) { memset(name, 0, 128); };
~SFont(void) { };
void ClearData(void);
bool fromBuffer(const u8 *buffer, const u32 bufferSize, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0, const char *genKey = NULL);
bool fromFile(const char *filename, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0);
bool fromBuffer(const u8 *buffer, const u32 bufferSize, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0, const char *fontname = "");
bool fromFile(const char *path, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0, const char *fontname = "");
FreeTypeGX *font;
u32 fSize;
u32 lineSpacing;
u32 weight;
u32 index;
char name[128];
private:
u8 *data;
size_t dataSize;

View File

@ -619,8 +619,8 @@ void CMenu::_Theme_Cleanup(void)
/* Other Theme Stuff */
for(TexSet::iterator texture = theme.texSet.begin(); texture != theme.texSet.end(); ++texture)
TexHandle.Cleanup(texture->second);
for(FontSet::iterator font = theme.fontSet.begin(); font != theme.fontSet.end(); ++font)
font->second.ClearData();
for(vector<SFont>::iterator font = theme.fontSet.begin(); font != theme.fontSet.end(); ++font)
font->ClearData();
for(SoundSet::iterator sound = theme.soundSet.begin(); sound != theme.soundSet.end(); ++sound)
sound->second->FreeMemory();
theme.texSet.clear();
@ -679,7 +679,7 @@ void CMenu::_loadCFCfg()
string texNoCoverFlat = fmt("%s/%s", m_themeDataDir.c_str(), m_theme.getString(domain, "missing_cover_flat").c_str());
CoverFlow.setTextures(texLoading, texLoadingFlat, texNoCover, texNoCoverFlat);
// Font
CoverFlow.setFont(_font(theme.fontSet, domain, "font", TITLEFONT), m_theme.getColor(domain, "font_color", CColor(0xFFFFFFFF)));
CoverFlow.setFont(_font(domain, "font", TITLEFONT), m_theme.getColor(domain, "font_color", CColor(0xFFFFFFFF)));
// Coverflow Count
m_numCFVersions = min(max(2, m_theme.getInt("_COVERFLOW", "number_of_modes", 2)), 15);
}
@ -959,16 +959,16 @@ void CMenu::_loadCFLayout(int version, bool forceAA, bool otherScrnFmt)
void CMenu::_buildMenus(void)
{
// Default fonts
theme.btnFont = _font(theme.fontSet, "GENERAL", "button_font", BUTTONFONT);
theme.btnFont = _font("GENERAL", "button_font", BUTTONFONT);
theme.btnFontColor = m_theme.getColor("GENERAL", "button_font_color", 0xD0BFDFFF);
theme.lblFont = _font(theme.fontSet, "GENERAL", "label_font", LABELFONT);
theme.lblFont = _font("GENERAL", "label_font", LABELFONT);
theme.lblFontColor = m_theme.getColor("GENERAL", "label_font_color", 0xD0BFDFFF);
theme.titleFont = _font(theme.fontSet, "GENERAL", "title_font", TITLEFONT);
theme.titleFont = _font("GENERAL", "title_font", TITLEFONT);
theme.titleFontColor = m_theme.getColor("GENERAL", "title_font_color", 0xFFFFFFFF);
theme.txtFont = _font(theme.fontSet, "GENERAL", "text_font", TEXTFONT);
theme.txtFont = _font("GENERAL", "text_font", TEXTFONT);
theme.txtFontColor = m_theme.getColor("GENERAL", "text_font_color", 0xFFFFFFFF);
// Default Sounds
@ -1186,9 +1186,9 @@ typedef struct
u32 res;
} FontHolder;
SFont CMenu::_font(CMenu::FontSet &fontSet, const char *domain, const char *key, u32 fontSize, u32 lineSpacing, u32 weight, u32 index, const char *genKey)
SFont CMenu::_font(const char *domain, const char *key, u32 fontSize, u32 lineSpacing, u32 weight, u32 index, const char *genKey)
{
string filename = "";
string filename;
bool general = strncmp(domain, "GENERAL", 7) == 0;
FontHolder fonts[3] = {{ "_size", 6u, 300u, fontSize, 0 }, { "_line_height", 6u, 300u, lineSpacing, 0 }, { "_weight", 1u, 32u, weight, 0 }};
@ -1214,27 +1214,28 @@ SFont CMenu::_font(CMenu::FontSet &fontSet, const char *domain, const char *key,
}
/* ONLY return the font if spacing and weight are the same */
fnt_type font_req;
font_req.name = upperCase(filename.c_str());
font_req.t1 = fonts[0].res;
font_req.t2 = fonts[1].res;
font_req.t3 = fonts[2].res;
FontSet::iterator i = fontSet.find(font_req);
if (i != fontSet.end()) return i->second;
std::vector<SFont>::iterator font_itr;
for(font_itr = theme.fontSet.begin(); font_itr != theme.fontSet.end(); ++font_itr)
{
if(strncmp(filename.c_str(), font_itr->name, 127) == 0 && font_itr->fSize == fonts[0].res &&
font_itr->lineSpacing == fonts[1].res && font_itr->weight && fonts[2].res)
break;
}
if (font_itr != theme.fontSet.end()) return *font_itr;
// TTF not found in memory, load it to create a new font
SFont retFont;
if (!useDefault && retFont.fromFile(fmt("%s/%s", m_themeDataDir.c_str(), filename.c_str()), fonts[0].res, fonts[1].res, fonts[2].res, index))
if(!useDefault && retFont.fromFile(fmt("%s/%s", m_themeDataDir.c_str(), filename.c_str()), fonts[0].res, fonts[1].res, fonts[2].res, index, filename.c_str()))
{
// Theme Font
fontSet[font_req] = retFont;
theme.fontSet.push_back(retFont);
return retFont;
}
/* Fallback to default font */
if(retFont.fromBuffer(m_base_font, m_base_font_size, fonts[0].res, fonts[1].res, fonts[2].res, index))
if(retFont.fromBuffer(m_base_font, m_base_font_size, fonts[0].res, fonts[1].res, fonts[2].res, index, filename.c_str()))
{
// Default font
fontSet[font_req] = retFont;
theme.fontSet.push_back(retFont);
return retFont;
}
return retFont;
@ -1386,7 +1387,7 @@ s16 CMenu::_addButton(const char *domain, SFont font, const wstringEx &text, int
btnTexSet.leftSel = _texture(domain, "texture_left_selected", theme.btnTexLS, false);
btnTexSet.rightSel = _texture(domain, "texture_right_selected", theme.btnTexRS, false);
btnTexSet.centerSel = _texture(domain, "texture_center_selected", theme.btnTexCS, false);
font = _font(theme.fontSet, domain, "font", BUTTONFONT);
font = _font(domain, "font", BUTTONFONT);
GuiSound *clickSound = _sound(theme.soundSet, domain, "click_sound", theme.clickSound->GetName());
GuiSound *hoverSound = _sound(theme.soundSet, domain, "hover_sound", theme.hoverSound->GetName());
return m_btnMgr.addButton(font, text, x, y, width, height, c, btnTexSet, clickSound, hoverSound);
@ -1414,7 +1415,7 @@ s16 CMenu::_addTitle(const char *domain, SFont font, const wstringEx &text, int
y = m_theme.getInt(domain, "y", y);
width = m_theme.getInt(domain, "width", width);
height = m_theme.getInt(domain, "height", height);
font = _font(theme.fontSet, domain, "font", TITLEFONT);
font = _font(domain, "font", TITLEFONT);
style = _textStyle(domain, "style", style);
return m_btnMgr.addLabel(font, text, x, y, width, height, c, style);
}
@ -1428,7 +1429,7 @@ s16 CMenu::_addText(const char *domain, SFont font, const wstringEx &text, int x
y = m_theme.getInt(domain, "y", y);
width = m_theme.getInt(domain, "width", width);
height = m_theme.getInt(domain, "height", height);
font = _font(theme.fontSet, domain, "font", TEXTFONT);
font = _font(domain, "font", TEXTFONT);
style = _textStyle(domain, "style", style);
return m_btnMgr.addLabel(font, text, x, y, width, height, c, style);
}
@ -1442,7 +1443,7 @@ s16 CMenu::_addLabel(const char *domain, SFont font, const wstringEx &text, int
y = m_theme.getInt(domain, "y", y);
width = m_theme.getInt(domain, "width", width);
height = m_theme.getInt(domain, "height", height);
font = _font(theme.fontSet, domain, "font", LABELFONT);
font = _font(domain, "font", LABELFONT);
style = _textStyle(domain, "style", style);
return m_btnMgr.addLabel(font, text, x, y, width, height, c, style);
}
@ -1456,7 +1457,7 @@ s16 CMenu::_addLabel(const char *domain, SFont font, const wstringEx &text, int
y = m_theme.getInt(domain, "y", y);
width = m_theme.getInt(domain, "width", width);
height = m_theme.getInt(domain, "height", height);
font = _font(theme.fontSet, domain, "font", BUTTONFONT);
font = _font(domain, "font", BUTTONFONT);
TexData texBg = _texture(domain, "background_texture", bg, false);
style = _textStyle(domain, "style", style);
return m_btnMgr.addLabel(font, text, x, y, width, height, c, style, texBg);

View File

@ -701,33 +701,12 @@ private:
WO_FORMAT,
WO_COPY_GAME,
};
struct fnt_type {
string name;
u32 t1;
u32 t2;
u32 t3;
};
struct cmp_fnt_type {
bool operator()(const fnt_type& l, const fnt_type& r)
{
if (l.name < r.name) return true;
if (l.name > r.name) return false;
if (l.t1 < r.t1) return true;
if (l.t1 > r.t1) return false;
if (l.t2 < r.t2) return true;
if (l.t2 > r.t2) return false;
if (l.t3 < r.t3) return true;
if (l.t3 > r.t3) return false;
return false;
}
};
typedef map<fnt_type, SFont, cmp_fnt_type> FontSet;
typedef map<string, TexData> TexSet;
typedef map<string, GuiSound*> SoundSet;
struct SThemeData
{
TexSet texSet;
FontSet fontSet;
vector<SFont> fontSet;
SoundSet soundSet;
SFont btnFont;
SFont lblFont;
@ -1072,7 +1051,7 @@ private:
void UpdateCache(u32 view = COVERFLOW_MAX);
void MIOSisDML();
void RemoveCover(const char *id);
SFont _font(CMenu::FontSet &fontSet, const char *domain, const char *key, u32 fontSize, u32 lineSpacing, u32 weight, u32 index, const char *genKey);
SFont _font(const char *domain, const char *key, u32 fontSize, u32 lineSpacing, u32 weight, u32 index, const char *genKey);
TexData _texture(const char *domain, const char *key, TexData &def, bool freeDef = true);
vector<TexData> _textures(const char *domain, const char *key);
void _showWaitMessage();

View File

@ -30,6 +30,7 @@
#include "SoundHandler.hpp"
#include "MusicPlayer.hpp"
#include "WavDecoder.hpp"
#include "fileOps/fileOps.h"
#include "loader/sys.h"
#include "banner/AnimatedBanner.h"
#include "memory/mem2.hpp"
@ -166,8 +167,7 @@ bool GuiSound::Load(const char *path)
if(path == NULL || path[strlen(path)-1] == '/')
return false;
FILE *f = fopen(path, "rb");
if(!f)
if(!fsop_FileExist(path))
{
gprintf("gui_sound.cpp: Failed to load file %s!!\n", path);
return false;