Changeset 2822 for libcaca/trunk/cxx
- Timestamp:
- Sep 27, 2008, 4:11:36 PM (12 years ago)
- Location:
- libcaca/trunk/cxx
- Files:
-
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cxx/Makefile.am
r2821 r2822 11 11 endif 12 12 13 libcaca___la_SOURCES = caca++.cpp c ucul++.cpp caca++.h13 libcaca___la_SOURCES = caca++.cpp caca++.h 14 14 libcaca___la_LDFLAGS = -no-undefined -version-number @LT_VERSION@ 15 15 libcaca___la_LIBADD = ../caca/libcaca.la -
libcaca/trunk/cxx/caca++.cpp
r2821 r2822 23 23 #include <iostream> 24 24 25 #include <stdio.h> // BUFSIZ 26 #include <stdarg.h> // va_* 27 25 28 #include "caca++.h" 29 30 uint32_t Charset::utf8ToUtf32(char const *s, size_t *read) 31 { 32 return caca_utf8_to_utf32(s, read); 33 } 34 size_t Charset::utf32ToUtf8(char *buf, uint32_t ch) 35 { 36 return caca_utf32_to_utf8(buf, ch); 37 } 38 uint8_t Charset::utf32ToCp437(uint32_t ch) 39 { 40 return caca_utf32_to_cp437(ch); 41 } 42 uint32_t Charset::cp437ToUtf32(uint8_t ch) 43 { 44 return caca_cp437_to_utf32(ch); 45 } 46 47 48 Canvas::Canvas() 49 { 50 cv = caca_create_canvas(0, 0); 51 if(!cv) 52 throw -1; 53 } 54 55 Canvas::Canvas(int width, int height) 56 { 57 cv = caca_create_canvas(width, height); 58 if(!cv) throw -1; 59 } 60 61 Canvas::~Canvas() 62 { 63 if(cv) 64 caca_free_canvas(cv); 65 } 66 67 caca_canvas_t *Canvas::get_caca_canvas_t() 68 { 69 return cv; 70 } 71 72 void Canvas::setSize(unsigned int width, unsigned int height) 73 { 74 caca_set_canvas_size(cv, width, height); 75 } 76 77 unsigned int Canvas::getWidth(void) 78 { 79 return caca_get_canvas_width(cv); 80 } 81 82 unsigned int Canvas::getHeight(void) 83 { 84 return caca_get_canvas_height(cv); 85 } 86 87 int Canvas::setColorANSI(uint8_t f, uint8_t b) 88 { 89 return caca_set_color_ansi(cv, f, b); 90 } 91 92 int Canvas::setColorARGB(unsigned int f, unsigned int b) 93 { 94 return caca_set_color_argb(cv, f, b); 95 } 96 97 void Canvas::putChar(int x, int y, uint32_t ch) 98 { 99 caca_put_char(cv, x, y, ch); 100 } 101 102 uint32_t Canvas::getChar(int x, int y) 103 { 104 return caca_get_char(cv, x, y); 105 } 106 107 void Canvas::putStr(int x, int y, char *str) 108 { 109 caca_put_str(cv, x, y, str); 110 } 111 112 void Canvas::Printf(int x, int y, char const * format, ...) 113 { 114 char tmp[BUFSIZ]; 115 char *buf = tmp; 116 va_list args; 117 118 va_start(args, format); 119 #if defined(HAVE_VSNPRINTF) 120 vsnprintf(buf, getWidth() - x + 1, format, args); 121 #else 122 vsprintf(buf, format, args); 123 #endif 124 buf[getWidth() - x] = '\0'; 125 va_end(args); 126 127 putStr(x, y, buf); 128 } 129 130 void Canvas::Clear(void) 131 { 132 caca_clear_canvas(cv); 133 } 134 135 void Canvas::Blit(int x, int y, Canvas* c1, Canvas* c2) 136 { 137 caca_blit(cv, x, y, c1->get_caca_canvas_t(), 138 c2 ? c2->get_caca_canvas_t() : NULL); 139 } 140 141 void Canvas::Invert() 142 { 143 caca_invert(cv); 144 } 145 146 void Canvas::Flip() 147 { 148 caca_flip(cv); 149 } 150 151 void Canvas::Flop() 152 { 153 caca_flop(cv); 154 } 155 156 void Canvas::Rotate180() 157 { 158 caca_rotate_180(cv); 159 } 160 161 void Canvas::RotateLeft() 162 { 163 caca_rotate_left(cv); 164 } 165 166 void Canvas::RotateRight() 167 { 168 caca_rotate_right(cv); 169 } 170 171 void Canvas::drawLine(int x1, int y1, int x2, int y2, uint32_t ch) 172 { 173 caca_draw_line(cv, x1, y1, x2, y2, ch); 174 } 175 176 void Canvas::drawPolyline(int const x[], int const y[], int f, uint32_t ch) 177 { 178 caca_draw_polyline(cv, x, y, f, ch); 179 } 180 181 void Canvas::drawThinLine(int x1, int y1, int x2, int y2) 182 { 183 caca_draw_thin_line(cv, x1, y1, x2, y2); 184 } 185 186 void Canvas::drawThinPolyline(int const x[], int const y[], int f) 187 { 188 caca_draw_thin_polyline(cv, x, y, f); 189 } 190 191 void Canvas::drawCircle(int x, int y, int d, uint32_t ch) 192 { 193 caca_draw_circle(cv, x, y, d, ch); 194 } 195 196 void Canvas::drawEllipse(int x, int y, int d1, int d2, uint32_t ch) 197 { 198 caca_draw_ellipse(cv, x, y, d1, d2, ch); 199 } 200 201 void Canvas::drawThinEllipse(int x, int y, int d1, int d2) 202 { 203 caca_draw_thin_ellipse(cv, x, y, d1, d2); 204 } 205 206 void Canvas::fillEllipse(int x, int y, int d1, int d2, uint32_t ch) 207 { 208 caca_fill_ellipse(cv, x, y, d1, d2, ch); 209 } 210 211 void Canvas::drawBox(int x, int y, int w, int h, uint32_t ch) 212 { 213 caca_draw_box(cv, x, y, w, h, ch); 214 } 215 216 void Canvas::drawThinBox(int x, int y, int w, int h) 217 { 218 caca_draw_thin_box(cv, x, y, w, h); 219 } 220 221 void Canvas::drawCP437Box(int x, int y, int w, int h) 222 { 223 caca_draw_cp437_box(cv, x, y, w, h); 224 } 225 226 void Canvas::fillBox(int x, int y, int w, int h, uint32_t ch) 227 { 228 caca_fill_box(cv, x, y, w, h, ch); 229 } 230 231 void Canvas::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, uint32_t ch) 232 { 233 caca_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch); 234 } 235 236 void Canvas::drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3) 237 { 238 caca_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3); 239 } 240 241 void Canvas::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, uint32_t ch) 242 { 243 caca_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch); 244 } 245 246 int Canvas::Rand(int min, int max) 247 { 248 return caca_rand(min, max); 249 } 250 251 const char * Canvas::getVersion() 252 { 253 return caca_get_version(); 254 } 255 256 int Canvas::setAttr(uint32_t attr) 257 { 258 return caca_set_attr(cv, attr); 259 } 260 261 uint32_t Canvas::getAttr(int x, int y) 262 { 263 return caca_get_attr(cv, x, y); 264 } 265 266 int Canvas::setBoundaries(caca_canvas_t *, int x, int y, 267 unsigned int w, unsigned int h) 268 { 269 return caca_set_canvas_boundaries(cv, x, y, h, w); 270 } 271 272 unsigned int Canvas::getFrameCount() 273 { 274 return caca_get_frame_count(cv); 275 } 276 int Canvas::setFrame(unsigned int f) 277 { 278 return caca_set_frame(cv, f); 279 } 280 int Canvas::createFrame(unsigned int f) 281 { 282 return caca_create_frame(cv, f); 283 } 284 int Canvas::freeFrame(unsigned int f) 285 { 286 return caca_create_frame(cv, f); 287 } 288 289 char const *const * Canvas::getImportList(void) 290 { 291 return caca_get_import_list(); 292 } 293 294 long int Canvas::importMemory(void const *buf, size_t len, char const *fmt) 295 { 296 return caca_import_memory(cv, buf, len, fmt); 297 } 298 299 long int Canvas::importFile(char const *file, char const *fmt) 300 { 301 return caca_import_file(cv, file, fmt); 302 } 303 304 char const *const * Canvas::getExportList(void) 305 { 306 return caca_get_export_list(); 307 } 308 309 void *Canvas::exportMemory(char const *fmt, size_t *len) 310 { 311 return caca_export_memory(cv, fmt, len); 312 } 313 314 Dither::Dither(unsigned int v1, unsigned int v2, unsigned int v3, unsigned int v4, unsigned int v5, unsigned int v6, unsigned int v7, unsigned int v8) 315 { 316 dither = caca_create_dither(v1, v2, v3, v4, v5, v6, v7, v8); 317 } 318 Dither::~Dither() 319 { 320 caca_free_dither(dither); 321 } 322 323 void Dither::setPalette(uint32_t r[], uint32_t g[], uint32_t b[], uint32_t a[]) 324 { 325 caca_set_dither_palette(dither, r, g, b, a); 326 } 327 328 void Dither::setBrightness(float f) 329 { 330 caca_set_dither_brightness(dither, f); 331 } 332 333 void Dither::setGamma(float f) 334 { 335 caca_set_dither_gamma(dither, f); 336 } 337 338 void Dither::setContrast(float f) 339 { 340 caca_set_dither_contrast(dither, f); 341 } 342 343 void Dither::setAntialias(char const *cv) 344 { 345 caca_set_dither_antialias(dither, cv); 346 } 347 348 char const *const * Dither::getAntialiasList() 349 { 350 return caca_get_dither_antialias_list(dither); 351 } 352 353 void Dither::setColor(char const *cv) 354 { 355 caca_set_dither_color(dither, cv); 356 } 357 358 char const *const * Dither::getColorList() 359 { 360 return caca_get_dither_color_list(dither); 361 } 362 363 void Dither::setCharset(char const *cv) 364 { 365 caca_set_dither_charset(dither, cv); 366 } 367 368 char const *const * Dither::getCharsetList() 369 { 370 return caca_get_dither_charset_list(dither); 371 } 372 373 void Dither::setMode(char const *cv) 374 { 375 caca_set_dither_algorithm(dither, cv); 376 } 377 378 char const *const * Dither::getModeList(void) 379 { 380 return caca_get_dither_algorithm_list(dither); 381 } 382 383 void Dither::Bitmap(Canvas *cv, int x, int y, int w, int h, void *v) 384 { 385 caca_dither_bitmap(cv->get_caca_canvas_t(), x, y, w, h, dither, v); 386 } 387 388 Font::Font(void const *s, unsigned int v) 389 { 390 font = caca_load_font(s, v); 391 if(!font) throw -1; 392 } 393 394 char const *const * Font::getList(void) 395 { 396 return caca_get_font_list(); 397 } 398 399 unsigned int Font::getWidth() 400 { 401 return caca_get_font_width(font); 402 } 403 404 unsigned int Font::getHeight() 405 { 406 return caca_get_font_height(font); 407 } 408 409 void Font::renderCanvas(Canvas *cv, uint8_t *buf, unsigned int x, unsigned int y, unsigned int w) 410 { 411 caca_render_canvas(cv->get_caca_canvas_t(), font, buf, x, y, w); 412 } 413 414 uint32_t const *Font::getBlocks() 415 { 416 return caca_get_font_blocks(font); 417 } 418 419 Font::~Font() 420 { 421 caca_free_font(font); 422 } 26 423 27 424 Caca::Caca(Canvas *cv) -
libcaca/trunk/cxx/caca++.h
r2821 r2822 25 25 26 26 #include <caca.h> 27 #include <caca++.h>28 #include <cucul++.h>29 27 30 28 #undef __class … … 34 32 # define __class class 35 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 int setBoundaries(caca_canvas_t *, int, int, unsigned int, unsigned int); 134 unsigned int getFrameCount(); 135 int setFrame(unsigned int); 136 int createFrame(unsigned int); 137 int freeFrame(unsigned int); 138 139 char const * const * getImportList(void); 140 long int importMemory(void const *, size_t, char const *); 141 long int importFile(char const *, char const *); 142 char const * const * getExportList(void); 143 void *exportMemory(char const *, size_t *); 144 145 static int Rand(int, int); 146 static char const * getVersion(); 147 148 protected: 149 caca_canvas_t *get_caca_canvas_t(); 150 151 private: 152 caca_canvas_t *cv; 153 }; 36 154 37 155 __class Event -
libcaca/trunk/cxx/cxxtest.cpp
r2821 r2822 16 16 #include <cstring> 17 17 18 #include <cucul++.h>19 18 #include <caca++.h> 20 19
Note: See TracChangeset
for help on using the changeset viewer.