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.

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