DISTRHO Plugin Framework
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.

169 lines
5.1KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "TopLevelWidgetPrivateData.hpp"
  17. #include "WidgetPrivateData.hpp"
  18. #include "WindowPrivateData.hpp"
  19. #include "pugl.hpp"
  20. START_NAMESPACE_DGL
  21. // -----------------------------------------------------------------------
  22. TopLevelWidget::PrivateData::PrivateData(TopLevelWidget* const s, Window& w)
  23. : self(s),
  24. selfw(s),
  25. window(w)
  26. {
  27. window.pData->topLevelWidgets.push_back(self);
  28. }
  29. TopLevelWidget::PrivateData::~PrivateData()
  30. {
  31. window.pData->topLevelWidgets.remove(self);
  32. }
  33. bool TopLevelWidget::PrivateData::keyboardEvent(const KeyboardEvent& ev)
  34. {
  35. // ignore event if we are not visible
  36. if (! selfw->pData->visible)
  37. return false;
  38. // give top-level widget chance to catch this event first
  39. if (self->onKeyboard(ev))
  40. return true;
  41. // propagate event to all subwidgets recursively
  42. return selfw->pData->giveKeyboardEventForSubWidgets(ev);
  43. }
  44. bool TopLevelWidget::PrivateData::specialEvent(const SpecialEvent& ev)
  45. {
  46. // ignore event if we are not visible
  47. if (! selfw->pData->visible)
  48. return false;
  49. // give top-level widget chance to catch this event first
  50. if (self->onSpecial(ev))
  51. return true;
  52. // propagate event to all subwidgets recursively
  53. return selfw->pData->giveSpecialEventForSubWidgets(ev);
  54. }
  55. bool TopLevelWidget::PrivateData::characterInputEvent(const CharacterInputEvent& ev)
  56. {
  57. // ignore event if we are not visible
  58. if (! selfw->pData->visible)
  59. return false;
  60. // give top-level widget chance to catch this event first
  61. if (self->onCharacterInput(ev))
  62. return true;
  63. // propagate event to all subwidgets recursively
  64. return selfw->pData->giveCharacterInputEventForSubWidgets(ev);
  65. }
  66. bool TopLevelWidget::PrivateData::mouseEvent(const MouseEvent& ev)
  67. {
  68. // ignore event if we are not visible
  69. if (! selfw->pData->visible)
  70. return false;
  71. MouseEvent rev = ev;
  72. if (window.pData->autoScaling)
  73. {
  74. const double autoScaleFactor = window.pData->autoScaleFactor;
  75. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  76. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  77. rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor);
  78. rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor);
  79. }
  80. // give top-level widget chance to catch this event first
  81. if (self->onMouse(ev))
  82. return true;
  83. // propagate event to all subwidgets recursively
  84. return selfw->pData->giveMouseEventForSubWidgets(rev);
  85. }
  86. bool TopLevelWidget::PrivateData::motionEvent(const MotionEvent& ev)
  87. {
  88. // ignore event if we are not visible
  89. if (! selfw->pData->visible)
  90. return false;
  91. MotionEvent rev = ev;
  92. if (window.pData->autoScaling)
  93. {
  94. const double autoScaleFactor = window.pData->autoScaleFactor;
  95. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  96. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  97. rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor);
  98. rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor);
  99. }
  100. // give top-level widget chance to catch this event first
  101. if (self->onMotion(ev))
  102. return true;
  103. // propagate event to all subwidgets recursively
  104. return selfw->pData->giveMotionEventForSubWidgets(rev);
  105. }
  106. bool TopLevelWidget::PrivateData::scrollEvent(const ScrollEvent& ev)
  107. {
  108. // ignore event if we are not visible
  109. if (! selfw->pData->visible)
  110. return false;
  111. ScrollEvent rev = ev;
  112. if (window.pData->autoScaling)
  113. {
  114. const double autoScaleFactor = window.pData->autoScaleFactor;
  115. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  116. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  117. rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor);
  118. rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor);
  119. rev.delta.setX(ev.delta.getX() / autoScaleFactor);
  120. rev.delta.setY(ev.delta.getY() / autoScaleFactor);
  121. }
  122. // give top-level widget chance to catch this event first
  123. if (self->onScroll(ev))
  124. return true;
  125. // propagate event to all subwidgets recursively
  126. return selfw->pData->giveScrollEventForSubWidgets(rev);
  127. }
  128. void TopLevelWidget::PrivateData::fallbackOnResize()
  129. {
  130. puglFallbackOnResize(window.pData->view);
  131. }
  132. // -----------------------------------------------------------------------
  133. END_NAMESPACE_DGL