Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

91 рядки
2.3 KiB

  1. /*
  2. * mouse libcaca mouse events
  3. * Copyright (c) 2006-2012 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * All Rights Reserved
  5. *
  6. * This program is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What the Fuck You Want
  9. * to Public License, Version 2, as published by Sam Hocevar. See
  10. * http://www.wtfpl.net/ for more details.
  11. */
  12. #include "config.h"
  13. #if !defined(__KERNEL__)
  14. # include <math.h>
  15. # include <string.h>
  16. # include <stdio.h>
  17. #endif
  18. #include "caca.h"
  19. int main(int argc, char *argv[])
  20. {
  21. int quit = 0;
  22. int x = 0, y = 0, p = 0, b = 0;
  23. caca_canvas_t *cv;
  24. caca_display_t *dp;
  25. cv = caca_create_canvas(80, 24);
  26. if (cv == NULL)
  27. {
  28. printf("Failed to create canvas\n");
  29. return 1;
  30. }
  31. dp = caca_create_display(cv);
  32. if (dp == NULL)
  33. {
  34. printf("Failed to create display\n");
  35. return 1;
  36. }
  37. caca_set_display_time(dp, 40000);
  38. caca_set_cursor(dp, 0);
  39. while (!quit)
  40. {
  41. caca_event_t ev;
  42. while (caca_get_event(dp, CACA_EVENT_ANY, &ev, 0))
  43. {
  44. if ((caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS))
  45. {
  46. quit = 1;
  47. }
  48. if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_MOTION)
  49. {
  50. x = caca_get_event_mouse_x(&ev);
  51. y = caca_get_event_mouse_y(&ev);
  52. }
  53. if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_PRESS)
  54. {
  55. p = 1;
  56. b = caca_get_event_mouse_button(&ev);
  57. }
  58. else if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_RELEASE)
  59. {
  60. p = 0;
  61. b = caca_get_event_mouse_button(&ev);
  62. }
  63. }
  64. caca_printf(cv, 0, 0, "%d,%d", x, y);
  65. if (b)
  66. {
  67. caca_printf(cv, 0, 1, "Mouse button %d %s", b,
  68. p == 1 ? "pressed" : "released");
  69. }
  70. caca_printf(cv, x - 2, y - 1, " |");
  71. caca_printf(cv, x - 2, y, "--|--");
  72. caca_printf(cv, x - 2, y + 1, " |");
  73. caca_refresh_display(dp);
  74. caca_clear_canvas(cv);
  75. }
  76. caca_free_display(dp);
  77. caca_free_canvas(cv);
  78. return 0;
  79. }