void ofxFlashXFLBuilder :: buildLayers () { int numOfLayers; numOfLayers = getNumTags( "DOMLayer" ); for( int i=numOfLayers-1; i>=0; i-- ) // work backwards through layers. so when adding to stage, objects sit in right order. { DOMLayer dom; dom.name = getAttribute( "DOMLayer", "name", "", i ); dom.color = getAttribute( "DOMLayer", "color", 0, i ); dom.locked = getAttribute( "DOMLayer", "locked", false, i ); dom.current = getAttribute( "DOMLayer", "current", false, i ); dom.isSelected = getAttribute( "DOMLayer", "isSelected", false, i ); dom.autoNamed = getAttribute( "DOMLayer", "autoNamed", false, i ); dom.layerType = getAttribute( "DOMLayer", "layerType", "", i ); domLayer = dom; if( domLayer.layerType == "guide" ) // skip guide layers. continue; pushTag( "DOMLayer", i ); pushTag( "frames", 0 ); buildFrames(); popTag(); popTag(); } }
void ofxFlashXFLBuilder :: setupStrokeForShape ( ofxFlashShape* shape ) { if( tagExists( "stroke", 0 ) ) { pushTag( "stroke", 0 ); int solidStrokeWeight; solidStrokeWeight = getAttribute( "SolidStroke", "weight", 0, 0 ); pushTag( "SolidStroke", 0 ); pushTag( "fill", 0 ); string fillSolidColor; fillSolidColor = getAttribute( "SolidColor", "color", "#000000", 0 ); fillSolidColor = cleanHexString( fillSolidColor ); float fillAlpha; fillAlpha = getAttribute( "SolidColor", "alpha", 1.0, 0 ); shape->setStroke( true ); shape->setStrokeWeight( solidStrokeWeight ); shape->setStrokeColor( stringToHex( fillSolidColor ) ); shape->setStrokeAlpha( fillAlpha ); ofColor c; popTag(); popTag(); popTag(); } }
void ofxFlashXFLBuilder :: buildTimelines () { int numOfTimelines; numOfTimelines = getNumTags( "DOMTimeline" ); for( int i=0; i<numOfTimelines; i++ ) { DOMTimeline dom; dom.name = getAttribute( "DOMTimeline", "name", "", i ); dom.currentFrame = getAttribute( "DOMTimeline", "currentFrame", 1, i ); domTimeline = dom; pushTag( "DOMTimeline", i ); pushTag( "layers", 0 ); buildLayers(); popTag(); popTag(); return; // SUPPORT ONLY ONE TIMELINE. } popTag(); }
void ofxXmlSettings::deserialize(ofAbstractParameter & parameter){ if(!parameter.isSerializable()) return; string name = parameter.getEscapedName(); if(parameter.type()==typeid(ofParameterGroup).name()){ ofParameterGroup & group = static_cast<ofParameterGroup&>(parameter); if(tagExists(name)){ pushTag(name); for(int i=0;i<group.size();i++){ deserialize(group.get(i)); } popTag(); } }else{ if(tagExists(name)){ if(parameter.type()==typeid(ofParameter<int>).name()){ parameter.cast<int>() = getValue(name,0); }else if(parameter.type()==typeid(ofParameter<float>).name()){ parameter.cast<float>() = getValue(name,0.0f); }else if(parameter.type()==typeid(ofParameter<bool>).name()){ parameter.cast<bool>() = getValue(name,false); }else if(parameter.type()==typeid(ofParameter<string>).name()){ parameter.cast<string>() = getValue(name,""); }else{ parameter.fromString(getValue(name,"")); } } } }
int ofXML::getNumTags(string fullPath, ...) { bool found=false; int ret=0; bool isRelative=true; if (fullPath[0]==';') { isRelative=false; while (prevLevel.size()>0) { popTag(); } fullPath=string(fullPath,1,fullPath.length()-1); } vector<string> tags=ofSplitString(fullPath, ":"); int which; va_list vl; int tagSize=tags.size(); va_start(vl,tagSize); for (unsigned int i=0; i<tags.size()-1; i++) { which=va_arg(vl,int); found=pushTag(tags[i], which); } va_end(vl); if(found) ret=currentLevel->getNumTags(tags[tags.size()-1]); else ret=0; return ret; }
void ofxFlashXFLBuilder :: build ( const string& root, const string& file, ofxFlashDisplayObjectContainer* container ) { xflRoot = root; xflFile = file; string xflFilePath = xflRoot + xflFile; this->container = container; bool success = loadFile( xflFilePath ); if( bVerbose ) { if( success ) cout << "[ ofxFlashXFLBuilder :: build ] - loading movieclip xml - SUCCESS :: " << xflFilePath << endl; else cout << "[ ofxFlashXFLBuilder :: build ] - loading movieclip xml - FAILED :: " << xflFilePath << endl; } if( success ) { TiXmlElement* child = ( storedHandle.FirstChild() ).ToElement(); domType = child->Value(); pushTag( domType, 0 ); if( domType == DOM_DOCUMENT_TYPE ) { pushTag( "timelines", 0 ); } else if( domType == DOM_SYMBOL_ITEM_TYPE ) { pushTag( "timeline", 0 ); } countTotalFrames(); ofxFlashMovieClip* mc; mc = (ofxFlashMovieClip*)container; mc->setTotalFrames( totalFrames ); buildTimelines(); popTag(); popTag(); } }
void ofXML::pushToTag(ofTag * tagToFind) { vector<int> ret; while (prevLevel.size()>0) { popTag(); } for (unsigned int i=0; i<nodes.size(); i++) { if (tagToFind==&nodes[i]) pushTag(i); else if(nodes[i].findTag(tagToFind).size()){ ret=nodes[i].findTag(tagToFind); while (ret.size()) { pushTag(ret[ret.size()-1]); ret.pop_back(); } } } }
MetricTag& MetricTag::operator+=(std::initializer_list<std::string>&& t) { if (t.size() != 2) { throw std::runtime_error("initializer_list is supposed to be {k, v}"); } return pushTag(std::move(*t.begin()), std::move(*(t.begin() + 1))); }
void ofxFlashXFLBuilder :: countTotalFrames () { pushTag( "DOMTimeline", 0 ); pushTag( "layers", 0 ); int numOfLayers; numOfLayers = getNumTags( "DOMLayer" ); for( int i=0; i<numOfLayers; i++ ) { string layerType; layerType = getAttribute( "DOMLayer", "layerType", "", i ); if( layerType == "guide" ) // skip guide layers. continue; pushTag( "DOMLayer", i ); pushTag( "frames", 0 ); int numOfFrames; numOfFrames = getNumTags( "DOMFrame" ); for( int j=0; j<numOfFrames; j++ ) { int frameIndex = getAttribute( "DOMFrame", "index", 0, j ); int frameDuration = getAttribute( "DOMFrame", "duration", 1, j ); int frameEnd = frameIndex + frameDuration; if( frameEnd > totalFrames ) { totalFrames = frameEnd; } } popTag(); popTag(); } popTag(); popTag(); }
void ofxFlashXFLBuilder :: buildRectangleShape () { ofxFlashShape* shape; shape = new ofxFlashShape(); //-- position & transform. float cx = domRectangleObject.x + domRectangleObject.objectWidth * 0.5; // center point. float cy = domRectangleObject.y + domRectangleObject.objectHeight * 0.5; // center point. float transformationPointX = cx; // default transformation point is center. float transformationPointY = cy; // default transformation point is center. if( tagExists( "transformationPoint", 0 ) ) { pushTag( "transformationPoint", 0 ); transformationPointX = getAttribute( "Point", "x", cx, 0 ); transformationPointY = getAttribute( "Point", "y", cy, 0 ); popTag(); } setupMatrixForDisplayObject( shape ); float shiftX = transformationPointX - cx; float shiftY = transformationPointY - cy; ofxFlashMatrix matrix; matrix = shape->matrix(); // get matrix. float tx = matrix.getTx() + shiftX; float ty = matrix.getTy() + shiftY; matrix.setTx( tx ); // adjust matrix. matrix.setTy( ty ); shape->matrix( matrix ); // set matrix. ofRectangle shapeRect; shapeRect.x = domRectangleObject.x + shiftX; shapeRect.y = domRectangleObject.y + shiftY; shapeRect.width = domRectangleObject.objectWidth; shapeRect.height = domRectangleObject.objectHeight; shape->setRectangle( shapeRect.x, shapeRect.y, shapeRect.width, shapeRect.height ); setupFillForShape( shape ); setupStrokeForShape( shape ); addDisplayObjectToFrames( shape ); }
void ofxFlashXFLBuilder :: setupColorForDisplayObject ( ofxFlashDisplayObject* displayObject ) { if( tagExists( "color", 0 ) ) { pushTag( "color", 0 ); float alphaMultiplier = getAttribute( "Color", "alphaMultiplier", 1.0, 0 ); displayObject->alpha( alphaMultiplier ); popTag(); } }
void ofxFlashXFLBuilder :: buildFrames () { int numOfFrames; numOfFrames = getNumTags( "DOMFrame" ); for( int i=0; i<numOfFrames; i++ ) { DOMFrame dom; dom.index = getAttribute( "DOMFrame", "index", 0, i ); dom.duration = getAttribute( "DOMFrame", "duration", 1, i ); dom.tweenType = getAttribute( "DOMFrame", "tweenType", "", i ); dom.motionTweenSnap = getAttribute( "DOMFrame", "motionTweenSnap", false, i ); dom.keyMode = getAttribute( "DOMFrame", "keyMode", 0, i ); domFrame = dom; pushTag( "DOMFrame", i ); pushTag( "elements", 0 ); buildElements(); popTag(); popTag(); } }
void ofxXmlSettings::serialize(const ofAbstractParameter & parameter){ if(!parameter.isSerializable()) return; string name = parameter.getEscapedName(); if(name=="") name="UnknownName"; if(parameter.type()==typeid(ofParameterGroup).name()){ const ofParameterGroup & group = static_cast<const ofParameterGroup&>(parameter); if(!tagExists(name)) addTag(name); pushTag(name); for(int i=0;i<group.size();i++){ serialize(group.get(i)); } popTag(); }else{ string value = parameter.toString(); if(!tagExists(name)) addValue(name,value); else setValue(name,value); } }
void ofxFlashXFLBuilder :: setupFillForShape ( ofxFlashShape* shape ) { if( tagExists( "fill", 0 ) ) { pushTag( "fill", 0 ); string fillSolidColor; fillSolidColor = getAttribute( "SolidColor", "color", "#000000", 0 ); fillSolidColor = cleanHexString( fillSolidColor ); float fillAlpha; fillAlpha = getAttribute( "SolidColor", "alpha", 1.0, 0 ); shape->setFill( true ); shape->setFillColor( stringToHex( fillSolidColor ) ); shape->setFillAlpha( fillAlpha ); popTag(); } }
void ofxFlashXFLBuilder :: setupMatrixForDisplayObject ( ofxFlashDisplayObject* displayObject ) { if( tagExists( "matrix", 0 ) ) { pushTag( "matrix", 0 ); float a = getAttribute( "Matrix", "a", 1.0, 0 ); float b = getAttribute( "Matrix", "b", 0.0, 0 ); float c = getAttribute( "Matrix", "c", 0.0, 0 ); float d = getAttribute( "Matrix", "d", 1.0, 0 ); float tx = getAttribute( "Matrix", "tx", 0.0, 0 ); float ty = getAttribute( "Matrix", "ty", 0.0, 0 ); ofxFlashMatrix matrix; matrix.set( a, b, c, d, tx, ty ); displayObject->matrix( matrix ); popTag(); } }
void ofXML::newCurrentTag(string label) { pushTag(label, addTag(label)); }
void ofXML::loadFile(string file) { nodes.clear(); while (prevLevel.size()) prevLevel.pop(); currentLevel=0; filename=file; ifstream input(ofToDataPath(file).c_str()); string buffer; bool tagOpen=false; while (input.peek()!=EOF) { getline(input, buffer); for (unsigned int i=0; i<buffer.length(); i++) { if(buffer[0]=='#') i=buffer.length(); else if(!tagOpen&&buffer[i]=='<'){ tagOpen=true; i++; try { if(buffer[i]=='/'){ i++; string close=getWord(buffer, i, " >"); if(!currentTag().compare(close)){ popTag(); i--; } else ofLog(OF_LOG_WARNING, "Tags don't match: "+close+" and " +currentTag()); } else { string newLabel=getWord(buffer, i, " >"); i--; int n=addTag(newLabel); pushTag(newLabel, n); } } catch (string except) { ofLog(OF_LOG_WARNING, except); } } else if(tagOpen){ i=buffer.find_first_not_of(" ",i); if(buffer[i]=='>'){ //writeOut(); tagOpen=false; } else if(buffer[i]=='/'&&i<buffer.length()-1&&buffer[i+1]=='>'){ popTag(); } else { string aName=getWord(buffer, i, " ="); i=buffer.find_first_not_of("=\"",i); string aValue=getWord(buffer, i, "\""); addAttribute(aName,aValue); } } else if(!tagOpen&&buffer[i]!='\t'&&buffer[i]!='\r'&&buffer[i]!='\n'){ string val=getWord(buffer,i,"<"); i--; currentLevel->setValue(val); } } } }
void startField(unsigned tag, const char *name) { pushTag(tag); getDerived().startFieldImpl(name); }
void wyBox2DPELoader::startElement(void* ctx, const xmlChar *name, const xmlChar **atts) { wyBox2DPELoader* thiz = (wyBox2DPELoader*)ctx; wyParseState* state = (wyParseState*)thiz->m_parseState; wyHashSet* hashSet = thiz->m_bodyMetas; // set tag pushTag(state, getPListTag((const char*)name)); switch(topTag(state)) { case TAG_DICT: if(state->lastKey == NULL) break; switch(state->state) { case State_ready: { if(0 == strcmp(state->lastKey, "metadata")) state->state = State_parsingMetadata; else if(0 == strcmp(state->lastKey, "bodies")) state->state = State_parsingBodies; break; } case State_parsingBodies: { wyB2BodyMeta* bodyMeta = WYNEW wyB2BodyMeta(state->lastKey); wyHashSetInsert(hashSet, wyUtils::strHash(state->lastKey), bodyMeta, NULL); state->bodyMeta = bodyMeta; state->state = State_parsingBody; break; } case State_parsingFixtures: { state->state = State_parsingFixture; break; } case State_parsingFixture: { if(0 == strcmp(state->lastKey, "circle")) { state->state = State_parsingCircle; } } default: break; } break; case TAG_ARRAY: switch(state->state) { case State_parsingBody: if(0 == strcmp(state->lastKey, "fixtures")) state->state = State_parsingFixtures; break; case State_parsingFixture: if(0 == strcmp(state->lastKey, "polygons")) { state->state = State_parsingShapes; } break; case State_parsingShapes: state->state = State_parsingShape; state->vertexIndex = 0; break; default: break; } break; case TAG_TRUE: switch(state->state) { case State_parsingFixture: { if(0 == strcmp(state->lastKey, "isSensor")) state->fixtureDef->isSensor = true; } default: break; } break; case TAG_FALSE: switch(state->state) { case State_parsingFixture: { if(0 == strcmp(state->lastKey, "isSensor")) state->fixtureDef->isSensor = false; } default: break; } break; } }
void ofxFlashXFLBuilder :: buildElements () { int numOfElements = 0; TiXmlElement* child = ( storedHandle.FirstChildElement() ).ToElement(); for( numOfElements = 0; child; child = child->NextSiblingElement(), ++numOfElements ) {} for( int i=0; i<numOfElements; i++ ) { TiXmlElement* child = ( storedHandle.ChildElement( i ) ).ToElement(); string elementTag = child->Value(); if( elementTag == "DOMGroup" ) { pushTagAt( i ); pushTag( "members", 0 ); buildElements(); popTag(); popTag(); } else if( elementTag == "DOMBitmapInstance" ) { DOMBitmapInstance dom; dom.libraryItemName = child->Attribute( "libraryItemName" ); dom.name = child->Attribute( "name" ); dom.referenceID = ""; domBitmapInstance = dom; pushTagAt( i ); buildBitmap(); popTag(); } else if( elementTag == "DOMSymbolInstance" ) { DOMSymbolInstance dom; dom.libraryItemName = child->Attribute( "libraryItemName" ); dom.name = child->Attribute( "name" ); dom.centerPoint3DX = 0.0; dom.centerPoint3DY = 0.0; domSymbolInstance = dom; pushTagAt( i ); buildMovieClip(); popTag(); } else if( elementTag == "DOMRectangleObject" ) { DOMRectangleObject dom; child->QueryFloatAttribute( "x", &dom.x ); child->QueryFloatAttribute( "y", &dom.y ); child->QueryFloatAttribute( "objectWidth", &dom.objectWidth ); child->QueryFloatAttribute( "objectHeight", &dom.objectHeight ); domRectangleObject = dom; pushTagAt( i ); buildRectangleShape(); popTag(); } else if( elementTag == "DOMOvalObject" ) { DOMOvalObject dom; child->QueryFloatAttribute( "x", &dom.x ); child->QueryFloatAttribute( "y", &dom.y ); child->QueryFloatAttribute( "objectWidth", &dom.objectWidth ); child->QueryFloatAttribute( "objectHeight", &dom.objectHeight ); child->QueryFloatAttribute( "endAngle", &dom.endAngle ); domOvalObject = dom; pushTagAt( i ); buildOvalShape(); popTag(); } else if( elementTag == "DOMShape" ) { continue; // NOT SUPPORTED AT THE MOMENT. } else if( elementTag == "DOMStaticText" ) { continue; // NOT SUPPORTED AT THE MOMENT. } else if( elementTag == "DOMDynamicText" ) { continue; // NOT SUPPORTED AT THE MOMENT. } else if( elementTag == "DOMInputText" ) { continue; // NOT SUPPORTED AT THE MOMENT. } } }