2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
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.
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.
17 #include "SubWidgetPrivateData.hpp"
18 #include "WidgetPrivateData.hpp"
19 #include "../TopLevelWidget.hpp"
23 // --------------------------------------------------------------------------------------------------------------------
25 SubWidget::SubWidget(Widget
* const parentWidget
)
26 : Widget(parentWidget
),
27 pData(new PrivateData(this, parentWidget
)) {}
29 SubWidget::~SubWidget()
35 bool SubWidget::contains(const T x
, const T y
) const noexcept
37 return Rectangle
<double>(0, 0,
38 static_cast<double>(getWidth()),
39 static_cast<double>(getHeight())).contains(x
, y
);
43 bool SubWidget::contains(const Point
<T
>& pos
) const noexcept
45 return contains(pos
.getX(), pos
.getY());
48 int SubWidget::getAbsoluteX() const noexcept
50 return pData
->absolutePos
.getX();
53 int SubWidget::getAbsoluteY() const noexcept
55 return pData
->absolutePos
.getY();
58 Point
<int> SubWidget::getAbsolutePos() const noexcept
60 return pData
->absolutePos
;
63 Rectangle
<int> SubWidget::getAbsoluteArea() const noexcept
65 return Rectangle
<int>(getAbsolutePos(), getSize().toInt());
68 Rectangle
<uint
> SubWidget::getConstrainedAbsoluteArea() const noexcept
70 const int x
= getAbsoluteX();
71 const int y
= getAbsoluteY();
74 return Rectangle
<uint
>(x
, y
, getSize());
76 const int xOffset
= std::min(0, x
);
77 const int yOffset
= std::min(0, y
);
78 const int width
= std::max(0, static_cast<int>(getWidth()) + xOffset
);
79 const int height
= std::max(0, static_cast<int>(getHeight()) + yOffset
);
81 return Rectangle
<uint
>(0, 0, static_cast<uint
>(width
), static_cast<uint
>(height
));
84 void SubWidget::setAbsoluteX(const int x
) noexcept
86 setAbsolutePos(Point
<int>(x
, getAbsoluteY()));
89 void SubWidget::setAbsoluteY(const int y
) noexcept
91 setAbsolutePos(Point
<int>(getAbsoluteX(), y
));
94 void SubWidget::setAbsolutePos(const int x
, const int y
) noexcept
96 setAbsolutePos(Point
<int>(x
, y
));
99 void SubWidget::setAbsolutePos(const Point
<int>& pos
) noexcept
101 if (pData
->absolutePos
== pos
)
104 PositionChangedEvent ev
;
105 ev
.oldPos
= pData
->absolutePos
;
108 pData
->absolutePos
= pos
;
109 onPositionChanged(ev
);
114 Point
<int> SubWidget::getMargin() const noexcept
116 return pData
->margin
;
119 void SubWidget::setMargin(const int x
, const int y
) noexcept
121 pData
->margin
= Point
<int>(x
, y
);
124 void SubWidget::setMargin(const Point
<int>& offset
) noexcept
126 pData
->margin
= offset
;
129 Widget
* SubWidget::getParentWidget() const noexcept
131 return pData
->parentWidget
;
134 void SubWidget::repaint() noexcept
139 if (TopLevelWidget
* const topw
= getTopLevelWidget())
141 if (pData
->needsFullViewportForDrawing
)
144 topw
->repaint(getConstrainedAbsoluteArea());
148 void SubWidget::toFront()
150 std::list
<SubWidget
*>& subwidgets(pData
->parentWidget
->pData
->subWidgets
);
152 subwidgets
.remove(this);
153 subwidgets
.push_back(this);
156 void SubWidget::setNeedsFullViewportDrawing(const bool needsFullViewportForDrawing
)
158 pData
->needsFullViewportForDrawing
= needsFullViewportForDrawing
;
161 void SubWidget::setNeedsViewportScaling(const bool needsViewportScaling
, const double autoScaleFactor
)
163 pData
->needsViewportScaling
= needsViewportScaling
;
164 pData
->viewportScaleFactor
= autoScaleFactor
;
167 void SubWidget::setSkipDrawing(const bool skipDrawing
)
169 pData
->skipDrawing
= skipDrawing
;
172 void SubWidget::onPositionChanged(const PositionChangedEvent
&)
176 // --------------------------------------------------------------------------------------------------------------------
177 // Possible template data types
180 bool SubWidget::contains(const Point
<double>& pos
) const noexcept
182 return contains(pos
.getX(), pos
.getY());
185 // float, int, uint, short, ushort
187 // --------------------------------------------------------------------------------------------------------------------