void ofxComposer::_mousePressed(ofMouseEventArgs &e){ ofVec3f mouse = ofVec3f(e.x, e.y, 0.0); ofVec3f mouse_transformed = mouse*this->getGlobalTransformMatrix(); // si no estoy clickeando sobre ninguna de las 2 scrollbars, veo que hago // si estoy clickeando una de las scrollbars, no tengo que hacer nada aca if(!draggingGrip && !draggingHGrip && !gui->getOtherSelected()) { int idPatchHit = isAnyPatchHit(mouse_transformed.x, mouse_transformed.y, mouse_transformed.z); // nico zoom/drag if(idPatchHit == -1){ disabledPatches = true; deactivateAllPatches(); }else{ disabledPatches = false; for(map<int,patch*>::iterator it = patches.begin(); it != patches.end(); it++ ){ if(!patches.find(idPatchHit)->second->bActive){ activePatch(idPatchHit); break; } } } selectedDot = -1; for(map<int,patch*>::iterator it = patches.begin(); it != patches.end(); it++ ){ if ( (it->second->getOutPutPosition().distance(ofPoint(mouse_transformed.x, mouse_transformed.y)) < 5) && (it->second->bEditMode) && !(it->second->bEditMask) ){ selectedDot = it->first; it->second->bActive = false; selectedID = -1; } } if (selectedDot == -1){ for(map<int,patch*>::iterator it = patches.begin(); it != patches.end(); it++ ){ if ((it->second->bActive) && (it->second->bEditMode) && !(it->second->bEditMask)){ selectedID = it->first; #ifdef USE_OFXGLEDITOR //if (bGLEditorPatch if ((it->second->getType() == "ofShader")){ editor.setText(it->second->getFrag(), 1); } #endif } } } // nico multipleSelect if(disabledPatches && e.button == 0 && !gui->getOtherSelected()){ multipleSelectFromX = mouse_transformed.x; multipleSelectFromY = mouse_transformed.y; multipleSelectRectangle.x = mouse_transformed.x; multipleSelectRectangle.y = mouse_transformed.y; } } }
/************************************** EMPIEZA SNIPPETS *********************************/ void ofxComposer::loadSnippet() { string snippetName = ""; ofFileDialogResult openFileResult; openFileResult = ofSystemLoadDialog("Select a snippet (.xml)"); if (openFileResult.bSuccess){ ofFile file (openFileResult.getPath()); if (file.exists()){ string fileExtension = ofToUpper(file.getExtension()); //We only want images // if (fileExtension == "SNI" || // fileExtension == "XML") { if(fileExtension == "XML"){ snippetName = openFileResult.getPath(); } else return; } file.close(); } ofxXmlSettings XML; int previousPatchesSize = patches.size(); int a = getMaxIdPatch(); deactivateAllPatches(); if (XML.loadFile(snippetName)){ #ifdef USE_OFXGLEDITOR editor.setup(XML.getValue("general:console:font", "menlo.ttf")); #endif int totalPatchs = XML.getNumTags("surface"); // Load each surface present on the xml file // for(int i = 0; i < totalPatchs ; i++){ patch *nPatch = new patch(); bool loaded = nPatch->loadSnippetPatch(snippetName, i, previousPatchesSize); if (loaded){ #ifdef USE_OFXGLEDITOR if (nPatch->getType() == "ofxGLEditor"){ ofLog(OF_LOG_NOTICE,"ofxComposer: ofxGLEditor loaded"); nPatch->setTexture( editorFbo.getTextureReference(), 0); bGLEditorPatch = true; } #endif // Listen to close bottom on the titleBar // ofAddListener( nPatch->title->close , this, &ofxComposer::closePatch); // Insert the new patch into the map // patches[nPatch->getId()] = nPatch; //mili nPatch->setMainCanvas(this->gui); // nPatch->bActive = true; } } // Load links between Patchs // for(int i = 0; i < totalPatchs ; i++){ if (XML.pushTag("surface", i)){ int fromID = XML.getValue("id", -1); if (XML.pushTag("out")){ int totalLinks = XML.getNumTags("dot"); for(int j = 0; j < totalLinks ; j++){ if (XML.pushTag("dot",j)){ int toID = XML.getValue("to", 0); int nTex = XML.getValue("tex", 0); // If everything goes ok "i" will match the position of the vector // with the position on the XML, in the same place of the vector array // defined on the previus loop // connect( fromID + previousPatchesSize, toID + previousPatchesSize, nTex); XML.popTag(); } } XML.popTag(); } XML.popTag(); } } } }