//-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ vector<ofColor> bgColors = myFlag->getBackground()->getColors(); ofPixels px; ofxDatGuiColorPicker* picker; ofxDatGui2dPad* pad; svgCanvas.readToPixels(px); for (int i = 0; i < bgColors.size(); i++) { picker = mainGui->getColorPicker("BG-" + ofToString(i)); if (picker->hitTest(ofPoint(x, y))) { lastHittedElement = "BG-" + ofToString(i); } } picker = mainGui->getColorPicker("BG-STKCOL"); if (picker->hitTest(ofPoint(x, y))) { lastHittedElement = "BG-STKCOL"; } vector<flagLayer*> layers = myFlag->getLayers(); for (int i = 0; i < layers.size(); i++) { picker = mainGui->getColorPicker("LY-" + ofToString(i) + "-0"); if (picker->hitTest(ofPoint(x, y))) { lastHittedElement = "LY-" + ofToString(i) + "-0"; } picker = mainGui->getColorPicker("LY-" + ofToString(i) + "-STKCOL"); if (picker->hitTest(ofPoint(x, y))) { lastHittedElement = "LY-" + ofToString(i) + "-STKCOL"; } } cout << lastHittedElement << endl; if ((x > FLAG_WIDTH && x < FLAG_WIDTH + svgCanvas.getWidth()) && (y > 0 && y < svgCanvas.getHeight())){ ofColor pickedColor = px.getColor(x, y); if (ofStringTimesInString(lastHittedElement, "BG") > 0) { if (ofStringTimesInString(lastHittedElement, "STKCOL") > 0) { myFlag->getBackground()->setStrokeColor(pickedColor); } else { int index = ofToInt(ofSplitString(lastHittedElement, "-")[1]); myFlag->getBackground()->setColor(index, pickedColor); } } if (ofStringTimesInString(lastHittedElement, "LY") > 0) { int numLayer = ofToInt(ofSplitString(lastHittedElement, "-")[1]); if (ofStringTimesInString(lastHittedElement, "STKCOL") > 0) { myFlag->getLayers()[numLayer]->setStrokeColor(pickedColor); } else { int index = ofToInt(ofSplitString(lastHittedElement, "-")[2]); myFlag->getLayers()[numLayer]->setColor(index, pickedColor); } } picker = mainGui->getColorPicker(lastHittedElement); picker->setColor(pickedColor); lastHittedElement = ""; } }
//======================================================================== int main( ){ #ifdef USE_PROGRAMMABLE_GL // we are using the programmable gl renderer. ofPtr<ofBaseRenderer> renderer(new ofGLProgrammableRenderer(false)); ofSetCurrentRenderer(renderer, false); ofSetupOpenGL(1280,720,OF_WINDOW); // <-------- setup the GL context #else // we are not using the progammable gl renderer. // when we are not using the programmable gl renderer it is not safe to assume // out current gl context provides us with the necessary openGL extensions to // run this example. // let's check if the current openGL context provides us with glDrawElementsInstanced // we do this after we have initialised our openGL context. ofSetupOpenGL(1280,720,OF_WINDOW); // <-------- setup the GL context ostringstream extStr; extStr << (char*)glGetString(GL_EXTENSIONS); // first get all available extensions. string extensionsAvailable = extStr.str(); if (ofStringTimesInString(extensionsAvailable, "GL_ARB_draw_instanced") == 0) { ofLogFatalError("App") << " GL_ARB_draw_instanced is needed for this example but it is not supported by your graphics card. Exiting App."; return -1; } else { // GL_ARB_draw_instanced is available... so far so good. // either one of these is needed, too: if (ofStringTimesInString(extensionsAvailable, "GL_EXT_gpu_shader4") == 0 && ofStringTimesInString(extensionsAvailable, "NV_vertex_program4") == 0 ) { ofLogFatalError("App") << " GL_EXT_gpu_shader4 or NV_vertex_program4 is needed for this example but it is not supported by your graphics card. Exiting App."; return -1; } } #endif // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN // pass in width and height too: ofRunApp(new ofApp()); }
ofColor ofxToColor(string s) { ofColor c; if (ofxStringStartsWith(s,"#")) ofStringReplace(s,"#","0x"); //#123456 if (ofxStringStartsWith(s,"0x")) return ofColor::fromHex(ofxToInteger(s)); //0x123456 (hex) else if (ofStringTimesInString(s,",")==3) return ofxToColor(ofxToVec4f(s)); //255,255,255,128 (r,g,b,alpha) else if (ofStringTimesInString(s,",")==2) return ofxToColor(ofxToVec3f(s)); //255,255,255 (r,g,b) else if (ofStringTimesInString(s,",")==1) return ofColor(ofxToVec2f(s).x,ofxToVec2f(s).y); //255,128 (gray,alpha) else if (ofStringTimesInString(s,",")==0) return ofColor(ofxToInteger(s)); //gray else { ofLogError() << "ofxToColor(" << s << ") is not a valid color"; return ofColor(); } }
bool ofxTextBlock::isMetaTag( string str_, string tag_ ){ if ( ofStringTimesInString( str_, tag_) > 0) { ofStringReplace( str_, tag_, ""); return true; } return false; };
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ if (ofStringTimesInString(lastHittedElement, "LY") > 0) { int numLayer = ofToInt(ofSplitString(lastHittedElement, "-")[1]); ofPoint pos = myFlag->getLayers()[numLayer]->getCenter(); if (key == OF_KEY_UP) pos.y--; else if (key == OF_KEY_DOWN) pos.y++; else if (key == OF_KEY_LEFT) pos.x--; else if (key == OF_KEY_RIGHT) pos.x++; myFlag->getLayers()[numLayer]->setCenter(pos); } }
void fanManager::setup(){ panel.setup("fan control"); panel.add(allOn.setup("all on", false)); panel.add(bManual.setup("manual control", false)); serial.listDevices(); devices = serial.getDeviceList(); xml.load("relaySettings.xml"); string deviceToMatch = xml.getValue("relayControl:deviceId", ""); whichDevice= 0; for (int i= 0; i < devices.size(); i++){ int howMany = ofStringTimesInString(devices[i].getDeviceName(), deviceToMatch); if (howMany > 0){ whichDevice = i; } bOnLastFrame[i] = false; } arduino.connect(devices[whichDevice].getDeviceName()); xml.pushTag("relayControl"); xml.pushTag("pins"); for (int i = 0; i < xml.getNumTags("pin"); i++){ xml.pushTag("pin", i); ///cout << xml.getValue("num", 0) << endl; ///cout << xml.getValue("flipOnOff", "true") << endl; ofParameter <bool> pin; relayPins.push_back(pin); pinIds.push_back(xml.getValue("num", 0)); bFlipMes.push_back(xml.getValue("flipOnOff", "true") == "true" ? true : false); bool bDefaultState = xml.getValue("defaultState", "true") == "true" ? true : false; panel.add(relayPins[relayPins.size()-1].set("fan id " + ofToString(i+1) + " pin " + ofToString(xml.getValue("num", 0)), bDefaultState)); arduino.sendDigitalPinMode(pinIds[i],ARD_OUTPUT); xml.popTag(); } for (int i= 0; i < relayPins.size(); i++){ energyPerFan[i] = 0; } }
void ofxLayout::updateAssets(ofxLayoutElement *element){ if(element->hasStyle(OSS_KEY::BACKGROUND_IMAGE)){ string imageFilename = element->getStringStyle(OSS_KEY::BACKGROUND_IMAGE); ofxLoaderBatch* imagesBatch = assets.getBatch(IMAGES_BATCH); if(ofStringTimesInString(imageFilename, ":")){ vector<string> ids = ofSplitString(imageFilename, ":"); imagesBatch = assets.getBatch(IMAGES_BATCH)->getBatch(ids[0]); imageFilename = ids[1]; } ofFile file(ofToDataPath(imageFilename)); string bgImgExt = ofToLower(file.getExtension()); bool fileExists = ofFile::doesFileExist(imageFilename); if(bgImgExt == "svg"){ if(fileExists){ element->loadSvg(imageFilename); } else if(element->isSVG){ element->getSvg()->clear(); } } else if((bgImgExt == "jpg" || bgImgExt == "png") &&!imageFilename.empty() && !imagesBatch->hasTexture(imageFilename)){ imagesBatch->addTexture(imageFilename, imageFilename); imagesBatch->loadTexture(imageFilename); } } // Get fonts if(element->hasStyle(OSS_KEY::FONT_FAMILY)){ string fontFilename = element->getStringStyle(OSS_KEY::FONT_FAMILY); if(fonts->count(fontFilename) == 0){ (*fonts)[fontFilename] = new ofxFontStash(); fonts->at(fontFilename)->setup(fontFilename, 1.0, 2048, true, 8, 1.0f ); } } }
void ofxLayout::populateExpressions(string& value){ while(ofStringTimesInString(value, "{{") > 0){ string leftDeliminator = "{{"; string rightDeliminator = "}}"; int leftDeliminatorPos = value.find(leftDeliminator); int rightDeliminatorPos = value.find(rightDeliminator); int dataKeyPos = leftDeliminatorPos+leftDeliminator.length(); int dataKeyLength = rightDeliminatorPos-dataKeyPos; string dataKey = value.substr(dataKeyPos, dataKeyLength); if(data.count(dataKey) > 0){ ofStringReplace(value, leftDeliminator+dataKey+rightDeliminator, data[dataKey]); } else{ ofLogWarning("ofxLayout::populateExpressions","Could not find data value for key '{{"+dataKey+"}}', replaced with ''."); ofStringReplace(value, leftDeliminator+dataKey+rightDeliminator, ""); } } }