#pragma once

#include "ofAddons.h"
#include "ofMain.h"

#include "ofAppEvents.h"
#include "ofKeyEvents.h"
#include "ofMouseEvents.h"
#include "ofAudioEvents.h"

static int sceneNo = 0;
class testApp;

class baseScene : public ofMouseListener, public ofKeyListener, public ofAppListener, public ofAudioListener{
		
	public:
		//----------------------------------
		baseScene(){
			audioListen		= false;
			appListen		= false;
			keyListen		= false;
			mouseListen		= false;
			autoRender		= true;
			pause			= false;
			hide			= false;
			debug			= false;
			camW			= 0;
			camH			= 0;
			screenW			= 0;
			screenH			= 0;
			sceneName		= "Untitled Scene "+ofToString(sceneNo);
			
			drawWidth		= 1024;
			drawHeight		= 768;
			sceneNo++;
		}
		
		//-------------------------------------
		void setSceneInfo(int _cameraW, int _cameraH, int _screenW, int _screenH){
				camW		= _cameraW;
				camH		= _cameraH;
				screenW		= _screenW;
				screenH		= _screenH;
				setupScene();
		}
		
		//-------------------------------------
		virtual void setupScene(){
			//put in any init stuff here!
			//like the events you want to add
			addAppListener();
			addKeyboardListener();
			setAutoRender(true);
			
			//also set the name of your scene!
			sceneName = "Yo fool! You shouldn't be seeing this!";
		}

		//this is where you draw
		//if auto draw is set then events call this function
		//otherwise you have to call it manually
		//--------------
		virtual void render(){
			if( hide || pause )return;
			
			ofSetColor(0x0022DD);
			//ofDrawBitmapString("scene:"+sceneName+" fps is:"+ofToString(ofGetFrameRate(), 2), 20, 30);
		}

		//--------------
		void drawTxtMsg(string msg, int x, int y){
			ofFill();
			ofSetColor(20, 20, 20);
			ofRect(x, y, msg.size() * 9, 20);
			ofSetColor(0x11FF55);
			ofDrawBitmapString(msg, x+5, y + 16);
		}
		
		//--------------
		void drawDebugTxt(int x, int y){
			drawTxtMsg(debugTxt, x, y);
		}		
		
		//--------------
		void setDebug(bool bDebug){
			debug = bDebug;
		}
		
		//--------------
		void setPause(bool bPause){
			pause = bPause;
		}
		
		//--------------
		void setHide(bool bHide){
			hide = bHide;
		}
		
		//--------------
		int camW;
		int camH;
		int screenW;
		int screenH;
		string sceneName;
		string debugTxt;
		
		bool debug;
		bool hide;
		bool pause;
	
		int drawWidth;
		int drawHeight;
	
		// I'm sorry this is ghetto
		testApp * theApp;
		
	private:
		void draw(){
			if( autoRender ){
				render();
			}
		}
		
	protected:
		virtual void update(){}
		virtual void exit(){}
		
		virtual void keyPressed( int key ){}
		virtual void keyReleased( int key ){}
		
		virtual void mouseMoved( int x, int y ){}
		virtual void mouseDragged( int x, int y, int button ){}
		virtual void mousePressed( int x, int y, int button ){}
		virtual void mouseReleased(int x, int y, int button ){}
	
		virtual void audioReceived( float * input, int bufferSize, int nChannels ){} 
		virtual void audioRequested( float * output, int bufferSize, int nChannels ){}	

		void setAutoRender(bool bAutoRender){
			 autoRender = bAutoRender;
		}

		void addAudioListener(){
			if( !audioListen )ofAudioEvents.addListener(this);
		}
		
		void removeAudioListener(){
			if( audioListen )ofAudioEvents.removeListener(this);
		}
	
		void addAppListener(){
			if( !appListen )ofAppEvents.addListener(this);
		}
		
		void removeAppListener(){
			if( appListen )ofAppEvents.removeListener(this);
		}

		void addMouseListener(){
			if( !mouseListen )ofMouseEvents.addListener(this);
		}
		
		void removeMouseListener(){
			if( mouseListen )ofMouseEvents.removeListener(this);
		}
		
		void addKeyboardListener(){
			if( !keyListen )ofKeyEvents.addListener(this);
		}
		
		void removeKeyboardListener(){
			if( keyListen)ofKeyEvents.removeListener(this);
		}
			
		void addAllEvents(){
			addAudioListener();	
			addAppListener();
			addMouseListener();
			addKeyboardListener();
		}			
		
		void removeAllEvents(){
			removeAudioListener();
			removeAppListener();
			removeMouseListener();
			removeKeyboardListener();
		}
		
		bool appListen;
		bool keyListen;
		bool mouseListen;
		bool audioListen;
		bool autoRender;
	
		
		
};