75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
#include "aditem.h"
|
|
#include <QPainter>
|
|
#include <QDebug>
|
|
|
|
|
|
ADItem::ADItem(int id, adType type, QList<QImage *> *images_, QRectF geometry, QGraphicsItem *parent) :
|
|
QGraphicsItem(parent)
|
|
{
|
|
m_id = id;
|
|
m_type = type;
|
|
anim = 0;
|
|
images = images_;
|
|
animcount = images->size();
|
|
QSize size = images->at(0)->size();
|
|
staticImage = false;
|
|
if (animcount == 1) staticImage = true;
|
|
if (geometry.isNull()) br = QRect(QPoint(-(size.width()/2), -(size.height()/2)), size);
|
|
else br = geometry;
|
|
if (type == Alien)
|
|
{
|
|
setFlag(QGraphicsItem::ItemIsSelectable);
|
|
barValue = 1.f;
|
|
hasBar = true;
|
|
} else hasBar = false;
|
|
if (staticImage)
|
|
{
|
|
setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
|
img = (*images)[0];
|
|
}
|
|
}
|
|
|
|
|
|
ADItem::ADItem(QPoint id, QImage *image, QRectF geometry, QGraphicsItem *parent) :
|
|
QGraphicsItem(parent)
|
|
{
|
|
hasBar = true;
|
|
barValue = 0.f;
|
|
m_type = Tower;
|
|
m_tid = id;
|
|
img = image;
|
|
QSize size = img->size();
|
|
if (geometry.isNull()) br = QRect(QPoint(-(size.width()/2),-(size.height()/2)),size);
|
|
else br = geometry;
|
|
staticImage = true;
|
|
setFlag(QGraphicsItem::ItemIsSelectable);
|
|
}
|
|
|
|
|
|
void ADItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
|
|
{
|
|
if (staticImage)
|
|
painter->drawImage(br,*img);
|
|
else painter->drawImage(br, *(images->at(qRound(anim))));
|
|
if (isSelected())
|
|
{
|
|
painter->setPen(Qt::red);
|
|
painter->drawRect(br);
|
|
}
|
|
}
|
|
|
|
|
|
QRectF ADItem::boundingRect() const
|
|
{
|
|
return br;
|
|
}
|
|
|
|
void ADItem::next(float step)
|
|
{
|
|
if (staticImage) return;
|
|
anim+=step;
|
|
if (qRound(anim) >= animcount)
|
|
anim = 0;
|
|
}
|
|
|