event.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  16. #ifndef BDE_EVENT_H
  17. #define BDE_EVENT_H
  18. #include "types.h"
  19. #include "terminal.h"
  20. #ifdef CTRL
  21. # undef CTRL
  22. #endif
  23. #define SHIFT 1
  24. #define CTRL 2
  25. #define ALT 4
  26. #define VIRTUAL 8
  27. enum EventType { evtKbd, evtMouse };
  28. class Event {
  29. public:
  30. EventType type;
  31. int modifiers;
  32. unichar ch;
  33. int keycode;
  34. bool operator== (const Event &other) const
  35. {
  36. return type == other.type &&
  37. modifiers == other.modifiers &&
  38. ch == other.ch &&
  39. keycode == other.keycode;
  40. }
  41. Event() { }
  42. Event(int modifiers, unichar ch, int keycode = 0)
  43. {
  44. type = evtKbd;
  45. this->modifiers = modifiers;
  46. this->ch = ch;
  47. this->keycode = keycode;
  48. }
  49. Event(int keycode)
  50. {
  51. type = evtKbd;
  52. this->modifiers = 0;
  53. this->ch = 0;
  54. this->keycode = keycode;
  55. }
  56. bool is_literal() const
  57. {
  58. return (ch != 0 && ch != 27/*ESC*/ && modifiers == 0);
  59. }
  60. bool empty() const
  61. {
  62. return !modifiers && !ch && !keycode;
  63. }
  64. u8string to_string() const;
  65. void print();
  66. };
  67. void get_next_event(Event &evt, WINDOW *wnd);
  68. void set_next_event(const Event &evt);
  69. #endif