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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * spritedit sprite editor for libcaca
  3. * Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "config.h"
  14. #include <stdio.h>
  15. #include "cucul.h"
  16. #include "caca.h"
  17. int main(int argc, char **argv)
  18. {
  19. cucul_t *qq;
  20. caca_t *kk;
  21. int quit = 0;
  22. struct cucul_sprite *sprite;
  23. int frame = 0;
  24. if(argc < 2)
  25. {
  26. fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
  27. return 1;
  28. }
  29. qq = cucul_init(0, 0);
  30. if(!qq)
  31. return 1;
  32. kk = caca_attach(qq);
  33. if(!kk)
  34. return 1;
  35. sprite = cucul_load_sprite(qq, argv[1]);
  36. if(!sprite)
  37. {
  38. caca_detach(kk);
  39. cucul_end(qq);
  40. fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
  41. return 1;
  42. }
  43. /* Go ! */
  44. while(!quit)
  45. {
  46. int xa, ya, xb, yb;
  47. char buf[BUFSIZ];
  48. int event;
  49. while((event = caca_get_event(kk, CACA_EVENT_KEY_PRESS)))
  50. {
  51. switch(event & 0x00ffffff)
  52. {
  53. case 0:
  54. break;
  55. case 'q':
  56. quit = 1;
  57. break;
  58. case '-':
  59. if(frame > 0)
  60. frame--;
  61. break;
  62. case '+':
  63. if(frame < cucul_get_sprite_frames(qq, sprite) - 1)
  64. frame++;
  65. break;
  66. }
  67. }
  68. cucul_clear(qq);
  69. cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  70. cucul_draw_thin_box(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1);
  71. cucul_putstr(qq, 3, 0, "[ Sprite editor for libcaca ]");
  72. sprintf(buf, "sprite `%s'", argv[1]);
  73. cucul_putstr(qq, 3, 2, buf);
  74. sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(qq, sprite) - 1);
  75. cucul_putstr(qq, 3, 3, buf);
  76. /* Crosshair */
  77. cucul_draw_thin_line(qq, 57, 2, 57, 18);
  78. cucul_draw_thin_line(qq, 37, 10, 77, 10);
  79. cucul_putchar(qq, 57, 10, '+');
  80. /* Boxed sprite */
  81. xa = -1 - cucul_get_sprite_dx(qq, sprite, frame);
  82. ya = -1 - cucul_get_sprite_dy(qq, sprite, frame);
  83. xb = xa + 1 + cucul_get_sprite_width(qq, sprite, frame);
  84. yb = ya + 1 + cucul_get_sprite_height(qq, sprite, frame);
  85. cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
  86. cucul_fill_box(qq, 57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
  87. cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  88. cucul_draw_thin_box(qq, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
  89. cucul_draw_sprite(qq, 57, 10, sprite, frame);
  90. /* Free sprite */
  91. cucul_draw_sprite(qq, 20, 10, sprite, frame);
  92. caca_display(kk);
  93. }
  94. /* Clean up */
  95. caca_detach(kk);
  96. cucul_end(qq);
  97. return 0;
  98. }