source: libcaca/trunk/caca/graphics.c @ 769

Last change on this file since 769 was 769, checked in by Sam Hocevar, 14 years ago
  • Removed \file directives from all files except caca.h and cucul.h, to remove redundencies in the Doxygen documentation.
  • Property svn:keywords set to Id
File size: 4.9 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: graphics.c 769 2006-04-14 07:30:53Z sam $
7 *
8 *  This library is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14/*
15 *  This file contains character and string drawing functions.
16 */
17
18#include "config.h"
19
20#include "caca.h"
21#include "caca_internals.h"
22#include "cucul.h"
23#include "cucul_internals.h"
24
25/** \brief Set the window title.
26 *
27 *  If libcaca runs in a window, try to change its title. This works with
28 *  the X11 and Win32 drivers.
29 *
30 *  \param title The desired window title.
31 *  \return 0 upon success, a non-zero value if an error occurs.
32 */
33int caca_set_window_title(caca_t *kk, char const *title)
34{
35    return kk->drv.set_window_title(kk, title);
36}
37
38/** \brief Get the window width.
39 *
40 *  If libcaca runs in a window, get the usable window width. This value can
41 *  be used for aspect ratio calculation. If libcaca does not run in a window
42 *  or if there is no way to know the font size, most drivers will assume a
43 *  6x10 font is being used. Note that the units are not necessarily pixels.
44 *
45 *  \return The window width.
46 */
47unsigned int caca_get_window_width(caca_t *kk)
48{
49    return kk->drv.get_window_width(kk);
50}
51
52/** \brief Get the window height.
53 *
54 *  If libcaca runs in a window, get the usable window height. This value can
55 *  be used for aspect ratio calculation. If libcaca does not run in a window
56 *  or if there is no way to know the font size, assume a 6x10 font is being
57 *  used. Note that the units are not necessarily pixels.
58 *
59 *  \return The window height.
60 */
61unsigned int caca_get_window_height(caca_t *kk)
62{
63    return kk->drv.get_window_height(kk);
64}
65
66/** \brief Set the refresh delay.
67 *
68 *  This function sets the refresh delay in microseconds. The refresh delay
69 *  is used by caca_display() to achieve constant framerate. See the
70 *  caca_display() documentation for more details.
71 *
72 *  If the argument is zero, constant framerate is disabled. This is the
73 *  default behaviour.
74 *
75 *  \param usec The refresh delay in microseconds.
76 */
77void caca_set_delay(caca_t *kk, unsigned int usec)
78{
79    kk->delay = usec;
80}
81
82/** \brief Get the average rendering time.
83 *
84 *  This function returns the average rendering time, which is the average
85 *  measured time between two caca_display() calls, in microseconds. If
86 *  constant framerate was activated by calling caca_set_delay(), the average
87 *  rendering time will not be considerably shorter than the requested delay
88 *  even if the real rendering time was shorter.
89 *
90 *  \return The render time in microseconds.
91 */
92unsigned int caca_get_rendertime(caca_t *kk)
93{
94    return kk->rendertime;
95}
96
97/** \brief Flush pending changes and redraw the screen.
98 *
99 *  This function flushes all graphical operations and prints them to the
100 *  screen. Nothing will show on the screen until caca_display() is
101 *  called.
102 *
103 *  If caca_set_delay() was called with a non-zero value, caca_display()
104 *  will use that value to achieve constant framerate: if two consecutive
105 *  calls to caca_display() are within a time range shorter than the value
106 *  set with caca_set_delay(), the second call will wait a bit before
107 *  performing the screen refresh.
108 */
109void caca_display(caca_t *kk)
110{
111#if !defined(_DOXYGEN_SKIP_ME)
112#define IDLE_USEC 10000
113#endif
114    int ticks = kk->lastticks + _caca_getticks(&kk->timer);
115
116    kk->drv.display(kk);
117
118    /* Once the display is finished, we can ack resizes */
119    if(kk->resize.resized)
120    {
121        kk->resize.resized = 0;
122        _caca_handle_resize(kk);
123    }
124
125    /* Wait until kk->delay + time of last call */
126    ticks += _caca_getticks(&kk->timer);
127    for(ticks += _caca_getticks(&kk->timer);
128        ticks + IDLE_USEC < (int)kk->delay;
129        ticks += _caca_getticks(&kk->timer))
130    {
131        _caca_sleep(IDLE_USEC);
132    }
133
134    /* Update the sliding mean of the render time */
135    kk->rendertime = (7 * kk->rendertime + ticks) / 8;
136
137    kk->lastticks = ticks - kk->delay;
138
139    /* If we drifted too much, it's bad, bad, bad. */
140    if(kk->lastticks > (int)kk->delay)
141        kk->lastticks = 0;
142}
143
144/** \brief Show or hide the mouse pointer.
145 *
146 *  This function shows or hides the mouse pointer, for devices that
147 *  support it.
148 *
149 *  \param flag 0 hides the pointer, 1 shows the system's default pointer
150 *              (usually an arrow). Other values are reserved for future use.
151 */
152void caca_set_mouse(caca_t *kk, int flag)
153{
154    if(kk->drv.set_mouse)
155        kk->drv.set_mouse(kk, flag);
156}
157
158/*
159 * XXX: following functions are local
160 */
161
162void _caca_handle_resize(caca_t *kk)
163{
164    kk->drv.handle_resize(kk);
165
166    /* Tell libcucul we changed size */
167    if(kk->resize.w != kk->qq->width || kk->resize.h != kk->qq->height)
168        _cucul_set_size(kk->qq, kk->resize.w, kk->resize.h);
169}
170
Note: See TracBrowser for help on using the repository browser.