edn/sources/appl/GlyphPainting.cpp

93 lines
2.6 KiB
C++
Raw Normal View History

2016-05-02 22:01:55 +02:00
/** @file
* @author Edouard DUPIN
2012-11-25 11:55:06 +01:00
* @copyright 2010, Edouard DUPIN, all right reserved
* @license GPL v3 (see license file)
*/
2016-10-03 22:01:55 +02:00
#include <appl/debug.hpp>
#include <appl/global.hpp>
#include <appl/GlyphPainting.hpp>
#include <ejson/ejson.hpp>
#include <etk/os/FSNode.hpp>
#include <gale/resource/Manager.hpp>
2013-10-23 21:19:30 +02:00
appl::GlyphPainting::GlyphPainting() {
addResourceType("appl::GlyphPainting");
}
2017-08-28 00:09:10 +02:00
void appl::GlyphPainting::init(const etk::String& _filename) {
gale::Resource::init(_filename);
APPL_DEBUG("SFP : load \"" << _filename << "\"");
2013-10-23 21:19:30 +02:00
reload();
}
appl::GlyphPainting::~GlyphPainting() {
2013-10-24 21:09:58 +02:00
}
void appl::GlyphPainting::reload() {
2013-10-24 21:09:58 +02:00
ejson::Document doc;
2016-04-20 21:19:11 +02:00
if (doc.load(m_name) == false) {
APPL_ERROR("Can not load file : '" << m_name << "' = " << etk::FSNode(m_name).getFileSystemName());
2013-10-24 21:09:58 +02:00
return;
}
2013-11-14 21:57:10 +01:00
// for debug only :
/*
APPL_WARNING("Load file : '" << m_name << "' = " << etk::FSNode(m_name).getFileSystemName());
2017-08-28 00:09:10 +02:00
etk::String tmppppp;
2013-11-14 21:57:10 +01:00
doc.generate(tmppppp);
APPL_DEBUG(tmppppp);
*/
2016-04-20 21:19:11 +02:00
ejson::Array baseArray = doc["ednColor"].toArray();
if (baseArray.exist() == false) {
2013-10-24 21:09:58 +02:00
APPL_ERROR("Can not get basic array : 'ednColor'");
return;
}
2016-04-20 21:19:11 +02:00
for (const auto it : baseArray) {
ejson::Object tmpObj = it.toObject();
if (tmpObj.exist() == false) {
APPL_DEBUG(" can not get object in 'ednColor' it=" << it);
2013-10-24 21:09:58 +02:00
continue;
2013-10-23 21:19:30 +02:00
}
2017-08-28 00:09:10 +02:00
etk::String name = tmpObj["name"].toString().get();
etk::String background = tmpObj["background"].toString().get("#FFF0");
etk::String foreground = tmpObj["foreground"].toString().get("#000F");
2016-04-29 21:47:54 +02:00
bool italic = tmpObj["italic"].toBoolean().get(false);
bool bold = tmpObj["bold"].toBoolean().get(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;
2014-06-02 21:04:35 +02:00
for (size_t jjj=0; jjj<m_list.size(); ++jjj) {
2013-10-24 21:09:58 +02:00
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);
2017-08-28 00:09:10 +02:00
m_list.pushBack(tmpDeco);
2013-10-23 21:19:30 +02:00
}
}
2013-10-24 21:09:58 +02:00
2017-08-28 00:09:10 +02:00
int32_t appl::GlyphPainting::request(const etk::String& _name) {
2014-06-02 21:04:35 +02:00
for (size_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);
2017-08-28 00:09:10 +02:00
m_list.pushBack(tmpDeco);
2013-10-24 21:09:58 +02:00
return m_list.size()-1;
2013-10-23 21:19:30 +02:00
}