/* vi: set sw=4 ts=4: */
/*
 * CCE - Console Chinese Environment -
 * Copyright (C) 1998-2003 Rui He (rhe@3eti.com)
 *
 * 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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 TERRENCE R. LAMBERT 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.
 * 
 */

#ifndef __CCE_GGI_H__
#define __CCE_GGI_H__

#include	"config.h"

#ifdef SUPPORT_GGILIB

#include	<ggi/gii.h>
#include	<ggi/ggi.h>
#include	<ggi/ggi-unix.h>

extern ggi_visual_t ggiVis;  /* GGI's Visual */
extern unsigned char *ggiPixBuf;

extern int IsGGIAvailable();
extern void HandleGIIEvents(int tty_fd);
extern void GGIOpDraw(int xpos, int ypos, u_char *code, int fc, int bc, int width, int height);
extern void GGIOpClear(int y, int height, int color);
extern void GGIOpCursor(CursorInfo *ci, int xpos, int ypos);

#ifdef SUPPORT_FREETYPE_FONT
#include	"ftfont.h"
extern void GGIDrawFreeTypeChar(int xpos, int ypos, FT_GlyphSlot glyph, int fc, int bc, 
	int width, int height);
#endif
	
#ifdef USE_DYNAMIC_GGILIB

#include	<dlfcn.h>  /* for dlopen etc */

extern int  (*p_ggiInit)(void);
extern int  (*p_ggiExit)(void);
extern ggi_visual_t (*p_ggiOpen)(const char *display,...);
extern int          (*p_ggiClose)(ggi_visual_t vis);

extern int (*p_ggiSetMode)(ggi_visual_t visual,ggi_mode *tm);
extern int (*p_ggiCheckGraphMode)(ggi_visual_t visual, int x, int y,
     int xv, int yv, ggi_graphtype type, ggi_mode *suggested_mode);

extern const ggi_pixelformat *(*p_ggiGetPixelFormat)(ggi_visual_t vis);
extern ggi_pixel (*p_ggiMapColor)(ggi_visual_t vis,ggi_color *col);
extern int (*p_ggiSetGCForeground)(ggi_visual_t vis,ggi_pixel  color);
extern int (*p_ggiDrawBox)(ggi_visual_t vis,int x,int y,int w,int h);
extern int (*p_ggiPutBox)(ggi_visual_t vis,int x,int y,int w,int h,void *buf);
extern int (*p_ggiGetBox)(ggi_visual_t vis,int x,int y,int w,int h,void *buf);

extern int (*p_ggiEventSelect)(ggi_visual_t vis, ggi_event_mask *mask, int n,
	fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    struct timeval *timeout);

extern int (*p_ggiEventRead)(ggi_visual_t vis, gii_event *ev,
	gii_event_mask mask);

#define GGIINIT 				(*p_ggiInit)
#define GGIEXIT					(*p_ggiExit)
#define GGIEVENTSELECT			(*p_ggiEventSelect)
#define GGIEVENTREAD			(*p_ggiEventRead)
#define GGIOPEN					(*p_ggiOpen)
#define GGICLOSE				(*p_ggiClose)
#define GGICHECKGRAPHMODE		(*p_ggiCheckGraphMode)
#define GGISETMODE				(*p_ggiSetMode)
#define GGIGETBOX				(*p_ggiGetBox)
#define GGIPUTBOX				(*p_ggiPutBox)
#define GGIDRAWBOX				(*p_ggiDrawBox)
#define GGISETGCFOREGROUND		(*p_ggiSetGCForeground)
#define GGIMAPCOLOR				(*p_ggiMapColor)
#define GGIGETPIXELFORMAT		(*p_ggiGetPixelFormat)

#if defined(__OpenBSD__)
#define SYMBOL_PREFIX "_"  /* strange for OpenBSD */
#else
#define SYMBOL_PREFIX ""
#endif

#define SYMBOL_GGIINIT 				SYMBOL_PREFIX "ggiInit"
#define SYMBOL_GGIEXIT				SYMBOL_PREFIX "ggiExit"
#define SYMBOL_GGIEVENTSELECT		SYMBOL_PREFIX "ggiEventSelect"
#define SYMBOL_GGIEVENTREAD			SYMBOL_PREFIX "ggiEventRead"
#define SYMBOL_GGIOPEN				SYMBOL_PREFIX "ggiOpen"
#define SYMBOL_GGICLOSE				SYMBOL_PREFIX "ggiClose"
#define SYMBOL_GGICHECKGRAPHMODE	SYMBOL_PREFIX "ggiCheckGraphMode"
#define SYMBOL_GGISETMODE			SYMBOL_PREFIX "ggiSetMode"
#define SYMBOL_GGIGETBOX			SYMBOL_PREFIX "ggiGetBox"
#define SYMBOL_GGIPUTBOX			SYMBOL_PREFIX "ggiPutBox"
#define SYMBOL_GGIDRAWBOX			SYMBOL_PREFIX "ggiDrawBox"
#define SYMBOL_GGISETGCFOREGROUND	SYMBOL_PREFIX "ggiSetGCForeground"
#define SYMBOL_GGIMAPCOLOR			SYMBOL_PREFIX "ggiMapColor"
#define SYMBOL_GGIGETPIXELFORMAT	SYMBOL_PREFIX "ggiGetPixelFormat"

#else  /* USE_DYNAMIC_GGILIB */

#define GGIINIT 				ggiInit
#define GGIEXIT					ggiExit
#define GGIEVENTSELECT			ggiEventSelect
#define GGIEVENTREAD			ggiEventRead
#define GGIOPEN					ggiOpen
#define GGICLOSE				ggiClose
#define GGICHECKGRAPHMODE		ggiCheckGraphMode
#define GGISETMODE				ggiSetMode
#define GGIGETBOX				ggiGetBox
#define GGIPUTBOX				ggiPutBox
#define GGIDRAWBOX				ggiDrawBox
#define GGISETGCFOREGROUND		ggiSetGCForeground
#define GGIMAPCOLOR				ggiMapColor
#define GGIGETPIXELFORMAT		ggiGetPixelFormat

#endif /* USE_DYNAMIC_GGILIB */

#endif  /* SUPPORT_GGILIB */

#endif  /* __CCE_GGI_H__ */
