Collection of DPF-based plugins for packaging
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.

135 lines
4.2KB

  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. // propagate event to all subwidgets recursively
  39. return selfw->pData->giveKeyboardEventForSubWidgets(ev);
  40. }
  41. bool TopLevelWidget::PrivateData::characterInputEvent(const CharacterInputEvent& ev)
  42. {
  43. // ignore event if we are not visible
  44. if (! selfw->pData->visible)
  45. return false;
  46. // propagate event to all subwidgets recursively
  47. return selfw->pData->giveCharacterInputEventForSubWidgets(ev);
  48. }
  49. bool TopLevelWidget::PrivateData::mouseEvent(const MouseEvent& ev)
  50. {
  51. // ignore event if we are not visible
  52. if (! selfw->pData->visible)
  53. return false;
  54. MouseEvent rev = ev;
  55. if (window.pData->autoScaling)
  56. {
  57. const double autoScaleFactor = window.pData->autoScaleFactor;
  58. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  59. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  60. rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor);
  61. rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor);
  62. }
  63. // propagate event to all subwidgets recursively
  64. return selfw->pData->giveMouseEventForSubWidgets(rev);
  65. }
  66. bool TopLevelWidget::PrivateData::motionEvent(const MotionEvent& ev)
  67. {
  68. // ignore event if we are not visible
  69. if (! selfw->pData->visible)
  70. return false;
  71. MotionEvent 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. // propagate event to all subwidgets recursively
  81. return selfw->pData->giveMotionEventForSubWidgets(rev);
  82. }
  83. bool TopLevelWidget::PrivateData::scrollEvent(const ScrollEvent& ev)
  84. {
  85. // ignore event if we are not visible
  86. if (! selfw->pData->visible)
  87. return false;
  88. ScrollEvent rev = ev;
  89. if (window.pData->autoScaling)
  90. {
  91. const double autoScaleFactor = window.pData->autoScaleFactor;
  92. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  93. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  94. rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor);
  95. rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor);
  96. rev.delta.setX(ev.delta.getX() / autoScaleFactor);
  97. rev.delta.setY(ev.delta.getY() / autoScaleFactor);
  98. }
  99. // propagate event to all subwidgets recursively
  100. return selfw->pData->giveScrollEventForSubWidgets(rev);
  101. }
  102. void TopLevelWidget::PrivateData::fallbackOnResize()
  103. {
  104. puglFallbackOnResize(window.pData->view);
  105. }
  106. // -----------------------------------------------------------------------
  107. END_NAMESPACE_DGL