#include "testApp.h"
#include "ScriptEngine.hxx"
#include <iostream>
//--------------------------------------------------------------
void testApp::setup(){	 
	counter = 0;
	vagRounded.loadFont("vag.ttf", 32);
	ofBackground(50,50,50);	
	
	scriptEngine::Start();
	scriptEngine::Load(ofToDataPath("myscript.py"));
	
	ofSetVerticalSync(true);
}


//--------------------------------------------------------------
void testApp::update(){
	if(ofGetFrameNum() % 120){
		scriptEngine::Load(ofToDataPath("myscript.py"));
	}	
	
	counter = counter + 0.033f;
}

//--------------------------------------------------------------
void testApp::draw(){
	
	sprintf (timeString, "time: %0.2i:%0.2i:%0.2i \n elapsed time %i", ofGetHours(), ofGetMinutes(), ofGetSeconds(), ofGetElapsedTimeMillis());
	
	float w = vagRounded.stringWidth(eventString);
	float h = vagRounded.stringHeight(eventString);
	
	ofSetColor(0xffffff);
	vagRounded.drawString(eventString, 98,198);
	
	ofSetColor(255,122,220);
	vagRounded.drawString(eventString, 100,200);
	
	
	ofSetColor(0xffffff);
	vagRounded.drawString(timeString, 98,98);
	
	ofSetColor(255,122,220);
	vagRounded.drawString(timeString, 100,100);
	
	ofSetColor(255,122,220);
	
	char infoFromScript[256];
	int a= scriptEngine::GetIntValue("numberA",0);
	sprintf (infoFromScript, "from myscript %d",a);
	vagRounded.drawString(infoFromScript, 100,250);

	float b= scriptEngine::GetFloatValue("numberB",0);
	sprintf (infoFromScript, "from myscript, %f",b);
	vagRounded.drawString(infoFromScript, 100,290);
	
	float c= scriptEngine::GetFloatValue("numberC",0);
	sprintf (infoFromScript, "from myscript, %f",c);
	vagRounded.drawString(infoFromScript, 100,340);
	
	vagRounded.drawString(scriptEngine::GetStrValue("textA",""), 100,380);
	
	scriptEngine::IntList array;
	scriptEngine::GetIntArray("intNumbersA",array);
	
	sprintf (infoFromScript, "from myscript, [%d,%d]",array[0],array[1]);
	vagRounded.drawString(infoFromScript, 100,420);

/*	int GetIntValue(const std::string& varName,int defaultValue=0);
	float GetFloatValue(const std::string& varName,float defaultValue=0.0f);
	std::string GetStrValue(const std::string& varName,const std::string& defaultValue="");
	int GetIntArray(const std::string& varName,IntList& list,bool clearArray=true);
	int GetFloatArray(const std::string& varName,FloatList& list,bool clearArray=true);
	int GetStrArray(const std::string& varName,StringList& list,bool clearArray=true);
*/
	vagRounded.drawString(timeString, 100,100);
}


//--------------------------------------------------------------
void testApp::keyPressed  (int key){ 
	sprintf(eventString, "keyPressed = (%i)", key);
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){ 
	
}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
	sprintf(eventString, "mouseMoved = (%i,%i)", x, y);
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
	sprintf(eventString, "mouseDragged = (%i,%i - button %i)", x, y, button);
}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
	sprintf(eventString, "mousePressed = (%i,%i - button %i)", x, y, button);

}

//--------------------------------------------------------------
void testApp::mouseReleased(){
	sprintf(eventString, "mouseReleased");

}

void testApp::exit()
{
	scriptEngine::End();
}
