First parsing of the theme File

This commit is contained in:
Edouard Dupin 2011-11-23 18:26:25 +01:00
parent 5308da4fc2
commit 6137705009
10 changed files with 338 additions and 57 deletions

View File

@ -25,6 +25,7 @@
#include <ewol/ewol.h>
#include <ewol/Font.h>
#include <ewol/themeManager.h>
#include <ewol/widget/Button.h>
#include <ewol/widget/CheckBox.h>
#include <ewol/widget/SizerHori.h>
@ -100,7 +101,7 @@ int main(int argc, char *argv[])
*/
ewol::SetFontFolder("Font");
ewol::SetDefaultFont("freefont/FreeMono", 14);
ewol::theme::LoadDefault("dataTest/exemple.eol");
Plop * myWindowsExample = new Plop();

View File

@ -27,5 +27,21 @@
#ifndef __EWOL_THEME_EOL_BASE__H__
#define __EWOL_THEME_EOL_BASE__H__
#include <etk/Types.h>
#include <etk/String.h>
#include <ewol/OObject.h>
namespace ewol {
namespace theme {
class EolBase {
public:
EolBase(void) { };
virtual ~EolBase(void) { };
};
};
};
#endif

View File

@ -23,7 +23,65 @@
*/
#include <ewol/theme/EolColor.h>
#undef __class__
#define __class__ "ewol::theme::EolColor"
ewol::theme::EolColor::EolColor(void)
{
}
ewol::theme::EolColor::~EolColor(void)
{
}
void ewol::theme::EolColor::Load(const char * data, int32_t len)
{
}
etk::String ewol::theme::EolColor::GetName(void)
{
return m_name;
}
void ewol::theme::EolColor::SetName(etk::String & newName)
{
m_name = newName;
}
bool ewol::theme::EolColor::HasName(etk::String & newName)
{
return m_name == newName;
}
color_ts ewol::theme::EolColor::Get(void)
{
return m_color;
}
void ewol::theme::EolColor::Set(color_ts newColor)
{
m_color = newColor;
}
void ewol::theme::EolColor::Set(etkFloat_t red, etkFloat_t green, etkFloat_t blue, etkFloat_t alpha)
{
m_color.red = red;
m_color.green = green;
m_color.blue = blue;
m_color.alpha = alpha;
}

View File

@ -26,5 +26,34 @@
#ifndef __EWOL_THEME_EOL_COLOR_H__
#define __EWOL_THEME_EOL_COLOR_H__
#include <etk/Types.h>
#include <etk/String.h>
#include <etk/File.h>
#include <ewol/OObject.h>
namespace ewol {
namespace theme {
class EolColor {
public:
EolColor(void);
virtual ~EolColor(void);
void Load(const char * data, int32_t len);
etk::String GetName(void);
void SetName(etk::String & newName);
bool HasName(etk::String & newName);
color_ts Get(void);
void Set(color_ts newColor);
void Set(etkFloat_t red, etkFloat_t green, etkFloat_t blue, etkFloat_t alpha = 1);
private:
color_ts m_color;
etk::String m_name;
};
};
};
#endif

View File

@ -27,7 +27,14 @@
#ifndef __EWOL_THEME_EOL_ELEMENT_H__
#define __EWOL_THEME_EOL_ELEMENT_H__
/*
#include <etk/Types.h>
#include <etk/String.h>
#include <etk/File.h>
#include <ewol/OObject.h>
#include <ewol/theme/EolColor.h>
#include <ewol/theme/EolElementFrame.h>
namespace ewol {
namespace theme {
class EolElement {
@ -40,17 +47,21 @@ namespace ewol {
int32_t GetNbFrame(int32_t id) {return 0;};
int32_t GetFrameId(int32_t id, etk::String & frameName) {return 0;};
int32_t GetObjectId(etk::String name) { return -1; };
* /
*/
private:
//etk::VectorType<ewol::theme::EolColor*> m_listColor;
//etk::VectorType<ewol::theme::EolBase*> m_listGroup;
//etk::VectorType<ewol::theme::EolElementFrame*> m_listElement;
etk::VectorType<ewol::theme::EolColor*> m_listColor;
etk::VectorType<ewol::theme::EolBase*> m_listGroup;
etk::VectorType<ewol::theme::EolElementFrame*> m_listElement;
etkFloat_t m_ratio;
bool m_clipX;
bool m_clipY;
coord2D_ts m_internalElemX;
coord2D_ts m_internalElemY;
public:
// acces to manage and create object ==> drawing system
};
};
};
*/
#endif

View File

