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.
 
 
 
 
 
 

93 lines
2.4 KiB

  1. /*
  2. * mouse libcaca mouse events
  3. * Copyright (c) 2006-2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * All Rights Reserved
  5. *
  6. * $Id: mouse.c 3495 2009-05-21 20:55:21Z jylam $
  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. #if !defined(__KERNEL__)
  16. # include <math.h>
  17. # include <string.h>
  18. # include <stdio.h>
  19. #endif
  20. #include "caca.h"
  21. int main(int argc, char *argv[])
  22. {
  23. int quit = 0;
  24. int x = 0, y = 0, p = 0, b = 0;
  25. caca_canvas_t *cv;
  26. caca_display_t *dp;
  27. cv = caca_create_canvas(80, 24);
  28. if (cv == NULL)
  29. {
  30. printf("Failed to create canvas\n");
  31. return 1;
  32. }
  33. dp = caca_create_display(cv);
  34. if (dp == NULL)
  35. {
  36. printf("Failed to create display\n");
  37. return 1;
  38. }
  39. caca_set_display_time(dp, 40000);
  40. caca_set_cursor(dp, 0);
  41. while (!quit)
  42. {
  43. caca_event_t ev;
  44. while (caca_get_event(dp, CACA_EVENT_ANY, &ev, 0))
  45. {
  46. if ((caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS))
  47. {
  48. quit = 1;
  49. }
  50. if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_MOTION)
  51. {
  52. x = caca_get_event_mouse_x(&ev);
  53. y = caca_get_event_mouse_y(&ev);
  54. }
  55. if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_PRESS)
  56. {
  57. p = 1;
  58. b = caca_get_event_mouse_button(&ev);
  59. }
  60. else if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_RELEASE)
  61. {
  62. p = 0;
  63. b = caca_get_event_mouse_button(&ev);
  64. }
  65. }
  66. caca_printf(cv, 0, 0, "%d,%d", x, y);
  67. if (b)
  68. {
  69. caca_printf(cv, 0, 1, "Mouse button %d %s", b,
  70. p == 1 ? "pressed" : "released");
  71. }
  72. caca_printf(cv, x - 2, y - 1, " |");
  73. caca_printf(cv, x - 2, y, "--|--");
  74. caca_printf(cv, x - 2, y + 1, " |");
  75. caca_refresh_display(dp);
  76. caca_clear_canvas(cv);
  77. }
  78. caca_free_display(dp);
  79. caca_free_canvas(cv);
  80. return 0;
  81. }