/*
-------------------------------------------------------------------------
This source file is a part of OGRE
(Object-oriented Graphics Rendering Engine)

For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2006 Torus Knot Software Ltd
Also see acknowledgements in Readme.html

This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License (LGPL) as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA or go to
http://www.gnu.org/copyleft/lesser.txt
-------------------------------------------------------------------------
*/
#ifndef _TEXTUREUNITCONTROLLER_H_
#define _TEXTUREUNITCONTROLLER_H_

#include <list>

#include <boost/signal.hpp>

#include "OgreTexture.h"
#include "OgreTextureUnitState.h"

#include "EventArgs.h"
#include "EventContainer.h"

class PassController;

using namespace Ogre;

class TextureUnitController;

class TextureUnitEventArgs : public EventArgs
{
public:
	TextureUnitEventArgs(TextureUnitController* tuc) : mController(tuc) {}
	~TextureUnitEventArgs() {}

	TextureUnitController* getController() { return mController; }

protected:
	TextureUnitController* mController;
};

class TextureUnitController : public EventContainer
{
public:
	enum TextureUnitEvent
	{
		TextureNameChanged,
		CubicTextureNameChanged,
		AnimatedTextureNameChanged,
		TextureDimensionsChanged,
		CurrentFrameChanged,
		FrameTextureNameChanged,
		FrameTextureNameAdded,
		FrameTextureNameRemoved,
		BindingTypeChanged,
		ContentTypeChanged,
		PixelFormatChanged,
		NumMipmapsChanged,
		AlphaChanged,
		TextureCoordSetChanged,
		TextureTransformChanged,
		TextureScrollChanged,
		TextureUScrollChanged,
		TextureVScrollChanged,
		TextureUScaleChanged,
		TextureVScaleChanged,
		TextureRotateChanged,
		TextureAddressingModeChanged,
		TextureBorderColourChanged,
		ColourOperationChanged,
		ColourOperationExChanged,
		ColourOpMultipassFallbackChanged,
		AlphaOperationChanged,
		EffectAdded,
		EnvironmentMapChanged,
		ScrollAnimationChanged,
		RotateAnimationChanged,
		TransformAnimationChanged,
		ProjectiveTexturingChanged,
		EffectRemoved,
		Blanked,
		TextureFilteringChanged,
		TextureAnisotropyChanged,
		TextureMipMapBiasChanged,
		NameChanged,
		TextureNameAliasChanged
	};

	TextureUnitController();
	TextureUnitController(TextureUnitState* textureUnit);
	TextureUnitController(PassController* parent, TextureUnitState* textureUnit);
	virtual ~TextureUnitController();

	TextureUnitState* getTextureUnit() const;
	void getTextureUnit(TextureUnitState* tus);

	PassController* getParentController() const;

	void setTextureName(const String &name, TextureType ttype);
	void setCubicTextureName(const String &name, bool forUVW = false);
	void setCubicTextureName(const String *const names, bool forUVW = false);
	void setAnimatedTextureName(const String &name, unsigned int numFrames, Real duration = 0); 
	void setAnimatedTextureName(const String *const names, unsigned int numFrames, Real duration = 0);
	void setCurrentFrame(unsigned int frameNumber);
	void setFrameTextureName(const String &name, unsigned int frameNumber); 
	void addFrameTextureName(const String &name);
	void deleteFrameTextureName(const size_t frameNumber); 
	void setBindingType(TextureUnitState::BindingType bt);
	void setContentType(TextureUnitState::ContentType ct);
	void setDesiredFormat(PixelFormat desiredFormat); 
	void setNumMipmaps(int numMipmaps);
	void setTextureCoordSet(unsigned int set); 
	void setTextureTransform(const Matrix4 &xform); 
	void setTextureScroll(Real u, Real v);
	void setTextureUScroll(Real value);
	void setTextureUScale(Real value);
	void setTextureVScale(Real value);
	void setTextureScale(Real uScale, Real vScale); 
	void setTextureRotate(const Radian &angle);
	void setTextureAddressingMode(TextureUnitState::TextureAddressingMode tam); 
	void setTextureAddressingMode(TextureUnitState::TextureAddressingMode u, TextureUnitState::TextureAddressingMode v, TextureUnitState::TextureAddressingMode w);
	void setTextureAddressingMode(const TextureUnitState::UVWAddressingMode &uvw);
	void setTextureBorderColour(const ColourValue &colour);
	void setColourOperationEx(LayerBlendOperationEx op, LayerBlendSource source1 = LBS_TEXTURE, LayerBlendSource source2 = LBS_CURRENT, const ColourValue &arg1 = ColourValue::White, const ColourValue &arg2 = ColourValue::White, Real manualBlend = 0.0);
	void setColourOperation(const LayerBlendOperation op); 
	void setColourOpMultipassFallback(const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
	void setAlphaOperation(LayerBlendOperationEx op, LayerBlendSource source1 = LBS_TEXTURE, LayerBlendSource source2 = LBS_CURRENT, Real arg1 = 1.0, Real arg2 = 1.0, Real manualBlend = 0.0);
	void addEffect(TextureUnitState::TextureEffect& effect);
	void setEnvironmentMap(bool enable, TextureUnitState::EnvMapType envMapType); 
	void setScrollAnimation(Real uSpeed, Real vSpeed);
	void setRotateAnimation(Real speed);
	void setTransformAnimation(const TextureUnitState::TextureTransformType ttype, const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1);
	void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
	void removeAllEffects(void); 
	void removeEffect(const TextureUnitState::TextureEffectType type); 
	void setBlank(void);
	void setTextureFiltering(TextureFilterOptions filterType); 
	void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter); 
	void setTextureAnisotropy(unsigned int maxAniso);
	void setTextureMipmapBias(float bias);
	void setName(const String &name);
	void setTextureNameAlias(const String &name); 
	bool applyTextureAliases(const AliasTextureNamePairList &aliasList, const bool apply = true);
		
protected:
	void registerEvents();

	PassController* mParentController;
	TextureUnitState* mTextureUnit;
};

#endif // _TEXTUREUNITCONTROLLER_H_


