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.

caca++.h 6.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. #include <caca_internals.h>
  24. #undef __class
  25. #if defined(_WIN32) && defined(__LIBCACA_PP__)
  26. # define __class class __declspec(dllexport)
  27. #else
  28. # define __class class
  29. #endif
  30. class Canvas;
  31. __class Charset
  32. {
  33. public:
  34. uint32_t utf8ToUtf32(char const *, size_t *);
  35. size_t utf32ToUtf8(char *, uint32_t);
  36. uint8_t utf32ToCp437(uint32_t);
  37. uint32_t cp437ToUtf32(uint8_t);
  38. };
  39. /* Ugly, I know */
  40. __class Font
  41. {
  42. public:
  43. ~Font();
  44. Font(void const *, unsigned int);
  45. char const *const * getList(void);
  46. unsigned int getWidth();
  47. unsigned int getHeight();
  48. void renderCanvas(Canvas *, uint8_t *, unsigned int,
  49. unsigned int, unsigned int);
  50. uint32_t const *getBlocks();
  51. private:
  52. caca_font *font;
  53. };
  54. __class Dither
  55. {
  56. public:
  57. Dither(unsigned int, unsigned int, unsigned int, unsigned int,
  58. unsigned int, unsigned int, unsigned int, unsigned int);
  59. ~Dither();
  60. void setPalette(uint32_t r[], uint32_t g[],
  61. uint32_t b[], uint32_t a[]);
  62. void setBrightness(float);
  63. void setGamma(float);
  64. void setContrast(float);
  65. void setAntialias(char const *);
  66. char const *const * getAntialiasList();
  67. void setColor(char const *);
  68. char const *const * getColorList();
  69. void setCharset(char const *);
  70. char const *const * getCharsetList();
  71. void setMode(char const *);
  72. char const *const * getModeList();
  73. void Bitmap(Canvas *, int, int, int, int, void *);
  74. private:
  75. caca_dither *dither;
  76. };
  77. __class Canvas
  78. {
  79. friend class Caca;
  80. friend class Dither;
  81. friend class Font;
  82. public:
  83. Canvas();
  84. Canvas(int width, int height);
  85. ~Canvas();
  86. void setSize(unsigned int w, unsigned int h);
  87. unsigned int getWidth(void);
  88. unsigned int getHeight(void);
  89. uint32_t getAttr(int, int);
  90. int setAttr(uint32_t);
  91. int setColorANSI(uint8_t f, uint8_t b);
  92. int setColorARGB(unsigned int f, unsigned int b);
  93. void Printf(int x, int y , char const * format, ...);
  94. void putChar(int x, int y, uint32_t ch);
  95. uint32_t getChar(int, int);
  96. void putStr(int x, int y, char *str);
  97. void Clear(void);
  98. void Blit(int, int, Canvas* c1, Canvas* c2);
  99. void Invert();
  100. void Flip();
  101. void Flop();
  102. void Rotate180();
  103. void RotateLeft();
  104. void RotateRight();
  105. void drawLine(int, int, int, int, uint32_t);
  106. void drawPolyline(int const x[], int const y[], int, uint32_t);
  107. void drawThinLine(int, int, int, int);
  108. void drawThinPolyline(int const x[], int const y[], int);
  109. void drawCircle(int, int, int, uint32_t);
  110. void drawEllipse(int, int, int, int, uint32_t);
  111. void drawThinEllipse(int, int, int, int);
  112. void fillEllipse(int, int, int, int, uint32_t);
  113. void drawBox(int, int, int, int, uint32_t);
  114. void drawThinBox(int, int, int, int);
  115. void drawCP437Box(int, int, int, int);
  116. void fillBox(int, int, int, int, uint32_t);
  117. void drawTriangle(int, int, int, int, int, int, uint32_t);
  118. void drawThinTriangle(int, int, int, int, int, int);
  119. void fillTriangle(int, int, int, int, int, int, uint32_t);
  120. void fillTriangleTextured(int coords[6], Canvas *tex, float uv[6]);
  121. int setBoundaries(caca_canvas_t *, int, int, unsigned int, unsigned int);
  122. unsigned int getFrameCount();
  123. int setFrame(unsigned int);
  124. int createFrame(unsigned int);
  125. int freeFrame(unsigned int);
  126. char const * const * getImportList(void);
  127. long int importFromMemory(void const *, size_t, char const *);
  128. long int importFromFile(char const *, char const *);
  129. char const * const * getExportList(void);
  130. void *exportToMemory(char const *, size_t *);
  131. static int Rand(int, int);
  132. static char const * getVersion();
  133. protected:
  134. caca_canvas_t *get_caca_canvas_t();
  135. private:
  136. caca_canvas_t *cv;
  137. };
  138. __class Event
  139. {
  140. friend class Caca;
  141. public:
  142. enum caca_event_type
  143. {
  144. CACA_EVENT_NONE = 0x0000, /**< No event. */
  145. CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */
  146. CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */
  147. CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */
  148. CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
  149. CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */
  150. CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */
  151. CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */
  152. } type;
  153. int caca_get_event_key_ch();
  154. enum caca_event_type caca_get_event_type();
  155. uint32_t caca_get_event_key_utf32();
  156. int caca_get_event_key_utf8(char *utf8);
  157. int caca_get_event_mouse_button();
  158. int caca_get_event_mouse_x();
  159. int caca_get_event_mouse_y();
  160. int caca_get_event_resize_width();
  161. int caca_get_event_resize_height();
  162. protected:
  163. caca_event_t e;
  164. };
  165. __class Caca
  166. {
  167. public:
  168. Caca();
  169. Caca(Canvas *cv);
  170. ~Caca();
  171. void Attach(Canvas *cv);
  172. void Detach();
  173. void setDisplayTime(unsigned int);
  174. void Display();
  175. unsigned int getDisplayTime();
  176. unsigned int getWidth();
  177. unsigned int getHeight();
  178. int setTitle(char const *);
  179. int getEvent(unsigned int, Event*, int);
  180. unsigned int getMouseX();
  181. unsigned int getMouseY();
  182. void setMouse(int);
  183. static char const * getVersion();
  184. private:
  185. caca_display_t *dp;
  186. };
  187. #endif /* _CACA_PP_H */