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