@ -27,5 +27,35 @@
#ifndef __EWOL_THEME_EOL_ELEMENT_FRAME_H__
#define __EWOL_THEME_EOL_ELEMENT_FRAME_H__
#include <etk/Types.h>
#include <etk/String.h>
#include <etk/File.h>
#include <ewol/OObject.h>
#include <ewol/theme/EolColor.h>
namespace ewol {
namespace theme {
class EolElementFrame {
public:
EolElementFrame(void) { };
virtual ~EolElementFrame(void) { };
/*
void Load(etk::File & newFile) { };
void Generate(int32_t id, int32_t frameId, OObject2DTextured & newObject, etkFloat_t posX, etkFloat_t posY, etkFloat_t sizeX, etkFloat_t sizeY) {};
int32_t GetNbFrame(int32_t id) {return 0;};
int32_t GetFrameId(int32_t id, etk::String & frameName) {return 0;};
int32_t GetObjectId(etk::String name) { return -1; };
*/
private:
etk::VectorType<ewol::theme::EolBase*> m_description; // all element to draw the image ...
public:
// acces to manage and create object ==> drawing system
};
};
};
#endif

View File

@ -22,6 +22,162 @@
*******************************************************************************
*/
#include <ewol/theme/Theme.h>
#undef __class__
#define __class__ "ewol::theme::Theme"
#define __class__ "ewol::theme::Theme"
#define MAX_LINE_SIZE (2048)
ewol::theme::Theme::Theme(void)
{
}
ewol::theme::Theme::~Theme(void)
{
}
static bool IsComment(char * line)
{
for(int32_t iii=0; iii<MAX_LINE_SIZE; iii++) {
if( line[iii]=='\r'
|| line[iii]=='\n') {
line[iii]='\0';
break;
}
}
for(int32_t iii=0; iii<MAX_LINE_SIZE; iii++) {
if( line[iii]=='\0') {
// enpty line ...
return true; //==> same a a comment ...
}
if( line[iii]!='\t'
&& line[iii]!=' ') {
if(line[iii]=='#') {
// find a comment
return true;
} else {
return false;
}
}
}
// empty line ...
return true;
}
static int32_t ClipOffset(char * line)
{
int32_t offset = 0;
int32_t spaceCount = 0;
int32_t copyOffset = 0;
for(int32_t iii=0; iii<MAX_LINE_SIZE; iii++) {
if( line[iii]=='\0') {
break;
}
if( line[iii]!='\t'
&& line[iii]!=' ') {
// end of parsing
copyOffset = iii;
break;
} else {
if(line[iii]==' ') {
spaceCount++;
if (spaceCount == 4) {
spaceCount = 0;
offset++;
}
} else {
spaceCount = 0;
offset++;
}
}
}
if (spaceCount != 0) {
return -1;
}
memmove(line, line + copyOffset, MAX_LINE_SIZE-copyOffset);
return offset;
}
void ewol::theme::Theme::Load(etk::File & newFile, bool defaultTheme)
{
if (newFile.HasExtention() == false) {
EWOL_ERROR("can not load theme with file, has no extention : " << newFile);
return;
}
if (newFile.GetExtention() != "eol") {
EWOL_ERROR("can not load theme with file, has not extention .eol : " << newFile);
return;
}
if (false == newFile.Exist()) {
EWOL_ERROR("File does not Exist ... " << newFile);
return;
} else {
char elementLine[MAX_LINE_SIZE];
int32_t lineID=1;
FILE * file = fopen(newFile.GetCompleateName().c_str(),"r");
if(NULL == file) {
EWOL_ERROR("Can not OPEN the file name=\"" << newFile << "\"");
return;
}
// load all element of the file ...
if (NULL != fgets(elementLine, MAX_LINE_SIZE, file)) {
if( elementLine[0] != 'e'
|| elementLine[1] != 'o'
|| elementLine[2] != 'l') {
EWOL_ERROR("Start file in error " << newFile << " ==> will start with eol \\n");
return;
}
}
lineID++;
while (NULL != fgets(elementLine, MAX_LINE_SIZE, file) )
{
if (true == IsComment(elementLine)) {
EWOL_VERBOSE("(l=" << lineID << ") Find a comment : \"" << elementLine << "\"");
} else {
// need to parse the element...
int32_t offset = ClipOffset(elementLine);
if (offset == -1) {
EWOL_ERROR("(l=" << lineID << ") indentation error 4 spaces or 1 tab : \"" << elementLine << "\"");
return;
} else {
if (elementLine[0] == '<') {
EWOL_INFO("(l=" << lineID << ") getting ELEMENT <> (indent=" << offset << ") : \"" << elementLine << "\"");
} else if (elementLine[0] == '[') {
EWOL_INFO("(l=" << lineID << ") getting block [] (indent=" << offset << ") : \"" << elementLine << "\"");
} else if (elementLine[0] == '{') {
EWOL_INFO("(l=" << lineID << ") getting drawing basic {} (indent=" << offset << ") : \"" << elementLine << "\"");
} else {
EWOL_DEBUG("(l=" << lineID << ") data OTHER ... (indent=" << offset << ") : \"" << elementLine << "\"");
}
}
}
lineID++;
}
}
}
void ewol::theme::Theme::Generate(int32_t id, int32_t frameId, OObject2DTextured & newObject, etkFloat_t posX, etkFloat_t posY, etkFloat_t sizeX, etkFloat_t sizeY)
{
}
int32_t ewol::theme::Theme::GetNbFrame(int32_t id)
{
return 0;
}
int32_t ewol::theme::Theme::GetFrameId(int32_t id, etk::String & frameName)
{
return 0;
}
int32_t ewol::theme::Theme::GetObjectId(etk::String name)
{
return -1;
}

