Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

171 rinda
4.9 KiB

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