QTfrontend/ui/widget/bgwidget.cpp
changeset 6241 e2c7771162ae
parent 6060 fdfc01419815
child 6242 27297c421bbc
--- a/QTfrontend/ui/widget/bgwidget.cpp	Sun Oct 30 08:01:26 2011 +0100
+++ b/QTfrontend/ui/widget/bgwidget.cpp	Sun Oct 30 15:31:30 2011 +0100
@@ -36,7 +36,8 @@
     fY += fYMov;
     iAngle += 4;
     if (iAngle >= 360) iAngle = 0;
-    if (fY > wParent->height()) reset();
+    if ((fX - fXMov) > wParent->width()) reset();
+    else if ((fY - fYMov) > wParent->height()) reset();
 }
 
 void SpritePosition::reset()
@@ -73,7 +74,7 @@
 
     for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i] = new SpritePosition(this, sprite.height());
 
-    for (int i = 0; i < 360; i++)
+    for (int i = 0; i < 90; i++)
     {
         rotatedSprites[i] = new QImage(sprite.width(), sprite.height(), QImage::Format_ARGB32);
         rotatedSprites[i]->fill(0);
@@ -85,7 +86,7 @@
     //  p.setRenderHint(QPainter::Antialiasing);
         p.setRenderHint(QPainter::SmoothPixmapTransform);
         p.translate(translate.x(), translate.y());
-        p.rotate(i);
+        p.rotate(4 * i);
         p.translate(-1*translate.x(), -1*translate.y());
         p.drawImage(0, 0, sprite);
     }
@@ -98,7 +99,7 @@
 BGWidget::~BGWidget()
 {
     for (int i = 0; i < SPRITE_MAX; i++) delete spritePositions[i];
-    for (int i = 0; i < 360; i++) delete rotatedSprites[i];
+    for (int i = 0; i < 90; i++) delete rotatedSprites[i];
     delete timerAnimation;
 }
 
@@ -107,13 +108,15 @@
     Q_UNUSED(event);
 
     QPainter p;
+
     p.begin(this);
-    //p.setRenderHint(QPainter::Antialiasing);
+
     for (int i = 0; i < SPRITE_MAX; i++)
     {
         QPoint point = spritePositions[i]->pos();
-        p.drawImage(point.x(), point.y(), *rotatedSprites[spritePositions[i]->getAngle()]);
+        p.drawImage(point.x(), point.y(), *rotatedSprites[spritePositions[i]->getAngle()/4]);
     }
+
     p.end();
 }
 
@@ -121,9 +124,13 @@
 {
     for (int i = 0; i < SPRITE_MAX; i++)
     {
-        // bottom edge of star *seems* clipped, but in fact, if I switch to just plain old repaint()/update() it is still clipped - artifact of transform?  As for 5, is arbitrary number. 4 was noticeably clipping, 5 seemed same as update() - I assume extra room is due to rotation and value really should be calculated proportional to width/height
-        update(spritePositions[i]->pos().x(),spritePositions[i]->pos().y(), sprite.width()+5, sprite.height()+5);
+        QPoint oldPos = spritePositions[i]->pos();
         spritePositions[i]->move();
+        QPoint newPos = spritePositions[i]->pos();
+
+        int xdiff = newPos.x() - oldPos.x();
+        int ydiff = newPos.y() - oldPos.y();
+        update(oldPos.x(), oldPos.y(), xdiff+sprite.width(), ydiff+sprite.height());
     }
 }