edn/sources/appl/GlyphPainting.cpp

116 lines
3.3 KiB
C++
Raw Normal View History

/**
* @author Edouard DUPIN
2012-11-25 11:55:06 +01:00
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
2012-11-25 11:55:06 +01:00
2013-10-25 20:49:26 +02:00
#include <appl/debug.h>
2012-04-24 09:42:14 +02:00
#include <appl/global.h>
#include <appl/GlyphPainting.h>
2013-10-24 21:09:58 +02:00
#include <ejson/ejson.h>
2012-11-01 10:47:36 +01:00
#include <etk/os/FSNode.h>
2013-10-23 21:19:30 +02:00
#include <ewol/resources/ResourceManager.h>
#undef __class__
#define __class__ "GlyphPainting"
appl::GlyphPainting::GlyphPainting(const etk::UString& _filename) :
ewol::Resource(_filename) {
EWOL_DEBUG("SFP : load \"" << _filename << "\"");
reload();
}
appl::GlyphPainting::~GlyphPainting(void) {
2013-10-24 21:09:58 +02:00
}
void appl::GlyphPainting::reload(void) {
ejson::Document doc;
if (false == doc.load(m_name)) {
APPL_ERROR("Can not load file : '" << m_name << "' = " << etk::FSNode(m_name).getFileSystemName());
2013-10-24 21:09:58 +02:00
return;
}
ejson::Array* baseArray = doc.getArray("ednColor");
if (baseArray == NULL) {
APPL_ERROR("Can not get basic array : 'ednColor'");
return;
}
for (esize_t iii = 0; iii < baseArray->size(); ++iii) {
ejson::Object* tmpObj = baseArray->getObject(iii);
if (tmpObj == NULL) {
APPL_DEBUG(" can not get object in 'ednColor' id=" << iii);
continue;
2013-10-23 21:19:30 +02:00
}
etk::UString name = tmpObj->getStringValue("name", "");
etk::UString background = tmpObj->getStringValue("background", "#FFF0");
etk::UString foreground = tmpObj->getStringValue("foreground", "#000F");
bool italic = tmpObj->getBooleanValue("italic", false);
bool bold = tmpObj->getBooleanValue("bold", false);
APPL_VERBOSE("find new color : '" << name << "' fg='" << foreground << "' bg='" << background << "' italic='" << italic << "' bold='" << bold << "'");
2013-10-24 21:09:58 +02:00
bool findElement = false;
for (esize_t jjj=0; jjj<m_list.size(); ++jjj) {
if (m_list[jjj].getName() != name) {
continue;
}
m_list[jjj].setForeground(foreground);
m_list[jjj].setBackground(background);
m_list[jjj].setItalic(italic);
m_list[jjj].setBold(bold);
2013-10-25 22:12:34 +02:00
findElement = true;
2013-10-24 21:09:58 +02:00
}
if (findElement == true) {
continue;
}
appl::GlyphDecoration tmpDeco(name);
tmpDeco.setForeground(foreground);
tmpDeco.setBackground(background);
tmpDeco.setItalic(italic);
tmpDeco.setBold(bold);
m_list.pushBack(tmpDeco);
2013-10-23 21:19:30 +02:00
}
}
2013-10-24 21:09:58 +02:00
esize_t appl::GlyphPainting::request(const etk::UString& _name) {
for (esize_t iii=0; iii<m_list.size(); ++iii) {
2013-10-25 22:12:34 +02:00
if (m_list[iii].getName() == _name) {
2013-10-24 21:09:58 +02:00
return iii;
}
}
// create an empty deco ...
2013-10-25 22:12:34 +02:00
appl::GlyphDecoration tmpDeco(_name);
2013-10-24 21:09:58 +02:00
m_list.pushBack(tmpDeco);
return m_list.size()-1;
2013-10-23 21:19:30 +02:00
}
appl::GlyphPainting* appl::GlyphPainting::keep(const etk::UString& _filename) {
2013-10-25 22:12:34 +02:00
//EWOL_INFO("KEEP : appl::GlyphPainting : file : \"" << _filename << "\"");
2013-10-23 21:19:30 +02:00
appl::GlyphPainting* object = static_cast<appl::GlyphPainting*>(getManager().localKeep(_filename));
if (NULL != object) {
return object;
}
// this element create a new one every time ....
2013-10-25 22:12:34 +02:00
EWOL_INFO("CREATE : appl::GlyphPainting : file : \"" << _filename << "\"");
2013-10-23 21:19:30 +02:00
object = new appl::GlyphPainting(_filename);
if (NULL == object) {
2013-10-25 22:12:34 +02:00
EWOL_ERROR("allocation error of a resource : ??GlyphPainting??");
2013-10-23 21:19:30 +02:00
return NULL;
}
getManager().localAdd(object);
return object;
}
void appl::GlyphPainting::release(appl::GlyphPainting*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}