get rid of local cursor artifacts
authorChristian Pulvermacher <christian@hazel.(none)>
Fri, 17 Sep 2010 01:00:37 +0000 (03:00 +0200)
committerChristian Pulvermacher <christian@hazel.(none)>
Fri, 17 Sep 2010 01:00:37 +0000 (03:00 +0200)
src/vncview.cpp

index 691ad86..bdfe3da 100644 (file)
@@ -456,17 +456,29 @@ void VncView::paintEvent(QPaintEvent *event)
     }
 
        //draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
+       //TODO check boundaries against event->rect()
        if((m_dotCursorState == CursorOn) || m_forceLocalCursor) {
                const uchar bits[] = { 0xff, 0x8e, 0x8e, 0x8e, 0xff };
                const bool little_endian = (Q_BYTE_ORDER == Q_LITTLE_ENDIAN);
                const QBitmap cursorBitmap = QBitmap::fromData(QSize(5,5), bits , little_endian?QImage::Format_Mono:QImage::Format_MonoLSB);
 
+
+               //Qt <= 4.4 doesn't support Xor, so expect some artifacts there (it's ancient, after all)
 #if QT_VERSION >= 0x040500
                painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
+
+               static int old_cursor_x = cursor_x;
+               static int old_cursor_y = cursor_y;
+
+               if(cursor_x != old_cursor_x or cursor_y != old_cursor_y) {
+                       //position changed, clear last position (since we're using xor, we'll just paint it again)
+                       painter.drawPixmap(old_cursor_x*m_horizontalFactor - 2, old_cursor_y*m_verticalFactor - 2, cursorBitmap);
+
+                       old_cursor_x = cursor_x; old_cursor_y = cursor_y;
+               }
 #endif
 
-               painter.drawPixmap(cursor_x-2, cursor_y-2, cursorBitmap);
-               //TODO update position of last cursor_x/y to avoid artifacts
+               painter.drawPixmap(cursor_x*m_horizontalFactor - 2, cursor_y*m_verticalFactor - 2, cursorBitmap);
        }
 
     RemoteView::paintEvent(event);