/*
 * $Id: geometrytext.h $
 *
 * Description  : One line description of file.
 * Author       : Jan Cejka <mail: 324987@mail.muni.cz>
 *
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __GEOMETRY_TEXT__H__
#define __GEOMETRY_TEXT__H__

#include <wx/font.h>

#include "geometry.h"
#include "geometrytriangles.h"
#include "flexilog.h"

namespace VRUT
{
	///Class representing a text, based mostly on vrml text shape
	class VRUT_CORE_API GeometryText : public Geometry
	{
	public:
		/// See vrml specification for better explanation
		enum Justify
		{
			Justify_First,		///< Leftmost for x, baseline of topmost line for y
			Justify_Begin,		///< Leftmost for x, topline of topmost line for y
			Justify_Middle,		///< Middle for x, middle for y
			Justify_End			///< Rightmost for x, baseline of topmost line for y
		};

	protected:
		wxString text;			///< Text of this GeometryText
		float size;				///< Size of one glyph in world units
		float spacing;			///< Spacing between lines of text
		Justify majorJustify;	///< Justify in major text direction (mostly x direction)
		Justify minorJustify;	///< Justify in minor text direction (mostly y direction)
		unsigned char fontFamily;///< The font family: in wxWidgets: 0 - default, 1 - decorative, 2 - roman (serif), 3 - script (handwriting), 4 - swiss (sans-serif), 5 - modern (fixed pitch),
								///6 - teletype (typewriter), 7 - custom (fontName is used)
		wxString fontName;		///< custom font name
		unsigned char fontStyle;///< bits: 0-1 - normal/light/bold/max, 2-3 - normal/italic/slant/max, 4 - underlined, 5 - strikethrough

	public:
		static const GEOMETRY_TYPE ClassType = GEOMETRY_TEXT;

		GeometryText(GEOMETRY_ID _gid);
		GeometryText(const GeometryText &g);
		virtual ~GeometryText() {}

		void SetText(const wxString &text);
		wxString GetText() const;

		void SetSize(float size);
		float GetSize() const;

		void SetSpacing(float spacing);
		float GetSpacing() const;

		void SetMajorJustify(Justify justify);
		Justify GetMajorJustify() const;
		void SetMinorJustify(Justify justify);
		Justify GetMinorJustify() const;

		void SetFontFamily(unsigned char fontFamily)
		{
			this->fontFamily=fontFamily;
		}
		unsigned char GetFontFamily() const
		{
			return this->fontFamily;
		}
		void SetFontName(const wxString &fontName)
		{
			this->fontName=fontName;
		}
		wxString GetFontName() const
		{
			return this->fontName;
		}
		void SetFontStyle(unsigned char fontStyle)
		{
			this->fontStyle=fontStyle;
		}
		unsigned char GetFontStyle() const
		{
			return this->fontStyle;
		}

		wxFont GetFont() const;

		// Overriden methods of Geometry
		virtual void BuildAABB() override;

		virtual bool Intersects(const Ray &ray, float *dist) const override
		{
			//LOGWARNING(wxT("GeometryText::Intersects not implemented properly"));
			GeometryTriangles geoTri(GetID());
			geoTri.AddBox(aabb.MinBound, aabb.MaxBound-aabb.MinBound);
			return geoTri.Intersects(ray, dist);
		}

		virtual bool CastRay(const Ray &ray, RayIntersectionInfo &info) const override
		{
			GeometryTriangles geoTri(GetID());
			geoTri.AddBox(aabb.MinBound, aabb.MaxBound-aabb.MinBound);
			return geoTri.CastRay(ray, info);
		}

		virtual std::vector<Triangle> Triangulate() const override;
		virtual std::vector<TriangleData> TriangulateData() const override;

		virtual void AddBox(const Vector3 &position, const Vector3 &size) override;
		virtual bool AddGeometry(const Geometry *geom) override;
		virtual bool AddGeometries(const std::vector<Geometry *> &geoms) override;

		virtual bool Transform(const Matrix * /*matrix*/) override
		{
			return false;//LOGVERBOSE(wxT("GeometryText::Transform not possible"));
		}

		virtual void Divide(std::vector<Geometry*> &segments) const override;
		virtual void DivideToPrimitives(std::vector<Geometry*> &segments) const override;
		virtual void FlipNormals() override;
		virtual void TextureMappingPlanar(const Matrix &texMatrix) override;
		virtual void TextureMappingTriplanar(const Matrix &texMatrix) override;
		virtual void TextureMappingSpherical(const Matrix &texMatrix) override;

		virtual void Clear() override;

		virtual bool IsSameAs(const smart_pointer<Geometry> & geo) const override;

		virtual wxString ToString() const override;

		virtual Geometry * Clone() const override;
	};
}

#endif
