Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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