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.

163 lines
4.7KB

  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. }
  78. // give top-level widget chance to catch this event first
  79. if (self->onMouse(ev))
  80. return true;
  81. // propagate event to all subwidgets recursively
  82. return selfw->pData->giveMouseEventForSubWidgets(rev);
  83. }
  84. bool TopLevelWidget::PrivateData::motionEvent(const MotionEvent& ev)
  85. {
  86. // ignore event if we are not visible
  87. if (! selfw->pData->visible)
  88. return false;
  89. MotionEvent rev = ev;
  90. if (window.pData->autoScaling)
  91. {
  92. const double autoScaleFactor = window.pData->autoScaleFactor;
  93. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  94. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  95. }
  96. // give top-level widget chance to catch this event first
  97. if (self->onMotion(ev))
  98. return true;
  99. // propagate event to all subwidgets recursively
  100. return selfw->pData->giveMotionEventForSubWidgets(rev);
  101. }
  102. bool TopLevelWidget::PrivateData::scrollEvent(const ScrollEvent& ev)
  103. {
  104. // ignore event if we are not visible
  105. if (! selfw->pData->visible)
  106. return false;
  107. ScrollEvent rev = ev;
  108. if (window.pData->autoScaling)
  109. {
  110. const double autoScaleFactor = window.pData->autoScaleFactor;
  111. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  112. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  113. rev.delta.setX(ev.delta.getX() / autoScaleFactor);
  114. rev.delta.setY(ev.delta.getY() / autoScaleFactor);
  115. }
  116. // give top-level widget chance to catch this event first
  117. if (self->onScroll(ev))
  118. return true;
  119. // propagate event to all subwidgets recursively
  120. return selfw->pData->giveScrollEventForSubWidgets(rev);
  121. }
  122. void TopLevelWidget::PrivateData::fallbackOnResize()
  123. {
  124. puglFallbackOnResize(window.pData->view);
  125. }
  126. // -----------------------------------------------------------------------
  127. END_NAMESPACE_DGL