/* 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_SDL_H__
#define __CCE_SDL_H__

#include	"config.h"

#ifdef SUPPORT_SDLLIB

#include	<SDL/SDL.h>

extern void HandleSDLEvents(int tty_fd);
extern void SDLOpDraw(int xpos, int ypos, u_char *code, int fc, int bc, int width, int height);
extern void SDLOpClear(int y, int height, int color);
extern void SDLOpCursor(CursorInfo *ci, int xpos, int ypos);

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

#ifdef USE_DYNAMIC_SDLLIB

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

extern int  (*p_SDL_Init)(Uint32 flags);
extern void (*p_SDL_Quit)(void);
extern char * (*p_SDL_VideoDriverName)(char *namebuf, int maxlen);
 
extern const SDL_VideoInfo * (*p_SDL_GetVideoInfo)(void);
extern SDL_Rect ** (*p_SDL_ListModes)(SDL_PixelFormat *format, Uint32 flags);
extern SDL_Surface * (*p_SDL_SetVideoMode)(int width, int height, int bpp, Uint32 flags);
extern void (*p_SDL_WM_SetCaption)(const char *title, const char *icon);

extern int (*p_SDL_FillRect)(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
extern Uint32 (*p_SDL_MapRGB)(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b);
extern int (*p_SDL_SetColors)(SDL_Surface *surface, 
			SDL_Color *colors, int firstcolor, int ncolors);

extern int (*p_SDL_LockSurface)(SDL_Surface *surface);
extern void (*p_SDL_UnlockSurface)(SDL_Surface *surface);
extern void (*p_SDL_UpdateRect)(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h);
extern int (*p_SDL_Flip)(SDL_Surface *screen);

extern void (*p_SDL_WarpMouse)(Uint16 x, Uint16 y);
extern int  (*p_SDL_PollEvent)(SDL_Event *event);
extern int  (*p_SDL_EnableKeyRepeat)(int delay, int interval);
extern int  (*p_SDL_EnableUNICODE)(int enable);

#define SDL_INIT 				(*p_SDL_Init)
#define SDL_QUIT				(*p_SDL_Quit)
#define SDL_VIDEODRIVERNAME     (*p_SDL_VideoDriverName)
#define SDL_GETVIDEOINFO		(*p_SDL_GetVideoInfo)
#define SDL_LISTMODES			(*p_SDL_ListModes)
#define SDL_SETVIDEOMODE		(*p_SDL_SetVideoMode)
#define SDL_WM_SETCAPTION       (*p_SDL_WM_SetCaption)
#define SDL_FILLRECT			(*p_SDL_FillRect)
#define SDL_MAPRGB				(*p_SDL_MapRGB)
#define SDL_SETCOLORS			(*p_SDL_SetColors)
#define SDL_LOCKSURFACE			(*p_SDL_LockSurface)
#define SDL_UNLOCKSURFACE		(*p_SDL_UnlockSurface)
#define SDL_UPDATERECT			(*p_SDL_UpdateRect)
#define SDL_FLIP				(*p_SDL_Flip)
#define SDL_WARPMOUSE			(*p_SDL_WarpMouse)
#define SDL_POLLEVENT			(*p_SDL_PollEvent)
#define SDL_ENABLEKEYREPEAT     (*p_SDL_EnableKeyRepeat)
#define SDL_ENABLEUNICODE		(*p_SDL_EnableUNICODE)

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

#define SYMBOL_SDL_INIT 			SYMBOL_PREFIX "SDL_Init"
#define SYMBOL_SDL_QUIT				SYMBOL_PREFIX "SDL_Quit"
#define SYMBOL_SDL_VIDEODRIVERNAME  SYMBOL_PREFIX "SDL_VideoDriverName"
#define SYMBOL_SDL_GETVIDEOINFO		SYMBOL_PREFIX "SDL_GetVideoInfo"
#define SYMBOL_SDL_LISTMODES		SYMBOL_PREFIX "SDL_ListModes"
#define SYMBOL_SDL_SETVIDEOMODE		SYMBOL_PREFIX "SDL_SetVideoMode"
#define SYMBOL_SDL_WM_SETCAPTION    SYMBOL_PREFIX "SDL_WM_SetCaption"
#define SYMBOL_SDL_FILLRECT			SYMBOL_PREFIX "SDL_FillRect"
#define SYMBOL_SDL_MAPRGB			SYMBOL_PREFIX "SDL_MapRGB"
#define SYMBOL_SDL_SETCOLORS		SYMBOL_PREFIX "SDL_SetColors"
#define SYMBOL_SDL_LOCKSURFACE		SYMBOL_PREFIX "SDL_LockSurface"
#define SYMBOL_SDL_UNLOCKSURFACE	SYMBOL_PREFIX "SDL_UnlockSurface"
#define SYMBOL_SDL_UPDATERECT		SYMBOL_PREFIX "SDL_UpdateRect"
#define SYMBOL_SDL_FLIP				SYMBOL_PREFIX "SDL_Flip"
#define SYMBOL_SDL_WARPMOUSE		SYMBOL_PREFIX "SDL_WarpMouse"
#define SYMBOL_SDL_POLLEVENT		SYMBOL_PREFIX "SDL_PollEvent"
#define SYMBOL_SDL_ENABLEKEYREPEAT  SYMBOL_PREFIX "SDL_EnableKeyRepeat"
#define SYMBOL_SDL_ENABLEUNICODE	SYMBOL_PREFIX "SDL_EnableUNICODE"

#else /* USE_DYNAMIC_SDLLIB */

#define SDL_INIT 				SDL_Init
#define SDL_QUIT				SDL_Quit
#define SDL_VIDEODRIVERNAME     SDL_VideoDriverName
#define SDL_GETVIDEOINFO		SDL_GetVideoInfo
#define SDL_LISTMODES			SDL_ListModes
#define SDL_SETVIDEOMODE		SDL_SetVideoMode
#define SDL_WM_SETCAPTION       SDL_WM_SetCaption
#define SDL_FILLRECT			SDL_FillRect
#define SDL_MAPRGB				SDL_MapRGB
#define SDL_SETCOLORS			SDL_SetColors
#define SDL_LOCKSURFACE			SDL_LockSurface
#define SDL_UNLOCKSURFACE		SDL_UnlockSurface
#define SDL_UPDATERECT			SDL_UpdateRect
#define SDL_FLIP				SDL_Flip
#define SDL_WARPMOUSE			SDL_WarpMouse
#define SDL_POLLEVENT			SDL_PollEvent
#define SDL_ENABLEKEYREPEAT     SDL_EnableKeyRepeat
#define SDL_ENABLEUNICODE		SDL_EnableUNICODE

#endif /* USE_DYNAMIC_SDLLIB */

#endif  /* SUPPORT_LIBSDL */

#endif  /* __CCE_SDL_H__ */
