25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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