Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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