[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegames/kolf
From: Stefan Majewsky <majewsky () gmx ! net>
Date: 2010-10-31 22:15:51
Message-ID: 20101031221551.BEA5DAC8B2 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1191691 by majewsky:
Finally port BlackHole to Tagaro::SpriteObjectItem via EllipticalCanvasItem.
This mostly concludes the removal of the obsolete resizing code. The
game is now about as stable as before, although I have the feeling that
wall collision is a bit worse now. No idea why, though.
M +15 -72 game.cpp
M +5 -25 game.h
--- trunk/KDE/kdegames/kolf/game.cpp #1191690:1191691
@@ -1146,58 +1146,37 @@
/////////////////////////
BlackHole::BlackHole(QGraphicsItem * parent)
- : QGraphicsEllipseItem(-8, -9, 16, 18, parent), exitDeg(0)
+ : EllipticalCanvasItem(true, QLatin1String("black_hole"), parent)
+ , exitDeg(0)
{
+ setSize(QSizeF(16, 18));
setZValue(998.1);
infoLine = 0;
m_minSpeed = 3.0;
m_maxSpeed = 5.0;
runs = 0;
- baseInfoLineThickness = 2;
- baseExitLineWidth = 15;
- baseWidth = rect().width();
- baseHeight = rect().height();
const QColor myColor((QRgb)(KRandom::random() % 0x01000000));
- QPen pen(myColor);
- setPen(Qt::NoPen);
- setBrush(myColor);
+ ellipseItem()->setBrush(myColor);
exitItem = new BlackHoleExit(this, Kolf::findBoard(this));
exitItem->setPen(QPen(myColor, 6));
exitItem->setPos(300, 100);
- setSize(QSizeF(baseWidth, baseHeight));
- pixmapInitialised=false;
-
moveBy(0, 0);
finishMe();
}
-void BlackHole::paint(QPainter *painter, const QStyleOptionGraphicsItem * option, \
QWidget *widget)
-{
- if(pixmapInitialised == false) {
- if(game == 0)
- return;
- else {
- pixmap=Kolf::renderer()->spritePixmap("black_hole", rect().size().toSize());
- pixmapInitialised=true;
- }
- }
- QGraphicsEllipseItem::paint(painter, option, widget);
- painter->drawPixmap((int)rect().x(), (int)rect().y(), pixmap);
-}
-
void BlackHole::showInfo()
{
delete infoLine;
infoLine = new HintedLineItem(true, Kolf::findBoard(this));
infoLine->setVisible(true);
- infoLine->setPen(QPen(exitItem->pen().color(), baseInfoLineThickness));
+ infoLine->setPen(QPen(exitItem->pen().color(), 2));
infoLine->setZValue(10000);
- infoLine->setLine(x(), y(), exitItem->x(), exitItem->y());
+ infoLine->setLine(QLineF(pos(), exitItem->pos()));
exitItem->showInfo();
}
@@ -1217,44 +1196,21 @@
delete exitItem;
}
-void BlackHole::resize(double resizeFactor)
-{
- this->resizeFactor = resizeFactor;
- exitItem->resizeFactor = resizeFactor;
- setPos(baseX*resizeFactor, baseY*resizeFactor);
- setRect(-0.5*baseWidth*resizeFactor, -0.5*baseHeight*resizeFactor, \
baseWidth*resizeFactor, baseHeight*resizeFactor);
- pixmap=Kolf::renderer()->spritePixmap("black_hole", QSize(baseWidth*resizeFactor, \
baseHeight*resizeFactor));
- exitItem->setPos(exitItem->baseX*resizeFactor, exitItem->baseY*resizeFactor);
- finishMe(baseExitLineWidth*resizeFactor);
- if(infoLine) {
- infoLine->setPen(QPen(exitItem->pen().color(), \
baseInfoLineThickness*resizeFactor));
- infoLine->setLine(x(), y(), exitItem->x(), exitItem->y());
- }
- exitItem->setArrowPen(QPen(exitItem->pen().color(), \
exitItem->getBaseArrowPenThickness()*resizeFactor));
- exitItem->updateArrowLength(resizeFactor);
-}
-
void BlackHole::updateInfo()
{
if (infoLine)
{
infoLine->setVisible(true);
- infoLine->setLine(x(), y(), exitItem->x(), exitItem->y());
+ infoLine->setLine(QLineF(pos(), exitItem->pos()));
exitItem->showInfo();
}
}
void BlackHole::moveBy(double dx, double dy)
{
- QGraphicsEllipseItem::moveBy(dx, dy);
+ EllipticalCanvasItem::moveBy(dx, dy);
updateInfo();
-
- if (game && game->isEditing())
- {
- baseX = x() / resizeFactor;
- baseY = y() / resizeFactor;
}
-}
void BlackHole::setExitDeg(int newdeg)
{
@@ -1371,18 +1327,12 @@
exitItem->updateArrowAngle();
exitItem->updateArrowLength();
- baseX = x();
- baseY = y();
- exitItem->baseX = exit.x();
- exitItem->baseY = exit.y();
-
finishMe();
}
-void BlackHole::finishMe(double width)
+void BlackHole::finishMe()
{
- if(width==0) //default value
- width=baseExitLineWidth;
+ const double width = 15; //width of exit line
double radians = deg2rad(exitDeg);
QPointF midPoint(0, 0);
@@ -1438,10 +1388,6 @@
arrow->setZValue(zValue() - .00001);
updateArrowLength();
arrow->setVisible(false);
- baseArrowPenThickness = 1;
-
- baseX = x();
- baseY = y();
}
void BlackHoleExit::aboutToDie()
@@ -1456,10 +1402,10 @@
blackHole->updateInfo();
}
-void BlackHoleExit::setPen(QPen p)
+void BlackHoleExit::setPen(const QPen& p)
{
QGraphicsLineItem::setPen(p);
- arrow->setPen(QPen(p.color(), baseArrowPenThickness));
+ arrow->setPen(QPen(p.color()));
}
void BlackHoleExit::updateArrowAngle()
@@ -1469,18 +1415,15 @@
arrow->updateSelf();
}
-void BlackHoleExit::updateArrowLength(double resizeFactor)
+void BlackHoleExit::updateArrowLength()
{
- arrow->setLength(resizeFactor * (10.0 + 5.0 * (double)(blackHole->minSpeed() + \
blackHole->maxSpeed()) / 2.0)); + arrow->setLength(10.0 + 5.0 * \
(double)(blackHole->minSpeed() + blackHole->maxSpeed()) / 2.0); arrow->updateSelf();
}
void BlackHoleExit::editModeChanged(bool editing)
{
- if (editing)
- showInfo();
- else
- hideInfo();
+ arrow->setVisible(editing);
}
void BlackHoleExit::showInfo()
--- trunk/KDE/kdegames/kolf/game.h #1191690:1191691
@@ -302,22 +302,15 @@
virtual bool deleteable() const { return false; }
virtual bool canBeMovedByOthers() const { return true; }
virtual void editModeChanged(bool editing);
- virtual void setPen(QPen p);
+ virtual void setPen(const QPen& p);
virtual void showInfo();
virtual void hideInfo();
void updateArrowAngle();
- void updateArrowLength(double resizeFactor=1);
+ void updateArrowLength();
void setArrowPen(QPen pen) { arrow->setPen(pen); }
virtual Config *config(QWidget *parent);
BlackHole *blackHole;
- double getBaseArrowPenThickness() { return baseArrowPenThickness; }
- double resizeFactor, baseX, baseY;
-
protected:
- /*
- * base numbers are the size or position when no resizing has taken place (i.e. the \
defaults)
- */
- double baseArrowPenThickness;
Arrow *arrow;
};
class BlackHoleTimer : public QObject
@@ -339,16 +332,15 @@
double m_speed;
Ball *m_ball;
};
-class BlackHole : public QObject, public QGraphicsEllipseItem, public CanvasItem
+class BlackHole : public EllipticalCanvasItem
{
Q_OBJECT
public:
BlackHole(QGraphicsItem *parent);
virtual bool canBeMovedByOthers() const { return true; }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem * option, QWidget * \
widget); +
virtual void aboutToDie();
- void resize(double resizeFactor);
virtual void showInfo();
virtual void hideInfo();
virtual bool place(Ball *ball, bool wasCenter);
@@ -371,10 +363,6 @@
virtual void moveBy(double dx, double dy);
- virtual void setSize(const QSizeF& size) { setRect(QRectF(rect().topLeft(), size)); \
}
- double width() { return rect().width(); }
- double height() { return rect().height(); }
-
virtual bool collision(Ball *ball, long int id);
public slots:
@@ -389,17 +377,9 @@
virtual HoleResult result(const QPointF, double, bool *wasCenter);
private:
- QPixmap pixmap;
- bool pixmapInitialised;
- /*
- * base numbers are the size or position when no resizing has taken place (i.e. the \
defaults)
- */
- double baseX, baseY, resizeFactor;
- double baseInfoLineThickness, baseExitLineWidth;
- double baseWidth, baseHeight;
int runs;
QGraphicsLineItem *infoLine;
- void finishMe(double width=0);
+ void finishMe();
};
class WallPoint;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic