Changeset 2822
- Timestamp:
- Sep 27, 2008, 4:11:36 PM (14 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 11 deleted
- 23 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/csharp/Caca.cs
r2307 r2822 19 19 using System.Drawing; 20 20 21 using Cucul;22 23 21 namespace Caca 24 22 { … … 28 26 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 29 27 SuppressUnmanagedCodeSecurity] 28 private static extern int caca_rand(int min, int max); 29 public static int Rand(int min, int max) 30 { 31 return caca_rand(min, max); 32 } 33 34 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 35 SuppressUnmanagedCodeSecurity] 30 36 private static extern IntPtr caca_get_version(); 31 37 public static string getVersion() … … 33 39 return Marshal.PtrToStringAnsi(caca_get_version()); 34 40 } 41 42 public const uint BLACK = 0x00, 43 BLUE = 0x01, 44 GREEN = 0x02, 45 CYAN = 0x03, 46 RED = 0x04, 47 MAGENTA = 0x05, 48 BROWN = 0x06, 49 LIGHTGRAY = 0x07, 50 DARKGRAY = 0x08, 51 LIGHTBLUE = 0x09, 52 LIGHTGREEN = 0x0a, 53 LIGHTCYAN = 0x0b, 54 LIGHTRED = 0x0c, 55 LIGHTMAGENTA = 0x0d, 56 YELLOW = 0x0e, 57 WHITE = 0x0f, 58 DEFAULT = 0x10, 59 TRANSPARENT = 0x20; 60 61 public const uint BOLD = 0x01, 62 ITALICS = 0x02, 63 UNDERLINE = 0x04, 64 BLINK = 0x08; 35 65 } 36 66 … … 111 141 } 112 142 143 public class CacaCanvas : IDisposable 144 { 145 public readonly IntPtr _c_cv; 146 147 /* libcaca basic functions */ 148 149 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 150 SuppressUnmanagedCodeSecurity] 151 private static extern IntPtr caca_create_canvas(int w, int h); 152 public CacaCanvas() 153 { 154 _c_cv = caca_create_canvas(0, 0); 155 } 156 157 public CacaCanvas(Size s) 158 { 159 _c_cv = caca_create_canvas(s.Width, s.Height); 160 } 161 162 public CacaCanvas(int w, int h) 163 { 164 _c_cv = caca_create_canvas(h, w); 165 } 166 167 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 168 SuppressUnmanagedCodeSecurity] 169 private static extern int caca_free_canvas(IntPtr cv); 170 public void Dispose() 171 { 172 /* FIXME: don't destroy ourselves if we're attached */ 173 caca_free_canvas(_c_cv); 174 GC.SuppressFinalize(this); 175 } 176 177 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 178 SuppressUnmanagedCodeSecurity] 179 private static extern int caca_set_canvas_size(IntPtr cv, 180 int w, int h); 181 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 182 SuppressUnmanagedCodeSecurity] 183 private static extern int caca_get_canvas_width(IntPtr cv); 184 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 185 SuppressUnmanagedCodeSecurity] 186 private static extern int caca_get_canvas_height(IntPtr cv); 187 public Size Size 188 { 189 get { return new Size(caca_get_canvas_width(_c_cv), 190 caca_get_canvas_height(_c_cv)); } 191 set { caca_set_canvas_size(_c_cv, value.Width, value.Height); } 192 } 193 194 public Rectangle Rectangle 195 { 196 get { return new Rectangle(0, 0, caca_get_canvas_width(_c_cv), 197 caca_get_canvas_height(_c_cv)); } 198 set { caca_set_canvas_size(_c_cv, value.Width, value.Height); } 199 } 200 201 /* canvas drawing */ 202 203 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 204 SuppressUnmanagedCodeSecurity] 205 private static extern int caca_gotoxy(IntPtr cv, int x, int y); 206 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 207 SuppressUnmanagedCodeSecurity] 208 private static extern int caca_get_cursor_x(IntPtr cv); 209 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 210 SuppressUnmanagedCodeSecurity] 211 private static extern int caca_get_cursor_y(IntPtr cv); 212 public Point Cursor 213 { 214 get { return new Point(caca_get_cursor_x(_c_cv), 215 caca_get_cursor_y(_c_cv)); } 216 set { caca_gotoxy(_c_cv, value.X, value.Y); } 217 } 218 219 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 220 SuppressUnmanagedCodeSecurity] 221 private static extern int caca_put_char(IntPtr cv, 222 int x, int y, uint c); 223 public int putChar(Point p, uint c) 224 { 225 return caca_put_char(_c_cv, p.X, p.Y, c); 226 } 227 228 public int putChar(int x, int y, uint c) 229 { 230 return caca_put_char(_c_cv, x, y, c); 231 } 232 233 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 234 SuppressUnmanagedCodeSecurity] 235 private static extern uint caca_get_char(IntPtr cv, int x, int y); 236 public uint getChar(Point p) 237 { 238 return caca_get_char(_c_cv, p.X, p.Y); 239 } 240 241 public uint getChar(int x, int y) 242 { 243 return caca_get_char(_c_cv, x, y); 244 } 245 246 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 247 SuppressUnmanagedCodeSecurity] 248 private static extern int caca_put_str(IntPtr cv, 249 int x, int y, string c); 250 public int putStr(Point p, string c) 251 { 252 return caca_put_str(_c_cv, p.X, p.Y, c); 253 } 254 255 public int putStr(int x, int y, string c) 256 { 257 return caca_put_str(_c_cv, x, y, c); 258 } 259 260 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 261 SuppressUnmanagedCodeSecurity] 262 private static extern int caca_get_attr(IntPtr cv, int x, int y); 263 public int getAttr(Point p) 264 { 265 return caca_get_attr(_c_cv, p.X, p.Y); 266 } 267 268 public int getAttr(int x, int y) 269 { 270 return caca_get_attr(_c_cv, x, y); 271 } 272 273 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 274 SuppressUnmanagedCodeSecurity] 275 private static extern int caca_set_attr(IntPtr cv, uint a); 276 public int setAttr(uint a) 277 { 278 return caca_set_attr(_c_cv, a); 279 } 280 281 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 282 SuppressUnmanagedCodeSecurity] 283 private static extern int caca_put_attr(IntPtr cv, 284 int x, int y, uint a); 285 public int putAttr(Point p, uint a) 286 { 287 return caca_put_attr(_c_cv, p.X, p.Y, a); 288 } 289 290 public int putAttr(int x, int y, uint a) 291 { 292 return caca_put_attr(_c_cv, x, y, a); 293 } 294 295 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 296 SuppressUnmanagedCodeSecurity] 297 private static extern int caca_set_color_ansi(IntPtr cv, 298 byte fg, byte bg); 299 public int setColorAnsi(uint fg, uint bg) 300 { 301 return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg); 302 } 303 304 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 305 SuppressUnmanagedCodeSecurity] 306 private static extern int caca_set_color_argb(IntPtr cv, 307 uint fg, uint bg); 308 public int setColorArgb(uint fg, uint bg) 309 { 310 return caca_set_color_argb(_c_cv, fg, bg); 311 } 312 313 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 314 SuppressUnmanagedCodeSecurity] 315 private static extern int caca_clear_canvas(IntPtr cv); 316 public int Clear() 317 { 318 return caca_clear_canvas(_c_cv); 319 } 320 321 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 322 SuppressUnmanagedCodeSecurity] 323 private static extern int caca_set_canvas_handle(IntPtr cv, 324 int x, int y); 325 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 326 SuppressUnmanagedCodeSecurity] 327 private static extern int caca_get_canvas_handle_x(IntPtr cv); 328 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 329 SuppressUnmanagedCodeSecurity] 330 private static extern int caca_get_canvas_handle_y(IntPtr cv); 331 public Point Handle 332 { 333 get { return new Point(caca_get_canvas_handle_x(_c_cv), 334 caca_get_canvas_handle_y(_c_cv)); } 335 set { caca_set_canvas_handle(_c_cv, value.X, value.Y); } 336 } 337 338 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 339 SuppressUnmanagedCodeSecurity] 340 private static extern int caca_blit(IntPtr cv, int x, int y, 341 IntPtr cv1, IntPtr cv2); 342 public int Blit(Point p, CacaCanvas canvas) 343 { 344 return caca_blit(_c_cv, p.X, p.Y, canvas._c_cv, IntPtr.Zero); 345 } 346 347 public int Blit(Point p, CacaCanvas cv, CacaCanvas mask) 348 { 349 return caca_blit(_c_cv, p.X, p.Y, cv._c_cv, mask._c_cv); 350 } 351 352 public int Blit(int x, int y, CacaCanvas canvas) 353 { 354 return caca_blit(_c_cv, x, y, canvas._c_cv, IntPtr.Zero); 355 } 356 357 public int Blit(int x, int y, CacaCanvas cv, CacaCanvas mask) 358 { 359 return caca_blit(_c_cv, x, y, cv._c_cv, mask._c_cv); 360 } 361 362 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 363 SuppressUnmanagedCodeSecurity] 364 private static extern int caca_set_canvas_boundaries(IntPtr cv, 365 int x, int y, 366 int h, int w); 367 public int setBoundaries(Rectangle r) 368 { 369 return caca_set_canvas_boundaries(_c_cv, r.X, r.Y, 370 r.Width, r.Height); 371 } 372 373 public int setBoundaries(int x, int y, int w, int h) 374 { 375 return caca_set_canvas_boundaries(_c_cv, x, y, w, h); 376 } 377 378 /* canvas transformation */ 379 380 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 381 SuppressUnmanagedCodeSecurity] 382 private static extern int caca_invert(IntPtr cv); 383 public int Invert() 384 { 385 return caca_invert(_c_cv); 386 } 387 388 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 389 SuppressUnmanagedCodeSecurity] 390 private static extern int caca_flip(IntPtr cv); 391 public int Flip() 392 { 393 return caca_flip(_c_cv); 394 } 395 396 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 397 SuppressUnmanagedCodeSecurity] 398 private static extern int caca_flop(IntPtr cv); 399 public int Flop() 400 { 401 return caca_flop(_c_cv); 402 } 403 404 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 405 SuppressUnmanagedCodeSecurity] 406 private static extern int caca_rotate_180(IntPtr cv); 407 public int Rotate180() 408 { 409 return caca_rotate_180(_c_cv); 410 } 411 412 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 413 SuppressUnmanagedCodeSecurity] 414 private static extern int caca_rotate_left(IntPtr cv); 415 public int RotateLeft() 416 { 417 return caca_rotate_left(_c_cv); 418 } 419 420 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 421 SuppressUnmanagedCodeSecurity] 422 private static extern int caca_rotate_right(IntPtr cv); 423 public int RotateRight() 424 { 425 return caca_rotate_right(_c_cv); 426 } 427 428 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 429 SuppressUnmanagedCodeSecurity] 430 private static extern int caca_stretch_left(IntPtr cv); 431 public int StretchLeft() 432 { 433 return caca_stretch_left(_c_cv); 434 } 435 436 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 437 SuppressUnmanagedCodeSecurity] 438 private static extern int caca_stretch_right(IntPtr cv); 439 public int StretchRight() 440 { 441 return caca_stretch_right(_c_cv); 442 } 443 444 /* primitives drawing */ 445 446 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 447 SuppressUnmanagedCodeSecurity] 448 private static extern int caca_draw_line(IntPtr cv, int x1, int y1, 449 int x2, int y2, uint c); 450 public int drawLine(Point p1, Point p2, uint c) 451 { 452 return caca_draw_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y, c); 453 } 454 455 public int drawLine(int x1, int y1, int x2, int y2, uint c) 456 { 457 return caca_draw_line(_c_cv, x1, y1, x2, y2, c); 458 } 459 460 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 461 SuppressUnmanagedCodeSecurity] 462 private static extern int caca_draw_polyline(IntPtr cv, int[] x, 463 int[] y, int n, uint c); 464 public int drawPolyline(Point[] lp, uint c) 465 { 466 int[] lx = new int[lp.Length]; 467 int[] ly = new int[lp.Length]; 468 for(int i = 0; i < lp.Length; i++) 469 { 470 lx[i] = lp[i].X; 471 ly[i] = lp[i].Y; 472 } 473 return caca_draw_polyline(_c_cv, lx, ly, lp.Length - 1, c); 474 } 475 476 public int drawPolyline(int[] lx, int[] ly, uint c) 477 { 478 if(lx.Length != ly.Length) 479 return -1; 480 481 return caca_draw_polyline(_c_cv, lx, ly, lx.Length - 1, c); 482 } 483 484 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 485 SuppressUnmanagedCodeSecurity] 486 private static extern int caca_draw_thin_line(IntPtr cv, int x1, 487 int y1, int x2, int y2); 488 public int drawThinLine(Point p1, Point p2) 489 { 490 return caca_draw_thin_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y); 491 } 492 493 public int drawThinLine(int x1, int y1, int x2, int y2) 494 { 495 return caca_draw_thin_line(_c_cv, x1, y1, x2, y2); 496 } 497 498 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 499 SuppressUnmanagedCodeSecurity] 500 private static extern int caca_draw_thin_polyline(IntPtr cv, int[] x, 501 int[] y, int n); 502 public int drawThinPolyline(Point[] lp) 503 { 504 int[] lx = new int[lp.Length]; 505 int[] ly = new int[lp.Length]; 506 for(int i = 0; i < lp.Length; i++) 507 { 508 lx[i] = lp[i].X; 509 ly[i] = lp[i].Y; 510 } 511 return caca_draw_thin_polyline(_c_cv, lx, ly, lp.Length - 1); 512 } 513 514 public int drawThinPolyline(int[] lx, int[] ly) 515 { 516 if(lx.Length != ly.Length) 517 return -1; 518 519 return caca_draw_thin_polyline(_c_cv, lx, ly, lx.Length - 1); 520 } 521 522 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 523 SuppressUnmanagedCodeSecurity] 524 private static extern int caca_draw_circle(IntPtr cv, int x, int y, 525 int r, uint c); 526 public int drawCircle(Point p, int r, uint c) 527 { 528 return caca_draw_circle(_c_cv, p.X, p.Y, r, c); 529 } 530 531 public int drawCircle(int x, int y, int r, uint c) 532 { 533 return caca_draw_circle(_c_cv, x, y, r, c); 534 } 535 536 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 537 SuppressUnmanagedCodeSecurity] 538 private static extern int caca_draw_ellipse(IntPtr cv, int x, int y, 539 int a, int b, uint c); 540 public int drawEllipse(Point p, int a, int b, uint c) 541 { 542 return caca_draw_ellipse(_c_cv, p.X, p.Y, a, b, c); 543 } 544 545 public int drawEllipse(int x, int y, int a, int b, uint c) 546 { 547 return caca_draw_ellipse(_c_cv, x, y, a, b, c); 548 } 549 550 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 551 SuppressUnmanagedCodeSecurity] 552 private static extern int caca_draw_thin_ellipse(IntPtr cv, 553 int x, int y, 554 int a, int b); 555 public int drawThinEllipse(Point p, int a, int b) 556 { 557 return caca_draw_thin_ellipse(_c_cv, p.X, p.Y, a, b); 558 } 559 560 public int drawThinEllipse(int x, int y, int a, int b) 561 { 562 return caca_draw_thin_ellipse(_c_cv, x, y, a, b); 563 } 564 565 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 566 SuppressUnmanagedCodeSecurity] 567 private static extern int caca_fill_ellipse(IntPtr cv, int x, int y, 568 int a, int b, uint c); 569 public int fillEllipse(Point p, int a, int b, uint c) 570 { 571 return caca_fill_ellipse(_c_cv, p.X, p.Y, a, b, c); 572 } 573 574 public int fillEllipse(int x, int y, int a, int b, uint c) 575 { 576 return caca_fill_ellipse(_c_cv, x, y, a, b, c); 577 } 578 579 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 580 SuppressUnmanagedCodeSecurity] 581 private static extern int caca_draw_box(IntPtr cv, int x, int y, 582 int w, int h, uint c); 583 public int drawBox(Rectangle r, uint c) 584 { 585 return caca_draw_box(_c_cv, r.X, r.Y, r.Width, r.Height, c); 586 } 587 588 public int drawBox(int x, int y, int w, int h, uint c) 589 { 590 return caca_draw_box(_c_cv, x, y, w, h, c); 591 } 592 593 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 594 SuppressUnmanagedCodeSecurity] 595 private static extern int caca_draw_thin_box(IntPtr cv, int x, int y, 596 int w, int h); 597 public int drawThinBox(Rectangle r) 598 { 599 return caca_draw_thin_box(_c_cv, r.X, r.Y, r.Width, r.Height); 600 } 601 602 public int drawThinBox(int x, int y, int w, int h) 603 { 604 return caca_draw_thin_box(_c_cv, x, y, w, h); 605 } 606 607 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 608 SuppressUnmanagedCodeSecurity] 609 private static extern int caca_draw_cp437_box(IntPtr cv, int x, int y, 610 int w, int h); 611 public int drawCp437Box(Rectangle r) 612 { 613 return caca_draw_cp437_box(_c_cv, r.X, r.Y, r.Width, r.Height); 614 } 615 616 public int drawCp437Box(int x, int y, int w, int h) 617 { 618 return caca_draw_cp437_box(_c_cv, x, y, w, h); 619 } 620 621 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 622 SuppressUnmanagedCodeSecurity] 623 private static extern int caca_fill_box(IntPtr cv, int x, int y, 624 int w, int h, uint c); 625 public int fillBox(Rectangle r, uint c) 626 { 627 return caca_fill_box(_c_cv, r.X, r.Y, r.Width, r.Height, c); 628 } 629 630 public int fillBox(int x, int y, int w, int h, uint c) 631 { 632 return caca_fill_box(_c_cv, x, y, w, h, c); 633 } 634 635 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 636 SuppressUnmanagedCodeSecurity] 637 private static extern int caca_draw_triangle(IntPtr cv, int x1, 638 int y1, int x2, int y2, 639 int x3, int y3, uint c); 640 public int drawTriangle(Point p1, Point p2, Point p3, uint c) 641 { 642 return caca_draw_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, 643 p3.X, p3.Y, c); 644 } 645 646 public int drawTriangle(int x1, int y1, int x2, int y2, 647 int x3, int y3, uint c) 648 { 649 return caca_draw_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c); 650 } 651 652 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 653 SuppressUnmanagedCodeSecurity] 654 private static extern int caca_draw_thin_triangle(IntPtr cv, 655 int x1, int y1, 656 int x2, int y2, 657 int x3, int y3); 658 public int drawThinTriangle(Point p1, Point p2, Point p3) 659 { 660 return caca_draw_thin_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, 661 p3.X, p3.Y); 662 } 663 664 public int drawThinTriangle(int x1, int y1, int x2, int y2, 665 int x3, int y3) 666 { 667 return caca_draw_thin_triangle(_c_cv, x1, y1, x2, y2, x3, y3); 668 } 669 670 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 671 SuppressUnmanagedCodeSecurity] 672 private static extern int caca_fill_triangle(IntPtr cv, int x1, 673 int y1, int x2, int y2, 674 int x3, int y3, uint c); 675 public int fillTriangle(Point p1, Point p2, Point p3, uint c) 676 { 677 return caca_fill_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, 678 p3.X, p3.Y, c); 679 } 680 681 public int fillTriangle(int x1, int y1, int x2, int y2, 682 int x3, int y3, uint c) 683 { 684 return caca_fill_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c); 685 } 686 687 /* frame handling */ 688 689 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 690 SuppressUnmanagedCodeSecurity] 691 private static extern int caca_get_frame_count(IntPtr cv); 692 public int getFrameCount() 693 { 694 return caca_get_frame_count(_c_cv); 695 } 696 697 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 698 SuppressUnmanagedCodeSecurity] 699 private static extern int caca_set_frame(IntPtr cv, int f); 700 public int setFrame(int f) 701 { 702 return caca_set_frame(_c_cv, f); 703 } 704 705 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 706 SuppressUnmanagedCodeSecurity] 707 private static extern string caca_get_frame_name(IntPtr cv); 708 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 709 SuppressUnmanagedCodeSecurity] 710 private static extern int caca_set_frame_name(IntPtr cv, string n); 711 public string FrameName 712 { 713 get { return caca_get_frame_name(_c_cv); } 714 set { caca_set_frame_name(_c_cv, value); } 715 } 716 717 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 718 SuppressUnmanagedCodeSecurity] 719 private static extern int caca_create_frame(IntPtr cv, int f); 720 public int createFrame(int f) 721 { 722 return caca_create_frame(_c_cv, f); 723 } 724 725 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 726 SuppressUnmanagedCodeSecurity] 727 private static extern int caca_free_frame(IntPtr cv, int f); 728 public int freeFrame(int f) 729 { 730 return caca_free_frame(_c_cv, f); 731 } 732 733 /* bitmap dithering */ 734 735 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 736 SuppressUnmanagedCodeSecurity] 737 private static extern int caca_dither_bitmap(IntPtr c, int x, int y, 738 int w, int h, 739 IntPtr d, IntPtr data); 740 public int ditherBitmap(Rectangle r, CacaDither d, object data) 741 { 742 GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); 743 int ret = caca_dither_bitmap(_c_cv, r.X, r.Y, r.Width, r.Height, 744 d._dither, gch.AddrOfPinnedObject()); 745 gch.Free(); 746 return ret; 747 } 748 749 public int ditherBitmap(int x, int y, int w, int h, 750 CacaDither d, object data) 751 { 752 GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); 753 int ret = caca_dither_bitmap(_c_cv, x, y, w, h, d._dither, 754 gch.AddrOfPinnedObject()); 755 gch.Free(); 756 return ret; 757 } 758 } 759 760 public class CacaAttr 761 { 762 private uint _attr; 763 764 public CacaAttr(uint attr) 765 { 766 _attr = attr; 767 } 768 769 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 770 SuppressUnmanagedCodeSecurity] 771 private static extern byte caca_attr_to_ansi(uint a); 772 public byte toAnsi() 773 { 774 return caca_attr_to_ansi(_attr); 775 } 776 777 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 778 SuppressUnmanagedCodeSecurity] 779 private static extern byte caca_attr_to_ansi_fg(uint a); 780 public byte toAnsiFg() 781 { 782 return caca_attr_to_ansi_fg(_attr); 783 } 784 785 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 786 SuppressUnmanagedCodeSecurity] 787 private static extern byte caca_attr_to_ansi_bg(uint a); 788 public byte toAnsiBg() 789 { 790 return caca_attr_to_ansi_bg(_attr); 791 } 792 } 793 794 public class CacaDither : IDisposable 795 { 796 public readonly IntPtr _dither; 797 798 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 799 SuppressUnmanagedCodeSecurity] 800 private static extern IntPtr caca_create_dither(int bpp, int w, 801 int h, int pitch, 802 uint rmask, 803 uint gmask, 804 uint bmask, 805 uint amask); 806 public CacaDither(int bpp, Size s, int pitch, 807 uint rmask, uint gmask, uint bmask, uint amask) 808 { 809 _dither = caca_create_dither(bpp, s.Width, s.Height, pitch, 810 rmask, gmask, bmask, amask); 811 } 812 813 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 814 SuppressUnmanagedCodeSecurity] 815 private static extern int caca_free_dither(IntPtr d); 816 public void Dispose() 817 { 818 caca_free_dither(_dither); 819 GC.SuppressFinalize(this); 820 } 821 822 /* TODO: fix this shit */ 823 824 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 825 SuppressUnmanagedCodeSecurity] 826 private static extern int caca_set_dither_palette(IntPtr d, 827 uint[] r, uint[] g, 828 uint[] b, uint[] a); 829 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 830 SuppressUnmanagedCodeSecurity] 831 private static extern int caca_set_dither_brightness(IntPtr d, float b); 832 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 833 SuppressUnmanagedCodeSecurity] 834 private static extern int caca_set_dither_gamma(IntPtr d, float g); 835 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 836 SuppressUnmanagedCodeSecurity] 837 private static extern int caca_set_dither_contrast(IntPtr d, float c); 838 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 839 SuppressUnmanagedCodeSecurity] 840 private static extern int caca_set_dither_invert(IntPtr d, int i); 841 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 842 SuppressUnmanagedCodeSecurity] 843 private static extern int caca_set_dither_antialias(IntPtr d, string s); 844 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 845 SuppressUnmanagedCodeSecurity] 846 private static extern string[] caca_get_dither_antialias_list(IntPtr d); 847 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 848 SuppressUnmanagedCodeSecurity] 849 private static extern int caca_set_dither_color(IntPtr d, string s); 850 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 851 SuppressUnmanagedCodeSecurity] 852 private static extern string[] caca_get_dither_color_list(IntPtr d); 853 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 854 SuppressUnmanagedCodeSecurity] 855 private static extern int caca_set_dither_charset(IntPtr d, string s); 856 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 857 SuppressUnmanagedCodeSecurity] 858 private static extern string[] caca_get_dither_charset_list(IntPtr d); 859 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 860 SuppressUnmanagedCodeSecurity] 861 private static extern int caca_set_dither_mode(IntPtr d, string s); 862 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 863 SuppressUnmanagedCodeSecurity] 864 private static extern string[] caca_get_dither_mode_list(IntPtr d); 865 866 867 public int setBrightness(float b) 868 { 869 return caca_set_dither_brightness(_dither, b); 870 } 871 872 public int setGamma(float g) 873 { 874 return caca_set_dither_gamma(_dither, g); 875 } 876 877 public int setContrast(float c) 878 { 879 return caca_set_dither_contrast(_dither, c); 880 } 881 882 public int setInvert(int i) 883 { 884 return caca_set_dither_invert(_dither, i); 885 } 886 887 public int setAntialias(string s) 888 { 889 return caca_set_dither_antialias(_dither, s); 890 } 891 892 public int setColor(string s) 893 { 894 return caca_set_dither_color(_dither, s); 895 } 896 897 public int setCharset(string s) 898 { 899 return caca_set_dither_charset(_dither, s); 900 } 901 902 public int setMode(string s) 903 { 904 return caca_set_dither_mode(_dither, s); 905 } 906 907 /* <FIXME> */ 908 public string[] getAntialiasList() 909 { 910 return caca_get_dither_antialias_list(_dither); 911 } 912 913 public string[] getColorList() 914 { 915 return caca_get_dither_color_list(_dither); 916 } 917 918 public string[] getCharsetList() 919 { 920 return caca_get_dither_charset_list(_dither); 921 } 922 923 public string[] getModeList() 924 { 925 return caca_get_dither_mode_list(_dither); 926 } 927 928 /* </FIXME> */ 929 } 930 931 public class CacaFont : IDisposable 932 { 933 private IntPtr _font; 934 private GCHandle _gch; 935 936 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 937 SuppressUnmanagedCodeSecurity] 938 private static extern IntPtr caca_load_font(IntPtr data, uint len); 939 public CacaFont(string s) 940 { 941 IntPtr name = Marshal.StringToHGlobalAnsi(s); 942 _font = caca_load_font(name, 0); 943 Marshal.FreeHGlobal(name); 944 } 945 946 public CacaFont(byte[] buf) 947 { 948 GCHandle _gch = GCHandle.Alloc(buf, GCHandleType.Pinned); 949 _font = caca_load_font(_gch.AddrOfPinnedObject(), 950 (uint)buf.Length); 951 } 952 953 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 954 SuppressUnmanagedCodeSecurity] 955 private static extern int caca_free_font(IntPtr d); 956 public void Dispose() 957 { 958 caca_free_font(_font); 959 _gch.Free(); 960 GC.SuppressFinalize(this); 961 } 962 963 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 964 SuppressUnmanagedCodeSecurity] 965 private static extern IntPtr caca_get_font_list(); 966 public static string[] getList() 967 { 968 IntPtr l = caca_get_font_list(); 969 970 int size; 971 for(size = 0; true; size++) 972 if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero) 973 break; 974 975 string[] ret = new string[size]; 976 for(int i = 0; i < size; i++) 977 { 978 IntPtr s = Marshal.ReadIntPtr(l, IntPtr.Size * i); 979 ret[i] = Marshal.PtrToStringAnsi(s); 980 } 981 982 return ret; 983 } 984 985 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 986 SuppressUnmanagedCodeSecurity] 987 private static extern int caca_get_font_width(IntPtr font); 988 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 989 SuppressUnmanagedCodeSecurity] 990 private static extern int caca_get_font_height(IntPtr font); 991 public Size Size 992 { 993 get { return new Size(caca_get_font_width(_font), 994 caca_get_font_height(_font)); } 995 } 996 997 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 998 SuppressUnmanagedCodeSecurity] 999 private static extern IntPtr caca_get_font_blocks(IntPtr font); 1000 public int[,] getBlocks() 1001 { 1002 IntPtr l = caca_get_font_blocks(_font); 1003 1004 int size; 1005 for(size = 1; true; size += 2) 1006 if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero) 1007 break; 1008 1009 int[,] ret = new int[size,2]; 1010 for(int i = 0; i < size; i++) 1011 { 1012 ret[i,0] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2); 1013 ret[i,1] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2 + 1); 1014 } 1015 1016 return ret; 1017 } 1018 1019 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 1020 SuppressUnmanagedCodeSecurity] 1021 private static extern int caca_render_canvas(IntPtr cv, IntPtr f, 1022 IntPtr buf, int w, int h, 1023 int pitch); 1024 public int Render(CacaCanvas cv, uint[,] buf, int pitch) 1025 { 1026 GCHandle gch = GCHandle.Alloc(buf, GCHandleType.Pinned); 1027 int ret = caca_render_canvas(cv._c_cv, _font, 1028 gch.AddrOfPinnedObject(), 1029 buf.GetLength(0), buf.GetLength(1), 1030 pitch); 1031 gch.Free(); 1032 return ret; 1033 } 1034 } 1035 113 1036 public class CacaEvent : IDisposable 114 1037 { … … 201 1124 public class CacaDisplay : IDisposable 202 1125 { 203 private C uculCanvas _cv;204 public C uculCanvas Canvas { get { return _cv; } }1126 private CacaCanvas _cv; 1127 public CacaCanvas Canvas { get { return _cv; } } 205 1128 206 1129 private IntPtr _c_cv; … … 210 1133 SuppressUnmanagedCodeSecurity] 211 1134 private static extern IntPtr caca_create_display(IntPtr cv); 212 public CacaDisplay(C uculCanvas cv)1135 public CacaDisplay(CacaCanvas cv) 213 1136 { 214 1137 _cv = cv; … … 220 1143 { 221 1144 /* XXX: we do not call caca_create_display() with a NULL 222 * argument because it's then impossible to create a C uculCanvas1145 * argument because it's then impossible to create a CacaCanvas 223 1146 * and I don't want to add a weird constructor */ 224 _cv = new C uculCanvas();1147 _cv = new CacaCanvas(); 225 1148 _c_cv = _cv._c_cv; 226 1149 _c_dp = caca_create_display(_c_cv); -
libcaca/trunk/csharp/Makefile.am
r2821 r2822 3 3 cacadir = $(libdir)/caca-sharp 4 4 5 caca_sources = $(srcdir)/AssemblyInfo.cs $(srcdir)/C ucul.cs $(srcdir)/Caca.cs5 caca_sources = $(srcdir)/AssemblyInfo.cs $(srcdir)/Caca.cs 6 6 7 7 if USE_CSHARP -
libcaca/trunk/csharp/test.cs
r2307 r2822 19 19 using System.Runtime.InteropServices; 20 20 21 using Cucul;22 21 using Caca; 23 22 24 class DemoCanvas : C uculCanvas23 class DemoCanvas : CacaCanvas 25 24 { 26 25 private uint[,] image; 27 26 28 27 private DateTime startTime; 29 private C uculDither d;30 private C uculCanvas scroll;28 private CacaDither d; 29 private CacaCanvas scroll; 31 30 32 31 public DemoCanvas() … … 36 35 string message = " --- POWERED BY LIBCACA --- OLDSCHOOL TEXT EFFECTS ARE 100% PURE WIN"; 37 36 38 scroll = new C uculCanvas(new Size(message.Length, 1));39 scroll.setColorAnsi(Libc ucul.WHITE, Libcucul.TRANSPARENT);37 scroll = new CacaCanvas(new Size(message.Length, 1)); 38 scroll.setColorAnsi(Libcaca.WHITE, Libcaca.TRANSPARENT); 40 39 scroll.putStr(new Point(0, 0), message); 41 40 42 C uculFont f = new CuculFont(CuculFont.getList()[1]);41 CacaFont f = new CacaFont(CacaFont.getList()[1]); 43 42 int w = f.Size.Width * message.Length; 44 43 int h = f.Size.Height; 45 44 image = new uint[w, h]; 46 d = new C uculDither(32, new Size(w, h), w * 4,45 d = new CacaDither(32, new Size(w, h), w * 4, 47 46 0xff00, 0xff0000, 0xff000000, 0xff); 48 47 f.Render(scroll, image, image.GetLength(0) * 4); … … 56 55 Clear(); 57 56 58 setColorAnsi(Libc ucul.WHITE, Libcucul.BLACK);57 setColorAnsi(Libcaca.WHITE, Libcaca.BLACK); 59 58 for(int i = 0; i < barCount; i++) 60 59 { … … 64 63 Point p2 = new Point(Size.Width - 1, (int)v); 65 64 66 setColorAnsi((uint)(i + 9), Libc ucul.BLACK);65 setColorAnsi((uint)(i + 9), Libcaca.BLACK); 67 66 /* drawLine is already clipped, we don't care about overflows */ 68 67 drawLine(p1 + new Size(0, -2), p2 + new Size(0, -2), '-'); … … 80 79 ditherBitmap(new Rectangle(12 * w - x, h / 2 - y, w * 12, y * 2), d, image); 81 80 82 setColorAnsi(Libc ucul.WHITE, Libcucul.BLUE);81 setColorAnsi(Libcaca.WHITE, Libcaca.BLUE); 83 82 putStr(new Point(-30, -2) + Size, " -=[ Powered by libcaca ]=- "); 84 setColorAnsi(Libc ucul.WHITE, Libcucul.BLACK);83 setColorAnsi(Libcaca.WHITE, Libcaca.BLACK); 85 84 } 86 85 } … … 122 121 Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>"); 123 122 124 /* Instanciate a c uculcanvas */123 /* Instanciate a caca canvas */ 125 124 DemoCanvas cv = new DemoCanvas(); 126 125 … … 130 129 /* Random number. This is a static method, 131 130 not to be used with previous instance */ 132 Console.WriteLine("A random number: {0}", Libc ucul.Rand(0, 1337));131 Console.WriteLine("A random number: {0}", Libcaca.Rand(0, 1337)); 133 132 134 133 dp.EventLoop(); -
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 -
libcaca/trunk/msvc/caca-sharp.csproj
r2084 r2822 38 38 <Compile Include="..\csharp\AssemblyInfo.cs" /> 39 39 </ItemGroup> 40 <ItemGroup>41 <ProjectReference Include="cucul-sharp.csproj">42 <Project>{C05C1521-F4E2-48D8-BD83-786EF345A887}</Project>43 <Name>cucul-sharp</Name>44 </ProjectReference>45 </ItemGroup>46 40 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 47 41 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
libcaca/trunk/msvc/libcaca++.vcproj
r2192 r2822 39 39 Name="VCCLCompilerTool" 40 40 Optimization="0" 41 AdditionalIncludeDirectories="..\msvc;..\c ucul;..\caca;..\cxx"41 AdditionalIncludeDirectories="..\msvc;..\caca;..\cxx" 42 42 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__LIBCACA_PP__" 43 43 MinimalRebuild="true" … … 115 115 <Tool 116 116 Name="VCCLCompilerTool" 117 AdditionalIncludeDirectories="..\msvc;..\c ucul;..\caca;..\cxx"117 AdditionalIncludeDirectories="..\msvc;..\caca;..\cxx" 118 118 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__LIBCACA_PP__" 119 119 RuntimeLibrary="2" -
libcaca/trunk/msvc/libcaca.vcproj
r2314 r2822 39 39 Name="VCCLCompilerTool" 40 40 Optimization="0" 41 AdditionalIncludeDirectories="..\msvc ;..\cucul"41 AdditionalIncludeDirectories="..\msvc" 42 42 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__LIBCACA__" 43 43 MinimalRebuild="true" … … 115 115 <Tool 116 116 Name="VCCLCompilerTool" 117 AdditionalIncludeDirectories="..\msvc ;..\cucul"117 AdditionalIncludeDirectories="..\msvc" 118 118 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__LIBCACA__" 119 119 RuntimeLibrary="2" … … 178 178 > 179 179 </File> 180 <File 181 RelativePath="..\caca\attr.c" 182 > 183 </File> 184 <File 185 RelativePath="..\caca\box.c" 186 > 187 </File> 188 <File 189 RelativePath="..\caca\string.c" 190 > 191 </File> 192 <File 193 RelativePath="..\caca\charset.c" 194 > 195 </File> 196 <File 197 RelativePath="..\caca\conic.c" 198 > 199 </File> 200 <File 201 RelativePath="..\caca\canvas.c" 202 > 203 </File> 204 <File 205 RelativePath="..\caca\dither.c" 206 > 207 </File> 208 <File 209 RelativePath="..\caca\export.c" 210 > 211 </File> 212 <File 213 RelativePath="..\caca\figfont.c" 214 > 215 </File> 216 <File 217 RelativePath="..\caca\file.c" 218 > 219 </File> 220 <File 221 RelativePath="..\caca\font.c" 222 > 223 </File> 224 <File 225 RelativePath="..\caca\frame.c" 226 > 227 </File> 228 <File 229 RelativePath="..\caca\import.c" 230 > 231 </File> 232 <File 233 RelativePath="..\caca\line.c" 234 > 235 </File> 236 <File 237 RelativePath="..\caca\transform.c" 238 > 239 </File> 240 <File 241 RelativePath="..\caca\triangle.c" 242 > 243 </File> 244 <File 245 RelativePath="..\caca\legacy.c" 246 > 247 </File> 180 248 <File 181 249 RelativePath="..\caca\driver_conio.c" … … 240 308 </File> 241 309 <File 310 RelativePath="..\caca\caca_types.h" 311 > 312 </File> 313 <File 314 RelativePath="..\stubs.h" 315 > 316 </File> 317 <File 242 318 RelativePath=".\config.h" 243 319 > -
libcaca/trunk/ruby/Makefile.am
r2821 r2822 31 31 EXTRA_DIST = ruby.dox \ 32 32 ruby-caca.dox \ 33 ruby-cucul.dox \34 33 lib/caca.rb \ 35 34 t/tc_canvas.rb \ -
libcaca/trunk/ruby/README
r2033 r2822 1 This a Ruby binding for libc ucul and libcaca.1 This a Ruby binding for libcaca. 2 2 3 You can play with it by doing require 'caca' or require 'cucul'and looking at4 the C ucul and Caca modules, or maybe read the documentation :)3 You can play with it by doing require 'caca' and looking at 4 the Caca module, or maybe read the documentation :) -
libcaca/trunk/ruby/caca-canvas.c
r2821 r2822 212 212 if(CLASS_OF(src) != cCanvas) 213 213 { 214 rb_raise(rb_eArgError, "src is not a C ucul::Canvas");214 rb_raise(rb_eArgError, "src is not a Caca::Canvas"); 215 215 } 216 216 Data_Get_Struct(src, caca_canvas_t, csrc); … … 220 220 if(CLASS_OF(mask) != cCanvas) 221 221 { 222 rb_raise(rb_eArgError, "mask is not a C ucul::Canvas");222 rb_raise(rb_eArgError, "mask is not a Caca::Canvas"); 223 223 } 224 224 Data_Get_Struct(mask, caca_canvas_t, cmask); … … 448 448 { 449 449 if(CLASS_OF(d) != cDither) 450 rb_raise(rb_eArgError, "d is not a C ucul::Dither");450 rb_raise(rb_eArgError, "d is not a Caca::Dither"); 451 451 Check_Type(pixels, T_STRING); 452 452 … … 518 518 if(CLASS_OF(font) != cFont) 519 519 { 520 rb_raise(rb_eArgError, "First argument is not a C ucul::Font");520 rb_raise(rb_eArgError, "First argument is not a Caca::Font"); 521 521 } 522 522 … … 571 571 /****/ 572 572 573 void Init_caca_canvas(VALUE mC ucul)574 { 575 cCanvas = rb_define_class_under(mC ucul, "Canvas", rb_cObject);573 void Init_caca_canvas(VALUE mCaca) 574 { 575 cCanvas = rb_define_class_under(mCaca, "Canvas", rb_cObject); 576 576 rb_define_alloc_func(cCanvas, canvas_alloc); 577 577 -
libcaca/trunk/ruby/caca-display.c
r2821 r2822 46 46 if(CLASS_OF(arg2) == cCanvas) 47 47 { 48 rb_raise(rb_eArgError, "Only one argument can be a C ucul::Canvas");48 rb_raise(rb_eArgError, "Only one argument can be a Caca::Canvas"); 49 49 } 50 50 } -
libcaca/trunk/ruby/caca-dither.c
r2821 r2822 180 180 get_set_str_from_list(algorithm) 181 181 182 void Init_caca_dither(VALUE mC ucul)183 { 184 cDither = rb_define_class_under(mC ucul, "Dither", rb_cObject);182 void Init_caca_dither(VALUE mCaca) 183 { 184 cDither = rb_define_class_under(mCaca, "Dither", rb_cObject); 185 185 rb_define_alloc_func(cDither, dither_alloc); 186 186 -
libcaca/trunk/ruby/caca-font.c
r2821 r2822 86 86 } 87 87 88 void Init_caca_font(VALUE mC ucul)88 void Init_caca_font(VALUE mCaca) 89 89 { 90 cFont = rb_define_class_under(mC ucul, "Font", rb_cObject);90 cFont = rb_define_class_under(mCaca, "Font", rb_cObject); 91 91 rb_define_alloc_func(cFont, font_alloc); 92 92 -
libcaca/trunk/ruby/lib/caca.rb
r2093 r2822 1 require 'cucul'2 1 require 'caca.so' 3 2 -
libcaca/trunk/ruby/ruby-caca.dox
r2093 r2822 1 /* 1 /*$Id$ */ /** \page libcaca-ruby-api Libcaca Ruby API 2 2 3 The 3 Theclasses available for libcaca are : 4 4 5 \li \b Caca::Display 6 \li \b Caca::Event 7 \li \b Caca::Event::Key 8 \li \b Caca::Event::Key::Press 9 \li \b Caca::Event::Key::Release 10 \li \b Caca::Event::Mouse 11 \li \b Caca::Event::Mouse::Press 12 \li \b Caca::Event::Mouse::Release 13 \li \b Caca::Event::Mouse::Motion 14 \li \b Caca::Event::Resize 15 \li \b Caca::Event::Quit 5 \li\b Caca::Canvas : functions that have a caca_canvas_t* as first argument 6 \li\b Caca::Dither : functions that have a caca_dither_t* as first argument 7 \li\b Caca::Font : functions that have a caca_font_t* as first argument 8 (The constructor can currently only accept the name of a builtin font) 9 \li\b Caca::Display 10 \li\b Caca::Event 11 \li\b Caca::Event::Key 12 \li\b Caca::Event::Key::Press 13 \li\b Caca::Event::Key::Release 14 \li\b Caca::Event::Mouse 15 \li\b Caca::Event::Mouse::Press 16 \li\b Caca::Event::Mouse::Release 17 \li\b Caca::Event::Mouse::Motion 18 \li\b Caca::Event::Resize 19 \li\b Caca::Event::Quit 20 21 Thecharacter set conversion functions are not available yet in the binding. 16 22 17 23 \code 18 $ 19 irb(main):001:0> 20 irb(main):002:1> 21 irb(main):003:2> 22 irb(main):004:2> 23 irb(main):005:1> 24 irb(main):006:2> 25 irb(main):007:2> 26 irb(main):008:1> 24 $irb -rcaca 25 irb(main):001:0>class Object 26 irb(main):002:1>def Object.my_instance_methods 27 irb(main):003:2>instance_methods.sort - ancestors[1].instance_methods 28 irb(main):004:2>end 29 irb(main):005:1>def Object.my_methods 30 irb(main):006:2>methods.sort - ancestors[1].methods 31 irb(main):007:2>end 32 irb(main):008:1>end 27 33 \endcode 28 34 29 35 \code 30 irb(main):009:0> Caca.my_methods 31 => ["version"] 36 irb(main):009:0>Caca.constants 37 =>["BROWN", "BOLD", "GREEN", "LIGHTMAGENTA", "LIGHTBLUE", "BLINK", 38 "MAGENTA","DEFAULT", "TRANSPARENT", "BLUE", "LIGHTRED", "DARKGRAY", 39 "UNDERLINE","RED", "WHITE", "BLACK", "LIGHTCYAN", "LIGHTGRAY", 40 "ITALICS","CYAN", "YELLOW", "LIGHTGREEN", "Canvas", "Dither", "Font"] 32 41 \endcode 33 42 34 43 \code 35 irb(main):010:0> Caca::Display.my_instance_methods 36 => ["canvas", "get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh", 37 "set_mouse", "set_time", "set_title", "time", "time=", "title=", "width"] 44 irb(main):010:0>Caca.my_methods 45 =>["version"] 38 46 \endcode 39 47 40 48 \code 41 irb(main):011:0> Caca::Event.constants42 => ["Key", "Quit", "TYPE", "Mouse", "Resize"]49 irb(main):011:0>Caca::Canvas.my_methods 50 =>["export_list", "import_list"] 43 51 \endcode 44 52 45 53 \code 46 irb(main):012:0> Caca::Event.my_instance_methods 47 => ["quit?"] 54 irb(main):012:0>Caca::Canvas.my_instance_methods 55 =>["attr=", "blit", "clear", "create_frame", "cursor_x", "cursor_y", 56 "dither_bitmap","draw_box", "draw_circle", "draw_cp437_box", "draw_ellipse", 57 "draw_line","draw_polyline", "draw_thin_box", "draw_thin_ellipse", 58 "draw_thin_line","draw_thin_polyline", "draw_thin_triangle", 59 "draw_triangle","export_memory", "fill_box", "fill_ellipse", 60 "fill_triangle","flip", "flop", "frame=", "frame_count", "frame_name", 61 "frame_name=","free_frame", "get_attr", "get_char", "gotoxy", 62 "handle_x","handle_y", "height", "height=", "import_file", 63 "import_memory","invert", "printf", "put_attr", "put_char", "put_str", 64 "rotate_180","rotate_left", "rotate_right", "set_attr", 65 "set_boundaries","set_color_ansi", "set_color_argb", "set_frame", 66 "set_frame_name","set_handle", "set_height", "set_size", "set_width", 67 "stretch_left","stretch_right", "width", "width="] 48 68 \endcode 49 69 50 70 \code 51 irb(main):013:0> Caca::Event::Key.my_instance_methods52 => ["ch", "utf32", "utf8"]71 irb(main):013:0>Caca::Font.my_methods 72 =>["list"] 53 73 \endcode 54 74 55 75 \code 56 irb(main):014:0> Caca::Event::Mouse.my_instance_methods57 => ["button", "x", "y"]76 irb(main):014:0>Caca::Font.my_instance_methods 77 =>["blocks", "height", "width"] 58 78 \endcode 59 79 60 80 \code 61 irb(main):015:0> Caca::Event::Resize.my_instance_methods 62 => ["w", "h"] 81 irb(main):015:0>Caca::Dither.my_instance_methods 82 =>["algorithm=", "algorithm_list", "antialias=", "antialias_list", 83 "brightness=","charset=", "charset_list", "color=", "color_list", 84 "contrast=","gamma=", "palette=", "set_algorithm", "set_antialias", 85 "set_brightness","set_charset", "set_color", "set_contrast", 86 "set_gamma","set_palette"] 63 87 \endcode 64 88 65 \section Samples 89 \code 90 irb(main):010:0>Caca::Display.my_instance_methods 91 =>["canvas", "get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh", 92 "set_mouse","set_time", "set_title", "time", "time=", "title=", "width"] 93 \endcode 66 94 67 95 \code 68 require 'caca' 69 c = Cucul::Canvas.new(20,10) 70 c.put_str(2, 3, "plop!") 71 c.draw_thin_polyline([[0,0], [0,2], [5,2], [0,0]]) 72 d = Caca::Display.new(c) 73 d.title = "Test !" 96 irb(main):011:0>Caca::Event.constants 97 =>["Key", "Quit", "TYPE", "Mouse", "Resize"] 98 \endcode 99 100 \code 101 irb(main):012:0>Caca::Event.my_instance_methods 102 =>["quit?"] 103 \endcode 104 105 \code 106 irb(main):013:0>Caca::Event::Key.my_instance_methods 107 =>["ch", "utf32", "utf8"] 108 \endcode 109 110 \code 111 irb(main):014:0>Caca::Event::Mouse.my_instance_methods 112 =>["button", "x", "y"] 113 \endcode 114 115 \code 116 irb(main):015:0>Caca::Event::Resize.my_instance_methods 117 =>["w", "h"] 118 \endcode 119 120 \sectionSamples 121 122 \code 123 $ruby -rcaca -e 'c=Caca::Canvas.new(6, 3).fill_box(0,0,2,2,"#"[0]); 124 c2=Caca::Canvas.new(1,1).put_str(0,0,"x"); c.blit(1,1,c2); puts 125 c.export_memory("irc")' 126 ### 127 #x# 128 ### 129 \endcode 130 131 \code 132 $ruby -e 'puts Caca::Canvas.new(6,3).draw_thin_polyline([[0,0], [0,2], 133 [5,2],[0,0]]).export_memory("irc")' 134 -. 135 |`. 136 ----`- 137 \endcode 138 139 \code 140 $ruby -rcaca -e 'p Caca::Canvas.export_list' 141 [["caca","native libcaca format"], ["ansi", "ANSI"], ["utf8", "UTF-8 142 withANSI escape codes"], ["utf8cr", "UTF-8 with ANSI escape codes and 143 MS-DOS\\r"], ["html", "HTML"], ["html3", "backwards-compatible HTML"], 144 ["irc","IRC with mIRC colours"], ["ps", "PostScript document"], ["svg", 145 "SVGvector image"], ["tga", "TGA image"]] 146 \endcode 147 148 \code 149 $ruby -rcaca -e 'p Caca::Font.list' 150 ["Monospace9", "Monospace Bold 12"] 151 \endcode 152 153 \code 154 require'caca' 155 c= Caca::Canvas.new(20,10) 156 c.put_str(2,3, "plop!") 157 c.draw_thin_polyline([[0,0],[0,2], [5,2], [0,0]]) 158 d= Caca::Display.new(c) 159 d.title= "Test !" 74 160 d.refresh 75 161 76 # 77 module 78 79 80 81 82 162 #Redefine Event::Key#quit? so that q, Q, and Esc become exit keys 163 moduleCaca 164 class Event::Key 165 def quit? 166 "qQ^[".split('').member?(@ch.chr) 167 end 168 end 83 169 end 84 170 85 while((e 86 87 171 while((e= d.get_event(Caca::Event, -1)) && ! e.quit?) 172 p e 173 d.refresh 88 174 end 89 175 \endcode -
libcaca/trunk/ruby/t/tc_canvas.rb
r2004 r2822 1 1 require 'test/unit' 2 require 'c ucul'2 require 'caca' 3 3 4 4 class TC_Canvas < Test::Unit::TestCase 5 5 def setup 6 @c = C ucul::Canvas.new(3, 3)6 @c = Caca::Canvas.new(3, 3) 7 7 end 8 8 def test_create 9 c = C ucul::Canvas.new(3, 3)9 c = Caca::Canvas.new(3, 3) 10 10 assert_not_nil(c, 'Canvas creation failed') 11 11 assert(c.width == 3 && c.height == 3, 'Wrong size for new canvas') … … 46 46 end 47 47 def test_render 48 c = C ucul::Canvas.new(4,4)48 c = Caca::Canvas.new(4,4) 49 49 c.put_str(0,0,"plop") 50 f = C ucul::Font.new(Cucul::Font.list[0])50 f = Caca::Font.new(Caca::Font.list[0]) 51 51 assert_not_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4)) 52 52 end 53 53 def test_fail_render 54 c = C ucul::Canvas.new(4,4)54 c = Caca::Canvas.new(4,4) 55 55 assert_raise(ArgumentError) { 56 56 c.render(nil, c.width, c.height, c.width*4) -
libcaca/trunk/ruby/t/tc_display.rb
r2298 r2822 15 15 driver = Caca::Display.driver_list[0] 16 16 assert_raise(ArgumentError){Caca::Display.new(driver, driver)} 17 c = C ucul::Canvas.new(3, 3)17 c = Caca::Canvas.new(3, 3) 18 18 assert_raise(ArgumentError){Caca::Display.new(c, c)} 19 19 end 20 20 def test_create_from_canvas 21 c = C ucul::Canvas.new(3, 3)21 c = Caca::Canvas.new(3, 3) 22 22 d = Caca::Display.new(c) 23 23 assert_not_nil(d, 'Display creation failed') … … 25 25 end 26 26 def test_set_title 27 c = C ucul::Canvas.new(3, 3)27 c = Caca::Canvas.new(3, 3) 28 28 d = Caca::Display.new(c) 29 29 d.title = "Test !" -
libcaca/trunk/ruby/t/tc_dither.rb
r2008 r2822 1 1 require 'test/unit' 2 require 'c ucul'2 require 'caca' 3 3 4 4 class TC_Canvas < Test::Unit::TestCase 5 5 def test_create 6 6 assert_nothing_raised { 7 d = C ucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)7 d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 8 8 } 9 9 end 10 10 def test_fail_create 11 11 assert_raise(RuntimeError) { 12 d = C ucul::Dither.new(-1, 32, 32, 32, 0, 0, 0, 0)12 d = Caca::Dither.new(-1, 32, 32, 32, 0, 0, 0, 0) 13 13 } 14 14 end 15 15 def test_set_palette 16 16 assert_nothing_raised { 17 d = C ucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)17 d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 18 18 d.palette=[[0xfff, 0xfff, 0xfff, 0xfff]]*256 19 19 } … … 21 21 def test_fail_set_palette 22 22 assert_raise(ArgumentError) { 23 d = C ucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)23 d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 24 24 d.palette=[] 25 25 } … … 27 27 def test_fail_set_palette2 28 28 assert_raise(RuntimeError) { 29 d = C ucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)29 d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 30 30 d.palette=[[0xffff, 0, 0, 0]]*256 31 31 } … … 33 33 def test_set_brightness 34 34 assert_nothing_raised { 35 d = C ucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)35 d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 36 36 d.brightness=0.5 37 37 } … … 39 39 def test_set_gamma 40 40 assert_nothing_raised { 41 d = C ucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)41 d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 42 42 d.gamma=0.5 43 43 } … … 45 45 def test_set_contrast 46 46 assert_nothing_raised { 47 d = C ucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)47 d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 48 48 d.contrast=0.5 49 49 } -
libcaca/trunk/ruby/t/tc_font.rb
r1995 r2822 1 1 require 'test/unit' 2 require 'c ucul'2 require 'caca' 3 3 4 4 class TC_Canvas < Test::Unit::TestCase 5 5 def test_list 6 assert_not_nil(C ucul::Font.list)6 assert_not_nil(Caca::Font.list) 7 7 end 8 8 def test_load 9 C ucul::Font.list.each{|f|10 font = C ucul::Font.new(f)9 Caca::Font.list.each{|f| 10 font = Caca::Font.new(f) 11 11 assert_not_nil(font) 12 12 assert_not_nil(font.width) … … 17 17 def test_fail_load 18 18 assert_raise(RuntimeError) { 19 C ucul::Font.new("This font should not exist")19 Caca::Font.new("This font should not exist") 20 20 } 21 21 end -
libcaca/trunk/ruby/t/tc_frame.rb
r1949 r2822 1 1 require 'test/unit' 2 require 'c ucul'2 require 'caca' 3 3 4 4 class TC_Frame < Test::Unit::TestCase 5 5 def setup 6 @c = C ucul::Canvas.new(3, 3)6 @c = Caca::Canvas.new(3, 3) 7 7 end 8 8 def test_create
Note: See TracChangeset
for help on using the changeset viewer.