PointerState.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "PointerState.h"
  2. #include "Actor.h"
  3. namespace oxygine
  4. {
  5. PointerState::PointerState(): _index(0)
  6. {
  7. init(_index);
  8. }
  9. void PointerState::init(int pointerIndex)
  10. {
  11. _index = pointerIndex;
  12. for (int i = 0; i < MouseButton_Count; ++i)
  13. _isPressed[i] = false;
  14. _position.setZero();
  15. }
  16. bool isFriend22(Actor* actor, Actor* max_parent, Actor* checkParent)
  17. {
  18. if (!max_parent)
  19. max_parent = actor;
  20. Actor* parent = actor;
  21. while (parent)
  22. {
  23. if (parent == checkParent)
  24. return true;
  25. Actor* copy = parent;
  26. parent = parent->getParent();
  27. if (copy == max_parent)
  28. break;
  29. }
  30. return false;
  31. }
  32. /*
  33. bool checkParent(spEventHandler eh, Actor *checkIsItChild)
  34. {
  35. Actor *parent = eh->getFriendActor();
  36. if (!parent)
  37. {
  38. if (eh->getClient() == checkIsItChild)
  39. return true;
  40. return false;
  41. }
  42. while (checkIsItChild)
  43. {
  44. if (checkIsItChild == parent)
  45. return true;
  46. checkIsItChild = checkIsItChild->getParent();
  47. }
  48. return false;
  49. }
  50. */
  51. Vector2 global2local(Actor* actor, const Vector2& globalPos)
  52. {
  53. Vector2 pos = globalPos;
  54. if (!actor)
  55. return pos;
  56. Actor* parent = actor->getParent();
  57. if (parent)
  58. {
  59. pos = global2local(parent, globalPos);
  60. }
  61. pos = actor->global2local(pos);
  62. return pos;
  63. }
  64. }