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.

146 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. /* if window already has a top-level-widget, make the new one match the first one in size
  28. * this is needed because window creation and resize is a synchronous operation in some systems.
  29. * as such, there's a chance the non-1st top-level-widgets would never get a valid size.
  30. */
  31. if (!window.pData->topLevelWidgets.empty())
  32. {
  33. TopLevelWidget* const first = window.pData->topLevelWidgets.front();
  34. selfw->pData->size = first->getSize();
  35. }
  36. window.pData->topLevelWidgets.push_back(self);
  37. }
  38. TopLevelWidget::PrivateData::~PrivateData()
  39. {
  40. window.pData->topLevelWidgets.remove(self);
  41. }
  42. bool TopLevelWidget::PrivateData::keyboardEvent(const KeyboardEvent& ev)
  43. {
  44. // ignore event if we are not visible
  45. if (! selfw->pData->visible)
  46. return false;
  47. // propagate event to all subwidgets recursively
  48. return selfw->pData->giveKeyboardEventForSubWidgets(ev);
  49. }
  50. bool TopLevelWidget::PrivateData::characterInputEvent(const CharacterInputEvent& ev)
  51. {
  52. // ignore event if we are not visible
  53. if (! selfw->pData->visible)
  54. return false;
  55. // propagate event to all subwidgets recursively
  56. return selfw->pData->giveCharacterInputEventForSubWidgets(ev);
  57. }
  58. bool TopLevelWidget::PrivateData::mouseEvent(const MouseEvent& ev)
  59. {
  60. // ignore event if we are not visible
  61. if (! selfw->pData->visible)
  62. return false;
  63. MouseEvent rev = ev;
  64. if (window.pData->autoScaling)
  65. {
  66. const double autoScaleFactor = window.pData->autoScaleFactor;
  67. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  68. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  69. rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor);
  70. rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor);
  71. }
  72. // propagate event to all subwidgets recursively
  73. return selfw->pData->giveMouseEventForSubWidgets(rev);
  74. }
  75. bool TopLevelWidget::PrivateData::motionEvent(const MotionEvent& ev)
  76. {
  77. // ignore event if we are not visible
  78. if (! selfw->pData->visible)
  79. return false;
  80. MotionEvent rev = ev;
  81. if (window.pData->autoScaling)
  82. {
  83. const double autoScaleFactor = window.pData->autoScaleFactor;
  84. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  85. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  86. rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor);
  87. rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor);
  88. }
  89. // propagate event to all subwidgets recursively
  90. return selfw->pData->giveMotionEventForSubWidgets(rev);
  91. }
  92. bool TopLevelWidget::PrivateData::scrollEvent(const ScrollEvent& ev)
  93. {
  94. // ignore event if we are not visible
  95. if (! selfw->pData->visible)
  96. return false;
  97. ScrollEvent rev = ev;
  98. if (window.pData->autoScaling)
  99. {
  100. const double autoScaleFactor = window.pData->autoScaleFactor;
  101. rev.pos.setX(ev.pos.getX() / autoScaleFactor);
  102. rev.pos.setY(ev.pos.getY() / autoScaleFactor);
  103. rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor);
  104. rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor);
  105. rev.delta.setX(ev.delta.getX() / autoScaleFactor);
  106. rev.delta.setY(ev.delta.getY() / autoScaleFactor);
  107. }
  108. // propagate event to all subwidgets recursively
  109. return selfw->pData->giveScrollEventForSubWidgets(rev);
  110. }
  111. void TopLevelWidget::PrivateData::fallbackOnResize(const uint width, const uint height)
  112. {
  113. puglFallbackOnResize(window.pData->view, width, height);
  114. }
  115. // -----------------------------------------------------------------------
  116. END_NAMESPACE_DGL