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.
 
 
 
 
 
 

144 regels
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 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. #define DELAY 100
  18. int main(int argc, char **argv)
  19. {
  20. cucul_t *qq;
  21. caca_t *kk;
  22. int quit = 0;
  23. cucul_sprite_t *sprite;
  24. int frame = 0;
  25. unsigned char play = 0;
  26. unsigned int delay = 0;
  27. if(argc < 2)
  28. {
  29. fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
  30. return 1;
  31. }
  32. qq = cucul_create(0, 0);
  33. if(!qq)
  34. return 1;
  35. kk = caca_attach(qq);
  36. if(!kk)
  37. return 1;
  38. sprite = cucul_load_sprite(argv[1]);
  39. if(!sprite)
  40. {
  41. caca_detach(kk);
  42. cucul_free(qq);
  43. fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
  44. return 1;
  45. }
  46. /* Go ! */
  47. while(!quit)
  48. {
  49. caca_event_t ev;
  50. int xa, ya, xb, yb;
  51. char buf[BUFSIZ];
  52. while(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
  53. {
  54. switch(ev.data.key.c)
  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 < cucul_get_sprite_frames(sprite) - 1)
  67. frame++;
  68. break;
  69. case 'p':
  70. play=!play;
  71. }
  72. }
  73. if(play) {
  74. if(!delay) {
  75. if(frame < cucul_get_sprite_frames(sprite) - 1) {
  76. frame++;
  77. }
  78. else {
  79. frame = 0;
  80. }
  81. }
  82. delay++;
  83. if(delay>=DELAY) {
  84. delay = 0;
  85. }
  86. }
  87. cucul_clear(qq);
  88. cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  89. cucul_draw_thin_box(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1);
  90. cucul_putstr(qq, 3, 0, "[ Sprite editor for libcaca ]");
  91. sprintf(buf, "sprite `%s'", argv[1]);
  92. cucul_putstr(qq, 3, 2, buf);
  93. sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(sprite) - 1);
  94. cucul_putstr(qq, 3, 3, buf);
  95. /* Crosshair */
  96. cucul_draw_thin_line(qq, 57, 2, 57, 18);
  97. cucul_draw_thin_line(qq, 37, 10, 77, 10);
  98. cucul_putchar(qq, 57, 10, '+');
  99. /* Boxed sprite */
  100. xa = -1 - cucul_get_sprite_dx(sprite, frame);
  101. ya = -1 - cucul_get_sprite_dy(sprite, frame);
  102. xb = xa + 1 + cucul_get_sprite_width(sprite, frame);
  103. yb = ya + 1 + cucul_get_sprite_height(sprite, frame);
  104. cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
  105. cucul_fill_box(qq, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " ");
  106. cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  107. cucul_draw_thin_box(qq, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
  108. cucul_draw_sprite(qq, 57, 10, sprite, frame);
  109. /* Free sprite */
  110. cucul_draw_sprite(qq, 20, 10, sprite, frame);
  111. caca_display(kk);
  112. }
  113. /* Clean up */
  114. caca_detach(kk);
  115. cucul_free(qq);
  116. return 0;
  117. }