Browse Source

* src/graphics.c:

+ Resize handling in the ncurses and slang drivers.
tags/v0.99.beta14
Sam Hocevar sam 21 years ago
parent
commit
7d22f724d8
3 changed files with 70 additions and 9 deletions
  1. +5
    -2
      configure.ac
  2. +5
    -1
      msvc/config.h
  3. +60
    -6
      src/graphics.c

+ 5
- 2
configure.ac View File

@@ -15,6 +15,7 @@ AC_PROG_RANLIB

AC_C_CONST
AC_C_INLINE
AC_TYPE_SIGNAL

dnl AC_PROG_EGREP only exists in autoconf 2.54+, so we use AC_EGREP_CPP right
dnl now otherwise it might be set in an obscure if statement.
@@ -40,8 +41,10 @@ dnl conditional builds
AC_ARG_ENABLE(doc,
[ --enable-doc build documentation (needs doxygen and LaTeX)])

AC_CHECK_HEADERS(sys/time.h inttypes.h endian.h unistd.h)
AC_CHECK_FUNCS(vsnprintf _vsnprintf getenv putenv strcasecmp usleep gettimeofday)
AC_CHECK_HEADERS(signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h)
AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp)
AC_CHECK_FUNCS(usleep gettimeofday)

AC_MSG_CHECKING(for Sleep)
AC_TRY_COMPILE([#include <windows.h>],[Sleep(42);],
[AC_MSG_RESULT(yes)


+ 5
- 1
msvc/config.h View File

@@ -10,6 +10,8 @@
#define HAVE_MEMORY_H 1
/* #undef HAVE_NCURSES_H */
#define HAVE_PUTENV 1
/* #undef HAVE_SIGNAL */
/* #undef HAVE_SIGNAL_H */
/* #undef HAVE_SLANG_H */
/* #undef HAVE_SLANG_SLANG_H */
#define HAVE_SLEEP 1
@@ -18,14 +20,15 @@
/* #undef HAVE_STRCASECMP */
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
/* #undef HAVE_SYS_IOCTL_H */
#define HAVE_SYS_STAT_H 1
/* #undef HAVE_SYS_TIME_H */
#define HAVE_SYS_TYPES_H 1
/* #undef HAVE_UNISTD_H */
/* #undef HAVE_USLEEP */
/* #undef HAVE_VSNPRINTF */
#define HAVE_WINDOWS_H 1
/* #undef HAVE_X11_XKBLIB_H */
#define HAVE__VSNPRINTF 1
/* #undef NO_MINUS_C_MINUS_O */
#define PACKAGE "libcaca"
#define PACKAGE_BUGREPORT ""
@@ -33,6 +36,7 @@
#define PACKAGE_STRING ""
#define PACKAGE_TARNAME ""
#define PACKAGE_VERSION ""
/* #undef RETSIGTYPE */
/* #undef SCREENUPDATE_IN_PC_H */
#define STDC_HEADERS 1
/* #undef USE_CONIO */


+ 60
- 6
src/graphics.c View File

@@ -69,6 +69,13 @@ typedef unsigned char uint8_t;
#endif
#include <stdarg.h>

#if defined(HAVE_SIGNAL_H)
# include <signal.h>
#endif
#if defined(HAVE_SYS_IOCTL_H)
# include <sys/ioctl.h>
#endif

#include "caca.h"
#include "caca_internals.h"

@@ -239,6 +246,10 @@ static void caca_handle_resize(void);
static void slang_init_palette(void);
#endif

#if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG))
static RETSIGTYPE sigwinch_handler(int);
#endif

#if defined(USE_X11)
static int x11_error_handler(Display *, XErrorEvent *);
#endif
@@ -563,6 +574,10 @@ void caca_clear(void)
#if !defined(_DOXYGEN_SKIP_ME)
int _caca_init_graphics(void)
{
#if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG))
signal(SIGWINCH, sigwinch_handler);
#endif

#if defined(USE_SLANG)
if(_caca_driver == CACA_DRIVER_SLANG)
{
@@ -1202,23 +1217,29 @@ static void caca_handle_resize(void)
_caca_width = _caca_new_width;
_caca_height = _caca_new_height;

free(_caca_empty_line);
_caca_empty_line = malloc(_caca_width + 1);
memset(_caca_empty_line, ' ', _caca_width);
_caca_empty_line[_caca_width] = '\0';
if(_caca_width != old_width)
{
free(_caca_empty_line);
_caca_empty_line = malloc(_caca_width + 1);
memset(_caca_empty_line, ' ', _caca_width);
_caca_empty_line[_caca_width] = '\0';

free(_caca_scratch_line);
_caca_scratch_line = malloc(_caca_width + 1);
free(_caca_scratch_line);
_caca_scratch_line = malloc(_caca_width + 1);
}

#if defined(USE_SLANG)
if(_caca_driver == CACA_DRIVER_SLANG)
{
SLsmg_reinit_smg();
}
else
#endif
#if defined(USE_NCURSES)
if(_caca_driver == CACA_DRIVER_NCURSES)
{
resize_term(_caca_height, _caca_width);
wrefresh(curscr);
}
else
#endif
@@ -1311,3 +1332,36 @@ static int x11_error_handler(Display *dpy, XErrorEvent *event)
}
#endif

#if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG))
static RETSIGTYPE sigwinch_handler(int sig)
{
struct winsize size;

#if defined(USE_SLANG)
if(_caca_driver == CACA_DRIVER_SLANG)
{
SLtt_get_screen_size();
_caca_new_width = SLtt_Screen_Cols;
_caca_new_height = SLtt_Screen_Rows;
}
else
#endif
#if defined(USE_NCURSES)
if(_caca_driver == CACA_DRIVER_NCURSES)
{
if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
{
_caca_new_width = size.ws_col;
_caca_new_height = size.ws_row;
}
}
else
#endif
{
/* Dummy */
}

signal(SIGWINCH, sigwinch_handler);;
}
#endif


Loading…
Cancel
Save