KWin
Loading...
Searching...
No Matches
itemgeometry.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
3 SPDX-FileCopyrightText: 2022 Arjen Hiemstra <ahiemstra@heimr.nl>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#pragma once
9
11
12namespace KWin
13{
14
21class KWIN_EXPORT WindowVertex
22{
23public:
25 WindowVertex(const QPointF &position, const QPointF &textureCoordinate);
26 WindowVertex(double x, double y, double tx, double ty);
27
28 double x() const
29 {
30 return px;
31 }
32 double y() const
33 {
34 return py;
35 }
36 double u() const
37 {
38 return tx;
39 }
40 double v() const
41 {
42 return ty;
43 }
44 void move(double x, double y);
45 void setX(double x);
46 void setY(double y);
47
48private:
49 friend class WindowQuad;
50 friend class WindowQuadList;
51 double px, py; // position
52 double tx, ty; // texture coords
53};
54
60// NOTE: This class expects the (original) vertices to be in the clockwise order starting from topleft.
61class KWIN_EXPORT WindowQuad
62{
63public:
64 WindowQuad();
65 WindowQuad makeSubQuad(double x1, double y1, double x2, double y2) const;
66 WindowVertex &operator[](int index);
67 const WindowVertex &operator[](int index) const;
68 double left() const;
69 double right() const;
70 double top() const;
71 double bottom() const;
72 QRectF bounds() const;
73
74private:
75 friend class WindowQuadList;
76 WindowVertex verts[4];
77};
78
79class KWIN_EXPORT WindowQuadList
80 : public QList<WindowQuad>
81{
82public:
83 WindowQuadList splitAtX(double x) const;
84 WindowQuadList splitAtY(double y) const;
85 WindowQuadList makeGrid(int maxquadsize) const;
86 WindowQuadList makeRegularGrid(int xSubdivisions, int ySubdivisions) const;
87};
88
96class KWIN_EXPORT RenderGeometry : public QList<GLVertex2D>
97{
98public:
110 None, //< No rounding, device coordinates containing fractional parts
111 // are passed directly to the rendering system.
112 Round, //< Perform a simple rounding, device coordinates will not have
113 // any fractional parts.
114 };
115
122 {
123 return m_vertexSnappingMode;
124 }
135 {
136 m_vertexSnappingMode = mode;
137 }
146 void copy(std::span<GLVertex2D> destination);
158 void appendWindowVertex(const WindowVertex &windowVertex, qreal deviceScale);
171 void appendWindowQuad(const WindowQuad &quad, qreal deviceScale);
187 void appendSubQuad(const WindowQuad &quad, const QRectF &subquad, qreal deviceScale);
198 void postProcessTextureCoordinates(const QMatrix4x4 &textureMatrix);
199
200private:
201 VertexSnappingMode m_vertexSnappingMode = VertexSnappingMode::Round;
202};
203
205 : px(0)
206 , py(0)
207 , tx(0)
208 , ty(0)
209{
210}
211
212inline WindowVertex::WindowVertex(double _x, double _y, double _tx, double _ty)
213 : px(_x)
214 , py(_y)
215 , tx(_tx)
216 , ty(_ty)
217{
218}
219
220inline WindowVertex::WindowVertex(const QPointF &position, const QPointF &texturePosition)
221 : px(position.x())
222 , py(position.y())
223 , tx(texturePosition.x())
224 , ty(texturePosition.y())
225{
226}
227
228inline void WindowVertex::move(double x, double y)
229{
230 px = x;
231 py = y;
232}
233
234inline void WindowVertex::setX(double x)
235{
236 px = x;
237}
238
239inline void WindowVertex::setY(double y)
240{
241 py = y;
242}
243
245{
246}
247
249{
250 Q_ASSERT(index >= 0 && index < 4);
251 return verts[index];
252}
253
254inline const WindowVertex &WindowQuad::operator[](int index) const
255{
256 Q_ASSERT(index >= 0 && index < 4);
257 return verts[index];
258}
259
260inline double WindowQuad::left() const
261{
262 return std::min(verts[0].px, std::min(verts[1].px, std::min(verts[2].px, verts[3].px)));
263}
264
265inline double WindowQuad::right() const
266{
267 return std::max(verts[0].px, std::max(verts[1].px, std::max(verts[2].px, verts[3].px)));
268}
269
270inline double WindowQuad::top() const
271{
272 return std::min(verts[0].py, std::min(verts[1].py, std::min(verts[2].py, verts[3].py)));
273}
274
275inline double WindowQuad::bottom() const
276{
277 return std::max(verts[0].py, std::max(verts[1].py, std::max(verts[2].py, verts[3].py)));
278}
279
280inline QRectF WindowQuad::bounds() const
281{
282 return QRectF(QPointF(left(), top()), QPointF(right(), bottom()));
283}
284
285} // namespace KWin
VertexSnappingMode vertexSnappingMode() const
void setVertexSnappingMode(VertexSnappingMode mode)
Class representing one area of a window.
double left() const
double bottom() const
WindowVertex & operator[](int index)
double right() const
double top() const
QRectF bounds() const
Vertex class.
double x() const
void move(double x, double y)
void setY(double y)
double u() const
void setX(double x)
double v() const
double y() const