55
55
#include < QOpenGLTexture>
56
56
#include < QOpenGLFunctions>
57
57
#include < QMatrix4x4>
58
+ #include < QPainter>
58
59
59
60
#include " compositor.h"
60
61
#include < QtWaylandCompositor/qwaylandseat.h>
@@ -72,25 +73,25 @@ void Window::setCompositor(Compositor *comp) {
72
73
73
74
void Window::initializeGL ()
74
75
{
75
- QImage backgroundImage = QImage (QLatin1String (" :/background.jpg" )).rgbSwapped ();
76
- backgroundImage.invertPixels ();
77
- m_backgroundTexture = new QOpenGLTexture (backgroundImage, QOpenGLTexture::DontGenerateMipMaps);
78
- m_backgroundTexture->setMinificationFilter (QOpenGLTexture::Nearest);
79
- m_backgroundImageSize = backgroundImage.size ();
80
76
m_textureBlitter.create ();
81
77
m_compositor->create (); // the compositor's hardware integration may depend on GL
82
78
}
83
79
84
80
void Window::drawBackground ()
85
81
{
86
- for (int y = 0 ; y < height (); y += m_backgroundImageSize.height ()) {
87
- for (int x = 0 ; x < width (); x += m_backgroundImageSize.width ()) {
88
- QMatrix4x4 targetTransform = QOpenGLTextureBlitter::targetTransform (QRect (QPoint (x,y), m_backgroundImageSize), QRect (QPoint (0 ,0 ), size ()));
89
- m_textureBlitter.blit (m_backgroundTexture->textureId (),
90
- targetTransform,
91
- QOpenGLTextureBlitter::OriginTopLeft);
92
- }
82
+ QColor backgroundColor = QColor (0xde , 0xde , 0xde );
83
+ QImage backgroundColorImage = QImage (this ->geometry ().size (), QImage::Format_RGB32);
84
+ backgroundColorImage.fill (backgroundColor);
85
+ QImage backgroundImage = m_backgroundImage;
86
+ if (this ->geometry ().width () < backgroundImage.width () || this ->geometry ().height () < backgroundImage.height ()) {
87
+ backgroundImage = m_backgroundImage.scaled (this ->geometry ().size (), Qt::KeepAspectRatio, Qt::SmoothTransformation);
93
88
}
89
+ QPainter painter (this );
90
+ int deltaX = this ->geometry ().width () - backgroundImage.width ();
91
+ int deltaY = this ->geometry ().height () - backgroundImage.height ();
92
+ painter.drawImage (this ->geometry (), backgroundColorImage);
93
+ painter.translate (deltaX / 2 , deltaY / 2 );
94
+ painter.drawImage (backgroundImage.rect (), backgroundImage);
94
95
}
95
96
96
97
QPointF Window::getAnchorPosition (const QPointF &position, int resizeEdge, const QSize &windowSize)
0 commit comments