DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit a0f81b0bd54621125d1eb1e0a5f9a94e6d17ec1f
parent 3d1ea2546596f99fe0013e3b6db8478c35eaefff
Author: falkTX <falktx@falktx.com>
Date:   Mon, 14 Jun 2021 22:20:47 +0100

Allow event coordinate margins in SubWidget

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdgl/SubWidget.hpp | 16++++++++++++++++
Mdgl/src/SubWidget.cpp | 25++++++++++++++++++++-----
Mdgl/src/SubWidgetPrivateData.cpp | 1+
Mdgl/src/SubWidgetPrivateData.hpp | 1+
Mdgl/src/WidgetPrivateData.cpp | 12++++++------
5 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/dgl/SubWidget.hpp b/dgl/SubWidget.hpp @@ -112,6 +112,22 @@ public: void setAbsolutePos(const Point<int>& pos) noexcept; /** + Get the margin currently in use for widget coordinates. + By default this value is (0,0). + */ + Point<int> getMargin() const noexcept; + + /** + Set a margin to be used for widget coordinates using @a x and @a y values. + */ + void setMargin(int x, int y) noexcept; + + /** + Set a margin to be used for widget coordinates. + */ + void setMargin(const Point<int>& offset) noexcept; + + /** Get parent Widget, as passed in the constructor. */ Widget* getParentWidget() const noexcept; diff --git a/dgl/src/SubWidget.cpp b/dgl/src/SubWidget.cpp @@ -32,9 +32,9 @@ SubWidget::~SubWidget() } template<typename T> -bool SubWidget::contains(T x, T y) const noexcept +bool SubWidget::contains(const T x, const T y) const noexcept { - return Rectangle<double>(0, 0, getWidth(), getHeight()).contains(x, y); + return Rectangle<double>(0, 0, getWidth()-pData->margin.getX(), getHeight()-pData->margin.getY()).contains(x, y); } template<typename T> @@ -70,17 +70,17 @@ Rectangle<uint> SubWidget::getConstrainedAbsoluteArea() const noexcept getSize()); } -void SubWidget::setAbsoluteX(int x) noexcept +void SubWidget::setAbsoluteX(const int x) noexcept { setAbsolutePos(Point<int>(x, getAbsoluteY())); } -void SubWidget::setAbsoluteY(int y) noexcept +void SubWidget::setAbsoluteY(const int y) noexcept { setAbsolutePos(Point<int>(getAbsoluteX(), y)); } -void SubWidget::setAbsolutePos(int x, int y) noexcept +void SubWidget::setAbsolutePos(const int x, const int y) noexcept { setAbsolutePos(Point<int>(x, y)); } @@ -100,6 +100,21 @@ void SubWidget::setAbsolutePos(const Point<int>& pos) noexcept repaint(); } +Point<int> SubWidget::getMargin() const noexcept +{ + return pData->margin; +} + +void SubWidget::setMargin(const int x, const int y) noexcept +{ + pData->margin = Point<int>(x, y); +} + +void SubWidget::setMargin(const Point<int>& offset) noexcept +{ + pData->margin = offset; +} + Widget* SubWidget::getParentWidget() const noexcept { return pData->parentWidget; diff --git a/dgl/src/SubWidgetPrivateData.cpp b/dgl/src/SubWidgetPrivateData.cpp @@ -26,6 +26,7 @@ SubWidget::PrivateData::PrivateData(SubWidget* const s, Widget* const pw) selfw((Widget*)s), parentWidget(pw), absolutePos(), + margin(), needsFullViewportForDrawing(false), needsViewportScaling(false), skipDrawing(false), diff --git a/dgl/src/SubWidgetPrivateData.hpp b/dgl/src/SubWidgetPrivateData.hpp @@ -28,6 +28,7 @@ struct SubWidget::PrivateData { Widget* const selfw; Widget* const parentWidget; Point<int> absolutePos; + Point<int> margin; bool needsFullViewportForDrawing; // needed for widgets drawing out of bounds bool needsViewportScaling; // needed for NanoVG bool skipDrawing; // for context reuse in NanoVG based guis diff --git a/dgl/src/WidgetPrivateData.cpp b/dgl/src/WidgetPrivateData.cpp @@ -152,8 +152,8 @@ bool Widget::PrivateData::giveMouseEventForSubWidgets(MouseEvent& ev) if (! widget->isVisible()) continue; - ev.pos = Point<double>(x - widget->getAbsoluteX(), - y - widget->getAbsoluteY()); + ev.pos = Point<double>(x - widget->getAbsoluteX() + widget->getMargin().getX(), + y - widget->getAbsoluteY() + widget->getMargin().getY()); if (widget->onMouse(ev)) return true; @@ -191,8 +191,8 @@ bool Widget::PrivateData::giveMotionEventForSubWidgets(MotionEvent& ev) if (! widget->isVisible()) continue; - ev.pos = Point<double>(x - widget->getAbsoluteX(), - y - widget->getAbsoluteY()); + ev.pos = Point<double>(x - widget->getAbsoluteX() + widget->getMargin().getX(), + y - widget->getAbsoluteY() + widget->getMargin().getY()); if (widget->onMotion(ev)) return true; @@ -230,8 +230,8 @@ bool Widget::PrivateData::giveScrollEventForSubWidgets(ScrollEvent& ev) if (! widget->isVisible()) continue; - ev.pos = Point<double>(x - widget->getAbsoluteX(), - y - widget->getAbsoluteY()); + ev.pos = Point<double>(x - widget->getAbsoluteX() + widget->getMargin().getX(), + y - widget->getAbsoluteY() + widget->getMargin().getY()); if (widget->onScroll(ev)) return true;