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.
 
 
 
 
 
 

117 lines
3.0 KiB

  1. /*
  2. * spritedit sprite editor using 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 GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. */
  23. #include "config.h"
  24. #include <stdio.h>
  25. #include "caca.h"
  26. int main(int argc, char **argv)
  27. {
  28. int quit = 0;
  29. struct caca_sprite *sprite;
  30. int frame = 0;
  31. if(argc < 2)
  32. {
  33. fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
  34. return 1;
  35. }
  36. if(caca_init())
  37. return 1;
  38. sprite = caca_load_sprite(argv[1]);
  39. if(!sprite)
  40. {
  41. caca_end();
  42. fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
  43. return 1;
  44. }
  45. /* Go ! */
  46. while(!quit)
  47. {
  48. int xa, ya, xb, yb;
  49. char buf[BUFSIZ];
  50. switch(caca_get_key())
  51. {
  52. case 0:
  53. break;
  54. case 'q':
  55. quit = 1;
  56. break;
  57. case '-':
  58. if(frame > 0)
  59. frame--;
  60. break;
  61. case '+':
  62. if(frame < caca_get_sprite_frames(sprite) - 1)
  63. frame++;
  64. break;
  65. }
  66. caca_clear();
  67. caca_set_color(CACA_COLOR_WHITE);
  68. caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1);
  69. caca_putstr(3, 0, "[ Sprite editor for libcaca ]");
  70. sprintf(buf, "sprite `%s'", argv[1]);
  71. caca_putstr(3, 2, buf);
  72. sprintf(buf, "frame %i/%i", frame, caca_get_sprite_frames(sprite) - 1);
  73. caca_putstr(3, 3, buf);
  74. /* Crosshair */
  75. caca_draw_thin_line(57, 2, 57, 18);
  76. caca_draw_thin_line(37, 10, 77, 10);
  77. caca_putchar(57, 10, '+');
  78. /* Boxed sprite */
  79. xa = -1 - caca_get_sprite_dx(sprite, frame);
  80. ya = -1 - caca_get_sprite_dy(sprite, frame);
  81. xb = xa + 1 + caca_get_sprite_width(sprite, frame);
  82. yb = ya + 1 + caca_get_sprite_height(sprite, frame);
  83. caca_set_color(CACA_COLOR_BLACK);
  84. caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
  85. caca_set_color(CACA_COLOR_WHITE);
  86. caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
  87. caca_draw_sprite(57, 10, sprite, frame);
  88. /* Free sprite */
  89. caca_draw_sprite(20, 10, sprite, frame);
  90. caca_refresh();
  91. }
  92. /* Clean up */
  93. caca_end();
  94. return 0;
  95. }