コード例 #1
0
pair<int, int> ofxPTZControl::getPanTiltPos(){
    //Example use:
    //pair<int, int> pantilt = ptzC.getPanTiltPos();
    //cout<<"pan: "<<pantilt.first<<endl;
    //cout<<"tilt: "<<pantilt.second<<endl;
    
    string data = sendCommand("APC");
    return make_pair(ofHexToInt(data.substr(3,4)), ofHexToInt(data.substr(7,4)));    
}
コード例 #2
0
ファイル: animations.cpp プロジェクト: v3ga/murmur
//--------------------------------------------------------------
void Animation::loadColors()
{
	OFAPPLOG->begin("Animation::loadColors()");
	string pathColorSettings = "Config/animations/__colors__.xml";
	
	ofxXmlSettings colorSettings;


	if (colorSettings.load(pathColorSettings))
	{
		OFAPPLOG->println("- loaded "+pathColorSettings);
		colorSettings.pushTag("colors");
	    int nbColors = colorSettings.getNumTags("color");
	    OFAPPLOG->println("- nb colors="+ofToString(nbColors));
    	for (int i=0;i<nbColors;i++)
    	{
        	string colorHex = ofToLower(colorSettings.getValue("color", "#FFFFFF",i));
			ofColor color = ofColor::fromHex( ofHexToInt(colorHex) );


			OFAPPLOG->println("    - color["+ofToString(i)+"] = "+colorHex+"/"+ofToString(color));


			m_colors.push_back(color  );
		}

		colorSettings.popTag();
	}
	else
	{
		OFAPPLOG->println(OF_LOG_ERROR, "- error loading "+pathColorSettings);
	}
	
	OFAPPLOG->end();
}
コード例 #3
0
ファイル: ofApp.cpp プロジェクト: BBDO/LUMI
//--------------------------------------------------------------
void ofApp::oscReceive()
{
    // check for waiting messages
	while(receiver.hasWaitingMessages())
    {
		// get the next message
		ofxOscMessage m;
		receiver.getNextMessage(&m);

        // pump our 2d array full of osc data
        pixelArray[(int)m.getArgAsFloat(1)][(int)m.getArgAsFloat(2)] = ofHexToInt(m.getArgAsString(0));        
    }
}
コード例 #4
0
ファイル: ofApp.cpp プロジェクト: shinabebel/ofApp-ArenaSpout
void ofApp::loadGuiTheme(ofxGuiGroupRef gui, string path)
{
	ofXml xml;
	if (!xml.load(path))
	{
		ofLog(OF_LOG_WARNING, "fail to load gui theme settings from %s\n", path.c_str());
		return;
	}

	gui->loadFont(xml.getValue("FONT_NAME"), xml.getIntValue("FONT_SIZE"));
	gui->setDefaultTextPadding(xml.getIntValue("TEXT_PADDING"));
	gui->setDefaultHeight(xml.getIntValue("HEIGHT"));

	string theme_name = xml.getValue("THEME_NAME");
	if (xml.exists(theme_name))
	{
		xml.setTo(theme_name);
		auto hexHeaderBackgroundColor = ofColor::fromHex(ofHexToInt(xml.getValue("HeaderBackgroundColor")));
		auto hexBackgroundColor = ofColor::fromHex(ofHexToInt(xml.getValue("BackgroundColor")));
		auto hexBorderColor = ofColor::fromHex(ofHexToInt(xml.getValue("BorderColor")));
		auto hexFillColor = ofColor::fromHex(ofHexToInt(xml.getValue("FillColor")));
		auto hexTextColor = ofColor::fromHex(ofHexToInt(xml.getValue("TextColor")));
		gui->setHeaderBackgroundColor(hexHeaderBackgroundColor);
		gui->setBackgroundColor(hexBackgroundColor);
		gui->setBorderColor(hexBorderColor);
		gui->setFillColor(hexFillColor);
		gui->setTextColor(hexTextColor);
		gui->setDefaultHeaderBackgroundColor(hexHeaderBackgroundColor);
		gui->setDefaultBackgroundColor(hexBackgroundColor);
		gui->setDefaultBorderColor(hexBorderColor);
		gui->setDefaultFillColor(hexFillColor);
		gui->setDefaultTextColor(hexTextColor);
	}
	else
	{
		ofLog(OF_LOG_WARNING, "gui theme [%s] is missing.\n", theme_name.c_str());
	}
}
コード例 #5
0
bool ColorPalette::loadPalette(string _sFile){
    
    bool success = false;
    
    ofxXmlSettings XML;
    
    if ( XML.loadFile(_sFile)){
        if ( XML.pushTag("palette")) {
            
            bVertical = XML.getValue("vertical", bVertical);
            maxOffSet = XML.getValue("offset", maxOffSet);
            margins = XML.getValue("margins", margins);
            
            for (int i = 0; i < XML.getNumTags("img"); i++){
                ofImage image;
                if ( image.loadImage( XML.getValue("img", "01.png", i ) ) ){
                    images.push_back(image);
                }
            }
            
            for (int i = 0; i < XML.getNumTags("imgtop"); i++){
                ofImage image;
                if ( image.loadImage( XML.getValue("imgtop", "01.png", i ) ) ){
                    imagesTop.push_back(image);
                }
            }
            
            
            int totalSchemes = XML.getNumTags("schemes");
            for (int j = 0; j < totalSchemes; j++ ){
                XML.pushTag("schemes",j);
                
                vector <ofColor> newScheme;
                
                for (int i = 0; i < XML.getNumTags("color"); i++){
                    string hexString = XML.getValue("color", "ee1b12", i );
                    int hexInt = ofHexToInt( hexString );
                    
                    ofColor color;
                    color.setHex( hexInt );
                    newScheme.push_back(color);
                }
                
                schemes.push_back( newScheme );
                XML.popTag();
            }
        }
    }
}
コード例 #6
0
void CloudsSVGMesh::recurseSVGTag(ofxXmlSettings& xml, const string& parentId, float parentOpacity){

	ofMesh strokeMesh;
	ofMesh fillMesh;
	//find geo on this layer
	//<line display="inline" opacity="0.49" fill="none" stroke="#FFFFFF" stroke-miterlimit="10" x1="87.313" y1="612.5" x2="749.313" y2="612.5"/>
	int numLineTags = xml.getNumTags("line");
	for(int l = 0; l < numLineTags; l++){
		strokeMesh.addVertex(ofVec3f(xml.getAttribute("line", "x1", 0., l),
									 xml.getAttribute("line", "y1", 0., l), 0));
		strokeMesh.addVertex(ofVec3f(xml.getAttribute("line", "x2", 0., l),
									 xml.getAttribute("line", "y2", 0., l), 0));

		string hexColor = xml.getAttribute("line", "stroke", "#FFFFFF", l);
		hexColor.erase(hexColor.begin());//kill the #
		ofColor color = ofColor::fromHex( ofHexToInt(hexColor) );
		if(xml.attributeExists("line","opacity",l)){
			color.a = xml.getAttribute("line", "opacity", 0., l)*255.;
		}
		color.a *= parentOpacity;
		strokeMesh.addColor(color);
		strokeMesh.addColor(color);
	}
	
	//sample rect tag
	//<rect x="519.813" y="144.5" display="inline" opacity="0.02" fill="none" stroke="#FFFFFF" stroke-miterlimit="10" width="29" height="18"/>
	int numRectTags = xml.getNumTags("rect");
	for(int r = 0; r < numRectTags; r++){
		ofRectangle rect(xml.getAttribute("rect", "x", 0., r),
						 xml.getAttribute("rect", "y", 0., r),
						 xml.getAttribute("rect", "width", 0., r),
						 xml.getAttribute("rect", "height", 0., r));

		//pull the vertices out as vec3s		
		ofVec3f a = rect.getTopLeft();
		ofVec3f b = rect.getTopRight();
		ofVec3f c = rect.getBottomRight();
		ofVec3f d = rect.getBottomLeft();
		
		string fillProperty = xml.getAttribute("rect", "fill", "none",r);
		bool isLines = fillProperty == "none";
		
		string hexColor = xml.getAttribute("rect", (isLines ? "stroke" : "fill"), "#FFFFFF", r);
		hexColor.erase(hexColor.begin());//kill the #
		ofColor color = ofColor::fromHex( ofHexToInt(hexColor));
		if(xml.attributeExists("rect","opacity",r)){
			color.a = xml.getAttribute("rect", "opacity", 0., r)*255.;
		}
		color.a *= parentOpacity;
		if(isLines){

			//we may wish to make this a line loop....
			//convert to line segments
			strokeMesh.addVertex(a);
			strokeMesh.addVertex(b);
			
			strokeMesh.addVertex(b);
			strokeMesh.addVertex(c);
			
			strokeMesh.addVertex(c);
			strokeMesh.addVertex(d);
			
			strokeMesh.addVertex(d);
			strokeMesh.addVertex(a);
			
			for(int i = 0; i < 8; i++){
				strokeMesh.addColor(color);
			}
		}
		else{
			
			
			fillMesh.addVertex(a);
			fillMesh.addVertex(b);
			fillMesh.addVertex(d);

			fillMesh.addVertex(b);
			fillMesh.addVertex(d);
			fillMesh.addVertex(c);

			for(int i = 0; i < 6; i++){
				fillMesh.addColor(color);
			}
		}
	}
	
	//if we added go throw it in the group, and give it a name
	if(strokeMesh.getNumVertices() > 0){
		SVGMesh m;
        m.visible = true;
		m.id = parentId;
		if(m.id != ""){
			meshIdIndex[m.id] = meshes.size();
		}
		m.mesh = ofVboMesh(strokeMesh);
		m.mesh.setMode(OF_PRIMITIVE_LINES);
		m.mesh.setUsage(GL_STATIC_DRAW);
		m.fill = false;
		meshes.push_back(m);
	}
	
	if(fillMesh.getNumVertices() > 0){
		SVGMesh m;
        m.visible = true;
		m.id = parentId;
		if(m.id != ""){
			meshIdIndex[m.id] = meshes.size();
		}
		m.mesh = ofVboMesh(fillMesh);
		m.mesh.setMode(OF_PRIMITIVE_TRIANGLES);
		m.mesh.setUsage(GL_STATIC_DRAW);
		m.fill = true;
		meshes.push_back(m);
	}
	
	//search other g tags
	int numGTags = xml.getNumTags("g");
	for(int i = 0; i < numGTags; i++){
		//is g tag displayed?
		if(xml.attributeExists("g", "display", i) &&
		   xml.getAttribute("g", "display", "", i) == "none")
		{
			//skipit
			continue;
		}
		string nextParentId;
		//does g tag have id;
		if(xml.attributeExists("g", "id", i)){
			nextParentId = xml.getAttribute("g", "id", "",i);
		}
		if(xml.attributeExists("g", "opacity", i)){
			parentOpacity *= xml.getAttribute("g", "opacity", 1.0, i);;
		}
		xml.pushTag("g",i);
		recurseSVGTag(xml, nextParentId, parentOpacity);
		xml.popTag();
	}
}
コード例 #7
0
ofVec2f ofxFontStash::drawMultiColumnFormatted(const string &_text, float size, float columnWidth, bool topLeftAlign, bool dryrun){

	float maxX=0;

	string text = _text;
	if (!utf8::is_valid(text.begin(), text.end())){
		text = LocaleToUtf8(text);
	}

	if (stash == NULL || fontIds.empty()) {
		ofLogError("ofxFontStash") << "error: stash not initialized or no font";
		return ofVec2f(0,0);
	}

	//TODO hack!
	//this is to fix the issue where two consecutive \n\n's are ignored
	string localText = text;
	ofStringReplace(localText, "\n", " \n");

	vector<std::string> allWords;
	vector<ofVec2f> wordSizes;
	vector<int> wordFonts;
	vector<ofColor> wordColors;
	vector<float> wordScales;

	int currentFontId = fontIds[0];
	ofColor currentColor = ofGetStyle().color;
	float currentScale = 1;

	// first, calculate the sizes of all the words
	//
	vector<std::string> lines = ofSplitString(localText, "\n");
	for (int i=0; i<lines.size(); i++) {

		vector<std::string> words = ofSplitString(lines[i], " ");

		for (int j=0; j<words.size(); j++) {

			// handle '@' code to change font id
			if (isFontCode(words[j])) {
				currentFontId = fontIds[ofToInt(words[j].substr(1, words[j].length()))];
				continue;
			}

			// handle '#' code to change color
			if (isColorCode(words[j])) {
				currentColor = ofColor::fromHex(ofHexToInt(words[j].substr(1, words[j].length())));
				continue;
			}

			// handle '%' code to change scale
			if (isScaleCode(words[j])) {
				currentScale = ofToFloat(words[j].substr(1, words[j].length()));
				continue;
			}

			std::string word = words[j];

			// add ' ' because we removed it when we did the split
			if (j != words.size()-1) {
				word += " ";
			}

			float x, y, w, h;
			ofx_sth_dim_text( stash, currentFontId, size * currentScale / dpiScale, word.c_str(), &x, &y, &w, &h);

			allWords.push_back(word);
			wordSizes.push_back(ofVec2f(w, h));
			wordFonts.push_back(currentFontId);
			wordColors.push_back(currentColor);
			wordScales.push_back(currentScale);

		}

		// all end of line
		allWords.push_back("\n");
		// a place holder to match indexes
		wordSizes.push_back(ofVec2f(0, 0));
		wordFonts.push_back(currentFontId);
		wordColors.push_back(currentColor);
		wordScales.push_back(currentScale);
	}

	// now draw the text
	//
	ofVec2f drawPointer(0, 0);
	float asc = 0.0f;

	if (topLeftAlign) {
		float desc, lineh;
		ofx_sth_vmetrics(stash, wordFonts[0], size, &asc, &desc, &lineh);

		ofPushMatrix();
		ofTranslate(0, asc);
	}

	if (!dryrun) {
		ofx_sth_begin_draw(stash);
	}

	for (int i=0; i<allWords.size(); i++) {

		// do we need to jump a line?
		if ((drawPointer.x + wordSizes[i].x > columnWidth ||
			allWords[i] == "\n") &&
			drawPointer.x != 0)
		{
			// jump one line down
			drawPointer.y += lineHeight * size * wordScales[i];
			drawPointer.x = 0;
		}

		// we need to flush the vertices if we change the color
		if (!dryrun) {
			if (wordColors[i] != ofGetStyle().color) {
				ofx_sth_end_draw(stash);
				ofx_sth_begin_draw(stash);

				ofSetColor(wordColors[i]);
			}
		}

		float dx = 0;
		if (!dryrun) {
			ofx_sth_draw_text( stash, wordFonts[i], size * wordScales[i], drawPointer.x, drawPointer.y, allWords[i].c_str(), &dx );
		}
		drawPointer.x += wordSizes[i].x;

		// save maxX so we'll return the size
		if (drawPointer.x > maxX) {
			maxX = drawPointer.x;
		}
	}

	if (!dryrun) {
		ofx_sth_end_draw(stash);
	}

	if (topLeftAlign) {
		ofPopMatrix();
	}

	return ofVec2f(maxX, drawPointer.y - (lineHeight * size / dpiScale - asc));
}
コード例 #8
0
ファイル: testApp.cpp プロジェクト: Elenka/openFrameworks
void testApp::setup() {
	string splitInput = " a,,b,c,";
	splitTest(" a,,b, c , ", ",");
	splitTest(" a<><>b<> c <> ", "<>");
	 
	 cout << "empty" << endl;
	 cout << ofToInt("") << endl;
	 cout << ofToFloat("") << endl;
	 cout << ofToBool("") << endl;
	 cout << ofToChar("") << endl;
	 cout << endl;
	 
	 cout << "strings" << endl;
	 cout << ofToString(123) << endl;
	 cout << ofToString(123.4) << endl;
	 cout << ofToString(123.4f) << endl;
	 cout << ofToString(123, 5) << endl;
	 cout << ofToString(123.4, 5) << endl;
	 cout << ofToString(123.4f, 5) << endl;
	 cout << endl;
	 
	 cout << "ints" << endl;
	 cout << ofToInt("123.") << endl;
	 cout << ofToInt("123.4") << endl;
	 cout << ofToInt("123.4f") << endl;
	 cout << ofToInt("+123.4") << endl;
	 cout << endl;
	 
	 cout << "float" << endl;
	 cout << ofToFloat("123.") << endl;
	 cout << ofToFloat("123.4") << endl;
	 cout << ofToFloat("123.4f") << endl;
	 cout << ofToFloat("+123.4") << endl;
	 cout << endl;
	 
	 cout << "bool" << endl;
	 cout << ofToBool("1") << endl;
	 cout << ofToBool("0") << endl;
	 cout << ofToBool("true") << endl;
	 cout << ofToBool("false") << endl;
	 cout << ofToBool("True") << endl;
	 cout << ofToBool("False") << endl;
	 cout << endl;
	 
	 cout << "char" << endl;
	 cout << ofToChar("a") << endl;
	 cout << ofToChar("b") << endl;
	 cout << ofToChar("1") << endl;
	 cout << ofToChar("0") << endl;
	 cout << endl;	
	 
	 cout << "to binary" << endl;
	 cout << ofToBinary(8) << endl;
	 cout << ofToBinary(64) << endl;
	 cout << ofToBinary(1024) << endl;
	 cout << ofToBinary('a') << endl;
	 cout << ofToBinary(8.5) << endl;
	 cout << ofToBinary(8.f) << endl;
	 cout << ofToBinary(8.5f) << endl;
	 cout << ofToBinary(9.f) << endl;
	 string strVal = "abc";
	 cout << ofToBinary(strVal) << endl;
	 cout << ofToBinary("abc") << endl;
	 cout << endl;
	 
	 cout << "to binary" << endl;
	 cout << ofBinaryToInt(ofToBinary(8)) << endl;
	 cout << ofBinaryToInt(ofToBinary(64)) << endl;
	 cout << ofBinaryToInt(ofToBinary(1024)) << endl;
	 cout << ofBinaryToChar(ofToBinary('a')) << endl;
	 cout << ofBinaryToFloat(ofToBinary(8.5f)) << endl;
	 cout << ofBinaryToFloat(ofToBinary(64.5f)) << endl;
	 cout << ofBinaryToString(ofToBinary("abc")) << endl;
	 cout << endl;
	 
	 cout << "to hex" << endl;
	 cout << ofToHex('a') << endl;
	 cout << ofToHex(128) << endl;
	 cout << ofToHex(128.f) << endl;
	 cout << ofToHex(128.) << endl;
	 cout << ofToHex("abc") << endl;
	 cout << ofToHex("abcd") << endl;
	 string val = "abcdefg";
	 cout << ofToHex(val) << endl;
	 cout << endl;
	 
	 cout << "hex to int" << endl;
	 cout << ofHexToInt("0xff") << endl;
	 cout << ofHexToInt("ff") << endl;
	 cout << ofHexToInt(ofToHex(128)) << endl;
	 cout << ofHexToFloat(ofToHex(128.5f)) << endl;
	 cout << ofHexToChar(ofToHex('a')) << endl;
	 cout << ofHexToString(ofToHex("abc")) << endl;
	 cout << endl;
}
コード例 #9
0
ファイル: ofxFlash.cpp プロジェクト: roikr/openFrameworks007
void ofxSymbolItem::setup(ofxDocument *doc) {
    
    ofxXmlSettings xml;
    this->doc = doc;
    
    if (xml.loadFile("LIBRARY/"+href)) {
        xml.pushTag("DOMSymbolItem");
        xml.pushTag("timeline");
        xml.pushTag("DOMTimeline");
        xml.pushTag("layers");
        for (int k=0; k<xml.getNumTags("DOMLayer");k++ ) {
            layer l;
            l.name = xml.getAttribute("DOMLayer", "name", "",k);
            l.currentFrame = 0;
            l.endTime = 0;
            xml.pushTag("DOMLayer",k);
            xml.pushTag("frames");
            for (int j=0; j<xml.getNumTags("DOMFrame"); j++) {
                frame f;
                f.index = xml.getAttribute("DOMFrame","index",1,j)-1; // flash frame start at 1
                f.duration = xml.getAttribute("DOMFrame","duration",1,j);
                
                
                xml.pushTag("DOMFrame",j);
                xml.pushTag("elements");
                for (int i=0; i<xml.getNumTags("DOMBitmapInstance"); i++) {
                    string libraryItemName = xml.getAttribute("DOMBitmapInstance", "libraryItemName", "",i);
                    xml.pushTag("DOMBitmapInstance",i);
                    ofxSymbolInstance si = parseInstance(xml);
                    si.bitmapItem = doc->getBitmapItem(libraryItemName);
                    //                if (bi.transformationPoint.empty()) {
                    //                    bi.transformationPoint.push_back(ofVec2f(bi.bitmapItem->width/2,bi.bitmapItem->height/2));
                    //                }
                    xml.popTag();
                    
                    si.type = BITMAP_INSTANCE;
                    f.instances.push_back(si);
                }
                for (int i=0; i<xml.getNumTags("DOMSymbolInstance"); i++) {
                    xml.pushTag("DOMSymbolInstance",i);
                    ofxSymbolInstance si = parseInstance(xml);
                    xml.popTag();
                    //                si.itemID = doc->itemsMap[];
                    si.name = xml.getAttribute("DOMSymbolInstance", "name", "",i);
                    si.type = SYMBOL_INSTANCE;
                    si.symbolItem = doc->getSymbolItem(xml.getAttribute("DOMSymbolInstance", "libraryItemName", "",i));
                    f.instances.push_back(si);
                }
                for (int i=0; i<xml.getNumTags("DOMShape"); i++) {
                    
                    xml.pushTag("DOMShape",i);
                    ofxSymbolInstance si;
                    si.shapeIndex = shapes.size();
                    shapes.push_back(parseShape(xml));
                    
                    if (!shapes.back().bitmapFill.empty()) {
                        ofxBitmapFill &bf = shapes.back().bitmapFill.front();
                        bf.bitmapItem = doc->getBitmapItem(bf.bitmapPath);
                    }
                    xml.popTag();
                    si.type = SHAPE;
                    f.instances.push_back(si);
                }
                for (int i=0; i<xml.getNumTags("DOMTLFText"); i++) {
                    tlfText tlf;
                    
                    tlf.width = xml.getAttribute("DOMTLFText", "right", 0,i)/PIXEL_SCALE;
                    tlf.height = xml.getAttribute("DOMTLFText", "bottom", 0,i)/PIXEL_SCALE;
                    
                    xml.pushTag("DOMTLFText",i);
                    
                    xml.pushTag("matrix");
                    float a = xml.getAttribute("Matrix", "a", 1.0);
                    float b = xml.getAttribute("Matrix", "b", 0.0);
                    float c = xml.getAttribute("Matrix", "c", 0.0);
                    float d = xml.getAttribute("Matrix", "d", 1.0);
                    float tx = xml.getAttribute("Matrix", "tx", 0.0);
                    float ty = xml.getAttribute("Matrix", "ty", 0.0);
                    
                    //bi.mat = ofMatrix4x4(a, c, 0, tx, b, d, 0, ty, 0, 0, 1, 0, 0, 0, 0, 1);
                    //bi.mat = ofMatrix4x4(sqrt(a*a+b*b)/20, 0, 0, 0, 0,sqrt(c*c+d*d)/20, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1);
                    
                    //                bi.width = (float)doc.items[bi.path].frameRight/PIXEL_SCALE;
                    //                bi.height = (float)doc.items[bi.path].frameBottom/PIXEL_SCALE;
                    //                bi.href = doc.items[bi.path].href;
                    
                    tlf.translation = ofVec2f(tx,ty);
                    tlf.sx = sqrt(a*a+b*b)/PIXEL_SCALE;
                    tlf.sy = sqrt(c*c+d*d)/PIXEL_SCALE;
                    tlf.r = atan2( b, a );
                    xml.popTag();
                    
                    xml.pushTag("markup");
                    xml.pushTag("tlfTextObject");
                    xml.pushTag("TextFlow");
                    
                    for (int j=0; j<xml.getNumTags("p"); j++) {
                        xml.pushTag("p",j);
                        for (int k=0; k<xml.getNumTags("span"); k++) {
                            string l = xml.getValue("span", "",k);
                            if (!l.empty()) {
                                span s;
                                s.text = l;
                                s.fontSize = xml.getAttribute("span", "fontSize", 12,k);
                                s.color = ofHexToInt(xml.getAttribute("span", "color", "",k).substr(1)); // eliminate the hex #
                                tlf.spans.push_back(s);
                                tlf.text.append(l+"\n");
                            }
                            
                            
                            
                        }
                        
                        xml.popTag();
                    }
                    
                    
                    xml.popTag(); // TextFlow
                    xml.popTag();
                    xml.popTag();
                    
                    
                    xml.popTag(); // DOMTLFText
                    
                    //                cout << tlf.text << endl;
                    f.texts.push_back(tlf);
                }
                
                
                xml.popTag();
                xml.popTag();
                l.frames.push_back(f);
                
            }
            
            
            
            
            xml.popTag();
            xml.popTag();
            layers.push_back(l);
        }
        
        
    
        xml.popTag();
        xml.popTag();
        xml.popTag();
        xml.popTag();
    }
    
}
コード例 #10
0
ファイル: ofxFlash.cpp プロジェクト: roikr/openFrameworks007
ofxShape parseShape(ofxXmlSettings &xml) {
    
    ofxShape s;
    
    xml.pushTag("paths");
    
    string str = xml.getAttribute("Path", "data", "");
    
    size_t found = str.find('L');
    if (found!=string::npos) {
        linePath p;
        p.p0 = parseVec(str.substr(1,found)).front(); // eliminate M (for moveTo)
        //ln.p1 = parseVec(str.substr(found+1)).front();
        
        p.bClosed = str.at(str.length()-1) == 'z';
        
        
        
        if (p.bClosed) {
            str = str.substr(found+1,str.npos-1); // eliminate z for closed
        } else {
            str = str.substr(found+1);
        }
        vector<string> svec = ofSplitString(str, "L");
//        cout << "numSegments: " << svec.size() << ", closed: " << p.bClosed<< endl;
        
        for (vector<string>::iterator iter=svec.begin(); iter!=svec.end(); iter++) {
            
            p.segments.push_back(parseVec(*iter).front());  
//            cout << p.segments.back().x << "," << p.segments.back().y << "\t";
        }
//        cout << endl;
        
        
        s.line.push_back(p);
        
//        cout << "rectangle: " << rect.x << " " << rect.y << " " << rect.width << " " << rect.height << " " << endl;
        
    } else {
        found = str.find('C');
        if (found!=string::npos) {
            curvePath p;
            p.p0 = parseVec(str.substr(1,found)).front(); // eliminate M
            
            vector<string> svec = ofSplitString(str.substr(found+1), "C");
            //                        cout << "numCurves: " << svec.size() << endl;
            
            for (vector<string>::iterator iter=svec.begin(); iter!=svec.end(); iter++) {
                vector<ofVec2f> bezier = parseVec(*iter);
                
                //                            cout << bezier.size() << "\t";
                p.segments.push_back(bezier);
            }
            
            s.curve.push_back(p);
            
            
        }
    }
    
    xml.pushTag("Path");
    
    if (xml.tagExists("stroke")) {
        xml.pushTag("stroke");
        xml.pushTag("SolidStroke");
        xml.pushTag("fill");
        
        if (xml.tagExists("SolidColor")) {
            s.solidColorStroke.push_back(ofHexToInt(xml.getAttribute("SolidColor", "color", "").substr(1)));
        }
        xml.popTag();
        xml.popTag();
        xml.popTag();
    }
    
    if (xml.tagExists("fill")) {
        xml.pushTag("fill");
        
        if (xml.tagExists("SolidColor")) {
            s.solidColorFill.push_back(ofHexToInt(xml.getAttribute("SolidColor", "color", "").substr(1)));
        } 
        
        if (xml.tagExists("BitmapFill")) {
            ofxBitmapFill bf;
            bf.bitmapPath = xml.getAttribute("BitmapFill", "bitmapPath", "");
            xml.pushTag("BitmapFill");
            
            if (xml.tagExists("matrix")) {
                xml.pushTag("matrix");
                
                float a = xml.getAttribute("Matrix", "a", 1.0);
                float b = xml.getAttribute("Matrix", "b", 0.0);
                float c = xml.getAttribute("Matrix", "c", 0.0);
                float d = xml.getAttribute("Matrix", "d", 1.0);
                float tx = xml.getAttribute("Matrix", "tx", 0.0);
                float ty = xml.getAttribute("Matrix", "ty", 0.0);
                
                //bi.mat = ofMatrix4x4(a, c, 0, tx, b, d, 0, ty, 0, 0, 1, 0, 0, 0, 0, 1);
                //bi.mat = ofMatrix4x4(sqrt(a*a+b*b)/20, 0, 0, 0, 0,sqrt(c*c+d*d)/20, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1);
                
                //                        bi.width = (float)doc.items[bi.path].frameRight/PIXEL_SCALE;
                //                        bi.height = (float)doc.items[bi.path].frameBottom/PIXEL_SCALE;
                //                        bi.href = doc.items[bi.path].href;
                
                
                //                        cout << bi.path << "\t" << bi.width << "x" << bi.height << endl;
                
                xml.popTag();
                
                bf.mat.scale(sqrt(a*a+b*b)/PIXEL_SCALE, sqrt(c*c+d*d)/PIXEL_SCALE, 1.0);
                bf.mat.rotate(atan2( b, a )*180/PI, 0, 0, 1.0);
                bf.mat.translate(ofVec2f(tx,ty));
            }
            
            
//            cout << bf.mat << endl;
            xml.popTag();
            
                        
            
            
            ofVec2f tl = s.line.front().segments[0];
            ofVec2f br = s.line.front().segments[2];
            
            bf.rect = ofRectangle(tl.x, tl.y, br.x-tl.x, br.y-tl.y); // roikr: what did I forget ? inside rect ?
            
            
            s.bitmapFill.push_back(bf);
        }
        
        xml.popTag();
    }
    
    xml.popTag(); 
    xml.popTag();
    
    return s;
}