Move to gitHub the edn project (remove history keep it on my nas)
This commit is contained in:
167
Sources/Colorize/Colorize.cpp
Normal file
167
Sources/Colorize/Colorize.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file Colorise.cpp
|
||||
* @brief Editeur De N'ours : Colirising system
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include "tools_debug.h"
|
||||
#include "tools_globals.h"
|
||||
#include "Colorize.h"
|
||||
#include "Edn.h"
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Colorize"
|
||||
|
||||
|
||||
Colorize::Colorize( Edn::String &newColorName)
|
||||
{
|
||||
|
||||
m_colorFG.red=0;
|
||||
m_colorFG.green=0;
|
||||
m_colorFG.blue=0;
|
||||
m_colorBG.red=0;
|
||||
m_colorBG.green=0;
|
||||
m_colorBG.blue=0;
|
||||
|
||||
italic = false;
|
||||
bold = false;
|
||||
haveFG = false;
|
||||
haveBG = false;
|
||||
SetName(newColorName);
|
||||
//EDN_INFO("New(Colorise)");
|
||||
}
|
||||
|
||||
Colorize::Colorize(void)
|
||||
{
|
||||
ColorName = "no_name";
|
||||
|
||||
m_colorFG.red=0;
|
||||
m_colorFG.green=0;
|
||||
m_colorFG.blue=0;
|
||||
m_colorBG.red=0;
|
||||
m_colorBG.green=0;
|
||||
m_colorBG.blue=0;
|
||||
|
||||
italic = false;
|
||||
bold = false;
|
||||
haveFG = false;
|
||||
haveBG = false;
|
||||
|
||||
//EDN_INFO("New(Colorise)");
|
||||
}
|
||||
|
||||
Colorize::~Colorize(void)
|
||||
{
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
|
||||
void Colorize::SetName(const char *newColorName)
|
||||
{
|
||||
//EDN_INFO("color change name : \"%s\" ==> \"%s\"",ColorName.c_str(), newColorName);
|
||||
ColorName = newColorName;
|
||||
}
|
||||
|
||||
void Colorize::SetName(Edn::String &newColorName)
|
||||
{
|
||||
//EDN_INFO("color change name : \"%s\" ==> \"%s\"",ColorName.c_str(), newColorName.c_str());
|
||||
ColorName = newColorName;
|
||||
}
|
||||
|
||||
|
||||
Edn::String Colorize::GetName(void)
|
||||
{
|
||||
return ColorName;
|
||||
}
|
||||
|
||||
|
||||
void Colorize::SetFgColor(const char *myColor)
|
||||
{
|
||||
haveFG = true;
|
||||
unsigned int r=0;
|
||||
unsigned int v=0;
|
||||
unsigned int b=0;
|
||||
sscanf(myColor, "#%02x%02x%02x", &r,&v,&b);
|
||||
m_colorFG.red = (float)r/255.0;
|
||||
m_colorFG.green = (float)v/255.0;
|
||||
m_colorFG.blue = (float)b/255.0;
|
||||
//EDN_INFO(myColor << " ==> r="<< r <<" v="<< v <<" b="<< b );
|
||||
}
|
||||
|
||||
void Colorize::SetBgColor(const char *myColor)
|
||||
{
|
||||
haveBG = true;
|
||||
unsigned int r,v,b;
|
||||
sscanf(myColor, "#%02x%02x%02x", &r,&v,&b);
|
||||
m_colorBG.red = (float)r/255.0;
|
||||
m_colorBG.green = (float)v/255.0;
|
||||
m_colorBG.blue = (float)b/255.0;
|
||||
}
|
||||
|
||||
bool Colorize::HaveBg(void)
|
||||
{
|
||||
return haveBG;
|
||||
}
|
||||
|
||||
|
||||
void Colorize::SetItalic(bool enable)
|
||||
{
|
||||
italic = enable;
|
||||
/*
|
||||
if (true == enable) {
|
||||
EDN_INFO("color : \"%s\" enable italic", ColorName.c_str());
|
||||
} else {
|
||||
EDN_INFO("color : \"%s\" disable italic", ColorName.c_str());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool Colorize::GetItalic(void)
|
||||
{
|
||||
return italic;
|
||||
}
|
||||
|
||||
|
||||
void Colorize::SetBold(bool enable)
|
||||
{
|
||||
bold = enable;
|
||||
/*
|
||||
if (true == enable) {
|
||||
EDN_INFO("color : \"%s\" enable bold", ColorName.c_str());
|
||||
} else {
|
||||
EDN_INFO("color : \"%s\" disable bold", ColorName.c_str());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool Colorize::GetBold(void)
|
||||
{
|
||||
return bold;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
81
Sources/Colorize/Colorize.h
Normal file
81
Sources/Colorize/Colorize.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file Colorize.h
|
||||
* @brief Editeur De N'ours : Colirizing system (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __COLORIZE_H__
|
||||
#define __COLORIZE_H__
|
||||
|
||||
#include "Edn.h"
|
||||
|
||||
extern "C" {
|
||||
typedef struct {
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
} color_ts;
|
||||
}
|
||||
|
||||
|
||||
class Colorize {
|
||||
public:
|
||||
// Constructeur
|
||||
Colorize(void);
|
||||
Colorize(Edn::String &newColorName);
|
||||
~Colorize(void);
|
||||
|
||||
void SetName(Edn::String &newColorName);
|
||||
void SetName(const char *newColorName);
|
||||
Edn::String GetName(void);
|
||||
void SetFgColor(const char *myColor);
|
||||
void SetBgColor(const char *myColor);
|
||||
void ApplyFG(cairo_t * cr) { cairo_set_source_rgb(cr, m_colorFG.red, m_colorFG.green, m_colorFG.blue); };
|
||||
void ApplyBG(cairo_t * cr) { cairo_set_source_rgb(cr, m_colorBG.red, m_colorBG.green, m_colorBG.blue); };
|
||||
|
||||
color_ts & GetFG(void) { return m_colorFG; };
|
||||
color_ts & GetBG(void) { return m_colorBG; };
|
||||
|
||||
bool HaveBg(void);
|
||||
|
||||
void SetItalic(bool enable);
|
||||
void SetBold(bool enable);
|
||||
bool GetItalic(void);
|
||||
bool GetBold(void);
|
||||
|
||||
void Display(int32_t i) { EDN_INFO(" " << i << " : \"" << ColorName.c_str() << "\"" /*<< " fg="<< m_colorFG.red <<","<< m_colorFG.green <<","<< m_colorFG.blue <<" bg="<< m_colorBG.red <<","<< m_colorBG.green <<","<< m_colorBG.blue*/ ); };
|
||||
|
||||
private:
|
||||
Edn::String ColorName; //!< curent color Name
|
||||
color_ts m_colorFG;
|
||||
color_ts m_colorBG;
|
||||
|
||||
bool italic;
|
||||
bool bold;
|
||||
bool haveFG;
|
||||
bool haveBG;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
256
Sources/Colorize/ColorizeManager.cpp
Normal file
256
Sources/Colorize/ColorizeManager.cpp
Normal file
@@ -0,0 +1,256 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ColoriseManager.cpp
|
||||
* @brief Editeur De N'ours : Colorising Manager
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "tools_debug.h"
|
||||
#include "tools_globals.h"
|
||||
#include "ColorizeManager.h"
|
||||
#include "tinyxml.h"
|
||||
|
||||
#define PFX "ColorizeManager "
|
||||
|
||||
|
||||
ColorizeManager::ColorizeManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
ColorizeManager::~ColorizeManager(void)
|
||||
{
|
||||
delete(errorColor);
|
||||
// TODO : delete all color previously
|
||||
listMyColor.clear();
|
||||
}
|
||||
|
||||
|
||||
void ColorizeManager::LoadFile(Edn::String &xmlFilename)
|
||||
{
|
||||
LoadFile(xmlFilename.c_str());
|
||||
}
|
||||
|
||||
void ColorizeManager::LoadFile(const char * xmlFilename)
|
||||
{
|
||||
errorColor = new Colorize();
|
||||
errorColor->SetBgColor("#000000");
|
||||
errorColor->SetFgColor("#FFFFFF");
|
||||
|
||||
// allocate the document in the stack
|
||||
TiXmlDocument XmlDocument;
|
||||
// open the curent File
|
||||
XmlDocument.LoadFile(xmlFilename);
|
||||
TiXmlElement* root = XmlDocument.FirstChildElement( "EdnColor" );
|
||||
if (NULL == root )
|
||||
{
|
||||
EDN_ERROR(PFX"(l ?) main node not find: \"EdnColor\"");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
TiXmlNode * pNode = root->FirstChild();
|
||||
while(NULL != pNode)
|
||||
{
|
||||
if (pNode->Type()==TiXmlNode::TINYXML_COMMENT) {
|
||||
// nothing to do, just proceed to next step
|
||||
} else if (!strcmp(pNode->Value(), "gui")) {
|
||||
TiXmlNode * pGuiNode = pNode->FirstChild();
|
||||
while(NULL != pGuiNode)
|
||||
{
|
||||
if (pGuiNode->Type()==TiXmlNode::TINYXML_COMMENT) {
|
||||
// nothing to do, just proceed to next step
|
||||
} else if (!strcmp(pGuiNode->Value(), "color")) {
|
||||
//--------------------------------------------------------------------------------------------
|
||||
//<color name="basicBackground" val="#000000"/>
|
||||
//--------------------------------------------------------------------------------------------
|
||||
const char *colorName = pGuiNode->ToElement()->Attribute("name");
|
||||
int32_t id = 0;
|
||||
if (NULL == colorName) {
|
||||
EDN_ERROR("(l "<< pGuiNode->Row() <<") node with no name");
|
||||
// get next node element
|
||||
pGuiNode = pGuiNode->NextSibling();
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(colorName, "CODE_space")) {
|
||||
id = COLOR_CODE_SPACE;
|
||||
} else if (!strcmp(colorName, "CODE_tabulation")) {
|
||||
id = COLOR_CODE_TAB;
|
||||
} else if (!strcmp(colorName, "CODE_basicBackgroung")) {
|
||||
id = COLOR_CODE_BASIC_BG;
|
||||
} else if (!strcmp(colorName, "CODE_cursor")) {
|
||||
id = COLOR_CODE_CURSOR;
|
||||
} else if (!strcmp(colorName, "CODE_lineNumber")) {
|
||||
id = COLOR_CODE_LINE_NUMBER;
|
||||
} else if (!strcmp(colorName, "LIST_backgroung1")) {
|
||||
id = COLOR_LIST_BG_1;
|
||||
} else if (!strcmp(colorName, "LIST_backgroung2")) {
|
||||
id = COLOR_LIST_BG_2;
|
||||
} else if (!strcmp(colorName, "LIST_backgroungSelected")) {
|
||||
id = COLOR_LIST_BG_SELECTED;
|
||||
} else if (!strcmp(colorName, "LIST_textNormal")) {
|
||||
id = COLOR_LIST_TEXT_NORMAL;
|
||||
} else if (!strcmp(colorName, "LIST_textModify")) {
|
||||
id = COLOR_LIST_TEXT_MODIFY;
|
||||
} else {
|
||||
EDN_ERROR("(l "<<pGuiNode->Row()<<") Unknown basic gui color : \"" << colorName << "\"" );
|
||||
// get next node element
|
||||
pGuiNode = pGuiNode->NextSibling();
|
||||
continue;
|
||||
}
|
||||
const char *color = pGuiNode->ToElement()->Attribute("val");
|
||||
if (NULL != color) {
|
||||
unsigned int r=0;
|
||||
unsigned int v=0;
|
||||
unsigned int b=0;
|
||||
sscanf(color, "#%02x%02x%02x", &r,&v,&b);
|
||||
basicColors[id].red = (float)r/255.0;
|
||||
basicColors[id].green = (float)v/255.0;
|
||||
basicColors[id].blue = (float)b/255.0;
|
||||
/*
|
||||
EDN_INFO(" Specify color for system ID="<< id );
|
||||
EDN_INFO(" " << color << " ==> r="<< r <<" v="<< v <<" b="<< b );
|
||||
EDN_INFO(" " << color << " ==> r="<< basicColors[id].red <<" v="<< basicColors[id].green <<" b="<< basicColors[id].blue );
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
EDN_ERROR("(l "<<pGuiNode->Row()<<") node not suported : \""<<pGuiNode->Value()<<"\" must be [color]");
|
||||
}
|
||||
// get next node element
|
||||
pGuiNode = pGuiNode->NextSibling();
|
||||
}
|
||||
} else if (!strcmp(pNode->Value(), "syntax")) {
|
||||
TiXmlNode * pGuiNode = pNode->FirstChild();
|
||||
while(NULL != pGuiNode)
|
||||
{
|
||||
if (pGuiNode->Type()==TiXmlNode::TINYXML_COMMENT) {
|
||||
// nothing to do, just proceed to next step
|
||||
} else if (!strcmp(pGuiNode->Value(), "color")) {
|
||||
Colorize *myNewColor = new Colorize();
|
||||
//--------------------------------------------------------------------------------------------
|
||||
//<color name="basicBackground" FG="#000000" BG="#000000" bold="no" italic="no"/>
|
||||
//--------------------------------------------------------------------------------------------
|
||||
// get the name of the Chaine
|
||||
const char *colorName = pGuiNode->ToElement()->Attribute("name");
|
||||
if (NULL == colorName) {
|
||||
EDN_ERROR(PFX"(l "<< pGuiNode->Row() <<") node with no name");
|
||||
// get next node element
|
||||
pGuiNode = pGuiNode->NextSibling();
|
||||
continue;
|
||||
} else {
|
||||
myNewColor->SetName(colorName);
|
||||
//EDN_INFO(PFX"Add a new color in the panel : \"%s\"", colorName);
|
||||
}
|
||||
|
||||
const char *colorBG = pGuiNode->ToElement()->Attribute("BG");
|
||||
if (NULL != colorBG) {
|
||||
myNewColor->SetBgColor(colorBG);
|
||||
}
|
||||
|
||||
const char *colorFG = pGuiNode->ToElement()->Attribute("FG");
|
||||
if (NULL != colorFG) {
|
||||
myNewColor->SetFgColor(colorFG);
|
||||
}
|
||||
|
||||
const char *bold = pGuiNode->ToElement()->Attribute("bold");
|
||||
if (NULL != bold) {
|
||||
if(0 == strcmp(bold, "yes") ) {
|
||||
myNewColor->SetBold(true);
|
||||
}
|
||||
}
|
||||
|
||||
const char *italic = pGuiNode->ToElement()->Attribute("italic");
|
||||
if (NULL != italic) {
|
||||
if(0 == strcmp(italic, "yes") ) {
|
||||
myNewColor->SetItalic(true);
|
||||
}
|
||||
}
|
||||
listMyColor.push_back(myNewColor);
|
||||
} else {
|
||||
EDN_ERROR(PFX"(l "<<pNode->Row()<<") node not suported : \""<<pNode->Value()<<"\" must be [color]");
|
||||
}
|
||||
pGuiNode = pGuiNode->NextSibling();
|
||||
}
|
||||
} else {
|
||||
EDN_ERROR(PFX"(l "<<pNode->Row()<<") node not suported : \""<<pNode->Value()<<"\" must be [gui,syntax]");
|
||||
}
|
||||
// get next node element
|
||||
pNode = pNode->NextSibling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Colorize *ColorizeManager::Get(const char *colorName)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i=0; i<listMyColor.size(); i++) {
|
||||
Edn::String elementName = listMyColor[i]->GetName();
|
||||
if (elementName == colorName) {
|
||||
return listMyColor[i];
|
||||
}
|
||||
}
|
||||
EDN_ERROR(PFX"Color does not Existed ["<< colorName<<"]" );
|
||||
// an error
|
||||
return errorColor;
|
||||
}
|
||||
|
||||
Colorize *ColorizeManager::Get(Edn::String &colorName)
|
||||
{
|
||||
return Get(colorName.c_str());
|
||||
}
|
||||
|
||||
color_ts & ColorizeManager::Get(basicColor_te myColor)
|
||||
{
|
||||
if (myColor < COLOR_NUMBER_MAX) {
|
||||
return basicColors[myColor];
|
||||
} else {
|
||||
return basicColors[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ColorizeManager::Exist(const char *colorName)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i=0; i<listMyColor.size(); i++) {
|
||||
Edn::String elementName = listMyColor[i]->GetName();
|
||||
if (elementName == colorName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool ColorizeManager::Exist(Edn::String &colorName)
|
||||
{
|
||||
return Exist(colorName.c_str());
|
||||
}
|
||||
|
||||
void ColorizeManager::DisplayListOfColor(void)
|
||||
{
|
||||
uint32_t i;
|
||||
EDN_INFO(PFX"List of ALL COLOR : ");
|
||||
for (i=0; i<listMyColor.size(); i++) {
|
||||
//Edn::String elementName = listMyColor[i]->GetName();
|
||||
//EDN_INFO(i << " : \"" << elementName.c_str() << "\"" );
|
||||
listMyColor[i]->Display(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
78
Sources/Colorize/ColorizeManager.h
Normal file
78
Sources/Colorize/ColorizeManager.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ColoriseManager.h
|
||||
* @brief Editeur De N'ours : Colorising Manager (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 14/12/2010
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __COLORIZE_MANAGER_H__
|
||||
#define __COLORIZE_MANAGER_H__
|
||||
|
||||
#include "Singleton.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Colorize.h"
|
||||
|
||||
typedef enum {
|
||||
// BASIC color for codeViewer
|
||||
COLOR_CODE_SPACE,
|
||||
COLOR_CODE_TAB,
|
||||
COLOR_CODE_BASIC_BG,
|
||||
COLOR_CODE_CURSOR,
|
||||
COLOR_CODE_LINE_NUMBER,
|
||||
// Basic color for list viewer
|
||||
COLOR_LIST_BG_1,
|
||||
COLOR_LIST_BG_2,
|
||||
COLOR_LIST_BG_SELECTED,
|
||||
COLOR_LIST_TEXT_NORMAL,
|
||||
COLOR_LIST_TEXT_MODIFY,
|
||||
// KNOW the number of BASIC color
|
||||
COLOR_NUMBER_MAX,
|
||||
}basicColor_te;
|
||||
|
||||
|
||||
|
||||
class ColorizeManager: public Singleton<ColorizeManager>
|
||||
{
|
||||
friend class Singleton<ColorizeManager>;
|
||||
// specific for sigleton system...
|
||||
private:
|
||||
// Constructeur
|
||||
ColorizeManager(void);
|
||||
~ColorizeManager(void);
|
||||
public:
|
||||
void LoadFile(Edn::String &xmlFilename);
|
||||
void LoadFile(const char * xmlFilename);
|
||||
Colorize * Get(const char *colorName);
|
||||
Colorize * Get(Edn::String &colorName);
|
||||
color_ts & Get(basicColor_te myColor);
|
||||
bool Exist(Edn::String &colorName);
|
||||
bool Exist(const char *colorName);
|
||||
void DisplayListOfColor(void);
|
||||
|
||||
private:
|
||||
std::vector<Colorize*> listMyColor; //!< List of ALL Color
|
||||
Colorize* errorColor;
|
||||
color_ts basicColors[COLOR_NUMBER_MAX];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user