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.

140 lines
4.5KB

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