View File

@ -41,17 +41,17 @@ namespace ewol {
namespace theme {
class Theme {
public:
Theme(void) { };
virtual ~Theme(void) { };
void Load(etk::File & newFile) { };
void Generate(int32_t id, int32_t frameId, OObject2DTextured & newObject, etkFloat_t posX, etkFloat_t posY, etkFloat_t sizeX, etkFloat_t sizeY) {};
int32_t GetNbFrame(int32_t id) {return 0;};
int32_t GetFrameId(int32_t id, etk::String & frameName) {return 0;};
int32_t GetObjectId(etk::String name) { return -1; };
Theme(void);
virtual ~Theme(void);
void Load(etk::File & newFile, bool defaultTheme=false);
void Generate(int32_t id, int32_t frameId, OObject2DTextured & newObject, etkFloat_t posX, etkFloat_t posY, etkFloat_t sizeX, etkFloat_t sizeY);
int32_t GetNbFrame(int32_t id);
int32_t GetFrameId(int32_t id, etk::String & frameName);
int32_t GetObjectId(etk::String name);
private:
//etk::VectorType<ewol::theme::EolColor*> m_listColor;
//etk::VectorType<ewol::theme::EolBase*> m_listGroup;
//etk::VectorType<ewol::theme::EolElement*> m_listElement;
etk::VectorType<ewol::theme::EolColor*> m_listColor;
etk::VectorType<ewol::theme::EolBase*> m_listGroup;
etk::VectorType<ewol::theme::EolElement*> m_listElement;
public:
// acces to manage and create object ==> drawing system

View File

@ -27,49 +27,39 @@
#undef __class__
#define __class__ "ewol::theme::"
#define __class__ "ewol::theme"
static ewol::theme::Theme defaultTheme;
static ewol::theme::Theme userTheme;
static ewol::theme::Theme localTheme;
void ewol::theme::Init(void)
{
EWOL_INFO("Init theme system");
}
void ewol::theme::UnInit(void)
{
EWOL_INFO("Un-Init theme system");
}
void ewol::theme::LoadDefault(etk::File filename)
{
defaultTheme.Load(filename);
EWOL_INFO("Load default Theme : " << filename);
localTheme.Load(filename, true);
}
void ewol::theme::Load(etk::File filename)
{
userTheme.Load(filename);
EWOL_INFO("Add personal theme : " << filename);
localTheme.Load(filename, false);
}
// if 0 ==> error not fined ...
// if <0 ==> default theme
// if >0 ==> user theme
int32_t ewol::theme::GetObjectId(etk::String name)
{
int32_t val = userTheme.GetObjectId(name);
if (-1 == val) {
val = defaultTheme.GetObjectId(name);
if (-1 == val) {
return 0;
} else {
return val*(-1);
}
}
return val+1;
return localTheme.GetObjectId(name);
}
// ???? GetObjectType(int32_t id);
@ -77,37 +67,27 @@ int32_t ewol::theme::GetObjectId(etk::String name)
void ewol::theme::Generate(int32_t id, int32_t frameId, OObject2DTextured & newObject, etkFloat_t posX, etkFloat_t posY, etkFloat_t sizeX, etkFloat_t sizeY)
{
if (id<=0) {
id *= -1;
defaultTheme.Generate(id, frameId, newObject, posX, posY, sizeX, sizeY);
} else {
userTheme.Generate(id+1, frameId, newObject, posX, posY, sizeX, sizeY);
if (id<0) {
return;
}
localTheme.Generate(id, frameId, newObject, posX, posY, sizeX, sizeY);
}
int32_t ewol::theme::GetNbFrame(int32_t id)
{
if (id==0) {
if (id<0) {
return 0;
} else if (id<=0) {
id *= -1;
return defaultTheme.GetNbFrame(id);
} else {
return userTheme.GetNbFrame(id+1);
}
return localTheme.GetNbFrame(id);
}
int32_t ewol::theme::GetFrameId(int32_t id, etk::String & frameName)
{
if (id==0) {
if (id<0) {
return 0;
} else if (id<=0) {
id *= -1;
return defaultTheme.GetFrameId(id, frameName);
} else {
return userTheme.GetFrameId(id+1, frameName);
}
return localTheme.GetFrameId(id, frameName);
}

View File

@ -6,7 +6,7 @@ FileType=Single
# Version :
version=1.0
<element=plop>
<plop> # name of the ELEMENT ....
# Number of sub frame of the element (default 1)
NbFrame=2
# Element display Ratio : ratio = x/y (default 1.0)
@ -24,7 +24,7 @@ version=1.0
# - #RRGGBBAA ==> in hexa 0x00<=x<=0xFF
# - R.R;G.G;B.B ==> in double 0<=x<=1
# - R.R;G.G;B.B;A.A ==> in double 0<=x<=1
# - &NameColor ==> searche internal color of the element and after global color ...
# - &NameColor ==> search internal color of the element and after global color ...
[Colors]
colorName=1.0;1.0;1.0;1.0
Background=0.0;0.000512;1.0;0.755562535