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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 "common.h"
  15. #include <stdio.h>
  16. #include "cucul.h"
  17. #include "caca.h"
  18. #define DELAY 100
  19. int main(int argc, char **argv)
  20. {
  21. #if 0
  22. cucul_canvas_t *cv;
  23. caca_display_t *dp;
  24. int quit = 0;
  25. cucul_sprite_t *sprite;
  26. int frame = 0;
  27. unsigned char play = 0;
  28. unsigned int delay = 0;
  29. if(argc < 2)
  30. {
  31. fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
  32. return 1;
  33. }
  34. cv = cucul_create_canvas(0, 0);
  35. if(!cv)
  36. return 1;
  37. dp = caca_create_display(cv);
  38. if(!dp)
  39. return 1;
  40. sprite = cucul_load_sprite(argv[1]);
  41. if(!sprite)
  42. {
  43. caca_free_display(dp);
  44. cucul_free_canvas(cv);
  45. fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
  46. return 1;
  47. }
  48. /* Go ! */
  49. while(!quit)
  50. {
  51. caca_event_t ev;
  52. int xa, ya, xb, yb;
  53. char buf[BUFSIZ];
  54. while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
  55. {
  56. switch(ev.data.key.ch)
  57. {
  58. case 0:
  59. break;
  60. case 'q':
  61. quit = 1;
  62. break;
  63. case '-':
  64. if(frame > 0)
  65. frame--;
  66. break;
  67. case '+':
  68. if(frame < cucul_get_sprite_frames(sprite) - 1)
  69. frame++;
  70. break;
  71. case 'p':
  72. play=!play;
  73. }
  74. }
  75. if(play) {
  76. if(!delay) {
  77. if(frame < cucul_get_sprite_frames(sprite) - 1) {
  78. frame++;
  79. }
  80. else {
  81. frame = 0;
  82. }
  83. }
  84. delay++;
  85. if(delay>=DELAY) {
  86. delay = 0;
  87. }
  88. }
  89. cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  90. cucul_clear_canvas(cv);
  91. cucul_draw_thin_box(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
  92. cucul_get_canvas_height(cv) - 1);
  93. cucul_putstr(cv, 3, 0, "[ Sprite editor for libcaca ]");
  94. sprintf(buf, "sprite `%s'", argv[1]);
  95. cucul_putstr(cv, 3, 2, buf);
  96. sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(sprite) - 1);
  97. cucul_putstr(cv, 3, 3, buf);
  98. /* Crosshair */
  99. cucul_draw_thin_line(cv, 57, 2, 57, 18);
  100. cucul_draw_thin_line(cv, 37, 10, 77, 10);
  101. cucul_putchar(cv, 57, 10, '+');
  102. /* Boxed sprite */
  103. xa = -1 - cucul_get_sprite_dx(sprite, frame);
  104. ya = -1 - cucul_get_sprite_dy(sprite, frame);
  105. xb = xa + 1 + cucul_get_sprite_width(sprite, frame);
  106. yb = ya + 1 + cucul_get_sprite_height(sprite, frame);
  107. cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
  108. cucul_fill_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " ");
  109. cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  110. cucul_draw_thin_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
  111. cucul_draw_sprite(cv, 57, 10, sprite, frame);
  112. /* Free sprite */
  113. cucul_draw_sprite(cv, 20, 10, sprite, frame);
  114. caca_refresh_display(dp);
  115. }
  116. /* Clean up */
  117. caca_free_display(dp);
  118. cucul_free_canvas(cv);
  119. #endif
  120. return 0;
  121. }