From e4a540868932f3a8c294ba0e075465339cb7a3d6 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 17 Jan 2004 22:32:39 +0000 Subject: [PATCH] * src/graphics.c: + Renamed caca_set_title() to caca_set_window_title(). + Implemented caca_get_window_width() and caca_get_window_height(). * examples/cacaview.c: + Set the window title to cacaview. --- TODO | 6 ++-- examples/cacaview.c | 2 +- src/caca.h | 4 ++- src/graphics.c | 68 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 459f120..ed635ec 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,7 @@ Low level stuff o Better keyboard driver in an X terminal, see http://groups.yahoo.com/group/zepp/message/381 - o Write a window resize handler. - + o DONE 13 Jan 2004: Write a window resize handler. o DONE 12 Nov 2003: Port to conio.h @@ -21,11 +20,10 @@ High level stuff o Alpha layer for sprites - o Clip all graphics primitives - o Fix the thin ellipse rendering o DONE 26 Nov 2003: Support more colour depths, more bitmask orderings + o DONE 15 Nov 2003: Clip all graphics primitives Misc diff --git a/examples/cacaview.c b/examples/cacaview.c index 5ee13af..3b25708 100644 --- a/examples/cacaview.c +++ b/examples/cacaview.c @@ -84,7 +84,7 @@ int main(int argc, char **argv) } /* Set the window title */ - caca_set_title("cacaview"); + caca_set_window_title("cacaview"); /* Load items into playlist */ for(i = 1; i < argc; i++) diff --git a/src/caca.h b/src/caca.h index c781741..84d251d 100644 --- a/src/caca.h +++ b/src/caca.h @@ -246,7 +246,9 @@ char const *caca_get_feature_name(enum caca_feature); unsigned int caca_get_rendertime(void); unsigned int caca_get_width(void); unsigned int caca_get_height(void); -int caca_set_title(char const *); +int caca_set_window_title(char const *); +unsigned int caca_get_window_width(void); +unsigned int caca_get_window_height(void); void caca_refresh(void); void caca_end(void); /* @} */ diff --git a/src/graphics.c b/src/graphics.c index f52ab48..796b674 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -979,7 +979,7 @@ int _caca_end_graphics(void) * \param title The desired window title. * \return 0 upon success, a non-zero value if an error occurs. */ -int caca_set_title(char const *title) +int caca_set_window_title(char const *title) { #if defined(USE_X11) if(_caca_driver == CACA_DRIVER_X11) @@ -1003,6 +1003,72 @@ int caca_set_title(char const *title) return 0; } +/** \brief Get the window width. + * + * If libcaca runs in a window, get the usable window width. This value can + * be used for aspect ratio calculation. If libcaca does not run in a window + * or if there is no way to know the font size, assume a 6x10 font is being + * used. Note that the units are not necessarily pixels. + * + * \return The window width. + */ +unsigned int caca_get_window_width(void) +{ +#if defined(USE_X11) + if(_caca_driver == CACA_DRIVER_X11) + { + return _caca_width * x11_font_width; + } + else +#endif +#if defined(USE_WIN32) + if(_caca_driver == CACA_DRIVER_WIN32) + { + /* FIXME */ + } + else +#endif + { + /* Dummy */ + } + + /* Fallback to a 6x10 font */ + return _caca_width * 6; +} + +/** \brief Get the window height. + * + * If libcaca runs in a window, get the usable window height. This value can + * be used for aspect ratio calculation. If libcaca does not run in a window + * or if there is no way to know the font size, assume a 6x10 font is being + * used. Note that the units are not necessarily pixels. + * + * \return The window height. + */ +unsigned int caca_get_window_height(void) +{ +#if defined(USE_X11) + if(_caca_driver == CACA_DRIVER_X11) + { + return _caca_height * x11_font_height; + } + else +#endif +#if defined(USE_WIN32) + if(_caca_driver == CACA_DRIVER_WIN32) + { + /* FIXME */ + } + else +#endif + { + /* Dummy */ + } + + /* Fallback to a 6x10 font */ + return _caca_height * 10; +} + /** \brief Set the refresh delay. * * This function sets the refresh delay in microseconds. The refresh delay