Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions examples/imagelayer/GameWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ QuasiGame {
drawType: Quasi.TiledDrawType
tileWidth: 32
tileHeight: 32
animated: true
source: ":/large_enough.png"
horizontalStep: -5
layerType: Quasi.MirroredType
Expand All @@ -63,7 +62,19 @@ QuasiGame {
}

Keys.onPressed: {
layer.animated = !layer.animated
if (event.key == Qt.Key_Right) {
if (layer.horizontalStep > 0)
layer.horizontalStep *= -1;

layer.moveX();
event.accepted = true;
} else if (event.key == Qt.Key_Left) {
if (layer.horizontalStep < 0)
layer.horizontalStep *= -1;

layer.moveX();
event.accepted = true;
}
}
}
}
25 changes: 2 additions & 23 deletions src/imagelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ ImageLayer::ImageLayer(Layer *parent)
, m_areaToDraw(2.0)
, m_columnOffset(0)
, m_latestPoint(0)
, m_globalXPos(0.0)
, m_localXPos(0.0)
, m_localYPos(0.0)
, m_initialized(false)
{
connect(this, SIGNAL(horizontalDirectionChanged()),
Expand Down Expand Up @@ -353,24 +350,9 @@ void ImageLayer::drawPixmap()
}

// move to a X value
void ImageLayer::moveX(const qreal &x)
void ImageLayer::moveX()
{
qreal newValue = x;
qreal delta = m_globalXPos + newValue;

m_globalXPos = newValue * -1;
m_localXPos -= delta;

if (m_localXPos <= -width()) {
drawPixmap();
m_localXPos = width() + m_localXPos;
} else if (m_localXPos >= 0) {
if (m_globalXPos != 0) {
drawPixmap();
m_localXPos = -width() + m_localXPos;
} else
m_localXPos = 0;
}
updateHorizontalStep();
}

void ImageLayer::moveY(const qreal &y)
Expand Down Expand Up @@ -412,9 +394,6 @@ void ImageLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
if (!m_currentImage)
return;

if (m_isAnimated)
updateHorizontalStep();

painter->drawImage(m_currentHorizontalStep, 0, *m_currentImage);
}

Expand Down
6 changes: 1 addition & 5 deletions src/imagelayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ImageLayer : public Layer

int count() const;

void moveX(const qreal &x);
Q_INVOKABLE void moveX();
void moveY(const qreal &y);

#if QT_VERSION >= 0x050000
Expand Down Expand Up @@ -120,10 +120,6 @@ protected slots:
bool m_drawGrid;
QColor m_gridColor;

qreal m_globalXPos;
qreal m_globalYPos;
qreal m_localXPos;
qreal m_localYPos;
qreal m_currentHorizontalStep;

bool m_initialized;
Expand Down
11 changes: 0 additions & 11 deletions src/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
//! Class constructor
Layer::Layer(QuasiDeclarativeItem *parent)
: QuasiPaintedItem(parent)
, m_isAnimated(false)
, m_horizontalStep(1.0)
, m_type(Quasi::InfiniteType)
{
Expand All @@ -45,16 +44,6 @@ Layer::~Layer()
{
}

void Layer::setAnimated(bool animated)
{
if (m_isAnimated == animated)
return;

m_isAnimated = animated;

emit animatedChanged();
}

void Layer::setHorizontalStep(const qreal &step)
{
if (m_horizontalStep == step)
Expand Down
6 changes: 0 additions & 6 deletions src/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,25 @@ class Layer: public QuasiPaintedItem
{
Q_OBJECT

Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated NOTIFY animatedChanged)
Q_PROPERTY(qreal horizontalStep READ horizontalStep WRITE setHorizontalStep NOTIFY horizontalStepChanged)
Q_PROPERTY(Quasi::LayerType layerType READ layerType WRITE setLayerType NOTIFY layerTypeChanged)

public:
Layer(QuasiDeclarativeItem *parent = 0);
virtual ~Layer();

bool isAnimated() const { return m_isAnimated; }
void setAnimated(bool animated);

qreal horizontalStep() const { return m_horizontalStep; }
void setHorizontalStep(const qreal &step);

Quasi::LayerType layerType() const { return m_type; };
void setLayerType(const Quasi::LayerType &type);

signals:
void animatedChanged();
void horizontalStepChanged();
void horizontalDirectionChanged();
void layerTypeChanged();

protected:
bool m_isAnimated;
qreal m_horizontalStep;
Quasi::LayerType m_type;
};
Expand Down