Beispiel #1
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);
             }*/
        }
    }
    
}
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);
            }
        }
        }
        
		
	}
	
}
Beispiel #3
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 oniActorApp::processOpenFileSelection(ofFileDialogResult openFileResult)
{
	ofLogVerbose("getName(): "  + openFileResult.getName());
	ofLogVerbose("getPath(): "  + openFileResult.getPath());
	ofFile file (openFileResult.getPath());
    if (file.exists())
    {
        setupPlayback(openFileResult.getPath());
        isLive = false;
    } else {
        ofLogVerbose("Problem with openFileResult: " + openFileResult.getName());
    }
}
Beispiel #5
0
void testApp::saveFileToSelection(ofFileDialogResult saveFileResult){
	
	// step 1 - build a string representation of the image data
	stringstream s;
	s
	<< TEMPLATE_HEADER << "\n"
	<< "// file: " << loaded_image_name << "\n"
	<< "// generated at " << ofGetTimestampString() << "\n\n"
	<< "#define N_FRAMES " << num_frames << "\n"
	<< "#define N_PIXELS " << num_leds << "\n\n";
	
	// eg const struct CRGB frame_0[1] = {{255,0,0}};
	for (int f=0; f<num_frames; f++){
		s << "const struct CRGB " << loaded_image_name << "_frame_" << f << "[" << num_leds << "] = {";
		for (int l=0; l<num_leds;l++){
			if (l != 0) s << ",";
			ofColor c = loadedImage.getColor(l,f);
			int r = c.r;
			int g = c.g;
			int b = c.b;
			s << "{" << r << "," << g << "," << b << "}";
		}
		s << "};\n";
	}
	
	// eg const struct CRGB* frames[1] = {frame_0}
	// s << "const struct CRGB*" << loaded_image_name << "_frames[" << num_frames << "] = {";
	s << "const struct CRGB* frames[" << num_frames << "] = {";
	for (int f=0; f<num_frames; f++){
		if (f != 0) s << ",";
		s << loaded_image_name << "_frame_" << f;
	}
	s << "};\n\n";
	
	s << "// end of generated image data\n";
	
	// step 2 - load a boilerplate arduino sketch
	ofBuffer buffer = ofBufferFromFile("arduino_template/arduino_template.ino");
	if(buffer.size()) {
		// step 3 - insert the image data into the arduino sketch
		string arduino_template = buffer.getText();
		ofStringReplace(arduino_template,TEMPLATE_PLACEHOLDER,s.str());
		buffer.set(arduino_template);
		// step 4 - save the file
		ofBufferToFile(saveFileResult.getPath(), buffer);
	}
}