/*
 * This file is part of libtqtvd_astronav
 *
 * Copyright (C) 2008-2017 TQTVD Software
 * Copyright (C) 2017 Mirakulo Software (mirakulo@mirakulo.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License 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., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#ifndef TQTVD_GRAPHIC_MANAGER_INTERFACE_H_
#define TQTVD_GRAPHIC_MANAGER_INTERFACE_H_

#include "atvGeneral.h"

namespace TQTVD {
namespace GraphicManager {

typedef unsigned ARGB32;        // RGBA quadruplet

class Window;
class DrawContext;

	class ARectangle
	{
		public:
			ARectangle() : x(0), y(0), w(0), h(0) { }
			ARectangle(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) { }
			~ARectangle() { }
		public:
			int x;
			int y;
			int w;
			int h;
	};

	struct Point2d {
		Point2d(int x, int y): x(x), y(y)
		{
		}
		int x;
		int y;
	};

	class IGraphicManagerAdapterFont
	{
		public:
			virtual	~IGraphicManagerAdapterFont () { }
		public:
			virtual	bool ContainsCharacters (char * glyphs, int numGlyphs) = 0;
			virtual	int GetGlyphExtents (char glyph, ARectangle * rect, int* advance) = 0;
			virtual	int GetAscender () = 0;
			virtual	int GetDescender () = 0;
			virtual	int GetHeight () = 0;
			virtual const char* GetFamily() = 0;
			virtual const char* GetStyle() = 0;
			virtual int GetSize() = 0;
	};

	class IGraphicManagerAdapterFontMapping
	{
		public:
			virtual	~IGraphicManagerAdapterFontMapping () { }
		public:
			virtual	IGraphicManagerAdapterFont * getFont (char * family, char * style, int size) = 0;
	};

	class IGraphicManagerAdapterSurface
	{
		public:
			typedef enum { BLENDMODE_REPLACE = 1, BLENDMODE_COMPOSE = 2 }		BlendMode_t;
		public:
			virtual	~IGraphicManagerAdapterSurface () { }
		public:
			virtual	int Clear (ARGB32 color = 0x00000000) = 0; // default: transparent.
			virtual	int GetSize (int* width, int* height ) = 0;
			virtual	int Blit ( IGraphicManagerAdapterSurface * src, ARectangle * area, int x, int y, int alpha) = 0;
			virtual	int SetColor (int red, int green, int blue, int alpha) = 0;
			virtual	int SetLineStyle (int style) = 0;
			virtual	int FillRectangle (int x, int y, int w, int h) = 0;
			virtual int FillConvexPolygon(const struct Point2d * points, int npoints) = 0;
			virtual	int DrawLine (int x1, int y1, int x2, int y2) = 0;
			virtual	int DrawEllipse (ARectangle * rect) = 0;
			virtual	int DrawRectangle (int x, int y, int w, int h) = 0;
			virtual	int GetClip (ARectangle * rect) = 0;
			virtual	int SetClip (ARectangle * region) = 0;
			virtual	int StretchBlit ( IGraphicManagerAdapterSurface * src, ARectangle * srcRect, ARectangle * dest) = 0;
			virtual	int SetFont (IGraphicManagerAdapterFont * font) = 0;
			virtual	int DrawGlyph (char glyph, int x, int y) = 0;
			virtual	int DrawString (char * glyphs, int numGlyphs, int x, int y) = 0;
			virtual	int SetBlendMode (BlendMode_t mode) = 0;
			virtual void SetPixels(int x, int y, const _u8* buffer, int bufferW, int bufferH, ARectangle * bufferClip = NULL) = 0;
	};

	class IGraphicManagerAdapter
	{
		public:
			virtual	~IGraphicManagerAdapter () { }
			//static IGraphicManagerAdapter& getInstance();
		public:
			virtual IGraphicManagerAdapterFont *		CreateFont (char * name, char * face, int size) = 0;
			virtual IGraphicManagerAdapterFont *		DestroyFont (IGraphicManagerAdapterFont * font) = 0;
			virtual IGraphicManagerAdapterFontMapping * CreateFontMapping () = 0;
			virtual IGraphicManagerAdapterFontMapping * DestroyFontMapping (IGraphicManagerAdapterFontMapping * font) = 0;
			virtual IGraphicManagerAdapterSurface *		CreateSurface (int width, int height, int depth) = 0;
			virtual IGraphicManagerAdapterSurface *		DestroySurface (IGraphicManagerAdapterSurface * surface) = 0;
	};

}
}

#endif // TQTVD_GRAPHIC_MANAGER_INTERFACE_H_

