sdl 1.3 up

This commit is contained in:
p.kosyh 2011-02-19 13:23:09 +00:00
parent f60ee2b6b7
commit ea911eb83a
12 changed files with 2364 additions and 1936 deletions

2
debian/changelog vendored
View file

@ -3,6 +3,8 @@ instead (1.3.2) unstable; urgency=low
* bug fix (dates in save slots); * bug fix (dates in save slots);
* bug fix (dbg fixes); * bug fix (dbg fixes);
* small bug fixes; * small bug fixes;
* s60 build;
* SDL 1.3 ready;
-- Peter Kosyh <p.kosyh@gmail.com> Mon, 14 Feb 2011 16:24:00 +0300 -- Peter Kosyh <p.kosyh@gmail.com> Mon, 14 Feb 2011 16:24:00 +0300

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,9 @@
/* /*
SDL_gfxBlitFunc: custom blitters (part of SDL_gfx library) SDL_gfxBlitFunc: custom blitters (part of SDL_gfx library)
LGPL (c) A. Schiffler
LGPL (c) A. Schiffler
*/ */
#ifndef _SDL_gfxBlitFunc_h #ifndef _SDL_gfxBlitFunc_h
@ -20,87 +20,123 @@ extern "C" {
#include <SDL.h> #include <SDL.h>
#include <SDL_video.h> #include <SDL_video.h>
int SDL_gfxBlitRGBA(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect); /* ---- Function Prototypes */
int SDL_gfxSetAlpha(SDL_Surface * src, Uint8 a); #if defined(WIN32) || defined(WIN64)
# if defined(DLL_EXPORT) && !defined(LIBSDL_GFX_DLL_IMPORT)
# define SDL_GFXBLITFUNC_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL_GFX_DLL_IMPORT
# define SDL_GFXBLITFUNC_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL_GFXBLITFUNC_SCOPE
# define SDL_GFXBLITFUNC_SCOPE extern
#endif
/* -------- Macros */ SDL_GFXBLITFUNC_SCOPE int SDL_gfxBlitRGBA(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect);
/* Define SDL macros locally as a substitute for a #include "SDL_blit.h", */ SDL_GFXBLITFUNC_SCOPE int SDL_gfxSetAlpha(SDL_Surface * src, Uint8 a);
/* which doesn't work since the include file doesn't get installed. */ SDL_GFXBLITFUNC_SCOPE int SDL_gfxMultiplyAlpha(SDL_Surface * src, Uint8 a);
/* The structure passed to the low level blit functions */ /* -------- Macros */
typedef struct {
Uint8 *s_pixels;
int s_width;
int s_height;
int s_skip;
Uint8 *d_pixels;
int d_width;
int d_height;
int d_skip;
void *aux_data;
SDL_PixelFormat *src;
Uint8 *table;
SDL_PixelFormat *dst;
} SDL_gfxBlitInfo;
/* Define SDL macros locally as a substitute for an #include "SDL_blit.h", */
/* which doesn't work since the include file doesn't get installed. */
/*!
\brief The structure passed to the low level blit functions.
*/
typedef struct {
Uint8 *s_pixels;
int s_width;
int s_height;
int s_skip;
Uint8 *d_pixels;
int d_width;
int d_height;
int d_skip;
void *aux_data;
SDL_PixelFormat *src;
Uint8 *table;
SDL_PixelFormat *dst;
} SDL_gfxBlitInfo;
/*!
\brief Unwrap RGBA values from a pixel using mask, shift and loss for surface.
*/
#define GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a) \ #define GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a) \
{ \ { \
r = ((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss; \ r = ((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss; \
g = ((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss; \ g = ((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss; \
b = ((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss; \ b = ((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss; \
a = ((pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss; \ a = ((pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss; \
} }
/*!
\brief Disassemble buffer pointer into a pixel and separate RGBA values.
*/
#define GFX_DISEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a) \ #define GFX_DISEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a) \
do { \ do { \
pixel = *((Uint32 *)(buf)); \ pixel = *((Uint32 *)(buf)); \
GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a); \ GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a); \
pixel &= ~fmt->Amask; \ pixel &= ~fmt->Amask; \
} while(0) } while(0)
/*!
\brief Wrap a pixel from RGBA values using mask, shift and loss for surface.
*/
#define GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a) \ #define GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a) \
{ \ { \
pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
((g>>fmt->Gloss)<<fmt->Gshift)| \ ((g>>fmt->Gloss)<<fmt->Gshift)| \
((b>>fmt->Bloss)<<fmt->Bshift)| \ ((b>>fmt->Bloss)<<fmt->Bshift)| \
((a<<fmt->Aloss)<<fmt->Ashift); \ ((a<<fmt->Aloss)<<fmt->Ashift); \
} }
/*!
\brief Assemble pixel into buffer pointer from separate RGBA values.
*/
#define GFX_ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \ #define GFX_ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \
{ \ { \
Uint32 pixel; \ Uint32 pixel; \
\ \
GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a); \ GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a); \
*((Uint32 *)(buf)) = pixel; \ *((Uint32 *)(buf)) = pixel; \
} }
/* Blend the RGB values of two pixels based on a source alpha value */ /*!
\brief Blend the RGB values of two pixels based on a source alpha value.
*/
#define GFX_ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \ #define GFX_ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \
do { \ do { \
dR = (((sR-dR)*(A))/255)+dR; \ dR = (((sR-dR)*(A))/255)+dR; \
dG = (((sG-dG)*(A))/255)+dG; \ dG = (((sG-dG)*(A))/255)+dG; \
dB = (((sB-dB)*(A))/255)+dB; \ dB = (((sB-dB)*(A))/255)+dB; \
} while(0) } while(0)
/* This is a very useful loop for optimizing blitters */ /*!
\brief 4-times unrolled DUFFs loop.
/* 4-times unrolled loop */ This is a very useful loop for optimizing blitters.
*/
#define GFX_DUFFS_LOOP4(pixel_copy_increment, width) \ #define GFX_DUFFS_LOOP4(pixel_copy_increment, width) \
{ int n = (width+3)/4; \ { int n = (width+3)/4; \
switch (width & 3) { \ switch (width & 3) { \
case 0: do { pixel_copy_increment; \ case 0: do { pixel_copy_increment; \
case 3: pixel_copy_increment; \ case 3: pixel_copy_increment; \
case 2: pixel_copy_increment; \ case 2: pixel_copy_increment; \
case 1: pixel_copy_increment; \ case 1: pixel_copy_increment; \
} while ( --n > 0 ); \ } while ( --n > 0 ); \
} \ } \
} }
/* Ends C function definitions when using C++ */
/* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,9 @@
/* /*
SDL_rotozoom - rotozoomer SDL_rotozoom - rotozoomer
LGPL (c) A. Schiffler LGPL (c) A. Schiffler
*/ */
@ -23,93 +23,79 @@ extern "C" {
#include "SDL.h" #include "SDL.h"
/* ---- Defines */ /* ---- Defines */
/*!
\brief Disable anti-aliasing (no smoothing).
*/
#define SMOOTHING_OFF 0 #define SMOOTHING_OFF 0
/*!
\brief Enable anti-aliasing (smoothing).
*/
#define SMOOTHING_ON 1 #define SMOOTHING_ON 1
/* ---- Structures */ /* ---- Function Prototypes */
typedef struct tColorRGBA { #if defined(WIN32) || defined(WIN64)
Uint8 r; # if defined(DLL_EXPORT) && !defined(LIBSDL_GFX_DLL_IMPORT)
Uint8 g; # define SDL_ROTOZOOM_SCOPE __declspec(dllexport)
Uint8 b; # else
Uint8 a; # ifdef LIBSDL_GFX_DLL_IMPORT
} tColorRGBA; # define SDL_ROTOZOOM_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL_ROTOZOOM_SCOPE
# define SDL_ROTOZOOM_SCOPE extern
#endif
typedef struct tColorY { /*
Uint8 y;
} tColorY; Rotozoom functions
*/
SDL_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
SDL_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY
(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
/* ---- Prototypes */ SDL_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
int *dstheight);
#define DLLINTERFACE SDL_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY
(int width, int height, double angle, double zoomx, double zoomy,
int *dstwidth, int *dstheight);
/* /*
rotozoomSurface()
Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. Zooming functions
'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
*/ */
DLLINTERFACE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth); SDL_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
DLLINTERFACE SDL_Surface *rotozoomSurfaceXY SDL_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
/* Returns the size of the target surface for a rotozoomSurface() call */ /*
DLLINTERFACE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, Shrinking functions
int *dstheight);
DLLINTERFACE void rotozoomSurfaceSizeXY */
(int width, int height, double angle, double zoomx, double zoomy,
int *dstwidth, int *dstheight);
/* SDL_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
zoomSurface()
Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. /*
'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
*/ Specialized rotation functions
DLLINTERFACE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth); */
/* Returns the size of the target surface for a zoomSurface() call */ SDL_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns);
DLLINTERFACE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight); /* Ends C function definitions when using C++ */
/*
shrinkSurface()
Shrinks a 32bit or 8bit 'src' surface ti a newly created 'dst' surface.
'factorx' and 'factory' are the shrinking ratios (i.e. 2=1/2 the size,
3=1/3 the size, etc.) The destination surface is antialiased by averaging
the source box RGBA or Y information. If the surface is not 8bit
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
*/
DLLINTERFACE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
/*
Other functions
*/
DLLINTERFACE SDL_Surface* rotateSurface90Degrees(SDL_Surface* pSurf, int numClockwiseTurns);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -644,8 +644,7 @@ int game_change_hz(int hz)
} }
unsigned int timer_counter = 0; unsigned int timer_counter = 0;
gtimer_t timer_han = NULL_TIMER;
gtimer_t timer_han = NULL;
static void anigif_do(void *data) static void anigif_do(void *data)
{ {
@ -832,7 +831,7 @@ void game_release_theme(void)
void game_done(int err) void game_done(int err)
{ {
gfx_del_timer(timer_han); gfx_del_timer(timer_han);
timer_han = NULL; timer_han = NULL_TIMER;
if (opt_autosave && curgame_dir && !err) if (opt_autosave && curgame_dir && !err)
game_save(0); game_save(0);
@ -1681,7 +1680,7 @@ inv:
} }
{ /* highlight new scene, to avoid flickering */ { /* highlight new scene, to avoid flickering */
int x, y; int x, y;
gfx_cursor(&x, &y, NULL, NULL); gfx_cursor(&x, &y);
game_highlight(x, y, 1); game_highlight(x, y, 1);
} }
game_cursor(CURSOR_DRAW); game_cursor(CURSOR_DRAW);
@ -2085,7 +2084,7 @@ void game_cursor(int on)
int oh = h; int oh = h;
if (on != CURSOR_DRAW) { if (on != CURSOR_DRAW) {
gfx_cursor(&xc, &yc, NULL, NULL); gfx_cursor(&xc, &yc);
xc -= game_theme.cur_x; xc -= game_theme.cur_x;
yc -= game_theme.cur_y; yc -= game_theme.cur_y;
} }
@ -2096,7 +2095,7 @@ void game_cursor(int on)
grab = gfx_grab_screen(xc, yc, w, h); grab = gfx_grab_screen(xc, yc, w, h);
if (mouse_focus()) if (mouse_focus())
gfx_draw(cur, xc, yc); gfx_draw(cur, xc, yc);
if (on != CURSOR_DRAW) { if (on != CURSOR_DRAW) {
gfx_update(xc, yc, w, h); gfx_update(xc, yc, w, h);
gfx_update(ox, oy, ow, oh); gfx_update(ox, oy, ow, oh);
@ -2218,7 +2217,7 @@ static void select_frame(int prev)
struct el *elem = NULL; struct el *elem = NULL;
int x, y, w, h; int x, y, w, h;
gfx_cursor(&x, &y, NULL, NULL); gfx_cursor(&x, &y);
elem = look_obj(x, y); elem = look_obj(x, y);
@ -2338,7 +2337,7 @@ static int select_ref(int prev, int last)
int x, y; int x, y;
struct el *elem = NULL; struct el *elem = NULL;
xref_t xref = NULL; xref_t xref = NULL;
gfx_cursor(&x, &y, NULL, NULL); gfx_cursor(&x, &y);
xref = look_xref(x, y, &elem); xref = look_xref(x, y, &elem);
@ -2379,7 +2378,7 @@ static void game_scroll_up(int count)
{ {
int xm, ym; int xm, ym;
struct el *o; struct el *o;
gfx_cursor(&xm, &ym, NULL, NULL); gfx_cursor(&xm, &ym);
o = look_obj(xm, ym); o = look_obj(xm, ym);
if (o && (o->id == el_scene || o->id == el_inv)) { if (o && (o->id == el_scene || o->id == el_inv)) {
scroll_up(o->id, count); scroll_up(o->id, count);
@ -2390,7 +2389,7 @@ static void game_scroll_down(int count)
{ {
int xm, ym; int xm, ym;
struct el *o; struct el *o;
gfx_cursor(&xm, &ym, NULL, NULL); gfx_cursor(&xm, &ym);
o = look_obj(xm, ym); o = look_obj(xm, ym);
if (o && (o->id == el_scene || o->id == el_inv)) { if (o && (o->id == el_scene || o->id == el_inv)) {
scroll_down(o->id, count); scroll_down(o->id, count);
@ -2401,7 +2400,7 @@ static int game_scroll_pup(void)
{ {
int xm, ym; int xm, ym;
struct el *o; struct el *o;
gfx_cursor(&xm, &ym, NULL, NULL); gfx_cursor(&xm, &ym);
o = look_obj(xm, ym); o = look_obj(xm, ym);
if (o && (o->id == el_scene || o->id == el_inv)) { if (o && (o->id == el_scene || o->id == el_inv)) {
return scroll_pup(o->id); return scroll_pup(o->id);
@ -2413,7 +2412,7 @@ static int game_scroll_pdown(void)
{ {
int xm, ym; int xm, ym;
struct el *o; struct el *o;
gfx_cursor(&xm, &ym, NULL, NULL); gfx_cursor(&xm, &ym);
o = look_obj(xm, ym); o = look_obj(xm, ym);
if (o && (o->id == el_scene || o->id == el_inv)) { if (o && (o->id == el_scene || o->id == el_inv)) {
return scroll_pdown(o->id); return scroll_pdown(o->id);
@ -2423,8 +2422,6 @@ static int game_scroll_pdown(void)
static int is_key(struct inp_event *ev, const char *name) static int is_key(struct inp_event *ev, const char *name)
{ {
if (!ev->sym)
return -1;
return strcmp(ev->sym, name); return strcmp(ev->sym, name);
} }
@ -2713,7 +2710,7 @@ int game_loop(void)
|| !is_key(&ev, ".") || !is_key(&ev, ".")
#endif #endif
)) { )) {
gfx_cursor(&x, &y, NULL, NULL); gfx_cursor(&x, &y);
game_highlight(-1, -1, 0); /* reset */ game_highlight(-1, -1, 0); /* reset */
game_click(x, y, 0, 0); game_click(x, y, 0, 0);
@ -2840,7 +2837,7 @@ int game_loop(void)
game_highlight(x, y, 1); game_highlight(x, y, 1);
else { else {
int x, y; int x, y;
gfx_cursor(&x, &y, NULL, NULL); gfx_cursor(&x, &y);
game_highlight(x, y, 1); game_highlight(x, y, 1);
} }
game_cursor(CURSOR_ON); game_cursor(CURSOR_ON);

View file

@ -588,7 +588,10 @@ img_t gfx_alpha_img(img_t src, int alpha)
else else
img = gfx_new(Surf(src)->w, Surf(src)->h); img = gfx_new(Surf(src)->w, Surf(src)->h);
if (!img) if (!img)
return NULL; return NULL;
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_SetAlpha(img, SDL_SRCALPHA, 255);
#endif
ptr = (Uint32*)img->pixels; ptr = (Uint32*)img->pixels;
size = img->w * img->h; size = img->w * img->h;
while (size --) { while (size --) {
@ -604,7 +607,11 @@ img_t gfx_alpha_img(img_t src, int alpha)
void gfx_set_alpha(img_t src, int alpha) void gfx_set_alpha(img_t src, int alpha)
{ {
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_SetAlpha((SDL_Surface *)src, SDL_SRCALPHA, alpha);
#else
SDL_SetAlpha((SDL_Surface *)src, SDL_SRCALPHA | SDL_RLEACCEL, alpha); SDL_SetAlpha((SDL_Surface *)src, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
#endif
} }
img_t gfx_combine(img_t src, img_t dst) img_t gfx_combine(img_t src, img_t dst)
@ -769,7 +776,11 @@ static img_t _gfx_load_image(char *filename)
rwop = SDL_RWFromFile(filename, "rb"); rwop = SDL_RWFromFile(filename, "rb");
if (rwop) { if (rwop) {
if (IMG_isBMP(rwop)) if (IMG_isBMP(rwop))
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_SetAlpha(img, 0, SDL_ALPHA_OPAQUE);
#else
SDL_SetAlpha(img, SDL_RLEACCEL, SDL_ALPHA_OPAQUE); SDL_SetAlpha(img, SDL_RLEACCEL, SDL_ALPHA_OPAQUE);
#endif
SDL_RWclose(rwop); SDL_RWclose(rwop);
} }
} }
@ -3596,22 +3607,16 @@ void txt_layout_real_size(layout_t lay, int *pw, int *ph)
*ph = h; *ph = h;
} }
void gfx_cursor(int *xp, int *yp, int *w, int *h) void gfx_cursor(int *xp, int *yp)
{ {
int x, y; int x, y;
SDL_Cursor *c = SDL_GetCursor();
if (!c)
return;
SDL_GetMouseState(&x, &y); SDL_GetMouseState(&x, &y);
if (w)
*w = c->area.w - c->hot_x;
if (h)
*h = c->area.h - c->hot_y;
if (xp) if (xp)
*xp = x; *xp = x;
if (yp) if (yp)
*yp = y; *yp = y;
} }
void gfx_warp_cursor(int x, int y) void gfx_warp_cursor(int x, int y)
{ {
SDL_WarpMouse(x, y); SDL_WarpMouse(x, y);
@ -3685,7 +3690,11 @@ void gfx_done(void)
gtimer_t gfx_add_timer(int delay, int (*fn)(int, void*), void *aux) gtimer_t gfx_add_timer(int delay, int (*fn)(int, void*), void *aux)
{ {
#if SDL_VERSION_ATLEAST(1,3,0)
return (gtimer_t)SDL_AddTimer(delay, (SDL_TimerCallback)fn, aux);
#else
return (gtimer_t)SDL_AddTimer(delay, (SDL_NewTimerCallback)fn, aux); return (gtimer_t)SDL_AddTimer(delay, (SDL_NewTimerCallback)fn, aux);
#endif
} }
void gfx_del_timer(gtimer_t han) void gfx_del_timer(gtimer_t han)

View file

@ -1,6 +1,6 @@
#ifndef __GRAPHICS_H__ #ifndef __GRAPHICS_H__
#define __GRAPHICS_H__ #define __GRAPHICS_H__
#include <SDL.h>
/* #define GFX_CACHE_SIZE 64 /* #define GFX_CACHE_SIZE 64
#define GFX_MAX_CACHED_W 256 #define GFX_MAX_CACHED_W 256
#define GFX_MAX_CACHED_H 256 #define GFX_MAX_CACHED_H 256
@ -8,7 +8,13 @@
#define LINK_CACHE_SIZE 64 #define LINK_CACHE_SIZE 64
*/ */
#if SDL_VERSION_ATLEAST(1,3,0)
typedef int gtimer_t;
#define NULL_TIMER 0
#else
typedef void* gtimer_t; typedef void* gtimer_t;
#define NULL_TIMER NULL
#endif
typedef void* img_t; typedef void* img_t;
typedef void* fnt_t; typedef void* fnt_t;
typedef void* layout_t; typedef void* layout_t;
@ -81,7 +87,7 @@ extern img_t gfx_display_alpha(img_t src);
extern img_t gfx_scale(img_t src, float xscale, float yscale); extern img_t gfx_scale(img_t src, float xscale, float yscale);
extern void gfx_draw_bg(img_t p, int x, int y, int width, int height); extern void gfx_draw_bg(img_t p, int x, int y, int width, int height);
extern void gfx_draw_from(img_t p, int x, int y, int xx, int yy, int width, int height); extern void gfx_draw_from(img_t p, int x, int y, int xx, int yy, int width, int height);
extern void gfx_cursor(int *xp, int *yp, int *w, int *h); extern void gfx_cursor(int *xp, int *yp);
extern void gfx_warp_cursor(int x, int y); extern void gfx_warp_cursor(int x, int y);
extern void gfx_change_screen(img_t src, int steps); extern void gfx_change_screen(img_t src, int steps);
extern int gfx_fading(void); extern int gfx_fading(void);

View file

@ -67,10 +67,9 @@ int input(struct inp_event *inp, int wait)
rc = SDL_PollEvent(&event); rc = SDL_PollEvent(&event);
if (!rc) if (!rc)
return 0; return 0;
inp->sym = NULL; inp->sym[0] = 0;
inp->type = 0; inp->type = 0;
inp->count = 1; inp->count = 1;
switch(event.type){ switch(event.type){
case SDL_ACTIVEEVENT: case SDL_ACTIVEEVENT:
if (event.active.state & SDL_APPACTIVE) { if (event.active.state & SDL_APPACTIVE) {
@ -88,7 +87,11 @@ int input(struct inp_event *inp, int wait)
mouse_cursor(1); /* is it hack?*/ mouse_cursor(1); /* is it hack?*/
} }
} }
#if SDL_VERSION_ATLEAST(1,3,0)
if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_ACTIVEEVENT, SDL_ACTIVEEVENT) > 0)
#else
if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_EVENTMASK(SDL_ACTIVEEVENT)) > 0) if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_EVENTMASK(SDL_ACTIVEEVENT)) > 0)
#endif
return AGAIN; /* to avoid flickering */ return AGAIN; /* to avoid flickering */
return 0; return 0;
case SDL_USEREVENT: { case SDL_USEREVENT: {
@ -102,19 +105,27 @@ int input(struct inp_event *inp, int wait)
case SDL_KEYDOWN: //A key has been pressed case SDL_KEYDOWN: //A key has been pressed
inp->type = KEY_DOWN; inp->type = KEY_DOWN;
inp->code = event.key.keysym.scancode; inp->code = event.key.keysym.scancode;
inp->sym = SDL_GetKeyName(event.key.keysym.sym); strncpy(inp->sym, SDL_GetKeyName(event.key.keysym.sym), sizeof(inp->sym));
inp->sym[sizeof(inp->sym) - 1] = 0;
tolow(inp->sym);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
inp->type = KEY_UP; inp->type = KEY_UP;
inp->code = event.key.keysym.scancode; inp->code = event.key.keysym.scancode;
inp->sym = SDL_GetKeyName(event.key.keysym.sym); strncpy(inp->sym, SDL_GetKeyName(event.key.keysym.sym), sizeof(inp->sym));
inp->sym[sizeof(inp->sym) - 1] = 0;
tolow(inp->sym);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
m_focus = 1; /* ahhh */ m_focus = 1; /* ahhh */
inp->type = MOUSE_MOTION; inp->type = MOUSE_MOTION;
inp->x = event.button.x; inp->x = event.button.x;
inp->y = event.button.y; inp->y = event.button.y;
#if SDL_VERSION_ATLEAST(1,3,0)
while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
#else
while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)) > 0) { while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)) > 0) {
#endif
inp->x = peek.button.x; inp->x = peek.button.x;
inp->y = peek.button.y; inp->y = peek.button.y;
} }
@ -139,7 +150,11 @@ int input(struct inp_event *inp, int wait)
inp->type = MOUSE_WHEEL_UP; inp->type = MOUSE_WHEEL_UP;
else if (event.button.button == 5) else if (event.button.button == 5)
inp->type = MOUSE_WHEEL_DOWN; inp->type = MOUSE_WHEEL_DOWN;
#if SDL_VERSION_ATLEAST(1,3,0)
while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN) > 0) {
#else
while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEBUTTONDOWN)) > 0) { while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEBUTTONDOWN)) > 0) {
#endif
if (!((event.button.button == 4 && if (!((event.button.button == 4 &&
inp->type == MOUSE_WHEEL_UP) || inp->type == MOUSE_WHEEL_UP) ||
(event.button.button == 5 && (event.button.button == 5 &&

View file

@ -14,7 +14,7 @@
struct inp_event { struct inp_event {
int type; int type;
int code; int code;
char *sym; char sym[64];
int x; int x;
int y; int y;
int count; int count;

View file

@ -7,7 +7,7 @@
/* the Lua interpreter */ /* the Lua interpreter */
static gtimer_t instead_timer = NULL; static gtimer_t instead_timer = NULL_TIMER;
static int instead_timer_nr = 0; static int instead_timer_nr = 0;
char *fromgame(const char *s); char *fromgame(const char *s);
@ -29,7 +29,7 @@ static int report (lua_State *L, int status)
lua_pop(L, 1); lua_pop(L, 1);
status = -1; status = -1;
gfx_del_timer(instead_timer); /* to avoid error loops */ gfx_del_timer(instead_timer); /* to avoid error loops */
instead_timer = NULL; instead_timer = NULL_TIMER;
} }
return status; return status;
} }
@ -491,7 +491,7 @@ static int luaB_set_timer(lua_State *L) {
const char *delay = luaL_optstring(L, 1, NULL); const char *delay = luaL_optstring(L, 1, NULL);
int d; int d;
gfx_del_timer(instead_timer); gfx_del_timer(instead_timer);
instead_timer = NULL; instead_timer = NULL_TIMER;
if (!delay) if (!delay)
d = 0; d = 0;
else else
@ -613,7 +613,7 @@ int instead_init(void)
void instead_done(void) void instead_done(void)
{ {
gfx_del_timer(instead_timer); gfx_del_timer(instead_timer);
instead_timer = NULL; instead_timer = NULL_TIMER;
#ifdef _HAVE_ICONV #ifdef _HAVE_ICONV
if (fromcp) if (fromcp)
free(fromcp); free(fromcp);

View file

@ -18,7 +18,7 @@ static mus_t mus;
static char *next_mus = NULL; static char *next_mus = NULL;
static int next_fadein = 0; static int next_fadein = 0;
static int next_loop = -1; static int next_loop = -1;
static SDL_TimerID timer_id = NULL; static SDL_TimerID timer_id = NULL_TIMER;
static int sound_on = 0; static int sound_on = 0;
@ -42,7 +42,7 @@ static void mus_callback(void *aux)
next_mus = NULL; next_mus = NULL;
} }
SDL_RemoveTimer(timer_id); SDL_RemoveTimer(timer_id);
timer_id = NULL; timer_id = NULL_TIMER;
} }
static Uint32 callback(Uint32 interval, void *aux) static Uint32 callback(Uint32 interval, void *aux)
@ -273,7 +273,7 @@ void snd_done(void)
Mix_HaltChannel(-1); Mix_HaltChannel(-1);
Mix_HaltMusic(); Mix_HaltMusic();
timer_id = NULL; timer_id = NULL_TIMER;
if (mus) if (mus)
snd_free_mus(mus); snd_free_mus(mus);
mus = NULL; mus = NULL;