You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

205 lines
5.7 KiB

  1. /*
  2. * libcaca++ C++ bindings for libcaca
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /** \file caca++.h
  15. * \version \$Id$
  16. * \author Jean-Yves Lamoureux <jylam@lnxscene.org>
  17. * \brief The \e libcaca++ public header.
  18. *
  19. * This header contains the public types and functions that applications
  20. * using \e libcaca++ may use.
  21. */
  22. #ifndef _CACA_PP_H
  23. #define _CACA_PP_H
  24. #include <caca.h>
  25. #undef __class
  26. #if defined(_WIN32) && defined(__LIBCACA_PP__)
  27. # define __class class __declspec(dllexport)
  28. #else
  29. # define __class class
  30. #endif
  31. class Canvas;
  32. __class Charset
  33. {
  34. public:
  35. uint32_t utf8ToUtf32(char const *, size_t *);
  36. size_t utf32ToUtf8(char *, uint32_t);
  37. uint8_t utf32ToCp437(uint32_t);
  38. uint32_t cp437ToUtf32(uint8_t);
  39. };
  40. /* Ugly, I know */
  41. __class Font
  42. {
  43. public:
  44. ~Font();
  45. Font(void const *, unsigned int);
  46. char const *const * getList(void);
  47. unsigned int getWidth();
  48. unsigned int getHeight();
  49. void renderCanvas(Canvas *, uint8_t *, unsigned int,
  50. unsigned int, unsigned int);
  51. uint32_t const *getBlocks();
  52. private:
  53. caca_font *font;
  54. };
  55. __class Dither
  56. {
  57. public:
  58. Dither(unsigned int, unsigned int, unsigned int, unsigned int,
  59. unsigned int, unsigned int, unsigned int, unsigned int);
  60. ~Dither();
  61. void setPalette(uint32_t r[], uint32_t g[],
  62. uint32_t b[], uint32_t a[]);
  63. void setBrightness(float);
  64. void setGamma(float);
  65. void setContrast(float);
  66. void setAntialias(char const *);
  67. char const *const * getAntialiasList();
  68. void setColor(char const *);
  69. char const *const * getColorList();
  70. void setCharset(char const *);
  71. char const *const * getCharsetList();
  72. void setMode(char const *);
  73. char const *const * getModeList();
  74. void Bitmap(Canvas *, int, int, int, int, void *);
  75. private:
  76. caca_dither *dither;
  77. };
  78. __class Canvas
  79. {
  80. friend class Caca;
  81. friend class Dither;
  82. friend class Font;
  83. public:
  84. Canvas();
  85. Canvas(int width, int height);
  86. ~Canvas();
  87. void setSize(unsigned int w, unsigned int h);
  88. unsigned int getWidth(void);
  89. unsigned int getHeight(void);
  90. uint32_t getAttr(int, int);
  91. int setAttr(uint32_t);
  92. int setColorANSI(uint8_t f, uint8_t b);
  93. int setColorARGB(unsigned int f, unsigned int b);
  94. void Printf(int x, int y , char const * format, ...);
  95. void putChar(int x, int y, uint32_t ch);
  96. uint32_t getChar(int, int);
  97. void putStr(int x, int y, char *str);
  98. void Clear(void);
  99. void Blit(int, int, Canvas* c1, Canvas* c2);
  100. void Invert();
  101. void Flip();
  102. void Flop();
  103. void Rotate180();
  104. void RotateLeft();
  105. void RotateRight();
  106. void drawLine(int, int, int, int, uint32_t);
  107. void drawPolyline(int const x[], int const y[], int, uint32_t);
  108. void drawThinLine(int, int, int, int);
  109. void drawThinPolyline(int const x[], int const y[], int);
  110. void drawCircle(int, int, int, uint32_t);
  111. void drawEllipse(int, int, int, int, uint32_t);
  112. void drawThinEllipse(int, int, int, int);
  113. void fillEllipse(int, int, int, int, uint32_t);
  114. void drawBox(int, int, int, int, uint32_t);
  115. void drawThinBox(int, int, int, int);
  116. void drawCP437Box(int, int, int, int);
  117. void fillBox(int, int, int, int, uint32_t);
  118. void drawTriangle(int, int, int, int, int, int, uint32_t);
  119. void drawThinTriangle(int, int, int, int, int, int);
  120. void fillTriangle(int, int, int, int, int, int, uint32_t);
  121. void fillTriangleTextured(int coords[6], Canvas *tex, float uv[6]);
  122. int setBoundaries(caca_canvas_t *, int, int, unsigned int, unsigned int);
  123. unsigned int getFrameCount();
  124. int setFrame(unsigned int);
  125. int createFrame(unsigned int);
  126. int freeFrame(unsigned int);
  127. char const * const * getImportList(void);
  128. long int importFromMemory(void const *, size_t, char const *);
  129. long int importFromFile(char const *, char const *);
  130. char const * const * getExportList(void);
  131. void *exportToMemory(char const *, size_t *);
  132. static int Rand(int, int);
  133. static char const * getVersion();
  134. protected:
  135. caca_canvas_t *get_caca_canvas_t();
  136. private:
  137. caca_canvas_t *cv;
  138. };
  139. __class Event
  140. {
  141. friend class Caca;
  142. public:
  143. enum caca_event_type
  144. {
  145. CACA_EVENT_NONE = 0x0000, /**< No event. */
  146. CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */
  147. CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */
  148. CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */
  149. CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
  150. CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */
  151. CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */
  152. CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */
  153. } type;
  154. protected:
  155. caca_event_t e;
  156. };
  157. __class Caca
  158. {
  159. public:
  160. Caca();
  161. Caca(Canvas *cv);
  162. ~Caca();
  163. void Attach(Canvas *cv);
  164. void Detach();
  165. void setDisplayTime(unsigned int);
  166. void Display();
  167. unsigned int getDisplayTime();
  168. unsigned int getWidth();
  169. unsigned int getHeight();
  170. int setTitle(char const *);
  171. int getEvent(unsigned int, Event*, int);
  172. unsigned int getMouseX();
  173. unsigned int getMouseY();
  174. void setMouse(int);
  175. static char const * getVersion();
  176. private:
  177. caca_display_t *dp;
  178. };
  179. #endif /* _CACA_PP_H */