[DEV] start rework color and highlight

This commit is contained in:
2013-10-23 21:19:30 +02:00
parent c8fd4183cd
commit 8c57b28d73
16 changed files with 487 additions and 388 deletions

View File

@@ -0,0 +1,55 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <appl/glyphDecoration/GlyphDecoration.h>
#undef __class__
#define __class__ "GlyphDecoration"
appl::GlyphDecoration::GlyphDecoration(const etk::UString &_newColorName) :
m_colorName(_newColorName),
m_colorFG(etk::color::black),
m_colorBG(etk::color::none),
m_italic(false),
m_bold(false)
{
APPL_VERBOSE("New(" << __class__ << ")");
}
void appl::GlyphDecoration::setItalic(bool _enable)
{
m_italic = _enable;
if (true == _enable) {
APPL_VERBOSE("color : \"" << m_colorName << "\" enable italic");
} else {
APPL_VERBOSE("color : \"" << m_colorName << "\" disable italic");
}
}
void appl::GlyphDecoration::setBold(bool _enable)
{
m_bold = _enable;
if (true == _enable) {
APPL_VERBOSE("color : \"" << m_colorName << "\" enable bold");
} else {
APPL_VERBOSE("color : \"" << m_colorName << "\" disable bold");
}
}
etk::CCout& appl::operator <<(etk::CCout& _os, const appl::GlyphDecoration& _obj)
{
_os << "{fg=" << _obj.getForeground();
_os << ",bg=" << _obj.getBackground();
_os << ",italic=" << _obj.getItalic();
_os << ",bold=" << _obj.getBold();
_os << "name='" << _obj.getName() << "'}";
return _os;
}

View File

@@ -0,0 +1,124 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __GLYPH_DECORATION_H__
#define __GLYPH_DECORATION_H__
#include <etk/Color.h>
#include <etk/UString.h>
namespace appl {
class GlyphDecoration {
public:
// Constructeur
GlyphDecoration(const etk::UString& _newColorName = "no_name");
~GlyphDecoration(void) {
// nothing to do ...
};
private:
etk::UString m_colorName; //!< curent color Name
public:
/**
* @brief Set color name of the element.
* @param[in] _newColorName new color name.
*/
void setName(const etk::UString& _newColorName) {
m_colorName = _newColorName;
};
/**
* @brief Get the color name.
* @return The name of the color.
*/
const etk::UString& getName(void) const {
return m_colorName;
};
private:
etk::Color<> m_colorFG; //!< Foreground color
public:
/**
* @brief Set foreground color.
* @param[in] _myColor new color description.
*/
void setForeground(const etk::UString& _myColor) {
m_colorFG = _myColor;
};
/**
* @brief Get the foreground color.
* @return The color.
*/
const etk::Color<>& getForeground(void) const {
return m_colorFG;
};
/**
* @brief Get the foreground color status.
* @return true if the color is visible.
*/
bool haveFg(void) const {
return m_colorFG.a() != 0;
};
private:
etk::Color<> m_colorBG; //!< Background color
public:
/**
* @brief Set background color.
* @param[in] _myColor new color description.
*/
void setBackground(const etk::UString& _myColor) {
m_colorBG = _myColor;
};
/**
* @brief Get the background color.
* @return The color.
*/
const etk::Color<>& getBackground(void) const {
return m_colorBG;
};
/**
* @brief Get the background color status.
* @return true if the color is visible.
*/
bool haveBackground(void) const {
return m_colorBG.a()!=0;
};
private:
bool m_italic; //!< the gryph might be italic.
public:
/**
* @brief Set the italic status.
* @param[in] _enable new status of italic request.
*/
void setItalic(bool _enable);
/**
* @brief Get the italic status.
* @return true if the glyph might be display in italic.
*/
bool getItalic(void) const {
return m_italic;
};
private:
bool m_bold; //!< the gryph might be bold.
public:
/**
* @brief Set the bold status.
* @param[in] _enable new status of bold request.
*/
void setBold(bool _enable);
/**
* @brief Get the bold status.
* @return true if the glyph might be display in bold.
*/
bool getBold(void) const {
return m_bold;
};
};
etk::CCout& operator <<(etk::CCout& _os, const appl::GlyphDecoration& _obj);
}
#endif

View File

