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.

88 lines
2.3KB

  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 "SubWidgetPrivateData.hpp"
  17. SubWidget::SubWidget(Widget* const widgetToGroupTo)
  18. : pData(new PrivateData(this, widgetToGroupTo)) {}
  19. SubWidget::~SubWidget()
  20. {
  21. delete pData;
  22. }
  23. template<typename T>
  24. bool SubWidget::contains(T x, T y) const noexcept
  25. {
  26. const Size<uint>& size(getSize());
  27. return (x >= 0 && y >= 0 && static_cast<uint>(x) < size.getWidth() && static_cast<uint>(y) < size.getHeight());
  28. }
  29. template<typename T>
  30. bool SubWidget::contains(const Point<T>& pos) const noexcept
  31. {
  32. return contains(pos.getX(), pos.getY());
  33. }
  34. int SubWidget::getAbsoluteX() const noexcept
  35. {
  36. return pData->absolutePos.getX();
  37. }
  38. int SubWidget::getAbsoluteY() const noexcept
  39. {
  40. return pData->absolutePos.getY();
  41. }
  42. const Point<int>& SubWidget::getAbsolutePos() const noexcept
  43. {
  44. return pData->absolutePos;
  45. }
  46. void SubWidget::setAbsoluteX(int x) noexcept
  47. {
  48. setAbsolutePos(Point<int>(x, getAbsoluteY()));
  49. }
  50. void SubWidget::setAbsoluteY(int y) noexcept
  51. {
  52. setAbsolutePos(Point<int>(getAbsoluteX(), y));
  53. }
  54. void SubWidget::setAbsolutePos(int x, int y) noexcept
  55. {
  56. setAbsolutePos(Point<int>(x, y));
  57. }
  58. void SubWidget::setAbsolutePos(const Point<int>& pos) noexcept
  59. {
  60. if (pData->absolutePos == pos)
  61. return;
  62. PositionChangedEvent ev;
  63. ev.oldPos = pData->absolutePos;
  64. ev.pos = pos;
  65. pData->absolutePos = pos;
  66. onPositionChanged(ev);
  67. getTopLevelWidget().repaint();
  68. }
  69. void SubWidget::onPositionChanged(const PositionChangedEvent&)
  70. {
  71. }