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.
 
 
 
 
 
 

149 rader
3.6 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. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. #include "config.h"
  15. #include "common.h"
  16. #if !defined(__KERNEL__)
  17. # include <stdio.h>
  18. #endif
  19. #include "cucul.h"
  20. #include "caca.h"
  21. #define MYDELAY 100
  22. int main(int argc, char **argv)
  23. {
  24. #if 0
  25. cucul_canvas_t *cv;
  26. caca_display_t *dp;
  27. int quit = 0;
  28. cucul_sprite_t *sprite;
  29. int frame = 0;
  30. unsigned char play = 0;
  31. unsigned int delay = 0;
  32. if(argc < 2)
  33. {
  34. fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
  35. return 1;
  36. }
  37. cv = cucul_create_canvas(0, 0);
  38. if(!cv)
  39. return 1;
  40. dp = caca_create_display(cv);
  41. if(!dp)
  42. return 1;
  43. sprite = cucul_load_sprite(argv[1]);
  44. if(!sprite)
  45. {
  46. caca_free_display(dp);
  47. cucul_free_canvas(cv);
  48. fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
  49. return 1;
  50. }
  51. /* Go ! */
  52. while(!quit)
  53. {
  54. caca_event_t ev;
  55. int xa, ya, xb, yb;
  56. char buf[BUFSIZ];
  57. while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
  58. {
  59. switch(ev.data.key.ch)
  60. {
  61. case 0:
  62. break;
  63. case 'q':
  64. quit = 1;
  65. break;
  66. case '-':
  67. if(frame > 0)
  68. frame--;
  69. break;
  70. case '+':
  71. if(frame < cucul_get_sprite_frames(sprite) - 1)
  72. frame++;
  73. break;
  74. case 'p':
  75. play=!play;
  76. }
  77. }
  78. if(play) {
  79. if(!delay) {
  80. if(frame < cucul_get_sprite_frames(sprite) - 1) {
  81. frame++;
  82. }
  83. else {
  84. frame = 0;
  85. }
  86. }
  87. delay++;
  88. if(delay>=MYDELAY) {
  89. delay = 0;
  90. }
  91. }
  92. cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
  93. cucul_clear_canvas(cv);
  94. cucul_draw_thin_box(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
  95. cucul_get_canvas_height(cv) - 1);
  96. cucul_put_str(cv, 3, 0, "[ Sprite editor for libcaca ]");
  97. sprintf(buf, "sprite `%s'", argv[1]);
  98. cucul_put_str(cv, 3, 2, buf);
  99. sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(sprite) - 1);
  100. cucul_put_str(cv, 3, 3, buf);
  101. /* Crosshair */
  102. cucul_draw_thin_line(cv, 57, 2, 57, 18);
  103. cucul_draw_thin_line(cv, 37, 10, 77, 10);
  104. cucul_put_char(cv, 57, 10, '+');
  105. /* Boxed sprite */
  106. xa = -1 - cucul_get_sprite_dx(sprite, frame);
  107. ya = -1 - cucul_get_sprite_dy(sprite, frame);
  108. xb = xa + 1 + cucul_get_sprite_width(sprite, frame);
  109. yb = ya + 1 + cucul_get_sprite_height(sprite, frame);
  110. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_BLACK);
  111. cucul_fill_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " ");
  112. cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
  113. cucul_draw_thin_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
  114. cucul_draw_sprite(cv, 57, 10, sprite, frame);
  115. /* Free sprite */
  116. cucul_draw_sprite(cv, 20, 10, sprite, frame);
  117. caca_refresh_display(dp);
  118. }
  119. /* Clean up */
  120. caca_free_display(dp);
  121. cucul_free_canvas(cv);
  122. #endif
  123. return 0;
  124. }