void VolumetricHybridApproach::update(const string childName, const string fontName)
{
    bool nameChange = _childName == ofToUpper(childName);
    _childName = ofToUpper(childName);
    font.load(fontName, 148, true, true, true, 0.3, 300);
    renderName();
    
    if (shaderChanged || nameChange)
    {
//        _volumetricShader.setUniform1i("iterations", _iterations.get());
//        _volumetricShader.setUniform1i("iterationsMultiplier", _iterationMultiplier.get());
//        _volumetricShader.setUniform1i("volsteps", _volSteps.get());
//        _volumetricShader.setUniform1i("volstepsMultiplier", _volStepsMultiplier.get());
//        _volumetricShader.setUniform1f("formuparam", _forumparam.get());
//        _volumetricShader.setUniform1f("forumparamMultiplier", _forumparamMultiplier.get());
//        _volumetricShader.setUniform1f("stepsize", _stepsize.get());
//        _volumetricShader.setUniform1f("stepsizeMultiplier", _stepsizeMultiplier.get());
//        _volumetricShader.setUniform1f("zoom", _zoom.get());
//        _volumetricShader.setUniform1f("brightness", _brightness.get());
//        _volumetricShader.setUniform1f("darkmatter", _darkmatter.get());
//        _volumetricShader.setUniform1f("distfading", _distfading.get());
//        _volumetricShader.setUniform1f("distfadingMultiplier", _distfadingMultiplier.get());
//        _volumetricShader.setUniform1f("saturation", _saturation.get());
//        _volumetricShader.setUniform1f("tile", _tile.get());
//        _volumetricShader.setUniform1f("time", (float)_time.get());
        
//        _volumetricShader.setUniformTexture("tex0", _textRendered.getTexture(), 0);
        
        shaderChanged = false;
        ofLog() << " shader changed ";
    }

    
}
Esempio n. 2
0
std::vector<GuiEvent> PresetManager::getParametersForPreset(std::string presetName){
   std::vector<GuiEvent> parameters;

   // Iterate xml files
   ofDirectory dir("presets/");
   dir.allowExt("xml");
   dir.listDir();
   for(int i = 0; i < dir.numFiles(); i++){
      
      // Iterate parameters in xml file
      ofxXmlSettings xmlFile;
      xmlFile.loadFile(dir.getPath(i));
      std::string pstName = xmlFile.getValue("preset:name", "No Name");
      if(ofToUpper(pstName) == ofToUpper(presetName)){
         xmlFile.pushTag("preset");
         xmlFile.pushTag("parameters");
         int numberOfParameters = xmlFile.getNumTags("parameter");

         for(int j = 0; j < numberOfParameters; j++){
            Parameter parameter = String2Parameter(xmlFile.getAttribute("parameter", "name", "???", j));
            float value = xmlFile.getAttribute("parameter", "value", -1.0, j);

            GuiEvent e;
            e.parameter = parameter;
            e.value = value;
            parameters.push_back(e);
         }
         xmlFile.popTag();
         xmlFile.popTag();
         break;
      }
   }

   return parameters;
}
Esempio n. 3
0
//--------------------------------------------------------------
void ofApp::onMessage( ofxLibwebsockets::Event& args )
{
  ofLog()<<"got message "<<args.message<<endl;
  vector<string> strings = ofSplitString(args.message, " ");
  for(int a = 0; a < strings.size(); a++)
  {
//    if(a > 100)
//      return;
    bool found = false;
    if(!duplicateWords)
    {
      for(int i = 0; i < foundWords.size(); i++)
      {
        if(ofToUpper(strings[a]) == ofToUpper(foundWords[i]))
          found = true;
      }
    }
    if(!found)
    {
      foundWords.push_back(ofToUpper(strings[a]));
      for(int i = 0; i < 5; i++)
        words.addNewWord(strings[a]);
    }
  }
  // trace out string messages or JSON messages!
  if ( !args.json.isNull() ){
    messages.push_back("New message: " + args.json.toStyledString() + " from " + args.conn.getClientName() );
  } else {
    messages.push_back("New message: " + args.message + " from " + args.conn.getClientName() );
  }
  
  // echo server = send message right back!
  args.conn.send( args.message );
}
Esempio n. 4
0
void TextWriter::drawFixedSize(ofRectangle box, string text, float glyphScaleFactor, bool centred) {
    text = ofToUpper(text);
    
	if(box.height<=0) box.height = 1;
	if(box.width<=0) box.width = 1;
    
    ofPushStyle();

    ofEnableAlphaBlending();
    ofEnableBlendMode(OF_BLENDMODE_ADD);
    ofSetLineWidth(glyphLineWeight);
    
    
    vector<string> lines;
    
    if( text.find('\n') == string::npos)  {
        lines.push_back(text);
    } else {
        lines = ofSplitString(text, "\n");
    }
    
	ofMesh writingMesh = getMesh(lines, box.getTopLeft(), glyphScaleFactor, centred);
	
	writingMesh.setMode(OF_PRIMITIVE_LINES);
    writingMesh.draw(); 
    
    ofPopStyle();
}
Esempio n. 5
0
void ofxDatGuiComponent::setLabel(string label)
{
    if (mLabel.forceUpperCase) label = ofToUpper(label);
    mLabel.text = label;
    mLabel.rect = mFont->rect(mLabel.text);
    positionLabel();
}
Esempio n. 6
0
void testApp::processOpenFileSelection(ofFileDialogResult openFileResult){
	
	ofFile file (openFileResult.getPath()); 
	
	if (file.exists()){
		image_loaded = false;
		loaded_image_name = file.getBaseName();
		string fileExtension = ofToUpper(file.getExtension());
		if (fileExtension == "JPG" || fileExtension == "PNG") {
			loadedImage.loadImage(openFileResult.getPath());
			num_leds = loadedImage.getWidth();
			if (num_leds <= MAX_LEDS){
				if (num_leds <= 32){
					led_spacing = 3;
					led_h = 30;
					led_w = 30;
				}
				if (num_leds > 32){
					led_spacing = 2;
					led_h = 16;
					led_w = 16;
				}
				if (num_leds > 64){
					led_spacing = 1;
					led_h = 11;
					led_w = 11;
				}
				num_frames = loadedImage.getHeight();
				current_frame = 0;
				image_loaded = true;
			}
		}
	}
	
}
void testApp::processOpenFileSelection(ofFileDialogResult openFileResult){
	
	ofLogVerbose("getName(): "  + openFileResult.getName());
	ofLogVerbose("getPath(): "  + openFileResult.getPath());
	
	ofFile file (openFileResult.getPath());
	
	if (file.exists()){

		string fileExtension = ofToUpper(file.getExtension());
		
		if (fileExtension == "XML") {
		
        canvasLocation.set(0, 500);
        if( XML.loadFile(openFileResult.fileName) ){
            enemies.clear();
            collectables.clear();
            for (int i = 0; i < XML.getNumTags("enemy"); i++) {
                ofPoint tmpPoint;
                tmpPoint.set(XML.getValue("enemy:x", 0, i), XML.getValue("enemy:y", 0, i), XML.getValue("enemy:size", 0, i));
                enemies.push_back(tmpPoint);
            }
        }
        }
        
		
	}
	
}
Esempio n. 8
0
//--------------------------------------------------------------
void testApp::processOpenFileSelection(ofFileDialogResult openFileResult){
    
    ofLogVerbose("getName(): "  + openFileResult.getName());
    ofLogVerbose("getPath(): "  + openFileResult.getPath());
    
    ofFile file (openFileResult.getPath());
    
    if (file.exists())
    {
        ofLogVerbose("The file exists - now checking the type via file extension");
        string fileExtension = ofToUpper(file.getExtension());
        
        //We only want images
        if (fileExtension == "JPG" || fileExtension == "PNG")
        {
            //Save the file extension to use when we save out
            originalFileExtension = fileExtension;
            
            //Load the selected image
            image.loadImage(openFileResult.getPath());
            /*if (image.getWidth()>ofGetWidth() || image.getHeight() > ofGetHeight())
             {
             image.resize(image.getWidth()/2, image.getHeight()/2);
             }*/
        }
    }
    
}
Esempio n. 9
0
void patch::guiEvent(ofxUIEventArgs &e)
{
//	int kind = e.widget->getKind();
    string name = e.widget->getName();
    
    if (name == "Image src btn" && ((ofxUIButton*)e.widget)->getValue()) {
        
        ofFileDialogResult openFileResult = ofSystemLoadDialog("Select an image (.jpg, .jpeg, .png or .bmp)");
        
        if (openFileResult.bSuccess){
            
            ofFile file (openFileResult.getPath());
            
            if (file.exists()){
                
                string fileExtension = ofToUpper(file.getExtension());
                
                //We only want images
                if (fileExtension == "JPG"  ||
                    fileExtension == "PNG"  ||
                    fileExtension == "JPEG" ||
                    fileExtension == "GIF"  ||
                    fileExtension == "BMP"  ) {
                    imageSrc = openFileResult.getPath();
                    ((ofxUITextInput*)inspector->getWidget("Image src"))->setTextString(imageSrc);
                }
                else return;
            }
            file.close();
        }
    }
}
Esempio n. 10
0
string ofApp::getHex(int hex)
{
// convert decimal value to hex //
    std::stringstream ss;
    ss<< std::hex << hex;
    std::string res ( ss.str() );
    while(res.size() < 6) res+="0";
    return "#"+ofToUpper(res);
}
Esempio n. 11
0
void ofApp::setAssets(int _currentIndex) {

    // Cast to String
    string file = artistMedia[_currentIndex];
    ofLogNotice("File Path Is " + file);

    // Copy & Trim String
    string temp = file;
    temp.erase(temp.begin(), temp.end() - 3);

    // Convert Copy To Uppercase
    string fileExtension = ofToUpper(temp);
    ofLogNotice("Object Is A " + fileExtension + " File ");

    // Video
    if (fileExtension == "MP4" || fileExtension == "MOV") {
        ofLogNotice("FILE IS A MOVIE");
        currentAssetIsMovie = true;

        // Clear Movie ?
        if(video.isLoaded() == true) {
            ofLog(OF_LOG_NOTICE, "Clearing Video Pixels...");
            video.closeMovie();
        }
        else {
            ofLog(OF_LOG_NOTICE, "Video Pixels Already Empty...");
        }

        // Load Movie
        video.loadMovie(artistMedia[_currentIndex]);
        video.firstFrame();
		video.setFrame(video.getTotalNumFrames() - 100);
		video.update();
        video.setPaused(true);
    }
    // Image
    else if (fileExtension == "JPG" || fileExtension == "PNG") {
        ofLogNotice("FILE IS AN IMAGE");
        currentAssetIsMovie = false;

        // Clear Image ?
        if(image.bAllocated() == true) {
            ofLog(OF_LOG_NOTICE, "Clearing Image Pixels...");
            image.clear();
        }
        else {
            ofLog(OF_LOG_NOTICE, "Image Pixels Already Empty...");
        }
        
        // Load Image
        image.loadImage(artistMedia[_currentIndex]);
    }

    // Console Padding
    cout << "" << endl;

}
Esempio n. 12
0
bool BaseGame :: draw() {
	if(laserManager==NULL) return false;
	
	LaserManager& lm = *laserManager;
	
	
	showHitAnimations();
	
	if(state == STATE_WAITING) {
		
		lm.addLaserText(ofToUpper(name), centre * ofVec2f(1,0.6), 10,cyan, true);
		
	}

	ofVec2f textpos = centre * ofVec2f(1,0.6);
	//textpos.y -= 50;

	if(state == STATE_COUNTDOWN) {
		
		int time = 1+(3-timeSinceStateChange);
		lm.addLaserText(ofToString(time), textpos, 10,white, true);
		
	}

	if(state == STATE_PLAYING) {
		if(timeSinceStateChange < 0.5) {
			//float progress = timeSinceStateChange/3;
			ofVec3f pos = textpos;
			
			//pos.z = 0;//progress * 5000;
			
			lm.addLaserText("GO", pos, 10,white, true);
			
		}
		lm.addLaserText(ofToString(shotsRemaining), centre * ofVec2f(0.5,0.5), 6,red, true);
		
	}
	
	
	if(state == STATE_GAMEOVER) {
		
		if(timeSinceStateChange > 5) {
			
			changeState(STATE_WAITING);
			
		} else {
			
			lm.addLaserText("GAME OVER", centre * ofVec2f(1,0.6), 10,cyan, true);
			lm.addLaserText("SCORE : " + ofToString(score), centre * ofVec2f(1,1), 10,red, true);
			
		}
		
		
	}
	return true; 
}
void CloudsVisualSystemFlocking::setupFboViewerGui(string name, ofFbo *fbo)
{
    ofxUISuperCanvas *fboGui = new ofxUISuperCanvas(ofToUpper(name), gui);
    fboGui->copyCanvasStyle(gui);
    fboGui->copyCanvasProperties(gui);
    fboGui->setName(name+"Settings");
    fboGui->setWidgetFontSize(OFX_UI_FONT_SMALL);
    fboGui->addSpacer();
    fboGui->addBaseDraws(name, fbo);
    fboGui->autoSizeToFitWidgets();
    addGui(fboGui);
}
Esempio n. 14
0
void ofApp::conversionTests()
{
    assert(ofx::TextConverter::toUTF8(0x30A1) == "\u30A1"); // just checking ...
    
    // do some case conversions
    std::string utf8_1_toLower = ofx::UTF8::toLower(testStrings[1]);
    std::cout << "From: " << testStrings[1] << std::endl;
    std::cout << "  To: " << utf8_1_toLower << std::endl;
    
    std::string utf8_6_toUpper = ofx::UTF8::toUpper(encoderStrings[0]);
    std::cout << "From: " << encoderStrings[0] << std::endl;
    std::cout << "  To: " << utf8_6_toUpper << std::endl;
    
    std::string utf8_8_toUpper = ofx::UTF8::toUpper(encoderStrings[1]);
    std::cout << "From: " << encoderStrings[1] << std::endl;
    std::cout << "  To: " << utf8_8_toUpper << std::endl;

    std::cout << "------------- of native -----------" << std::endl;
    {
    // do some case conversions
    std::string utf8_1_toLower = ofToLower(testStrings[1]);
    std::cout << "From: " << testStrings[1] << std::endl;
    std::cout << "  To: " << utf8_1_toLower << std::endl;

    std::string utf8_6_toUpper = ofToUpper(encoderStrings[0]);
    std::cout << "From: " << encoderStrings[0] << std::endl;
    std::cout << "  To: " << utf8_6_toUpper << " (incorrect w/o correct locale)" << std::endl;

    std::string utf8_6_toUpper_hu = ofToUpper(encoderStrings[0], "hu_HU");
    std::cout << "From: " << encoderStrings[0] << std::endl;
    std::cout << "  To: " << utf8_6_toUpper_hu << " (correct w/ hu_HU locale)" << std::endl;

    std::string utf8_8_toUpper = ofToUpper(encoderStrings[1]);
    std::cout << "From: " << encoderStrings[1] << std::endl;
    std::cout << "  To: " << utf8_8_toUpper << std::endl;
    }

}
Esempio n. 15
0
ofx2DPro::ofx2DPro():
bPlaying(false),
doublClickThreshold(0.2),
currentPresetName("Working"),
bDebug(false),
bRenderSystem(true),
bUpdateSystem(true)
{
    guiTemplate = new ofxUISuperCanvas(ofToUpper(getSystemName()));
    guiTemplate->setName("TEMPLATE");
    guiTemplate->setWidgetFontSize(OFX_UI_FONT_SMALL);
    
    setupNumViewports(1);
};
Esempio n. 16
0
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
	
	//Create a comparable string from an int
	string myKey;
	myKey = (char) key;
	myKey = ofToUpper(myKey);
	
	for (unsigned int i=0; i<morseCodeSymbols.size(); i++) {
		if (morseCodeSymbols[i].character == myKey){
			currentSymbol = morseCodeSymbols[i];
			player.playCode(currentSymbol.code);
		}
		
	}
}
Esempio n. 17
0
//--------------------------------------------------------------
void testApp::setup(){

	this->width = 1280;
	this->height = 720;

	ofDirectory dir;
	dir.listDir(".");
	for(auto file : dir.getFiles()) {
		if (ofToUpper(file.getExtension()) == "PNG") {
			ofPixels pixels;
			ofLoadImage(pixels, file.getFileName());
			images.push_back(pixels);
		}
	}

	A = this->images[0];
	B = this->images[1];

	A.update();
	B.update();

	this->interpolation = ofPtr<Interpolation::OpticalFlow>(new Interpolation::GPUOpticalFlow(this->width, this->height));
	this->interpolation->UpdateFlow(A, B);

	this->gui.init();
	this->gui.add(A, "A");
	this->gui.add(B, "B");
	this->gui.add(interpolation->getAtoB(), "A to B");
	this->gui.add(interpolation->getBtoA(), "B to A");
	this->outputPanel = this->gui.add(interpolation->getResultFbo(), "Output");

	this->outputPanel->onKeyboard += [this] (KeyboardArguments & args) {
		if (args.key == ' ') {
			this->interpolation->reload();
		}
		if (args.key == 'o') {
			Profiler.clear();
			this->interpolation->UpdateFlow(A, B);
			this->interpolation->UpdateResult(x, this->A.getTextureReference(), this->B.getTextureReference());
			cout << Profiler.getResultsString();
		}
	};

	this->outputPanel->onMouse += [this] (MouseArguments & args) {
		this->x = args.localNormalised.x;
		this->interpolation->UpdateResult(x, this->A.getTextureReference(), this->B.getTextureReference());
	};
}
Esempio n. 18
0
ofxUICanvas* ofxUIPageManager::createPage(string name) {
    // setup gui page with common stuff
    gui = new ofxUIScrollableCanvas(0, 0, pageWidth, ofGetHeight());
    gui->setName(name);
    gui->setWidgetSpacing(spacer);
    ((ofxUIScrollableCanvas*)gui)->setScrollAreaToScreenHeight();
    gui->setDrawBack(true);
    gui->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);
    gui->addWidgetDown(new ofxUILabel("page", "--/--", OFX_UI_FONT_SMALL));
    gui->addWidgetRight(new ofxUILabel("title", ofToUpper(name), OFX_UI_FONT_LARGE));
    gui->addWidgetDown(new ofxUIFPS(OFX_UI_FONT_SMALL));
    gui->addButton(UI_SAVE_LABEL, false);
    gui->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
    gui->addSpacer(0, spacer);
    gui->addButton("<", false);
    gui->addButton(">", false);
    gui->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);
    gui->addSpacer(pageWidth, 2);
    gui->addSpacer(0, spacer);
    return gui;
}
Esempio n. 19
0
//--------------------------------------------------------------------------------------------------------------
void phdVisualFile::loadFromFile(string _fileName) {

	masterOutput.schema.shapes.setFocused(NULL);
	masterOutput.schema.shapes.setSelected(NULL, true);

	freeItems();

	ifstream _fin; //declare a file stream  
	_fin.open( ofToDataPath(_fileName).c_str() ); //open your text file  
     
	vector<string> _data; //declare a vector of strings to store data
	_data.clear();
      
	while(_fin != NULL) { //as long as theres still text to be read
		string _str = ""; //declare a string for storage  
		getline(_fin, _str); //get a line from the file, put it in the string
		if(_str != "") {
			_data.push_back(ofToUpper(_str)); //push the string onto a vector of strings  
			//printf(_str.c_str()); printf("\n");
		}
	}

	_fin.close();

	if(_data.size() == 0) return; // empty file

	phdDesigner * _designer = NULL;
	phdWarpShapeSchema * _shapeSchema = NULL;
	phdWarpLinkSchema * _linkSchema = NULL;
	phdShapeQuadWarp * _shape = NULL;

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

		vector<string> _items = ofSplitString(_data[i], ":", true, true);

		if(_items.size() > 0) {
			if(_items[0] == "DESIGNERCOUNT") {
					
				// resize designer array

			} else if(_items[0] == "MASTEROUTPUT" && _items.size() == 8) {
				
				_designer = &masterOutput;
				_designer->name = _items[1];

				float _x = ofToFloat(_items[2]);
				float _y = ofToFloat(_items[3]);
				float _w = ofToFloat(_items[4]);
				float _h = ofToFloat(_items[5]);

				_designer->setup(_x,_y,_w,_h, NULL, ofToFloat(_items[6]), ofToFloat(_items[7]));

			} else if(_items[0] == "DESIGNER" && _items.size() == 8) {
				
				_designer = NULL;
				_designer = (phdDesigner*) addDesigner(new phdDesignerFbo());
				_designer->name = ofToUpper(_items[1]);

				float _x = ofToFloat(_items[2]);
				float _y = ofToFloat(_items[3]);
				float _w = ofToFloat(_items[4]);
				float _h = ofToFloat(_items[5]);

				_designer->setup(_x,_y,_w,_h, NULL, ofToFloat(_items[6]), ofToFloat(_items[7]));

			} else if(_items[0] == "SHAPESCHEMA" && _items.size() == 3 && _designer != NULL) {
				
				_shapeSchema = &_designer->schema;
				_shapeSchema->name = _items[1];

			} else if(_items[0] == "SHAPE" && _items.size() == 3 && _designer != NULL) {//_shapeSchema != NULL) {

				_shape = _designer->schema.addShape(_items[1]);
				//_shape = _shapeSchema->addShape(_items[1]);
				_shape->faceType = (phdWarpFaceType) ofToInt(_items[2]);

			} else if(_items[0] == "GIMBAL" && _items.size() == 8 && _shape != NULL) {

				_shape->gimbal.angle = ofToFloat(_items[1]);
				_shape->gimbal.cx = ofToFloat(_items[2]);
				_shape->gimbal.cy = ofToFloat(_items[3]);
				_shape->gimbal.sx = ofToFloat(_items[4]);
				_shape->gimbal.sy = ofToFloat(_items[5]);
				_shape->gimbal.w = ofToFloat(_items[6]);
				_shape->gimbal.h = ofToFloat(_items[7]);

			} else if(_items[0] == "VERTEXCOUNT" && _items.size() > 3 && _shape != NULL) {

				_shape->vertices.vertices.reserve(ofToInt(_items[1]));
				
				for(int k = 2; k < _items.size()-1; k += 2) {
					_shape->addVertex(ofToFloat(_items[k]), ofToFloat(_items[k+1]));
				}

			} else if(_items[0] == "LINKSCHEMACOUNT") {

			} else if(_items[0] == "LINKSCHEMA" && _items.size() == 3) {

				_linkSchema = addLinkSchema(new phdWarpLinkSchema());
				_linkSchema->name = _items[1];

			} else if(_items[0] == "LINK" && _items.size() == 7 && _linkSchema != NULL) {

				phdDesigner * _dgnIN  = findDesignerByName(_items[1]);
				phdDesigner * _dgnOUT = findDesignerByName(_items[3]);
				if(_dgnOUT == NULL) _dgnOUT = &masterOutput;

				if(_dgnIN != NULL && _dgnOUT != NULL) {

					phdShapeQuadWarp * _quadIN  = _dgnIN->schema.findByShapeName(_items[2]);
					phdShapeQuadWarp * _quadOUT = _dgnOUT->schema.findByShapeName(_items[4]);

					phdWarpLink * _link = _linkSchema->addLink(_quadIN, _dgnIN, _quadOUT, _dgnOUT);
					_link->horMirror = (_items[5] == "SIM");
					_link->verMirror = (_items[6] == "SIM");
					_link->updated = true;
				}
			}
		}
	}

	if(_linkSchema != NULL) {
		curLinkSchema = _linkSchema;
	} else {
		curLinkSchema = addLinkSchema(new phdWarpLinkSchema());
		curLinkSchema->name = "LINKS";
	}
}
Esempio n. 20
0
void phdVisualFile::saveToFile(string _fileName) {

	ofstream fout; // declare a file stream
	fout.open( ofToDataPath(_fileName).c_str() ); // open your text file

	string _line = "";
	vector<string> _strings;

	_strings.clear(); masterOutput.saveToStrings(_strings, "MASTEROUTPUT");
	for(int s = 0; s < _strings.size(); s++) fout.write(ofToUpper(_strings[s]).c_str(), _strings[s].size());

	_line = "DESIGNERCOUNT:" + ofToString(designers.size()) + ":\n";
	fout.write(ofToUpper(_line).c_str(), _line.size());

	for(int i = 0; i < designers.size(); i++) {
		_strings.clear(); designers[i]->saveToStrings(_strings, "DESIGNER");
		for(int s = 0; s < _strings.size(); s++) fout.write(ofToUpper(_strings[s]).c_str(), _strings[s].size());
	}

	_line = "LINKSCHEMACOUNT:" + ofToString(linkSchemas.size()) + ":\n";
	fout.write(ofToUpper(_line).c_str(), _line.size());

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

		_line = "LINKSCHEMA:" + linkSchemas[i]->name + ":" + ofToString(linkSchemas[i]->links.size()) + ":\n";
		fout.write(ofToUpper(_line).c_str(), _line.size());
			
		for(int j = 0; j < linkSchemas[i]->links.size(); j++) {

			phdDesigner * _dgnIN = NULL;
			if(linkSchemas[i]->links[j]->quadIn != NULL) _dgnIN = findDesignerByQuadWarp(linkSchemas[i]->links[j]->quadIn);

			if(_dgnIN != NULL) {

				phdDesigner * _dgnOUT = &masterOutput;
				if(linkSchemas[i]->links[j]->quadOut != NULL && _dgnOUT->schema.indexOf(linkSchemas[i]->links[j]->quadOut) == -1) {
					_dgnOUT = findDesignerByQuadWarp(linkSchemas[i]->links[j]->quadOut);
				}

				if(_dgnOUT != NULL) {
					_line = "LINK:";
					if(linkSchemas[i]->links[j]->quadIn != NULL) {
						_line += _dgnIN->name + ":";
						_line += linkSchemas[i]->links[j]->quadIn->name + ":";
					} else {
						_line += "::";
					}
					if(linkSchemas[i]->links[j]->quadOut != NULL) {
						_line += _dgnOUT->name + ":";
						_line += linkSchemas[i]->links[j]->quadOut->name + ":";
					} else {
						_line += "::";
					}
					_line += linkSchemas[i]->links[j]->horMirror ? "SIM:" : "NAO:";
					_line += linkSchemas[i]->links[j]->verMirror ? "SIM:" : "NAO:";

					_line += "\n";
					fout.write(ofToUpper(_line).c_str(), _line.size());
				}
			}
		}
	}

	fout.close(); // close file stream
}
Esempio n. 21
0
void TextWriter::draw(ofRectangle box, string text, bool centred) {
    text = ofToUpper(text);
    
	// added these lines otherwise you get horribleness! 
	if(box.height<=0) box.height = 1;
	if(box.width<=0) box.width = 1;
	
	
    ofPushStyle();

    ofEnableAlphaBlending();
    ofEnableBlendMode(OF_BLENDMODE_ADD);
    ofSetLineWidth(glyphLineWeight);
    
    ofPushStyle();
    ofSetColor(10, 10, 255, 128);
    ofNoFill();
	
    ofPopStyle();
    
    float boxRatio = box.height / (float)box.width;
    int textLength = text.length();
    string longestLine = "";
    vector<string> lines;
    
    int numRows = (int)sqrt(boxRatio * textLength / glyphRatio);
    if( (text.find(' ') == string::npos) || (numRows == 0) ) {
        longestLine = trim(text);
        lines.push_back(longestLine);
    } else {
        int numCols = textLength / numRows;
        int start = numCols;
        int index = 0;
        int last;
        
        for( int row = 0; row < numRows - 1; row++ ) {
            last = index;
            index = findBestBreak(text, start, numCols * 2);
            
            string linePart = trim(text.substr(last, index - last));
            
            if( linePart.length() > longestLine.length() ) {
                longestLine = linePart;
            }
            
            lines.push_back(linePart);
            
            start = index + numCols;
        }
        
          string linePart = trim(text.substr(index));
        lines.push_back(linePart);
        if( linePart.length() > longestLine.length() ) {
            longestLine = linePart;
        }
        
          }
    
    float glyphScaleFactor = (box.width / (float)longestLine.length()) / (float)(glyphWidth + glyphSpacing);
    float glyphRenderWidth = glyphWidth * glyphScaleFactor;
    float glyphRenderHeight = glyphHeight * glyphScaleFactor;
    float glyphRenderSpacing = glyphSpacing * glyphScaleFactor;
    
    float marginTop = ((box.height - ((glyphRenderHeight + glyphRenderSpacing) * lines.size())) / 2.0);
    float marginLeft = 0; //(int)((box.width - calculateBlockWidth(longestLine, glyphRenderWidth, glyphRenderSpacing)) / 2.0); 
    
    map <int, Letter>& letters = font.letters;
    
	ofMesh writingMesh; 
	
    float ofsX = marginLeft, ofsY = marginTop;
    for( int j = 0; j < lines.size(); j++ ) {
        string line = lines[j];
        float glyphMarginLeft = centred ? ((box.width - calculateBlockWidth(line, glyphRenderWidth, glyphRenderSpacing)) / 2.0) : 0;
        for( int i = 0; i < line.length(); i++ ) {
			addGlyphToMesh(letters[line[i]], ofRectangle(box.x + ofsX + glyphMarginLeft, box.y + ofsY, glyphRenderWidth, glyphRenderHeight), writingMesh);
            ofsX += glyphRenderWidth + glyphRenderSpacing;
        }
        ofsX = marginLeft;
        ofsY += glyphRenderHeight + glyphRenderSpacing;
    }
	
	writingMesh.setMode(OF_PRIMITIVE_LINES);
    writingMesh.draw();
    writingMesh.setMode(OF_PRIMITIVE_POINTS);
	writingMesh.draw();
    

	
    ofPopStyle();
	
	return writingMesh; 
}
Esempio n. 22
0
void ofxControlWidget::setLabel(const string &label_) 
{
	label = ofToUpper(label_);
	displayLabel.clear();
	for (int i = 0; i < label.size(); i++) { displayLabel += toupper(label[i]); }
}
//--------------------------------------------------------------
void testApp::guiEvent(ofxUIEventArgs &e)
{
	string name = e.widget->getName();
	int kind = e.widget->getKind();
    if(kind == OFX_UI_WIDGET_TOGGLE)
    {
        ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
        if (name == "ENEMIES") {
            creatingEnemies = true;
        }
        if (name == "COLLECTABLES") {
            creatingEnemies = false;
        }
    }
    if (name == "Included Patterns") {
        if (patternList->isOpen() == true) {
            cout << "Show Remove Button" << endl;
            removeButton->setVisible(true);
            removeButton->setLabelText("REMOVE");
        }
        else {
            cout << "Hide Remove Button" << endl;
            removeButton->setVisible(false);
        }
    }

    if (name == "Starting") {
        ofxUISlider *speedSlider = (ofxUISlider *) e.getSlider();
        speed = speedSlider->getScaledValue();
        currentSpeed = speed;
    }
    
    if (name == "Multiplier") {
        ofxUISlider *multiSlider = (ofxUISlider *) e.getSlider();
        multiplier = multiSlider->getScaledValue();

    }

    
    if(name == "SIZE")
	{
		ofxUISlider *slider = (ofxUISlider *) e.getSlider();
        pointSize = slider->getScaledValue();
	}
    
    if(name == "clear pattern") {
        buttonCount++;
        if(buttonCount ==2) {
            enemies.clear();
            collectables.clear();
            XML.clear();
        }
    }

    if (name == "save pattern") {
        buttonCount++;
        if (buttonCount == 2) {
            savePattern();
            buttonCount = 0;
        }
    }
    if (name == "add to level") {
        buttonCount++;
        if (buttonCount == 2) {
            patterns.push_back(patternInput->getTextString() + ".xml");
            patternList->addToggle(patternInput->getTextString());
            savePattern();
            buttonCount = 0;
        }
    }
    if (name == "REMOVE PATTERN") {
        buttonCount++;
        if (buttonCount ==2) {
            vector<ofxUIWidget *> &selected = patternList->getSelected();
            for(int i = 0; i < selected.size(); i++)
            {
                cout << "SELECTED: " << selected[i]->getName() << endl;
                patterns.erase(patterns.begin() + i);
                patternList->removeToggle(selected[i]->getName());
            }
            buttonCount = 0;
        }
    }
        
    if (name == "SAVE LEVEL") {
        buttonCount++;
        if (buttonCount == 2) {
            ofxXmlSettings levelXML;

            levelXML.setValue("name", levelInput->getTextString());
            levelXML.setValue("author", authorInput->getTextString());
            levelXML.setValue("complete", completeInput->getTextString());
            levelXML.setValue("speed", speedSlider->getValue());
            levelXML.setValue("multiplier", multiSlider->getValue());
            
            for (int i = 0; i < patterns.size(); i++) {
                levelXML.setValue("file", patterns[i], i);

            }
            
            
            levelXML.saveFile("new.level");
            levelXML.clear();
            buttonCount = 0;
        }
    }
    if(name == "OPEN EXISTING PATTERN") {
        buttonCount++;
        if (buttonCount == 2) {
		ofFileDialogResult openFileResult= ofSystemLoadDialog("Select a pattern to open");
        
		//Check if the user opened a file
		if (openFileResult.bSuccess){

            cout <<             openFileResult.getName() << endl;
			ofLogVerbose("User selected a file");
			
			//We have a file, check it and process it
            ofFile file (openFileResult.getPath());
            
            if (file.exists()){
                
                string fileExtension = ofToUpper(file.getExtension());
                
                if (fileExtension == "XML") {
                    cout << "it's XML" << " " << file.getAbsolutePath() << endl;
                    patternInput->setTextString(file.getBaseName());
                    canvasLocation.set(0, 500);
                    if( XML.loadFile(file.getAbsolutePath()) ){
                        enemies.clear();
                        collectables.clear();
                        for (int i = 0; i < XML.getNumTags("enemy"); i++) {
                            ofPoint tmpPoint;
                            tmpPoint.set(XML.getValue("enemy:x", 0, i), XML.getValue("enemy:y", 0, i), XML.getValue("enemy:size", 0, i));
                            enemies.push_back(tmpPoint);
                        }
                        for (int i = 0; i < XML.getNumTags("collectables"); i++) {
                            ofPoint tmpPoint;
                            tmpPoint.set(XML.getValue("collectable:x", 0, i), XML.getValue("collectable:y", 0, i), XML.getValue("collectable:size", 0, i));
                            collectables.push_back(tmpPoint);
                        }
                        
                    }
                    else {
                        cout << "can't load file" << endl;
                    }
                }
                else {
                    cout << "it's not XML" << endl;

                }
                
                
            }
		
			
		}
            buttonCount = 0;
        }
        
    }
    
}
Esempio n. 24
0
//------------------------------------------------------------------
void textInput::guiEvent(ofxUIEventArgs &event_){
    
    if(event_.widget == this->dropdownList && this->dropdownList->getSelected().size()) {
        
        string selectedName = this->dropdownList->getSelected()[0]->getName();
        
        if (selectedName == "INPUTS" || selectedName == "LAYERS" || selectedName == "MIXERS" || selectedName == "OUTPUTS"){
            return;
        }
        
        this->dropdownList->setVisible(false);
        this->setTextString(selectedName);
        
        textInputEvent e;
        e.point.set(this->getRect()->getX(), this->getRect()->getY());
        e.widget = this;
        e.type = this->dropdownList->getSelected()[0]->getName();
        
        ofFileDialogResult openFileResult;
        
        if (e.type == "midi device") {
            
            vector<string>& midiPortList = midiIn->getPortList();
            if (midiPortList.size() == 0) {
                midiPortList.push_back("No devices available");
            }
            
            if(midiList == NULL) {
                midiList = new ofxUIDropDownList("", midiPortList, 250, this->getRect()->x, this->getRect()->y);
                this->getCanvasParent()->addWidget(midiList);
                midiList->open();
                midiList->setAutoClose(true);
                this->addEmbeddedWidget(midiList);
                
                ofAddListener(((ofxUISuperCanvas*) midiList->getCanvasParent())->newGUIEvent,this,&textInput::guiMidiEvent);
            }
            else {
                midiList->clearToggles();
                midiList->addToggles(midiPortList);
            }
            midiList->setVisible(true);
            for(auto n : midiList->getToggles()) {
                n->setColorBack(ofxUIColor (70,70,70,250));
                n->setColorOutline(ofxUIColor (50,50,50,250));
                n->setColorFillHighlight(ofxUIColor (30,30,30,250));
                n->setDrawOutline(true);
            }
            
        }
        else if ((e.type == "image or video")){

            openFileResult = ofSystemLoadDialog("Select an image (.jpg, .jpeg, .png, .bmp or .gif) or video (.mov, .mpg, .mp4 or .m4v)");

            if (openFileResult.bSuccess){

                ofFile file (openFileResult.getPath());

                if (file.exists()){

                    string fileExtension = ofToUpper(file.getExtension());

                    //We only want images
                    if (fileExtension == "JPG"  ||
                        fileExtension == "PNG"  ||
                        fileExtension == "JPEG" ||
                        fileExtension == "GIF"  ||
                        fileExtension == "BMP"  ||
                        fileExtension == "MOV"  ||
                        fileExtension == "MPG"  ||
                        fileExtension == "MP4"  ||
                        fileExtension == "M4V" ) {
                        e.path = openFileResult.getPath();
                        e.name = file.getFileName();
                    }
                    else {
                        ConsoleLog::getInstance()->pushError("Select a valid image or video file (.jpg, .jpeg, .gif, .bmp, .mov, .mpg, .mp4 or .m4v)");
                        return;
                    }
                }
                file.close();
                ofNotifyEvent(createNode, e , this);
            }
            else {
                dropdownList->clearSelected();
                return;
            }
        }
        else if(e.type == "shader"){
            openFileResult = ofSystemLoadDialog("Select a shader (.fs)");
            
            if (openFileResult.bSuccess){
                
                ofFile file (openFileResult.getPath());
                
                if (file.exists()){
                    
                    string fileExtension = ofToUpper(file.getExtension());
                    
                    //We only want shaders
                    if (fileExtension == "fs" || fileExtension == "FS") {
                        e.path = openFileResult.getPath();
                        e.name = file.getFileName();
                    }
                    else {
                        ConsoleLog::getInstance()->pushError("Select a valid shader file (.fs)");
                        return;
                    }
                }
                file.close();
                ofNotifyEvent(createNode, e , this);
            }
            else {
                dropdownList->clearSelected();
                return;
            }
        }
        else {
            ofNotifyEvent(createNode, e , this);
        }
    }
}
Esempio n. 25
0
void CloudsIntroSequence::drawHelperType(){

	ofPushStyle();
	glDisable(GL_DEPTH_TEST);
	ofDisableLighting();
    
	if(!helperFont.isLoaded() || currentHelperFontSize != helperFontSize){
		//helperFont.loadFont(GetCloudsDataPath() + "font/Blender-BOOK.ttf", helperFontSize);
#ifdef OCULUS_RIFT
		helperFont.loadFont(GetFontPath(), helperFontSize-2	); //hack!
#else
		helperFont.loadFont(GetFontPath(), helperFontSize	); //hack!
#endif		
		currentHelperFontSize = helperFontSize;
	}

	string helpHoverText;
	ofVec3f basePosition(0,0,0);
	float helperTextOpacity = 0.0;
	float scaleModifier = 1.0;// * ofGetMouseX() / ofGetWidth();

	
	#ifdef OCULUS_RIFT
	if(!startedOnclick){
		if(introNodeThree.hover || introNodeTwo.finished){
			helpHoverText = "< " + GetTranslationForString("LOOK CENTER");
			basePosition = introNodeTwo.worldPosition;
			helperTextOpacity = powf(ofMap(ofGetElapsedTimef(),
										   CalibrationNode::nodeActivatedTime,
										   CalibrationNode::nodeActivatedTime+.8,0.0,.8,true), 2.) * (1.0 - introNodeThree.percentComplete);
		}
		else if(introNodeTwo.hover || introNodeOne.finished){
			helpHoverText = GetTranslationForString("LOOK RIGHT") + " >";
			basePosition = introNodeOne.worldPosition;
			helperTextOpacity = powf(ofMap(ofGetElapsedTimef(),
										   CalibrationNode::nodeActivatedTime,
										   CalibrationNode::nodeActivatedTime+.8,0.0,.8,true), 2.);
		}
		else {
			helpHoverText = "< " + GetTranslationForString("LOOK LEFT");
			basePosition = introNodeThree.worldPosition;
			helperTextOpacity = (currentTitleOpacity - titleTypeOpacity) * (1.0 - introNodeOne.percentComplete);
		}
		helperFont.setLetterSpacing(helperFontTracking);
	}

	#endif
	
	if(caughtQuestion != NULL){
		basePosition = caughtQuestion->hoverPosition;
		helpHoverText = GetTranslationForString( caughtQuestion->question );
		helperTextOpacity = ofMap(caughtQuestion->hoverPercentComplete, 0.0, .05, 0.0, 1.0, true);

		scaleModifier = .5;
		helperFont.setLetterSpacing(helperFontTracking*.1);
	}

    //draw the text
	if(helpHoverText != ""){
        ofPushMatrix();
		helpHoverText = ofToUpper(helpHoverText);
		
		float hoverTextWidth = helperFont.stringWidth(helpHoverText);
		float hoverTextWidth2,questionTextHeight2;
		string secondLine;
		bool twoLines = hoverTextWidth > 500;
		if(helpHoverText.find("\n") != string::npos){
			twoLines = true;
			vector<string> split = ofSplitString(helpHoverText, "\n", true,true);
			helpHoverText = split[0];
			secondLine = split[1];
			hoverTextWidth = helperFont.stringWidth(helpHoverText);
			hoverTextWidth2 = helperFont.stringWidth(secondLine);
            
//            cout << "QUESTION " << helpHoverText << " " << secondLine << endl;
		}
		else if(twoLines){
			vector<string> pieces = ofSplitString(helpHoverText, " ", true,true);
			vector<string> firstHalf;
			vector<string> secondHalf;
			int halfsize = pieces.size() / 2;
			firstHalf.insert(firstHalf.begin(), pieces.begin(), pieces.begin() + halfsize);
			secondHalf.insert(secondHalf.begin(), pieces.begin() + halfsize, pieces.end());
			helpHoverText = ofJoinString(firstHalf, " ");
			secondLine = ofJoinString(secondHalf, " ");
			hoverTextWidth  = helperFont.stringWidth(helpHoverText);
			hoverTextWidth2 = helperFont.stringWidth(secondLine);
		}
		float hoverTextHeight = helperFont.stringHeight(helpHoverText);
		
        //basePosition = ofVec3f(0,0,warpCamera.getPosition().z + questionZStopRange.max);

		#ifdef OCULUS_RIFT
		getOculusRift().multBillboardMatrix( basePosition );
		#else
		ofTranslate(basePosition);
		#endif
		ofRotate(180, 0, 0, 1); //flip around
		ofScale(scaleModifier*helperFontScale,
				scaleModifier*helperFontScale,
				scaleModifier*helperFontScale);
		
		ofSetColor(255,255*helperTextOpacity);
		
        bool showAbove = !bUseOculusRift && caughtQuestion != NULL && caughtQuestion->tunnelQuadrantIndex == 2;
		int yOffsetMult = (showAbove) ? -1 : 1;
		//helperFont.drawString(helpHoverText, -hoverTextWidth/2, yOffsetMult * (helperFontY - hoverTextHeight/2) );
        
//        cout << "helper text opacity " << helperTextOpacity << endl;
//        cout << "helper font y " << helperFontY << endl;
		if(twoLines){
            if(showAbove){
//                cout << "drawing " << helpHoverText << " w " << hoverTextWidth << " h " <<  helperFontY + hoverTextHeight*1.5 << endl;
//                cout << "drawing " << secondLine << " w " << hoverTextWidth << " h " << hoverTextHeight << endl;
                helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY + hoverTextHeight*1.5) );
                helperFont.drawString(secondLine, -hoverTextWidth2*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5));
            }
            else{
//                cout << "drawing " << secondLine << " w " << hoverTextWidth << " h " <<  hoverTextHeight << endl;
//                cout << "drawing " << helpHoverText << " w " << hoverTextWidth << " h " << hoverTextHeight << endl;
                helperFont.drawString(secondLine, -hoverTextWidth2*.5, yOffsetMult * (helperFontY + hoverTextHeight*1.5) );
                helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5));
            }
		}
        else{
            helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5));
        }
		ofPopMatrix();
	}
    
    if(firstQuestionStopped){
        ofPushMatrix();
        
        float questionhintAlpha = ofMap(ofGetElapsedTimef(),
                                        firstQuestionStoppedTime, firstQuestionStoppedTime+2,
                                        0.0, .2, true) * (1.0-helperTextOpacity);
        
        float hintTextWidth  = helperFont.stringWidth(GetTranslationForString("SELECT A QUESTION"));
		float hintTextHeight = helperFont.stringHeight(GetTranslationForString("SELECT A QUESTION"));
		basePosition = ofVec3f(0,0,warpCamera.getPosition().z + questionZStopRange.max);
#ifdef OCULUS_RIFT
		getOculusRift().multBillboardMatrix( basePosition );
#else
		ofTranslate(basePosition);
#endif
		ofRotate(180, 0, 0, 1); //flip around
		ofScale(helperFontScale*.8,
				helperFontScale*.8,
				helperFontScale*.8);
        
        ofSetColor(255, 255*questionhintAlpha);
		helperFont.drawString(GetTranslationForString("SELECT A QUESTION"), -hintTextWidth*.5, hintTextHeight*.5 );

        if(caughtQuestion != NULL){
            float questionHoldAlpha = ofMap(caughtQuestion->hoverPercentComplete, .2, .3, 0.0, .2, true);
            ofSetColor(255, 255*questionHoldAlpha);
#ifdef MOUSE_INPUT
//			string textPrompt = GetTranslationForString("CLICK TO SELECT");
            string textPrompt = GetTranslationForString("");
#else
			string textPrompt = GetTranslationForString("HOLD TO SELECT");
#endif
            hintTextWidth = helperFont.stringWidth(textPrompt);
            hintTextHeight = helperFont.stringWidth(textPrompt);
            helperFont.drawString(textPrompt, -hintTextWidth*.5, hintTextHeight*.5 );
        }
        
        ofPopMatrix();
    }

    ofEnableLighting();
	glEnable(GL_DEPTH_TEST);
	ofPopStyle();

}
Esempio n. 26
0
void CloudsIntroSequence::updateQuestions(){

	for(int i = 0; i < startQuestions.size(); i++){
		CloudsPortal& curQuestion = startQuestions[i];
		curQuestion.scale = questionScale;
		curQuestion.update();
		
		if(curQuestion.hoverPosition.z < warpCamera.getPosition().z){
			curQuestion.hoverPosition.z += questionWrapDistance;
		}
		
		float slowDownFactor = 0.0;
		//hold the questions
		if(questionChannels[ curQuestion.tunnelQuadrantIndex ]){
			//let it go with time
			slowDownFactor = powf(ofMap(ofGetElapsedTimef(),
											  channelPauseTime[curQuestion.tunnelQuadrantIndex] + questionPauseDuration,
											  channelPauseTime[curQuestion.tunnelQuadrantIndex] + questionPauseDuration+2, 1.0, 0.0, true), 2.0);
			if(slowDownFactor == 0.0){
				questionChannels[ curQuestion.tunnelQuadrantIndex ] = false;
			}
			
		}
		else{
			float distanceFromCamera = (curQuestion.hoverPosition.z - warpCamera.getPosition().z);
			//if it's in front of the stop range
			if(distanceFromCamera > questionZStopRange.min){
				slowDownFactor = powf(ofMap(distanceFromCamera, questionZStopRange.min, questionZStopRange.max, 1.0, 0.0, true), 2.0);
//				curQuestion.hoverPosition.z += slowDownFactor * cameraForwardSpeed;
				if(slowDownFactor > .9){
					//pause this node and all the ones behind it
                    if(!firstQuestionStopped){
                        firstQuestionStoppedTime = ofGetElapsedTimef();
                        firstQuestionStopped = true;
                    }
					questionChannels[curQuestion.tunnelQuadrantIndex] = true;
					channelPauseTime[curQuestion.tunnelQuadrantIndex] = ofGetElapsedTimef();
				}
			}
		}
		
		if(&curQuestion == caughtQuestion){
			slowDownFactor = 1.0;
		}
		
		curQuestion.hoverPosition.z += cameraForwardSpeed * slowDownFactor;

		if(curQuestion.hoverPosition.z - warpCamera.getPosition().z < questionZStopRange.max || &curQuestion == caughtQuestion){
#ifdef OCULUS_RIFT
            ofVec3f screenPos = getOculusRift().worldToScreen(curQuestion.hoverPosition, true);
			ofRectangle viewport = getOculusRift().getOculusViewport();
            float distanceToQuestion = ofDist(screenPos.x, screenPos.y,viewport.getCenter().x, viewport.getCenter().y);
#else
            ofVec2f mouseNode = cursor;
			float distanceToQuestion = startQuestions[i].screenPosition.distance(mouseNode);
#endif
			if(selectedQuestion == NULL && caughtQuestion == NULL){
				if( distanceToQuestion < questionTugDistance.max ){
					if(distanceToQuestion < questionTugDistance.min){
						caughtQuestion = &curQuestion;
						if (caughtQuestion->startHovering()) {
							getClick()->setPosition(0);
							getClick()->play();
                        }
					}
				}
			}
			
			//we have a caught question make sure it's still close
			else if(caughtQuestion == &curQuestion){

				if( caughtQuestion->isSelected() && !bQuestionDebug && selectedQuestion == NULL){
					getSelectLow()->setPosition(0);
					getSelectLow()->play();

					selectedQuestion = caughtQuestion;
					selectedQuestionTime = ofGetElapsedTimef();
					selectQuestionStartPos = warpCamera.getPosition();
					selectQuestionStartRot = warpCamera.getOrientationQuat();

					CloudsPortalEventArgs args( GetTranslationForString( ofToUpper(selectedQuestion->question) ) );
					ofNotifyEvent(events.portalHoverBegan, args);
					
				}
				else if(distanceToQuestion > questionTugDistance.max && selectedQuestion == NULL){
					caughtQuestion->stopHovering();
					caughtQuestion = NULL;
                    if(firstQuestionStopped){
                        firstQuestionStoppedTime = ofGetElapsedTimef();
                    }
				}
			}
		}
	}
    
    if (caughtQuestion != NULL) {
        // move the sticky cursor towards the caught question
        stickyCursor.interpolate(caughtQuestion->screenPosition - ofVec2f(bleed,bleed)*.5, 0.2f);
    }
    else {
        stickyCursor.interpolate(cursor, 0.5f);
    }
}
Esempio n. 27
0
/************************************** 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();
            }
        }
    }
}
Esempio n. 28
0
	void run(){
		test_eq(ofTrimFront("    trim this string    "),"trim this string    ","trimfront");
		test_eq(ofTrimBack("    trim this string    "),"    trim this string","trimback");
		test_eq(ofTrim("    trim this string    "),"trim this string","trim");

		auto split0 = ofSplitString("hi this is a split test", " ");
		test_eq(split0.size(),6u,"split size");
		test_eq(split0[0],"hi","split 0");
		test_eq(split0[1],"this","split 1");
		test_eq(split0[2],"is","split 2");
		test_eq(split0[3],"a","split 3");
		test_eq(split0[4],"split","split 4");
		test_eq(split0[5],"test","split 5");


		auto split1 = ofSplitString(" hi this is a split test ", " ");
		test_eq(split1.size(),8u,"split no trim size");
		test_eq(split1[0],"","split no trim 0");
		test_eq(split1[1],"hi","split no trim 1");
		test_eq(split1[2],"this","split no trim 2");
		test_eq(split1[3],"is","split no trim 3");
		test_eq(split1[4],"a","split no trim 4");
		test_eq(split1[5],"split","split no trim 5");
		test_eq(split1[6],"test","split no trim 6");
		test_eq(split1[7],"","split no trim 7");

		auto split2 = ofSplitString(" hi this is a split test ", " ", true, true);
		test_eq(split2.size(),6u,"split trim size");
		test_eq(split2[0],"hi","split trim 0");
		test_eq(split2[1],"this","split trim 1");
		test_eq(split2[2],"is","split trim 2");
		test_eq(split2[3],"a","split trim 3");
		test_eq(split2[4],"split","split trim 4");
		test_eq(split2[5],"test","split trim 5");

		auto split3 = ofSplitString(" hi      this is a split test ", " ", true, true);
		test_eq(split2.size(),6u,"split trim2 size");
		test_eq(split2[0],"hi","split trim2 0");
		test_eq(split2[1],"this","split trim2 1");
		test_eq(split2[2],"is","split trim2 2");
		test_eq(split2[3],"a","split trim2 3");
		test_eq(split2[4],"split","split trim2 4");
		test_eq(split2[5],"test","split trim2 5");

		test_eq(ofJoinString({"hi","this","is","a","join","test"}," "),"hi this is a join test","join string");
		test_eq(ofJoinString({"hi"}," "),"hi","join string 1 element");
		test_eq(ofJoinString({}," "),"","join string 0 elements");

		std::string replace = "hi this is a replace test";
		ofStringReplace(replace,"replace","replaceeee");
		test_eq(replace , "hi this is a replaceeee test","replace string element");

        test_eq(ofToLower("AbCéÉBbCcc"),"abcéébbccc","tolower");
        test_eq(ofToUpper("AbCéÉBbCcc"),"ABCÉÉBBCCC","toupper");

		// test #4363
		std::vector<string> strs;
		strs.push_back("hi");
		strs.push_back("this");
		strs.push_back("is");
		strs.push_back("a");
		strs.push_back("join");
		strs.push_back("test");
		test_eq(ofJoinString(strs,","),"hi,this,is,a,join,test","test #4363");
	}
Esempio n. 29
0
void testApp::takePicture(){
	unsigned char * greyPixels =  bmp.getPixels();
	
	ofPixels pixels;
	pixels.allocate(bmp.getWidth(), bmp.getHeight(), 3);
	imageSmall.readToPixels(pixels);
	ofPixels channel = pixels.getChannel(0);
	
	for (int i = 0; i < channel.size(); i++) {
		greyPixels[i] = channel[i];
	}
	
	bmp.update();
	string timestamp = ofToString(ofGetUnixTime());
	
	
	string filename = timestamp + ".bmp";
	bmp.saveImage(filename);
	
	
	
	
	/*ofPixels pixelsBig;
	pixelsBig.allocate(image.getWidth(), image.getHeight(), 3);
	image.readToPixels(pixelsBig);
	ofPixels channelBig = pixelsBig.getChannel(0);
	uint8_t * printData = new uint8_t [(int) image.getWidth()* (int)image.getHeight()];
	uint8_t currByte;
	for (int i = 0; i < channelBig.size(); i++) {
		currByte <<= 1;
		currByte |= ((int)channelBig[i] > 100) ? 0 : 1;
		if(i%8 == 7){
			printData[i] = currByte;
		}
	}*/
	//printBitmap(image.getWidth(), image.getHeight(), printData);
	
	
	
	string script = ofFilePath::getEnclosingDirectory(ofFilePath::getCurrentExePath(), false) + "../Resources/Bits2DNA.pl";
	string command = "perl " + script + " \"" + ofToDataPath(filename) + "\" \"" + ofToDataPath(filename)+".dna" + "\"";
	system(command.c_str());
	
	ofBuffer buffer = ofBufferFromFile(filename + ".dna" );
	vector<int> data;
	while (!buffer.isLastLine()) {
		string line = ofToUpper(buffer.getNextLine());
		for (int i = 0; i < line.size(); i++) {
			char letter = line[i];
			switch (letter) {
				case 'A':
					data.push_back(0);
					break;
				case 'G':
					data.push_back(1);
					break;
				case 'T':
					data.push_back(2);
					break;
				case 'C':
					data.push_back(3);
					break;
			}
		}
	}
	printImage.allocate(384, 50 + 384 + (int) (data.size() / (384 / 4)) * 4);
	//printImage.allocate(100, 20 );
	printImage.begin();
	ofClear(255,255,255);
	ofSetColor(0, 0, 0, 255);
	ofDrawBitmapString("ART HACK DAY STOCKHOLM 2013", 0, 14);
	ofDrawBitmapString(timestamp + ".BMP.DNA", 0, 30);
	ofSetColor(255, 255, 255, 255);
	image.draw(20, 60, 344,344);
	//image.draw(0, 0, 344,344);
	
	int row = 0;
	int col = 0;
	int maxCols = 384/4;
	ofPushMatrix();
	ofTranslate(0, 50 + 384);
	
	for (int i = 0; i < data.size(); i++) {
		ofSetColor(255,255,255);
		bases[data[i]].draw(col*4, row*4, 4,4);
		col++;
		if(col >= maxCols){
			col = 0;
			row++;
		}
	}
	ofPopMatrix();
	
	printImage.end();
	
	
	ofImage printBmp;
	printBmp.allocate(printImage.getWidth(), printImage.getHeight(), OF_IMAGE_GRAYSCALE);
	unsigned char * printPixels =  printBmp.getPixels();
	ofPixels printFBOpixels;
	printFBOpixels.allocate(printImage.getWidth(), printImage.getHeight(), 3);
	printImage.readToPixels(printFBOpixels);
	ofPixels printChannel = printFBOpixels.getChannel(0);
	
	
	//uint8_t * printData = new uint8_t [(int) printImage.getWidth()* (int)printImage.getHeight()/8];
	//uint8_t currByte;
	
	for (int i = 0; i < printChannel.size(); i++) {
		printPixels[i] = ((int)printChannel[i] > 100) ? 255 : 0;
		
		//currByte <<= 1;
		//currByte |= ((int)channel[i] > 100) ? 0 : 1;
		//if(i%8 == 7){
			//printData[i] = currByte;
		//}
	}

	
	printBmp.update();
	int width = printImage.getWidth();
	int height = printImage.getHeight();
	//zzprintBitmap(width, height, printData);
	//delete printData;
	
	printBmp.saveImage(filename+".print.bmp");
}