Initial work on icon theme
This commit is contained in:
parent
95a74a9917
commit
e6801e1599
@ -157,8 +157,8 @@ void LayoutManager::readCoords(Widget* self)
|
||||
if (self->m_properties[PROP_ICON].size() > 0)
|
||||
{
|
||||
// PROP_ICON includes paths (e.g. gui/icons/logo.png)
|
||||
ITexture* texture = irr_driver->getTexture(file_manager->getAsset(
|
||||
self->m_properties[PROP_ICON]));
|
||||
ITexture* texture = irr_driver->getTexture(
|
||||
GUIEngine::getSkin()->getThemedIcon(self->m_properties[PROP_ICON]));
|
||||
|
||||
if (texture != NULL)
|
||||
{
|
||||
|
@ -53,6 +53,8 @@ namespace SkinConfig
|
||||
{
|
||||
static std::map<std::string, BoxRenderParams> m_render_params;
|
||||
static std::map<std::string, SColor> m_colors;
|
||||
static std::string m_data_path;
|
||||
static bool m_icon_theme;
|
||||
|
||||
static void parseElement(const XMLNode* node)
|
||||
{
|
||||
@ -153,6 +155,12 @@ namespace SkinConfig
|
||||
*/
|
||||
static void loadFromFile(std::string file)
|
||||
{
|
||||
// Clear global variables for android
|
||||
m_render_params.clear();
|
||||
m_colors.clear();
|
||||
m_data_path.clear();
|
||||
m_icon_theme = false;
|
||||
|
||||
XMLNode* root = file_manager->createXMLTree(file);
|
||||
if(!root)
|
||||
{
|
||||
@ -161,6 +169,8 @@ namespace SkinConfig
|
||||
throw std::runtime_error("Invalid skin file");
|
||||
}
|
||||
|
||||
m_data_path = StringUtils::getPath(file_manager
|
||||
->getFileSystem()->getAbsolutePath(file.c_str()).c_str()) + "/";
|
||||
const int amount = root->getNumNodes();
|
||||
for (int i=0; i<amount; i++)
|
||||
{
|
||||
@ -174,6 +184,15 @@ namespace SkinConfig
|
||||
{
|
||||
parseColor(node);
|
||||
}
|
||||
else if (node->getName() == "advanced")
|
||||
{
|
||||
bool ret = false;
|
||||
if (node->get("icon_theme", &ret))
|
||||
{
|
||||
if (file_manager->fileExists(m_data_path + "data/gui/icons/"))
|
||||
m_icon_theme = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::error("skin", "Unknown node in XML file '%s'.",
|
||||
@ -2610,3 +2629,40 @@ void Skin::setSpriteBank (IGUISpriteBank *bank)
|
||||
{
|
||||
m_fallback_skin->setSpriteBank(bank);
|
||||
} // setSpriteBank
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
const std::string& Skin::getDataPath() const
|
||||
{
|
||||
return SkinConfig::m_data_path;
|
||||
} // getDataPath
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool Skin::hasIconTheme() const
|
||||
{
|
||||
return SkinConfig::m_icon_theme;
|
||||
} // hasIconTheme
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/* Return a themed icon from its relative path, if not found return the bundled
|
||||
* icon. */
|
||||
std::string Skin::getThemedIcon(const std::string& relative_path) const
|
||||
{
|
||||
if (!SkinConfig::m_icon_theme ||
|
||||
relative_path.find("gui/icons/") == std::string::npos)
|
||||
{
|
||||
return file_manager->getAsset(relative_path);
|
||||
}
|
||||
|
||||
if (relative_path.find(SkinConfig::m_data_path) != std::string::npos &&
|
||||
file_manager->fileExists(relative_path))
|
||||
{
|
||||
// Absolute path given
|
||||
return relative_path;
|
||||
}
|
||||
|
||||
std::string test_path = SkinConfig::m_data_path + "data/" + relative_path;
|
||||
if (file_manager->fileExists(test_path))
|
||||
return test_path;
|
||||
else
|
||||
return file_manager->getAsset(relative_path);
|
||||
} // getThemedIcon
|
||||
|
@ -420,7 +420,11 @@ namespace GUIEngine
|
||||
|
||||
gui::IGUISkin* getFallbackSkin() { return m_fallback_skin; }
|
||||
|
||||
const std::string& getDataPath() const;
|
||||
|
||||
bool hasIconTheme() const;
|
||||
|
||||
std::string getThemedIcon(const std::string& relative_path) const;
|
||||
}; // Skin
|
||||
} // guiengine
|
||||
#endif
|
||||
|
@ -75,7 +75,8 @@ void IconButtonWidget::add()
|
||||
}
|
||||
else if (m_icon_path_type == ICON_PATH_TYPE_RELATIVE)
|
||||
{
|
||||
std::string file = file_manager->getAsset(m_properties[PROP_ICON]);
|
||||
std::string file =
|
||||
GUIEngine::getSkin()->getThemedIcon(m_properties[PROP_ICON]);
|
||||
setTexture(irr_driver->getTexture(file));
|
||||
}
|
||||
}
|
||||
@ -106,8 +107,8 @@ void IconButtonWidget::add()
|
||||
else if (m_icon_path_type == ICON_PATH_TYPE_RELATIVE)
|
||||
{
|
||||
m_highlight_texture =
|
||||
irr_driver->getTexture(file_manager->getAsset(
|
||||
m_properties[PROP_FOCUS_ICON]));
|
||||
irr_driver->getTexture(
|
||||
GUIEngine::getSkin()->getThemedIcon(m_properties[PROP_FOCUS_ICON]));
|
||||
}
|
||||
|
||||
}
|
||||
@ -272,7 +273,7 @@ void IconButtonWidget::setImage(const char* path_to_texture, IconPathType pathTy
|
||||
}
|
||||
else if (m_icon_path_type == ICON_PATH_TYPE_RELATIVE)
|
||||
{
|
||||
std::string file = file_manager->getAsset(m_properties[PROP_ICON]);
|
||||
std::string file = GUIEngine::getSkin()->getThemedIcon(m_properties[PROP_ICON]);
|
||||
setTexture(irr_driver->getTexture(file));
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ void RibbonWidget::add()
|
||||
GUIEngine::getGUIEnv()->addButton(icon_part, subbtn,
|
||||
same_id, L"");
|
||||
icon->setScaleImage(true);
|
||||
std::string filename = file_manager->getAsset(
|
||||
std::string filename = GUIEngine::getSkin()->getThemedIcon(
|
||||
m_active_children[i].m_properties[PROP_ICON]);
|
||||
icon->setImage( irr_driver->getTexture(filename.c_str()) );
|
||||
icon->setUseAlphaChannel(true);
|
||||
@ -340,7 +340,7 @@ void RibbonWidget::add()
|
||||
GUIEngine::getGUIEnv()->addButton(icon_part, subbtn,
|
||||
same_id, L"");
|
||||
icon->setScaleImage(true);
|
||||
std::string filename = file_manager->getAsset(
|
||||
std::string filename = GUIEngine::getSkin()->getThemedIcon(
|
||||
m_active_children[i].m_properties[PROP_ICON]);
|
||||
icon->setImage( irr_driver->getTexture(filename.c_str()) );
|
||||
icon->setUseAlphaChannel(true);
|
||||
@ -403,7 +403,7 @@ void RibbonWidget::add()
|
||||
|
||||
// calculate the size of the image
|
||||
std::string filename =
|
||||
file_manager->getAsset(m_active_children[i].m_properties[PROP_ICON]);
|
||||
GUIEngine::getSkin()->getThemedIcon(m_active_children[i].m_properties[PROP_ICON]);
|
||||
video::ITexture* image =
|
||||
irr_driver->getTexture((filename).c_str());
|
||||
if(!image)
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/skin.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "utils/command_line.hpp"
|
||||
@ -131,6 +133,7 @@ FileManager* file_manager = 0;
|
||||
*/
|
||||
FileManager::FileManager()
|
||||
{
|
||||
m_root_dirs.clear();
|
||||
resetSubdir();
|
||||
#ifdef __APPLE__
|
||||
// irrLicht's createDevice method has a nasty habit of messing the CWD.
|
||||
@ -775,7 +778,16 @@ std::string FileManager::getAssetChecked(FileManager::AssetType type,
|
||||
std::string FileManager::getAsset(FileManager::AssetType type,
|
||||
const std::string &name) const
|
||||
{
|
||||
return m_subdir_name[type]+name;
|
||||
if (type == GUI_ICON && GUIEngine::getSkin()->hasIconTheme())
|
||||
{
|
||||
const std::string test_path = GUIEngine::getSkin()->getDataPath() +
|
||||
"data/gui/icons/" + name;
|
||||
if (fileExists(test_path))
|
||||
return test_path;
|
||||
else
|
||||
return m_subdir_name[type] + name;
|
||||
}
|
||||
return m_subdir_name[type] + name;
|
||||
} // getAsset
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user