KWin
Loading...
Searching...
No Matches
pixelgrid.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kwin_export.h"
10
11#include <QRect>
12
13namespace KWin
14{
15
16KWIN_EXPORT inline QPoint snapToPixelGrid(const QPointF &point)
17{
18 return QPoint(std::round(point.x()), std::round(point.y()));
19}
20
21KWIN_EXPORT inline QPointF snapToPixelGridF(const QPointF &point)
22{
23 return QPointF(std::round(point.x()), std::round(point.y()));
24}
25
26KWIN_EXPORT inline QRect snapToPixelGrid(const QRectF &rect)
27{
28 const QPoint topLeft = snapToPixelGrid(rect.topLeft());
29 const QPoint bottomRight = snapToPixelGrid(rect.bottomRight());
30 return QRect(topLeft.x(), topLeft.y(), bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y());
31}
32
33KWIN_EXPORT inline QRectF snapToPixelGridF(const QRectF &rect)
34{
35 return QRectF(snapToPixelGridF(rect.topLeft()), snapToPixelGridF(rect.bottomRight()));
36}
37
38} // namespace KWin
KWIN_EXPORT QPointF snapToPixelGridF(const QPointF &point)
Definition pixelgrid.h:21
KWIN_EXPORT QPoint snapToPixelGrid(const QPointF &point)
Definition pixelgrid.h:16