Browse Source

Allow event coordinate margins in SubWidget

Signed-off-by: falkTX <falktx@falktx.com>
pull/292/head
falkTX 3 years ago
parent
commit
a0f81b0bd5
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 44 additions and 11 deletions
  1. +16
    -0
      dgl/SubWidget.hpp
  2. +20
    -5
      dgl/src/SubWidget.cpp
  3. +1
    -0
      dgl/src/SubWidgetPrivateData.cpp
  4. +1
    -0
      dgl/src/SubWidgetPrivateData.hpp
  5. +6
    -6
      dgl/src/WidgetPrivateData.cpp

+ 16
- 0
dgl/SubWidget.hpp View File

@@ -111,6 +111,22 @@ public:
*/ */
void setAbsolutePos(const Point<int>& pos) noexcept; 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. Get parent Widget, as passed in the constructor.
*/ */


+ 20
- 5
dgl/src/SubWidget.cpp View File

@@ -32,9 +32,9 @@ SubWidget::~SubWidget()
} }


template<typename T> 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> template<typename T>
@@ -70,17 +70,17 @@ Rectangle<uint> SubWidget::getConstrainedAbsoluteArea() const noexcept
getSize()); getSize());
} }


void SubWidget::setAbsoluteX(int x) noexcept
void SubWidget::setAbsoluteX(const int x) noexcept
{ {
setAbsolutePos(Point<int>(x, getAbsoluteY())); setAbsolutePos(Point<int>(x, getAbsoluteY()));
} }


void SubWidget::setAbsoluteY(int y) noexcept
void SubWidget::setAbsoluteY(const int y) noexcept
{ {
setAbsolutePos(Point<int>(getAbsoluteX(), y)); 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)); setAbsolutePos(Point<int>(x, y));
} }
@@ -100,6 +100,21 @@ void SubWidget::setAbsolutePos(const Point<int>& pos) noexcept
repaint(); 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 Widget* SubWidget::getParentWidget() const noexcept
{ {
return pData->parentWidget; return pData->parentWidget;


+ 1
- 0
dgl/src/SubWidgetPrivateData.cpp View File

@@ -26,6 +26,7 @@ SubWidget::PrivateData::PrivateData(SubWidget* const s, Widget* const pw)
selfw((Widget*)s), selfw((Widget*)s),
parentWidget(pw), parentWidget(pw),
absolutePos(), absolutePos(),
margin(),
needsFullViewportForDrawing(false), needsFullViewportForDrawing(false),
needsViewportScaling(false), needsViewportScaling(false),
skipDrawing(false), skipDrawing(false),


+ 1
- 0
dgl/src/SubWidgetPrivateData.hpp View File

@@ -28,6 +28,7 @@ struct SubWidget::PrivateData {
Widget* const selfw; Widget* const selfw;
Widget* const parentWidget; Widget* const parentWidget;
Point<int> absolutePos; Point<int> absolutePos;
Point<int> margin;
bool needsFullViewportForDrawing; // needed for widgets drawing out of bounds bool needsFullViewportForDrawing; // needed for widgets drawing out of bounds
bool needsViewportScaling; // needed for NanoVG bool needsViewportScaling; // needed for NanoVG
bool skipDrawing; // for context reuse in NanoVG based guis bool skipDrawing; // for context reuse in NanoVG based guis


+ 6
- 6
dgl/src/WidgetPrivateData.cpp View File

@@ -152,8 +152,8 @@ bool Widget::PrivateData::giveMouseEventForSubWidgets(MouseEvent& ev)
if (! widget->isVisible()) if (! widget->isVisible())
continue; 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)) if (widget->onMouse(ev))
return true; return true;
@@ -191,8 +191,8 @@ bool Widget::PrivateData::giveMotionEventForSubWidgets(MotionEvent& ev)
if (! widget->isVisible()) if (! widget->isVisible())
continue; 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)) if (widget->onMotion(ev))
return true; return true;
@@ -230,8 +230,8 @@ bool Widget::PrivateData::giveScrollEventForSubWidgets(ScrollEvent& ev)
if (! widget->isVisible()) if (! widget->isVisible())
continue; 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)) if (widget->onScroll(ev))
return true; return true;


Loading…
Cancel
Save