25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

event.c 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * event event lister for libcaca
  3. * Copyright (c) 2004 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 GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. */
  23. #include "config.h"
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "caca.h"
  27. static void print_event(int, int, unsigned int);
  28. int main(int argc, char **argv)
  29. {
  30. int *events;
  31. int i, h;
  32. if(caca_init())
  33. return 1;
  34. caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
  35. caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
  36. caca_refresh();
  37. h = caca_get_height();
  38. events = malloc(h * sizeof(int));
  39. memset(events, 0, h * sizeof(int));
  40. for( ; ; )
  41. {
  42. unsigned int event = caca_wait_event(CACA_EVENT_ANY);
  43. if(!event)
  44. continue;
  45. memmove(events + 1, events, (h - 1) * sizeof(int));
  46. events[0] = event;
  47. caca_clear();
  48. /* Print current event */
  49. caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
  50. caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
  51. print_event(0, 0, event);
  52. /* Print previous events */
  53. caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
  54. for(i = 1; i < h && events[i]; i++)
  55. print_event(0, i, events[i]);
  56. /* q quits */
  57. if(event == (CACA_EVENT_KEY_PRESS | 'q'))
  58. break;
  59. caca_refresh();
  60. }
  61. /* Clean up */
  62. caca_end();
  63. return 0;
  64. }
  65. static void print_event(int x, int y, unsigned int event)
  66. {
  67. switch(event & 0xff000000)
  68. {
  69. case CACA_EVENT_NONE:
  70. caca_printf(x, y, "CACA_EVENT_NONE");
  71. break;
  72. case CACA_EVENT_KEY_PRESS:
  73. caca_printf(x, y, "CACA_EVENT_KEY_PRESS 0x%02x",
  74. event & 0x00ffffff);
  75. break;
  76. case CACA_EVENT_KEY_RELEASE:
  77. caca_printf(x, y, "CACA_EVENT_KEY_RELEASE 0x2%x",
  78. event & 0x00ffffff);
  79. break;
  80. case CACA_EVENT_MOUSE_MOTION:
  81. caca_printf(x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
  82. (event & 0x00fff000) >> 12, event & 0x00000fff);
  83. break;
  84. case CACA_EVENT_MOUSE_PRESS:
  85. caca_printf(x, y, "CACA_EVENT_MOUSE_PRESS %u",
  86. event & 0x00ffffff);
  87. break;
  88. case CACA_EVENT_MOUSE_RELEASE:
  89. caca_printf(x, y, "CACA_EVENT_MOUSE_RELEASE %u",
  90. event & 0x00ffffff);
  91. break;
  92. default:
  93. caca_printf(x, y, "CACA_EVENT_UNKNOWN");
  94. }
  95. }