/* * DISTRHO Plugin Framework (DPF) * Copyright (C) 2012-2021 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this * permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "SubWidgetPrivateData.hpp" #include "../TopLevelWidget.hpp" START_NAMESPACE_DGL // -------------------------------------------------------------------------------------------------------------------- SubWidget::SubWidget(Widget* const parentWidget) : Widget(parentWidget), pData(new PrivateData(this, parentWidget)) {} SubWidget::~SubWidget() { delete pData; } template bool SubWidget::contains(T x, T y) const noexcept { return Rectangle(0, 0, getWidth(), getHeight()).contains(x, y); } template bool SubWidget::contains(const Point& pos) const noexcept { return contains(pos.getX(), pos.getY()); } int SubWidget::getAbsoluteX() const noexcept { return pData->absolutePos.getX(); } int SubWidget::getAbsoluteY() const noexcept { return pData->absolutePos.getY(); } Point SubWidget::getAbsolutePos() const noexcept { return pData->absolutePos; } Rectangle SubWidget::getAbsoluteArea() const noexcept { return Rectangle(getAbsolutePos(), getSize().toInt()); } Rectangle SubWidget::getConstrainedAbsoluteArea() const noexcept { return Rectangle(static_cast(std::max(0, getAbsoluteX())), static_cast(std::max(0, getAbsoluteY())), getSize()); } void SubWidget::setAbsoluteX(int x) noexcept { setAbsolutePos(Point(x, getAbsoluteY())); } void SubWidget::setAbsoluteY(int y) noexcept { setAbsolutePos(Point(getAbsoluteX(), y)); } void SubWidget::setAbsolutePos(int x, int y) noexcept { setAbsolutePos(Point(x, y)); } void SubWidget::setAbsolutePos(const Point& pos) noexcept { if (pData->absolutePos == pos) return; PositionChangedEvent ev; ev.oldPos = pData->absolutePos; ev.pos = pos; pData->absolutePos = pos; onPositionChanged(ev); // repaint the bounds of parent pData->parentWidget->repaint(); } Widget* SubWidget::getParentWidget() const noexcept { return pData->parentWidget; } void SubWidget::repaint() noexcept { if (! isVisible()) return; if (TopLevelWidget* const topw = getTopLevelWidget()) { if (pData->needsFullViewportForDrawing) topw->repaint(); else topw->repaint(getConstrainedAbsoluteArea()); } } void SubWidget::setNeedsFullViewportDrawing(const bool needsFullViewportForDrawing) { pData->needsFullViewportForDrawing = needsFullViewportForDrawing; } void SubWidget::onPositionChanged(const PositionChangedEvent&) { } // -------------------------------------------------------------------------------------------------------------------- // Possible template data types template<> bool SubWidget::contains(const Point& pos) const noexcept { return contains(pos.getX(), pos.getY()); } // float, int, uint, short, ushort // -------------------------------------------------------------------------------------------------------------------- END_NAMESPACE_DGL