File indexing completed on 2024-05-19 05:31:36
0001 /* 0002 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kwin_export.h" 0010 0011 #include <QRect> 0012 0013 namespace KWin 0014 { 0015 0016 KWIN_EXPORT inline QPoint snapToPixelGrid(const QPointF &point) 0017 { 0018 return QPoint(std::round(point.x()), std::round(point.y())); 0019 } 0020 0021 KWIN_EXPORT inline QPointF snapToPixelGridF(const QPointF &point) 0022 { 0023 return QPointF(std::round(point.x()), std::round(point.y())); 0024 } 0025 0026 KWIN_EXPORT inline QRect snapToPixelGrid(const QRectF &rect) 0027 { 0028 const QPoint topLeft = snapToPixelGrid(rect.topLeft()); 0029 const QPoint bottomRight = snapToPixelGrid(rect.bottomRight()); 0030 return QRect(topLeft.x(), topLeft.y(), bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y()); 0031 } 0032 0033 KWIN_EXPORT inline QRectF snapToPixelGridF(const QRectF &rect) 0034 { 0035 return QRectF(snapToPixelGridF(rect.topLeft()), snapToPixelGridF(rect.bottomRight())); 0036 } 0037 0038 } // namespace KWin