From 809fbda03c5014ba9cd361f5113d1d717cd41ea6 Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 26 Jan 2016 18:32:38 +0100 Subject: Version 0.8.0 beta --- coreengine/attributes.c | 447 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 447 insertions(+) create mode 100644 coreengine/attributes.c (limited to 'coreengine/attributes.c') diff --git a/coreengine/attributes.c b/coreengine/attributes.c new file mode 100644 index 0000000..97387d4 --- /dev/null +++ b/coreengine/attributes.c @@ -0,0 +1,447 @@ +#include "attributes.h" +#include "../config.h" + +/*************************************************************************** +* cViewAttribs +***************************************************************************/ +cViewAttribs::cViewAttribs(int numAttributes) : cAttributes(numAttributes) { + orientation = NULL; + SetAttributesDefs(); +} + +cViewAttribs::~cViewAttribs(void) { + delete orientation; +} + +void cViewAttribs::Set(vector &attributes) { + for (vector::iterator att = attributes.begin(); att != attributes.end(); att++) { + const char *attName = (*att).first.c_str(); + const char *attVal = (*att).second.c_str(); + int id = AttributeId(attName); + if (id == ATTR_UNKNOWN) { + esyslog("skindesigner: unknown view attribute \"%s\" = \"%s\"", attName, attVal); + continue; + } + if (SetCommon(id, attVal)) + continue; + if (IdEqual(id, (int)eViewAttribs::shifttype)) { + SetShiftType(id, attVal); + } else if (IdEqual(id, (int)eViewAttribs::shiftmode)) { + SetShiftMode(id, attVal); + } else if (IdEqual(id, (int)eViewAttribs::orientation)) { + SetOrientationDynamic(id, attVal); + } else if (IdEqual(id, (int)eViewAttribs::hideroot)) { + SetBool(id, attVal); + } else { + attribCtors[id] = new cNumericExpr(attVal); + if ( (id == (int)eViewAttribs::starty + (int)eCommonAttribs::count) || + (id == (int)eViewAttribs::scaletvy + (int)eCommonAttribs::count) || + (id == (int)eViewAttribs::scaletvheight + (int)eCommonAttribs::count) ) { + attribCtors[id]->SetVertical(); + } + } + } +} + +void cViewAttribs::SetAttributesDefs(void) { + attribIDs.insert(pair("fadetime", (int)eViewAttribs::fadetime)); + attribIDs.insert(pair("shifttime", (int)eViewAttribs::shifttime)); + attribIDs.insert(pair("shifttype", (int)eViewAttribs::shifttype)); + attribIDs.insert(pair("shiftmode", (int)eViewAttribs::shiftmode)); + attribIDs.insert(pair("startx", (int)eViewAttribs::startx)); + attribIDs.insert(pair("starty", (int)eViewAttribs::starty)); + attribIDs.insert(pair("scaletvx", (int)eViewAttribs::scaletvx)); + attribIDs.insert(pair("scaletvy", (int)eViewAttribs::scaletvy)); + attribIDs.insert(pair("scaletvwidth", (int)eViewAttribs::scaletvwidth)); + attribIDs.insert(pair("scaletvheight", (int)eViewAttribs::scaletvheight)); + attribIDs.insert(pair("orientation", (int)eViewAttribs::orientation)); + attribIDs.insert(pair("debuggrid", (int)eViewAttribs::debuggrid)); + attribIDs.insert(pair("hideroot", (int)eViewAttribs::hideroot)); + attribNames.insert(pair((int)eViewAttribs::fadetime, "fadetime")); + attribNames.insert(pair((int)eViewAttribs::shifttime, "shifttime")); + attribNames.insert(pair((int)eViewAttribs::shifttype, "shifttype")); + attribNames.insert(pair((int)eViewAttribs::shiftmode, "shiftmode")); + attribNames.insert(pair((int)eViewAttribs::startx, "startx")); + attribNames.insert(pair((int)eViewAttribs::starty, "starty")); + attribNames.insert(pair((int)eViewAttribs::scaletvx, "scaletvx")); + attribNames.insert(pair((int)eViewAttribs::scaletvy, "scaletvy")); + attribNames.insert(pair((int)eViewAttribs::scaletvwidth, "scaletvwidth")); + attribNames.insert(pair((int)eViewAttribs::scaletvheight, "scaletvheight")); + attribNames.insert(pair((int)eViewAttribs::orientation, "orientation")); + attribNames.insert(pair((int)eViewAttribs::debuggrid, "debuggrid")); + attribNames.insert(pair((int)eViewAttribs::hideroot, "hideroot")); +} + +void cViewAttribs::Cache(void) { + tokenContainer = new skindesignerapi::cTokenContainer(); + cAttributes::Cache(); + if (orientation) { + orientation->SetGlobals(globals); + orientation->SetTokenContainer(tokenContainer); + orientation->Cache(); + char *res = orientation->DeterminateText(); + if (res) { + SetOrientation((int)eViewAttribs::orientation + (int)eCommonAttribs::count, res); + } + free(res); + } +} + +void cViewAttribs::Debug(void) { + esyslog("skindesigner: --> View Attribs"); + cAttributes::Debug(); +} + +eOrientation cViewAttribs::Orientation(void) { + int orientation = GetValue((int)eViewAttribs::orientation); + if (orientation == -1) + return eOrientation::vertical; + if (orientation == (int)eOrientation::none) + return eOrientation::vertical; + return (eOrientation)orientation; +} + +cRect cViewAttribs::TvFrame(void) { + int frameX = GetValue((int)eViewAttribs::scaletvx); + int frameY = GetValue((int)eViewAttribs::scaletvy); + int frameWidth = GetValue((int)eViewAttribs::scaletvwidth); + int frameHeight = GetValue((int)eViewAttribs::scaletvheight); + if (frameX < 0 || frameY < 0 || frameWidth <= 0 || frameHeight <= 0) + return cRect::Null; + frameX += cOsd::OsdLeft(); + frameY += cOsd::OsdTop(); + return cRect(frameX, frameY, frameWidth, frameHeight); +} + +void cViewAttribs::SetOrientationDynamic(int id, const char *val) { + if (strchr(val, '{') && strchr(val, '}')) { + orientation = new cTextExpr(val); + } else { + SetOrientation(id, val); + } +} + +/*************************************************************************** +* cViewElementAttribs +***************************************************************************/ +cViewElementAttribs::cViewElementAttribs(int numAttributes) : cAttributes(numAttributes) { + name = NULL; + SetAttributesDefs(); +} + +cViewElementAttribs::cViewElementAttribs(const cViewElementAttribs &other) : cAttributes(other) { + name = NULL; +} + +cViewElementAttribs::~cViewElementAttribs(void) { + free(name); +} + +void cViewElementAttribs::Set(vector &attributes) { + for (vector::iterator att = attributes.begin(); att != attributes.end(); att++) { + const char *attName = (*att).first.c_str(); + const char *attVal = (*att).second.c_str(); + int id = AttributeId(attName); + if (id == ATTR_UNKNOWN) { + esyslog("skindesigner: unknown view element attribute \"%s\" = \"%s\"", attName, attVal); + continue; + } + if (SetCommon(id, attVal)) + continue; + if (IdEqual(id, (int)eViewElementAttribs::mode)) { + SetViewElementMode(id, attVal); + } else if (IdEqual(id, (int)eViewElementAttribs::shifttype)) { + SetShiftType(id, attVal); + } else if (IdEqual(id, (int)eViewElementAttribs::shiftmode)) { + SetShiftMode(id, attVal); + } else if (IdEqual(id, (int)eViewElementAttribs::orientation)) { + SetOrientation(id, attVal); + } else if (IdEqual(id, (int)eViewElementAttribs::name)) { + name = strdup(attVal); + } else { + attribCtors[id] = new cNumericExpr(attVal); + if (id == (int)eViewElementAttribs::starty + (int)eCommonAttribs::count) { + attribCtors[id]->SetVertical(); + } + } + } +} + +void cViewElementAttribs::SetAttributesDefs(void) { + attribIDs.insert(pair("delay", (int)eViewElementAttribs::delay)); + attribIDs.insert(pair("fadetime", (int)eViewElementAttribs::fadetime)); + attribIDs.insert(pair("shifttime", (int)eViewElementAttribs::shifttime)); + attribIDs.insert(pair("shifttype", (int)eViewElementAttribs::shifttype)); + attribIDs.insert(pair("shiftmode", (int)eViewElementAttribs::shiftmode)); + attribIDs.insert(pair("startx", (int)eViewElementAttribs::startx)); + attribIDs.insert(pair("starty", (int)eViewElementAttribs::starty)); + attribIDs.insert(pair("orientation", (int)eViewElementAttribs::orientation)); + attribIDs.insert(pair("mode", (int)eViewElementAttribs::mode)); + attribIDs.insert(pair("name", (int)eViewElementAttribs::name)); + attribNames.insert(pair((int)eViewElementAttribs::delay, "delay")); + attribNames.insert(pair((int)eViewElementAttribs::fadetime, "fadetime")); + attribNames.insert(pair((int)eViewElementAttribs::shifttime, "shifttime")); + attribNames.insert(pair((int)eViewElementAttribs::shifttype, "shifttype")); + attribNames.insert(pair((int)eViewElementAttribs::shiftmode, "shiftmode")); + attribNames.insert(pair((int)eViewElementAttribs::startx, "startx")); + attribNames.insert(pair((int)eViewElementAttribs::starty, "starty")); + attribNames.insert(pair((int)eViewElementAttribs::orientation, "orientation")); + attribNames.insert(pair((int)eViewElementAttribs::mode, "mode")); + attribNames.insert(pair((int)eViewElementAttribs::name, "name")); +} + +eOrientation cViewElementAttribs::Orientation(void) { + int orientation = GetValue((int)eViewElementAttribs::orientation); + if (orientation == -1) + return eOrientation::vertical; + if (orientation == (int)eOrientation::none) + return eOrientation::vertical; + return (eOrientation)orientation; +} + +void cViewElementAttribs::Debug(void) { + esyslog("skindesigner: ---> View Element Attribs"); + cAttributes::Debug(); +} + +/*************************************************************************** +* cViewListAttribs +***************************************************************************/ +cViewListAttribs::cViewListAttribs(int numAttributes) : cAttributes(numAttributes) { + determinateFont = NULL; + SetAttributesDefs(); +} + +cViewListAttribs::~cViewListAttribs(void) { + free(determinateFont); +} + +void cViewListAttribs::Set(vector &attributes) { + for (vector::iterator att = attributes.begin(); att != attributes.end(); att++) { + const char *attName = (*att).first.c_str(); + const char *attVal = (*att).second.c_str(); + int id = AttributeId(attName); + if (id == ATTR_UNKNOWN) { + esyslog("skindesigner: unknown view list attribute \"%s\" = \"%s\"", attName, attVal); + continue; + } + if (SetCommon(id, attVal)) + continue; + if (IdEqual(id, (int)eViewListAttribs::align)) { + SetAlign(id, attVal); + } else if (IdEqual(id, (int)eViewListAttribs::determinatefont)) { + determinateFont = strdup(attVal); + } else if (IdEqual(id, (int)eViewListAttribs::orientation)) { + SetOrientation(id, attVal); + } else { + attribCtors[id] = new cNumericExpr(attVal); + } + } +} + +int cViewListAttribs::NumListElements(void) { + return GetValue((int)eViewListAttribs::numlistelements); +} + +int cViewListAttribs::MenuItemWidth(void) { + return GetValue((int)eViewListAttribs::menuitemwidth); +} + +const char *cViewListAttribs::DeterminateFont(void) { + return determinateFont; +} + +eAlign cViewListAttribs::Align(void) { + int align = GetValue((int)eViewListAttribs::align); + if (align < 0) + return eAlign::top; + return (eAlign)align; +} + +eOrientation cViewListAttribs::Orientation(void) { + int orientation = GetValue((int)eViewListAttribs::orientation); + if (orientation < 0) + return eOrientation::vertical; + return (eOrientation)orientation; +} + +void cViewListAttribs::SetAttributesDefs(void) { + attribIDs.insert(pair("align", (int)eViewListAttribs::align)); + attribIDs.insert(pair("menuitemwidth", (int)eViewListAttribs::menuitemwidth)); + attribIDs.insert(pair("determinatefont", (int)eViewListAttribs::determinatefont)); + attribIDs.insert(pair("numlistelements", (int)eViewListAttribs::numlistelements)); + attribIDs.insert(pair("orientation", (int)eViewListAttribs::orientation)); + attribIDs.insert(pair("condition", (int)eViewListAttribs::condition)); + attribNames.insert(pair((int)eViewListAttribs::align, "align")); + attribNames.insert(pair((int)eViewListAttribs::menuitemwidth, "menuitemwidth")); + attribNames.insert(pair((int)eViewListAttribs::determinatefont, "determinatefont")); + attribNames.insert(pair((int)eViewListAttribs::numlistelements, "numlistelements")); + attribNames.insert(pair((int)eViewListAttribs::orientation, "orientation")); + attribNames.insert(pair((int)eViewListAttribs::condition, "condition")); +} + +void cViewListAttribs::Debug(void) { + esyslog("skindesigner: ---> View List Attribs"); + esyslog("skindesigner: DeterminateFont %s", determinateFont); + cAttributes::Debug(); +} + +/*************************************************************************** +* cAreaAttribs +***************************************************************************/ +cAreaAttribs::cAreaAttribs(int numAttributes) : cAttributes(numAttributes) { + name = NULL; + scrollElement = NULL; + dynamic = false; + SetAttributesDefs(); +} + +cAreaAttribs::cAreaAttribs(const cAreaAttribs &other) : cAttributes(other) { + name = NULL; + if (other.name) + name = new cTextExpr(*other.name); + scrollElement = NULL; + if (other.scrollElement) + scrollElement = strdup(other.scrollElement); + dynamic = false; +} + +cAreaAttribs::~cAreaAttribs(void) { + delete name; + free(scrollElement); +} + +void cAreaAttribs::Set(vector &attributes) { + for (vector::iterator att = attributes.begin(); att != attributes.end(); att++) { + const char *attName = (*att).first.c_str(); + const char *attVal = (*att).second.c_str(); + int id = AttributeId(attName); + if (id == ATTR_UNKNOWN) { + esyslog("skindesigner: unknown area attribute \"%s\" = \"%s\"", attName, attVal); + continue; + } + if (SetCommon(id, attVal)) + continue; + if (IdEqual(id, (int)eAreaAttribs::scrollelement)) { + scrollElement = strdup(attVal); + } else if (IdEqual(id, (int)eAreaAttribs::mode)) { + SetScrollMode(id, attVal); + } else if (IdEqual(id, (int)eAreaAttribs::orientation)) { + SetOrientation(id, attVal); + } else if (IdEqual(id, (int)eAreaAttribs::scrollspeed)) { + SetScrollSpeed(id, attVal); + } else if (IdEqual(id, (int)eAreaAttribs::background)) { + SetBool(id, attVal); + } else if (IdEqual(id, (int)eAreaAttribs::name)) { + name = new cTextExpr(attVal); + } else { + attribCtors[id] = new cNumericExpr(attVal); + } + } +} + +int cAreaAttribs::Layer(void) { + if (GetValue((int)eAreaAttribs::layer) > 0) { + return GetValue((int)eAreaAttribs::layer); + } + return 1; +} + +bool cAreaAttribs::BackgroundArea(void) { + int isBackground = GetValue((int)eAreaAttribs::background); + if (isBackground == 1) + return true; + return false; +} + +void cAreaAttribs::CheckDynamic(void) { + for (int i = (int)eCommonAttribs::x; i <= (int)eCommonAttribs::height; ++i ) { + if (attribCtors[i] && attribCtors[i]->Dynamic()) { + dynamic = true; + return; + } + } +} + +const char *cAreaAttribs::Name(void) { + if (name) + return name->DeterminateText(); + return NULL; +} + +void cAreaAttribs::SetAttributesDefs(void) { + attribIDs.insert(pair("layer", (int)eAreaAttribs::layer)); + attribIDs.insert(pair("transparency", (int)eAreaAttribs::transparency)); + attribIDs.insert(pair("mode", (int)eAreaAttribs::mode)); + attribIDs.insert(pair("orientation", (int)eAreaAttribs::orientation)); + attribIDs.insert(pair("scrollelement", (int)eAreaAttribs::scrollelement)); + attribIDs.insert(pair("scrollspeed", (int)eAreaAttribs::scrollspeed)); + attribIDs.insert(pair("delay", (int)eAreaAttribs::delay)); + attribIDs.insert(pair("background", (int)eAreaAttribs::background)); + attribIDs.insert(pair("name", (int)eAreaAttribs::name)); + attribIDs.insert(pair("scrollheight", (int)eAreaAttribs::scrollheight)); + attribNames.insert(pair((int)eAreaAttribs::layer, "layer")); + attribNames.insert(pair((int)eAreaAttribs::transparency, "transparency")); + attribNames.insert(pair((int)eAreaAttribs::mode, "mode")); + attribNames.insert(pair((int)eAreaAttribs::orientation, "orientation")); + attribNames.insert(pair((int)eAreaAttribs::scrollelement, "scrollelement")); + attribNames.insert(pair((int)eAreaAttribs::scrollspeed, "scrollspeed")); + attribNames.insert(pair((int)eAreaAttribs::delay, "delay")); + attribNames.insert(pair((int)eAreaAttribs::background, "background")); + attribNames.insert(pair((int)eAreaAttribs::name, "name")); + attribNames.insert(pair((int)eAreaAttribs::scrollheight, "scrollheight")); +} + +void cAreaAttribs::Cache(void) { + cAttributes::Cache(); + if (name) { + name->SetGlobals(globals); + name->SetTokenContainer(tokenContainer); + name->Cache(); + } +} + +void cAreaAttribs::Debug(void) { + if (!name) { + esyslog("skindesigner: ---> Area Attribs"); + } else { + esyslog("skindesigner: ---> Tab %s Attribs", name->DeterminateText()); + } + cAttributes::Debug(); +} + +/*************************************************************************** +* cAreaContainerAttribs +***************************************************************************/ +cAreaContainerAttribs::cAreaContainerAttribs(int numAttributes) : cAttributes(numAttributes) { + SetAttributesDefs(); +} + +cAreaContainerAttribs::cAreaContainerAttribs(const cAreaContainerAttribs &other) : cAttributes(other) { +} + +cAreaContainerAttribs::~cAreaContainerAttribs(void) { +} + +void cAreaContainerAttribs::Set(vector &attributes) { + for (vector::iterator att = attributes.begin(); att != attributes.end(); att++) { + const char *attName = (*att).first.c_str(); + const char *attVal = (*att).second.c_str(); + int id = AttributeId(attName); + if (id == ATTR_UNKNOWN) { + esyslog("skindesigner: unknown area container attribute \"%s\" = \"%s\"", attName, attVal); + continue; + } + if (SetCommon(id, attVal)) + continue; + } +} + +void cAreaContainerAttribs::SetAttributesDefs(void) { +} + +void cAreaContainerAttribs::Debug(void) { + esyslog("skindesigner: ---> Area Container Attribs"); + cAttributes::Debug(); +} + -- cgit v1.2.3