@@ -0,0 +1,377 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <appl/glyphDecoration/GlyphPainting.h>
#include <exml/exml.h>
#include <etk/os/FSNode.h>
#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) {
// remove all element
for (int32_t iii=0; iii<m_list.size(); iii++){
if (NULL != m_list[iii]) {
delete(m_list[iii]);
m_list[iii] = NULL;
}
}
m_list.clear();
}
void appl::GlyphPainting::reload(void) {
}
appl::GlyphPainting* appl::GlyphPainting::keep(const etk::UString& _filename) {
EWOL_INFO("KEEP : SimpleConfig : file : \"" << _filename << "\"");
appl::GlyphPainting* object = static_cast<appl::GlyphPainting*>(getManager().localKeep(_filename));
if (NULL != object) {
return object;
}
// this element create a new one every time ....
object = new appl::GlyphPainting(_filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??Mesh.obj??");
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;
}
class classColorManager: public ewol::EObject {
private:
etk::UString m_fileColor;
etk::Vector<Colorize*> listMyColor; //!< List of ALL Color
Colorize * errorColor;
etk::Color<> basicColors[COLOR_NUMBER_MAX];
public:
// Constructeur
classColorManager(void) {
//ewol::widgetMessageMultiCast::add(getWidgetId(), ednMsgGuiChangeColor);
}
~classColorManager(void) {
delete(errorColor);
int32_t i;
// clean all Element
for (i=0; i< listMyColor.size(); i++) {
if (NULL != listMyColor[i]) {
delete(listMyColor[i]);
listMyColor[i] = NULL;
}
}
// clear the compleate list
listMyColor.clear();
}
const char * const getObjectType(void) {
return "Appl::ColorManager";
}
void onReceiveMessage(const ewol::EMessage& _msg) {
/*
switch (id)
{
case APPL_MSG__RELOAD_COLOR_FILE:
{
// Reaload file
// TODO : Check this : Pb in the recopy etk::UString element
etk::UString plop = m_fileColor;
loadFile(plop);
}
break;
}
*/
}
public:
void loadFile(const etk::UString& _xmlFilename);
Colorize* get(const etk::UString& _colorName) {
int32_t i;
for (i=0; i<listMyColor.size(); i++) {
if (listMyColor[i]->getName() == _colorName) {
return listMyColor[i];
}
}
APPL_ERROR(PFX"Color does not Existed ["<< _colorName<<"]" );
// an error
return errorColor;
}
etk::Color<>& get(basicColor_te _myColor) {
if (_myColor < COLOR_NUMBER_MAX) {
return basicColors[_myColor];
} else {
return basicColors[0];
}
}
bool exist(const etk::UString& _colorName) {
int32_t i;
for (i=0; i<listMyColor.size(); i++) {
if (listMyColor[i]->getName() == _colorName) {
return true;
}
}
return false;
}
void displayListOfColor(void) {
int32_t i;
APPL_INFO(PFX"List of ALL COLOR : ");
for (i=0; i<listMyColor.size(); i++) {
//etk::UString elementName = listMyColor[i]->getName();
//APPL_INFO(i << " : \"" << elementName.c_str() << "\"" );
listMyColor[i]->display(i);
}
}
};
void classColorManager::loadFile(const etk::UString& _xmlFilename) {
// remove all old color :
for (int32_t iii=0; iii< listMyColor.size(); iii++) {
if (NULL != listMyColor[iii]) {
delete(listMyColor[iii]);
listMyColor[iii] = NULL;
}
}
// clear the compleate list
listMyColor.clear();
m_fileColor = _xmlFilename;
APPL_DEBUG("open file (COLOR) \"" << _xmlFilename << "\" ? = \"" << m_fileColor << "\"");
errorColor = new Colorize();
errorColor->setBgColor("#00FF00FF");
errorColor->setFgColor("#FF00FFFF");
// open the curent file
etk::UString fileName(etk::UString("DATA:color/") + _xmlFilename + etk::UString(".xml"));
exml::Document doc;
if (doc.load(fileName) == false) {
APPL_ERROR(" can not load file XML : " << fileName);
return;
}
exml::Element* root = (exml::Element*)doc.getNamed("EdnColor");
if (NULL == root ) {
APPL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l ?) main node not find: \"EdnColor\" ...");
return;
}
// parse all the elements :
for(int32_t iii=0; iii< root->size(); iii++) {
exml::Element* pNode = root->getElement(iii);
if (pNode == NULL) {
// trash here all that is not element.
continue;
}
if (pNode->getValue() == "gui") {
for(int32_t iii=0; iii< pNode->size(); iii++) {
exml::Element* pGuiNode = pNode->getElement(iii);
if (pGuiNode == NULL) {
// trash here all that is not element.
continue;
}
if (pGuiNode->getValue()!="color") {
APPL_ERROR("(l "<<pGuiNode->getPos()<<") node not suported : \""<<pGuiNode->getValue()<<"\" must be [color]");
continue;
}
//--------------------------------------------------------------------------------------------
//<color name="basicBackground" val="#000000"/>
//--------------------------------------------------------------------------------------------
etk::UString colorName = pGuiNode->getAttribute("name");
if (colorName.size() == 0) {
APPL_ERROR("(l "<< pGuiNode->getPos() <<") node with no name");
continue;
}
int32_t id = 0;
if (colorName == "CODE_space") {
id = COLOR_CODE_SPACE;
} else if (colorName == "CODE_tabulation") {
id = COLOR_CODE_TAB;
} else if (colorName == "CODE_basicBackgroung") {
id = COLOR_CODE_BASIC_BG;
} else if (colorName == "CODE_cursor") {
id = COLOR_CODE_CURSOR;
} else if (colorName == "CODE_lineNumber") {
id = COLOR_CODE_LINE_NUMBER;
} else if (colorName == "LIST_backgroung1") {
id = COLOR_LIST_BG_1;
} else if (colorName == "LIST_backgroung2") {
id = COLOR_LIST_BG_2;
} else if (colorName == "LIST_backgroungSelected") {
id = COLOR_LIST_BG_SELECTED;
} else if (colorName == "LIST_textNormal") {
id = COLOR_LIST_TEXT_NORMAL;
} else if (colorName == "LIST_textModify") {
id = COLOR_LIST_TEXT_MODIFY;
} else {
APPL_ERROR("(l "<<pGuiNode->getPos()<<") Unknown basic gui color : \"" << colorName << "\"" );
continue;
}
etk::UString color = pGuiNode->getAttribute("val");
if (color.size()!=0) {
basicColors[id] = color;
}
}
} else if (pNode->getValue() == "syntax") {
for(int32_t iii=0; iii< pNode->size(); iii++) {
exml::Element* pGuiNode = pNode->getElement(iii);
if (pGuiNode == NULL) {
continue;
}
if (pGuiNode->getValue()!="color") {
APPL_ERROR(PFX"(l "<<pGuiNode->getPos()<<") node not suported : \""<<pGuiNode->getValue()<<"\" must be [color]");
continue;
}
//--------------------------------------------------------------------------------------------
//<color name="basicBackground" FG="#000000" BG="#000000" bold="no" italic="no"/>
//--------------------------------------------------------------------------------------------
// get the name of the Chaine
etk::UString colorName = pGuiNode->getAttribute("name");
if (colorName.size() == 0) {
APPL_ERROR(PFX"(l "<< pGuiNode->getPos() <<") node with no name");
continue;
}
Colorize* myNewColor = new Colorize();
if (NULL == myNewColor) {
APPL_ERROR(PFX"(l "<< pGuiNode->getPos() <<") == > allocation error");
continue;
}
myNewColor->setName(colorName);
etk::UString colorBG = pGuiNode->getAttribute("BG");
if (colorBG.size()!=0) {
myNewColor->setBgColor(colorBG);
}
etk::UString colorFG = pGuiNode->getAttribute("FG");
if (colorFG.size()!=0) {
myNewColor->setFgColor(colorFG);
}
etk::UString bold = pGuiNode->getAttribute("bold");
if (bold.size()!=0) {
myNewColor->setBold(bold.toBool());
}
etk::UString italic = pGuiNode->getAttribute("italic");
if (italic.size()!=0) {
myNewColor->setItalic(italic.toBool());
}
listMyColor.pushBack(myNewColor);
}
}
}
//SendMessage(APPL_MSG__COLOR_HAS_CHANGE);
//SendMessage(APPL_MSG__USER_DISPLAY_CHANGE);
}
static classColorManager * localManager = NULL;
void ColorizeManager::init(void) {
if (NULL != localManager) {
EWOL_ERROR("ColorizeManager == > already exist, just unlink the previous ...");
localManager = NULL;
}
localManager = new classColorManager();
if (NULL == localManager) {
EWOL_CRITICAL("Allocation of HighlightManager not done ...");
}
}
void ColorizeManager::unInit(void) {
if (NULL == localManager) {
EWOL_ERROR("ColorizeManager == > request UnInit, but does not exist ...");
return;
}
delete(localManager);
localManager = NULL;
}
void ColorizeManager::loadFile(const etk::UString& _xmlFilename) {
if (NULL == localManager) {
return;
}
localManager->loadFile(_xmlFilename);
}
Colorize* ColorizeManager::get(const etk::UString& _colorName) {
if (NULL == localManager) {
return NULL;
}
return localManager->get(_colorName);
}
etk::Color<>& ColorizeManager::get(basicColor_te _myColor) {
static etk::Color<> errorColor;
if (NULL == localManager) {
return errorColor;
}
return localManager->get(_myColor);
}
bool ColorizeManager::exist(const etk::UString& _colorName) {
if (NULL == localManager) {
return false;
}
return localManager->exist(_colorName);
}
void ColorizeManager::displayListOfColor(void) {
if (NULL == localManager) {
return;
}
localManager->displayListOfColor();
}

View File

@@ -0,0 +1,47 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __GLYPH_DECORATION_MANAGER_H__
#define __GLYPH_DECORATION_MANAGER_H__
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/resources/Resource.h>
#include <appl/glyphDecoration/GlyphDecoration.h>
namespace appl {
class GlyphPainting : public ewol::Resource {
private:
etk::Vector<appl::GlyphDecoration*> m_list;
protected:
GlyphPainting(const etk::UString& _filename);
virtual ~GlyphPainting(void);
public:
const char* getType(void) {
return "appl::GlyphPainting";
};
void reload(void);
public:
/**
* @brief keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured.
*/
static appl::GlyphPainting* keep(const etk::UString& _filename = "GlyphPainting::default");
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(appl::GlyphPainting*& _object);
};
};
#endif
*/