2010-09-24 19:58:56 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2010
|
|
|
|
* by Dimok
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
***************************************************************************/
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "CTheme.h"
|
|
|
|
#include "libwiigui/gui.h"
|
2010-12-31 00:49:22 +01:00
|
|
|
#include "settings/CSettings.h"
|
2010-12-28 18:02:10 +01:00
|
|
|
#include "FileOperations/fileops.h"
|
|
|
|
#include "FreeTypeGX.h"
|
|
|
|
|
|
|
|
FreeTypeGX * fontSystem = NULL;
|
2011-01-08 13:35:41 +01:00
|
|
|
static FT_Byte * MainFont = NULL;
|
|
|
|
static u32 MainFontSize = 0;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
bool Theme::ShowTooltips = true;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
void Theme::CleanUp()
|
2010-09-24 19:58:56 +02:00
|
|
|
{
|
2010-12-26 18:02:14 +01:00
|
|
|
ThemeCleanUp();
|
2010-09-26 10:33:43 +02:00
|
|
|
Resources::Clear();
|
2010-12-28 18:02:10 +01:00
|
|
|
ClearFontData();
|
2010-09-24 19:58:56 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
void Theme::SetDefault()
|
2010-09-24 19:58:56 +02:00
|
|
|
{
|
2010-12-28 18:02:10 +01:00
|
|
|
ShowTooltips = true;
|
|
|
|
CleanUp();
|
2010-12-31 00:49:22 +01:00
|
|
|
strcpy(Settings.theme, "");
|
2010-12-28 18:02:10 +01:00
|
|
|
LoadFont("");
|
|
|
|
}
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
bool Theme::Load(const char * theme_file_path)
|
|
|
|
{
|
|
|
|
bool result = LoadTheme(theme_file_path);
|
|
|
|
if(!result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Theme::ShowTooltips = (thInt("1 - Enable tooltips: 0 for off and 1 for on") != 0);
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
FILE * file = fopen(theme_file_path, "rb");
|
|
|
|
if(!file)
|
|
|
|
return false;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
char line[300];
|
|
|
|
char * Foldername = NULL;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), file))
|
|
|
|
{
|
2010-12-26 18:02:14 +01:00
|
|
|
char * ptr = strcasestr(line, "Image-Folder:");
|
|
|
|
if(!ptr)
|
|
|
|
continue;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
ptr += strlen("Image-Folder:");
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
while(*ptr != '\0' && *ptr == ' ') ptr++;
|
2010-09-26 10:33:43 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
Foldername = ptr;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
while(*ptr != '\\' && *ptr != '"' && *ptr != '\0') ptr++;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
*ptr = '\0';
|
|
|
|
break;
|
|
|
|
}
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
fclose(file);
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
if(!Foldername)
|
|
|
|
return result;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-31 00:49:22 +01:00
|
|
|
char theme_path[300];
|
|
|
|
snprintf(theme_path, sizeof(theme_path), theme_file_path);
|
|
|
|
|
|
|
|
char * ptr = strrchr(theme_path, '/');
|
|
|
|
if(ptr) *ptr = '\0';
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
snprintf(theme_path, sizeof(theme_path), "%s/%s", theme_path, Foldername);
|
2011-01-02 10:23:44 +01:00
|
|
|
if(!Resources::LoadFiles(theme_path))
|
|
|
|
{
|
|
|
|
const char * ThemeFilename = strrchr(theme_file_path, '/')+1;
|
|
|
|
char Filename[255];
|
|
|
|
snprintf(Filename, sizeof(Filename), ThemeFilename);
|
|
|
|
|
|
|
|
char * fileext = strrchr(Filename, '.');
|
|
|
|
if(fileext) *fileext = 0;
|
|
|
|
|
|
|
|
char * ptr = strrchr(theme_path, '/');
|
|
|
|
*ptr = 0;
|
|
|
|
snprintf(theme_path, sizeof(theme_path), "%s/%s", theme_path, Filename);
|
2011-01-02 10:31:32 +01:00
|
|
|
Resources::LoadFiles(theme_path);
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
//! Override font.ttf with the theme font.ttf if it exists in the image folder
|
|
|
|
char FontPath[300];
|
|
|
|
snprintf(FontPath, sizeof(FontPath), "%s/font.ttf", theme_path);
|
|
|
|
|
|
|
|
if(CheckFile(FontPath))
|
|
|
|
Theme::LoadFont(theme_path);
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
return result;
|
2010-09-24 19:58:56 +02:00
|
|
|
}
|
2010-12-28 18:02:10 +01:00
|
|
|
|
|
|
|
bool Theme::LoadFont(const char *path)
|
|
|
|
{
|
|
|
|
char FontPath[300];
|
|
|
|
bool result = false;
|
|
|
|
FILE *pfile = NULL;
|
|
|
|
|
|
|
|
ClearFontData();
|
|
|
|
|
|
|
|
snprintf(FontPath, sizeof(FontPath), "%s/font.ttf", path);
|
|
|
|
|
|
|
|
pfile = fopen(FontPath, "rb");
|
|
|
|
|
|
|
|
if (pfile)
|
|
|
|
{
|
|
|
|
fseek(pfile, 0, SEEK_END);
|
|
|
|
MainFontSize = ftell(pfile);
|
|
|
|
rewind(pfile);
|
|
|
|
|
|
|
|
MainFont = new (std::nothrow) FT_Byte[MainFontSize];
|
2011-01-08 13:35:41 +01:00
|
|
|
if (MainFont)
|
2010-12-28 18:02:10 +01:00
|
|
|
{
|
|
|
|
fread(MainFont, 1, MainFontSize, pfile);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
fclose(pfile);
|
|
|
|
}
|
|
|
|
|
2011-01-08 13:35:41 +01:00
|
|
|
FT_Byte * loadedFont = MainFont ? MainFont : (FT_Byte *) Resources::GetFile("font.ttf");
|
|
|
|
u32 loadedFontSize = MainFont ? MainFontSize : Resources::GetFileSize("font.ttf");
|
|
|
|
|
|
|
|
fontSystem = new FreeTypeGX(loadedFont, loadedFontSize);
|
2010-12-28 18:02:10 +01:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::ClearFontData()
|
|
|
|
{
|
2011-01-08 13:35:41 +01:00
|
|
|
if (fontSystem)
|
|
|
|
delete fontSystem;
|
2010-12-28 18:02:10 +01:00
|
|
|
fontSystem = NULL;
|
|
|
|
|
2011-01-08 13:35:41 +01:00
|
|
|
if (MainFont)
|
|
|
|
delete [] MainFont;
|
|
|
|
MainFont = NULL;
|
2010-12-28 18:02:10 +01:00
|
|
|
}
|