Kaynağa Gözat

* src/graphics.c src/io.c:

+ Beginning of an X11 driver. Currently we merely open the window and
      check keyboard events.
tags/v0.99.beta14
Sam Hocevar sam 21 yıl önce
ebeveyn
işleme
19c757c91e
5 değiştirilmiş dosya ile 127 ekleme ve 1 silme
  1. +16
    -0
      configure.ac
  2. +11
    -1
      src/caca.c
  3. +7
    -0
      src/caca_internals.h
  4. +73
    -0
      src/graphics.c
  5. +20
    -0
      src/io.c

+ 16
- 0
configure.ac Dosyayı Görüntüle

@@ -23,6 +23,8 @@ AC_ARG_ENABLE(slang,
[ --enable-slang slang graphics support (default disabled)])
AC_ARG_ENABLE(conio,
[ --enable-conio DOS conio.h graphics support (default disabled)])
AC_ARG_ENABLE(x11,
[ --enable-x11 X11 support (default disabled)])

AC_CHECK_HEADERS(inttypes.h endian.h)
AC_CHECK_FUNCS(vsnprintf getenv putenv strcasecmp)
@@ -41,6 +43,20 @@ elif test "${enable_slang}" = "yes"; then
AC_CHECK_LIB(slang,SLkp_init,:,AC_MSG_ERROR([cannot find slang library]))
AC_DEFINE(USE_SLANG, 1, Define if the backend driver is slang)
CACA_LIBS="${CACA_LIBS} -lslang"
elif test "${enable_x11}" = "yes"; then
AC_PATH_X
AC_CHECK_LIB(X11, XOpenDisplay,
[ac_cv_my_have_x11=yes
X_CFLAGS="-I${x_includes}"
X_LIBS="-lX11 -L${x_libraries}"],
[ac_cv_my_have_x11=no],
[[-lXt -L${x_libraries}]])
if test "${ac_cv_my_have_x11}" != "yes"; then
AC_MSG_ERROR([cannot find X11 development files])
fi
AC_DEFINE(USE_X11, 1, Define if the backend driver is X11)
CPPFLAGS="${CPPFLAGS} ${X_CFLAGS}"
CACA_LIBS="${CACA_LIBS} ${X_LIBS}"
elif test "${enable_ncurses}" != "no"; then
AC_CHECK_HEADER(ncurses.h,:,AC_MSG_ERROR([cannot find ncurses headers]))
AC_CHECK_LIB(ncurses,initscr,:,AC_MSG_ERROR([cannot find ncurses library]))


+ 11
- 1
src/caca.c Dosyayı Görüntüle

@@ -38,6 +38,8 @@
#elif defined(USE_CONIO)
# include <dos.h>
# include <conio.h>
#elif defined(USE_X11)
# include <X11/Xlib.h>
#else
# error "no graphics library detected"
#endif
@@ -113,6 +115,9 @@ int caca_init(void)
_setcursortype(_NOCURSOR);
clrscr();

#elif defined(USE_X11)
/* Nothing to do */

#endif
if(_caca_init_graphics())
return -1;
@@ -229,6 +234,8 @@ const char *caca_get_feature_name(enum caca_feature feature)

void caca_end(void)
{
_caca_end_graphics();

#if defined(USE_SLANG)
SLtt_set_mouse_mode(0, 0);
SLtt_set_cursor_visibility(1);
@@ -245,6 +252,8 @@ void caca_end(void)
gotoxy(_caca_width, _caca_height);
cputs("\r\n");
_setcursortype(_NORMALCURSOR);
#elif defined(USE_X11)
/* Nothing to do */
#endif
}

@@ -294,7 +303,8 @@ static void caca_init_features(void)

static void caca_init_terminal(void)
{
#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) \
&& (defined(USE_SLANG) || defined(USE_NCURSES))
char *term, *colorterm, *other;

term = getenv("TERM");


+ 7
- 0
src/caca_internals.h Dosyayı Görüntüle

@@ -31,6 +31,7 @@
#define __CACA_INTERNALS_H__

extern int _caca_init_graphics(void);
extern int _caca_end_graphics(void);

/* Cached screen size */
extern unsigned int _caca_width;
@@ -41,4 +42,10 @@ extern enum caca_feature _caca_background;
extern enum caca_feature _caca_dithering;
extern enum caca_feature _caca_antialiasing;

#if defined(USE_X11)
#include <X11/Xlib.h>
extern Display *_caca_dpy;
extern Window _caca_window;
#endif

#endif /* __CACA_INTERNALS_H__ */

+ 73
- 0
src/graphics.c Dosyayı Görüntüle

@@ -38,6 +38,8 @@
# if defined(SCREENUPDATE_IN_PC_H)
# include <pc.h>
# endif
#elif defined(USE_X11)
# include <X11/Xlib.h>
#else
# error "no graphics library detected"
#endif
@@ -75,6 +77,12 @@ static struct text_info ti;
static char *_caca_screen;
#endif

#if defined(USE_X11)
Display *_caca_dpy;
Window _caca_window;
GC _caca_gc;
#endif

static char *_caca_empty_line;
static char *_caca_scratch_line;

@@ -98,6 +106,8 @@ void caca_set_color(enum caca_color fgcolor, enum caca_color bgcolor)
#elif defined(USE_CONIO)
textbackground(bgcolor);
textcolor(fgcolor);
#elif defined(USE_X11)
/* FIXME */
#endif
}

