Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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