/*
**	$Id: GfxDisplay.hpp 1.7 1995/12/03 12:16:23 olsen Exp olsen $
**
**	:ts=4
*/

/*
 * Amiga changes copyright © 1995 by Olaf Barthel, All Rights Reserved
 *
 * Copyright (c) 1992, 1993 Arno Augustin, Frank Hoering, University of
 * Erlangen-Nuremberg, Germany.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the University of
 *      Erlangen-Nuremberg, Germany.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software has not been validated by the ``Bundesamt fuer Zulassungen in
 * der Telekommunikation'' of the ``Deutsche Bundepost Telekom'' and thus
 * must not be used for accessing the BTX-Network of the Telekom in Germany.
 *
 * Diese Software hat keine Zulassung durch das Bundesamt fuer Zulassungen in
 * der Telekommunikation der Deutschen Bundespost Telekom und darf daher nicht
 * am Netz der Deutschen Bundespost Telekom in Deutschland betrieben werden.
 */

#ifndef _GFXDISPLAY_HPP
#define _GFXDISPLAY_HPP 1

/****************************************************************************/

#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <exec/memory.h>

/****************************************************************************/

#ifndef _TYPES_HPP
#include "Types.hpp"
#endif

#ifndef _BTXDISPLAY_HPP
#include "BTXDisplay.hpp"
#endif

#ifndef _FONT_H
#include "Font.h"
#endif

/****************************************************************************/

#define MAX_ZOOM 8

typedef struct btxchar
{
	struct btxchar	*link;
	unsigned char	*raw;
	unsigned char	bits;
	struct BitMap	*map[4];
} btxchar;

typedef struct colorentry
{
	unsigned char	red;
	unsigned char	green;
	unsigned char	blue;
} colorentry;

class GfxDisplay : public BTXDisplay
{
	public:

		GfxDisplay();
		~GfxDisplay();

		LONG	Open(STRPTR PubScreenName,int XScale,int YScale,BOOL DirectRender);
		VOID	Close(VOID);
		VOID	MonitorData(int *btx_rows,int *btx_fontheight);
		ULONG	WaitMask(VOID);
		LONG	GetChar(VOID);
		LONG	Waiting(VOID);
		VOID	PutLine(STRPTR Line);

		void	xputc(int c,int set,int x,int y,int xdouble,int ydouble,int underline,int diacrit,int fg,int bg);
		void	xclearscreen(void);
		void	xcursor(int x,int y);
		void	define_raw_DRC(int c,unsigned char *data,int bits);
		void	define_color(int index,int r,int g,int b);
		void	define_DCLUT(int entry,int index);
		void	define_fullrow_bg(int row,int index);
		void	free_DRCS(void);
		void	default_colors(void);

	private:

		void				 xdraw_normal_char(btxchar *ch,int x,int y,int xd,int yd,int ul,btxchar *dia,int fg,int bg);
		void				 xdraw_multicolor_char(btxchar *ch,int x,int y,int xd,int yd);
		struct BitMap		*rawfont2bitmap(unsigned char *src,int xzoom,int yzoom);
		struct BitMap		*createpixmapfromfont(unsigned char *src,int xzoom,int yzoom,int bits);
		void				 init_fonts(void);
		void				 free_font_pixmaps(void);
		void				 store_colors(void);
		void				 init_colormap(void);

		btxchar				 btx_font[6*96];
		int					 fullrow_bg[24]; 	/* fullrow background color for eacch row */
		int					 dclut[4];			/* map the 4-color DRC's */
		colorentry			 colormap[32+4+24];	/* store pixel value for each colorcell */
		int					 cur_fg,
							 cur_bg;
		unsigned char		 data[FONT_HEIGHT*2*2*FONT_WIDTH*2*2*MAX_ZOOM],
							 row[FONT_WIDTH*2*2*MAX_ZOOM];

		int					*rows;
		int					*fontheight;

		int					 ScaleX;
		int					 ScaleY;

		WORD				 PutIndex;

		BOOL				 DirectRender;

		UBYTE				 FgBgMinterms[8];
		UBYTE				 FgMinterms[8];
		struct RastPort 	 LocalRPort;
		struct BitMap		 LocalBitMap;

		struct RastPort 	 TempRPort;

		struct Screen		*BtxScreen;
		struct Window		*BtxWindow;

		struct ViewPort 	*VPort;

		struct InputEvent	 Event;

		LONG				 FgPen,BgPen;

		struct MsgPort		*WindowPort;
		ULONG				 WindowMask;

		WORD				 WaitingChar;

		UWORD				 DisplayWidth;
		UWORD				 DisplayHeight;

		LONG				 Pen[60];
		struct RastPort 	*RPort;

		VOID				 PreparePaintFgBg(UBYTE Fore,UBYTE Back,UBYTE *Minterms=NULL);
		VOID				 PreparePaintFg(UBYTE Fore,UBYTE *Minterms=NULL);
		VOID				 DrawTemplate(CONST struct BitMap *BitMap,CONST UBYTE *Minterms,UWORD Left,UWORD Top,UWORD Width,UWORD Height);
		struct BitMap		*NewBitMap(LONG Depth,LONG Width,LONG Height);
		VOID				 DisposeBitMap(struct BitMap *BitMap);
		VOID				 SetFgPen(LONG Index);
		VOID				 SetBgPen(LONG Index);
		VOID				 SetPens(LONG Fg,LONG Bg);
		VOID				 Fill(LONG Left,LONG Top,LONG Width,LONG Height);
		VOID				 Complement(LONG Left,LONG Top,LONG Width,LONG Height);
		VOID				 SetColour(LONG Index,UBYTE Red,UBYTE Green,UBYTE Blue);
		BOOL				 InitColours(VOID);
		LONG				 MapKey(struct IntuiMessage *Message);
		ULONG				 FindBestModeID(Tag FirstTag,...);
		VOID				 ReleaseColours(VOID);
};

#endif	// _GFXDISPLAY_HPP
