pgMouseWatcherRegion.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file pgMouseWatcherRegion.cxx
  10. * @author drose
  11. * @date 2001-07-02
  12. */
  13. #include "pgMouseWatcherRegion.h"
  14. #include "pgItem.h"
  15. #include "string_utils.h"
  16. int PGMouseWatcherRegion::_next_index = 0;
  17. TypeHandle PGMouseWatcherRegion::_type_handle;
  18. /**
  19. *
  20. */
  21. PGMouseWatcherRegion::
  22. PGMouseWatcherRegion(PGItem *item) :
  23. #ifndef CPPPARSER
  24. MouseWatcherRegion("pg" + format_string(_next_index++), 0, 0, 0, 0),
  25. #endif
  26. _item(item)
  27. {
  28. }
  29. /**
  30. *
  31. */
  32. PGMouseWatcherRegion::
  33. ~PGMouseWatcherRegion() {
  34. }
  35. /**
  36. * This is a callback hook function, called whenever the mouse enters the
  37. * region. The mouse is only considered to be "entered" in one region at a
  38. * time; in the case of nested regions, it exits the outer region before
  39. * entering the inner one.
  40. */
  41. void PGMouseWatcherRegion::
  42. enter_region(const MouseWatcherParameter &param) {
  43. if (_item != nullptr) {
  44. _item->enter_region(param);
  45. }
  46. }
  47. /**
  48. * This is a callback hook function, called whenever the mouse exits the
  49. * region. The mouse is only considered to be "entered" in one region at a
  50. * time; in the case of nested regions, it exits the outer region before
  51. * entering the inner one.
  52. */
  53. void PGMouseWatcherRegion::
  54. exit_region(const MouseWatcherParameter &param) {
  55. if (_item != nullptr) {
  56. _item->exit_region(param);
  57. }
  58. }
  59. /**
  60. * This is a callback hook function, called whenever the mouse moves within
  61. * the boundaries of the region, even if it is also within the boundaries of a
  62. * nested region. This is different from "enter", which is only called
  63. * whenever the mouse is within only that region.
  64. */
  65. void PGMouseWatcherRegion::
  66. within_region(const MouseWatcherParameter &param) {
  67. if (_item != nullptr) {
  68. _item->within_region(param);
  69. }
  70. }
  71. /**
  72. * This is a callback hook function, called whenever the mouse moves
  73. * completely outside the boundaries of the region. See within_region().
  74. */
  75. void PGMouseWatcherRegion::
  76. without_region(const MouseWatcherParameter &param) {
  77. if (_item != nullptr) {
  78. _item->without_region(param);
  79. }
  80. }
  81. /**
  82. * This is a callback hook function, called whenever a mouse or keyboard
  83. * button is depressed while the mouse is within the region.
  84. */
  85. void PGMouseWatcherRegion::
  86. press(const MouseWatcherParameter &param) {
  87. if (_item != nullptr) {
  88. _item->press(param, false);
  89. }
  90. }
  91. /**
  92. * This is a callback hook function, called whenever a mouse or keyboard
  93. * button previously depressed with press() is released.
  94. */
  95. void PGMouseWatcherRegion::
  96. release(const MouseWatcherParameter &param) {
  97. if (_item != nullptr) {
  98. _item->release(param, false);
  99. }
  100. }
  101. /**
  102. * This is a callback hook function, called whenever the user presses a key.
  103. */
  104. void PGMouseWatcherRegion::
  105. keystroke(const MouseWatcherParameter &param) {
  106. if (_item != nullptr) {
  107. _item->keystroke(param, false);
  108. }
  109. }
  110. /**
  111. * This is a callback hook function, called whenever the user selects an
  112. * option from the IME menu.
  113. */
  114. void PGMouseWatcherRegion::
  115. candidate(const MouseWatcherParameter &param) {
  116. if (_item != nullptr) {
  117. _item->candidate(param, false);
  118. }
  119. }
  120. /**
  121. * This is a callback hook function, called whenever the user moves the mouse
  122. * within the region
  123. */
  124. void PGMouseWatcherRegion::
  125. move(const MouseWatcherParameter &param) {
  126. if (_item != nullptr) {
  127. _item->move(param);
  128. }
  129. }