From 8b7bd031a724aeaabe47c9645f00dcf55dd86cf6 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 18 Jan 2004 04:17:35 +0000 Subject: [PATCH] * src/graphics.c: + When resizing under X11, copy the old pixmap to the new one. * examples/cacaview.c: + Resizing support. --- examples/cacaview.c | 23 +++++++++++++++++------ src/event.c | 4 ++-- src/graphics.c | 11 +++++++++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/cacaview.c b/examples/cacaview.c index 3b25708..57e33d2 100644 --- a/examples/cacaview.c +++ b/examples/cacaview.c @@ -111,21 +111,22 @@ int main(int argc, char **argv) /* Go ! */ while(!quit) { - int ww = caca_get_width(); - int wh = caca_get_height(); - + int ww, wh; unsigned int event, new_status = 0, new_help = 0; + ww = caca_get_width(); + wh = caca_get_height(); + if(update) - event = caca_get_event(CACA_EVENT_KEY_PRESS); + event = caca_get_event(CACA_EVENT_KEY_PRESS | CACA_EVENT_RESIZE); else - event = caca_wait_event(CACA_EVENT_KEY_PRESS); + event = caca_wait_event(CACA_EVENT_KEY_PRESS | CACA_EVENT_RESIZE); while(event) { unsigned int key = event & 0x00ffffff; - switch(key) + if(key) switch(key) { case 'n': case 'N': @@ -231,6 +232,14 @@ int main(int argc, char **argv) break; } + if(event == CACA_EVENT_RESIZE) + { + caca_refresh(); + ww = caca_get_width(); + wh = caca_get_height(); + update = 1; + } + if(status || new_status) status = new_status; @@ -258,6 +267,8 @@ int main(int argc, char **argv) caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); caca_putstr((ww - strlen(buffer)) / 2, wh / 2, buffer); caca_refresh(); + ww = caca_get_width(); + wh = caca_get_height(); unload_image(); load_image(list[current]); diff --git a/src/event.c b/src/event.c index 3cb9cda..0d33643 100644 --- a/src/event.c +++ b/src/event.c @@ -273,10 +273,10 @@ static unsigned int _lowlevel_event(void) { unsigned int w, h; - h = (xevent.xconfigure.height + x11_font_height / 3) - / x11_font_height; w = (xevent.xconfigure.width + x11_font_width / 3) / x11_font_width; + h = (xevent.xconfigure.height + x11_font_height / 3) + / x11_font_height; if(w == _caca_width && h == _caca_height) continue; diff --git a/src/graphics.c b/src/graphics.c index 8287957..b50b9f7 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1320,18 +1320,25 @@ static void caca_handle_resize(void) #if defined(USE_X11) if(_caca_driver == CACA_DRIVER_X11) { + Pixmap new_pixmap; + _caca_width = x11_new_width; _caca_height = x11_new_height; - XFreePixmap(x11_dpy, x11_pixmap); free(x11_char); free(x11_attr); - x11_pixmap = XCreatePixmap(x11_dpy, x11_window, + new_pixmap = XCreatePixmap(x11_dpy, x11_window, _caca_width * x11_font_width, _caca_height * x11_font_height, DefaultDepth(x11_dpy, DefaultScreen(x11_dpy))); + XCopyArea(x11_dpy, x11_pixmap, new_pixmap, x11_gc, 0, 0, + old_width * x11_font_width, old_height * x11_font_height, + 0, 0); + XFreePixmap(x11_dpy, x11_pixmap); + x11_pixmap = new_pixmap; + x11_char = malloc(_caca_width * _caca_height * sizeof(int)); memset(x11_char, 0, _caca_width * _caca_height * sizeof(int)); x11_attr = malloc(_caca_width * _caca_height * sizeof(int));