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.
 
 
 
 
 
 

122 lines
3.3 KiB

  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 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. int event;
  51. while((event = caca_get_event()))
  52. {
  53. if(event & CACA_EVENT_KEY_PRESS)
  54. switch(event & 0xff)
  55. {
  56. case 0:
  57. break;
  58. case 'q':
  59. quit = 1;
  60. break;
  61. case '-':
  62. if(frame > 0)
  63. frame--;
  64. break;
  65. case '+':
  66. if(frame < caca_get_sprite_frames(sprite) - 1)
  67. frame++;
  68. break;
  69. }
  70. }
  71. caca_clear();
  72. caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
  73. caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1);
  74. caca_putstr(3, 0, "[ Sprite editor for libcaca ]");
  75. sprintf(buf, "sprite `%s'", argv[1]);
  76. caca_putstr(3, 2, buf);
  77. sprintf(buf, "frame %i/%i", frame, caca_get_sprite_frames(sprite) - 1);
  78. caca_putstr(3, 3, buf);
  79. /* Crosshair */
  80. caca_draw_thin_line(57, 2, 57, 18);
  81. caca_draw_thin_line(37, 10, 77, 10);
  82. caca_putchar(57, 10, '+');
  83. /* Boxed sprite */
  84. xa = -1 - caca_get_sprite_dx(sprite, frame);
  85. ya = -1 - caca_get_sprite_dy(sprite, frame);
  86. xb = xa + 1 + caca_get_sprite_width(sprite, frame);
  87. yb = ya + 1 + caca_get_sprite_height(sprite, frame);
  88. caca_set_color(CACA_COLOR_BLACK, CACA_COLOR_BLACK);
  89. caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
  90. caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
  91. caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
  92. caca_draw_sprite(57, 10, sprite, frame);
  93. /* Free sprite */
  94. caca_draw_sprite(20, 10, sprite, frame);
  95. caca_refresh();
  96. }
  97. /* Clean up */
  98. caca_end();
  99. return 0;
  100. }