@@ -132,6 +142,8 @@ void caca_putchar(int x, int y, char c)
data[1] = (_caca_bgcolor << 4) | _caca_fgcolor;
// gotoxy(x + 1, y + 1);
// putch(c);
#elif defined(USE_X11)
/* FIXME */
#endif
}

@@ -175,6 +187,8 @@ void caca_putstr(int x, int y, const char *s)
}
// gotoxy(x + 1, y + 1);
// cputs(s);
#elif defined(USE_X11)
/* FIXME */
#endif
}

@@ -335,6 +349,42 @@ int _caca_init_graphics(void)
_caca_width = ti.screenwidth;
_caca_height = ti.screenheight;

#elif defined(USE_X11)
int black_color;
int white_color;

_caca_dpy = XOpenDisplay(NULL);
if(_caca_dpy == NULL)
return -1;

black_color = BlackPixel(_caca_dpy, DefaultScreen(_caca_dpy));
white_color = WhitePixel(_caca_dpy, DefaultScreen(_caca_dpy));

_caca_window = XCreateSimpleWindow(_caca_dpy, DefaultRootWindow(_caca_dpy),
0, 0, 400, 300, 0,
black_color, black_color);
XSelectInput(_caca_dpy, _caca_window, StructureNotifyMask);
XMapWindow(_caca_dpy, _caca_window);

_caca_gc = XCreateGC(_caca_dpy, _caca_window, 0, NULL);
XSetForeground(_caca_dpy, _caca_gc, white_color);

for(;;)
{
XEvent event;
XNextEvent(_caca_dpy, &event);
if (event.type == MapNotify)
break;
}

XSelectInput(_caca_dpy, _caca_window, KeyPressMask);

/* FIXME */
_caca_width = 80;
_caca_height = 24;

XSync(_caca_dpy, False);

#endif
_caca_empty_line = malloc(_caca_width + 1);
memset(_caca_empty_line, ' ', _caca_width);
@@ -348,6 +398,26 @@ int _caca_init_graphics(void)
return 0;
}

int _caca_end_graphics(void)
{
#if defined(USE_SLANG)
/* Nothing to do */
#elif defined(USE_NCURSES)
/* Nothing to do */
#elif defined(USE_CONIO)
free(_caca_screen);
#elif defined(USE_X11)
XSync(_caca_dpy, False);
XFreeGC(_caca_dpy, _caca_gc);
XUnmapWindow(_caca_dpy, _caca_window);
XDestroyWindow(_caca_dpy, _caca_window);
XCloseDisplay(_caca_dpy);
#endif
free(_caca_empty_line);

return 0;
}

void caca_set_delay(unsigned int usec)
{
_caca_delay = usec;
@@ -394,6 +464,9 @@ void caca_refresh(void)
# else
/* FIXME */
# endif
#elif defined(USE_X11)
/* FIXME */
XFlush(_caca_dpy);
#endif

/* Wait until _caca_delay + time of last call */


+ 20
- 0
src/io.c Dosyayı Görüntüle

@@ -35,6 +35,9 @@
# include <curses.h>
#elif defined(USE_CONIO)
# include <conio.h>
#elif defined(USE_X11)
# include <X11/Xlib.h>
# include <X11/Xutil.h>
#else
# error "no graphics library detected"
#endif
@@ -204,6 +207,23 @@ static unsigned int _read_key(void)
return (key == ERR) ? 0 : key;
#elif defined(USE_CONIO)
return _conio_kbhit() ? getch() : 0;
#elif defined(USE_X11)
XEvent event;
char key;

while(XCheckWindowEvent(_caca_dpy, _caca_window, KeyPressMask, &event)
== True)
{
if(event.type == KeyPress)
{
//KeySym keysym;
//keysym = XKeycodeToKeysym(_caca_dpy, event.xkey.keycode, 0);
if(XLookupString(&event.xkey, &key, 1, NULL, NULL))
return key;
}
}

return 0;
#endif
}


Yükleniyor…
İptal
Kaydet