All pastes #1802648 Raw Edit

Miscellany

public diff v1 · immutable
#1802648 ·published 2010-02-19 13:56 UTC
rendered paste body
diff --git a/src/sprite.cpp b/src/sprite.cppindex e69de29..8a6457e 100644--- a/src/sprite.cpp+++ b/src/sprite.cpp@@ -0,0 +1,39 @@+/*+ * QmlArcade+ * Copyright (C) 2010 Jared Adams+ *+ * This file is part of the QmlArcade.+ *+ * QmlArcade is free software; you can redistribute it and/or modify it+ * under the terms of the GNU General Public License as published by the Free+ * Software Foundation; either version 2 of the License, or (at your option)+ * any later version.+ *+ * QmlArcade is distributed in the hope that it will be useful, but WITHOUT+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for+ * more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with QmlArcade.  If not, see <http://www.gnu.org/licenses/>.+ */++#include "sprite.h"++QML_DEFINE_TYPE(QmlArcade, 1,0, Sprite, Sprite);++Sprite::Sprite():+    CoRenderer(QPointF(0, 0))+{+}++Sprite::~Sprite()+{+}++void Sprite::draw(QPainter *painter, const QRectF &exposed)+{+    // Avoid warnings for now+    painter->background();+    exposed.width();+}diff --git a/src/sprite.h b/src/sprite.hindex e69de29..8bc9cea 100644--- a/src/sprite.h+++ b/src/sprite.h@@ -0,0 +1,48 @@+/*+ * QmlArcade+ * Copyright (C) 2010 Jared Adams+ *+ * This file is part of the QmlArcade.+ *+ * QmlArcade is free software; you can redistribute it and/or modify it+ * under the terms of the GNU General Public License as published by the Free+ * Software Foundation; either version 2 of the License, or (at your option)+ * any later version.+ *+ * QmlArcade is distributed in the hope that it will be useful, but WITHOUT+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for+ * more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with QmlArcade.  If not, see <http://www.gnu.org/licenses/>.+ */++#ifndef SPRITE_H+#define SPRITE_H++#include <QmlComponent>+#include <corenderer.h>++class Sprite : public QmlComponent, public Tiled::CoRenderer+{+    Q_OBJECT++    Q_PROPERTY(qreal x READ x WRITE setX NOTIFY positionChanged)+    Q_PROPERTY(qreal y READ y WRITE setY NOTIFY positionChanged)++public:+    Sprite();++    ~Sprite();++    virtual void draw(QPainter *painter, const QRectF &exposed);++signals:+    void positionChanged(const qreal &dummy);++};++QML_DECLARE_TYPE(Sprite)++#endif // SPRITE_Hdiff --git a/src/src.pro b/src/src.proindex 67660e7..8ff66e7 100644--- a/src/src.pro+++ b/src/src.pro@@ -8,8 +8,10 @@ OBJECTS_DIR = .obj SOURCES += main.cpp \     viewer.cpp \     mapitem.cpp \-    tilelayeritem.cpp+    tilelayeritem.cpp \+    sprite.cpp HEADERS += viewer.h \     mapitem.h \-    tilelayeritem.h+    tilelayeritem.h \+    sprite.h OTHER_FILES += main.qmldiff --git a/src/tiled/corenderer.cpp b/src/tiled/corenderer.cppindex e69de29..e38249b 100644--- a/src/tiled/corenderer.cpp+++ b/src/tiled/corenderer.cpp@@ -0,0 +1,29 @@+/*+ * Tiled Map Editor (Qt)+ * Copyright 2009 Tiled (Qt) developers (see AUTHORS file)+ *+ * This file is part of Tiled (Qt).+ *+ * This program is free software; you can redistribute it and/or modify it+ * under the terms of the GNU General Public License as published by the Free+ * Software Foundation; either version 2 of the License, or (at your option)+ * any later version.+ *+ * This program is distributed in the hope that it will be useful, but WITHOUT+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for+ * more details.+ *+ * You should have received a copy of the GNU General Public License along with+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple+ * Place, Suite 330, Boston, MA 02111-1307, USA.+ */++#include "corenderer.h"++using namespace Tiled;++CoRenderer::CoRenderer(QPointF pos):+        mPos(pos)+{+}diff --git a/src/tiled/corenderer.h b/src/tiled/corenderer.hindex e69de29..7cd3e06 100644--- a/src/tiled/corenderer.h+++ b/src/tiled/corenderer.h@@ -0,0 +1,71 @@+/*+ * Tiled Map Editor (Qt)+ * Copyright 2009 Tiled (Qt) developers (see AUTHORS file)+ *+ * This file is part of Tiled (Qt).+ *+ * This program is free software; you can redistribute it and/or modify it+ * under the terms of the GNU General Public License as published by the Free+ * Software Foundation; either version 2 of the License, or (at your option)+ * any later version.+ *+ * This program is distributed in the hope that it will be useful, but WITHOUT+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for+ * more details.+ *+ * You should have received a copy of the GNU General Public License along with+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple+ * Place, Suite 330, Boston, MA 02111-1307, USA.+ */++#ifndef CORENDERER_H+#define CORENDERER_H++#include <QList>+#include <QPainter>+#include <QPointF>+#include <QRectF>++namespace Tiled {++class CoRenderer+{+public:+    CoRenderer(QPointF pos);++    virtual ~CoRenderer() {}++    /**+     * Returns the x position of this object.+     */+    qreal x() const { return mPos.x(); }++    /**+     * Sets the x position of this object.+     */+    void setX(qreal x) { mPos.setX(x); }++    /**+     * Returns the y position of this object.+     */+    qreal y() const { return mPos.y(); }++    /**+     * Sets the x position of this object.+     */+    void setY(qreal y) { mPos.setY(y); }++    bool operator<(const CoRenderer &other) { return y() < other.y(); }++    virtual void draw(QPainter *painter, const QRectF &exposed) = 0;++private:+    QPointF mPos;+};++typedef QList<CoRenderer*> CoRenderers;++} // namespace Tiled++#endif // CORENDERER_Hdiff --git a/src/tiled/layer.h b/src/tiled/layer.hindex 1ff41dc..aea8ab7 100644--- a/src/tiled/layer.h+++ b/src/tiled/layer.h@@ -28,6 +28,8 @@ #include <QString> #include <QVector> +#include "corenderer.h"+ namespace Tiled {  class Map;@@ -153,6 +155,14 @@ public:      */     virtual Layer *clone() const = 0; +    QList<CoRenderer*> coRenderers() const { return mCoRenderers; }++    void addCoRenderer(CoRenderer* coRenderer)+    { mCoRenderers.append(coRenderer); }++    int removeCoRenderer(CoRenderer* coRenderer)+    { return mCoRenderers.removeAll(coRenderer); }+ protected:     Layer *initializeClone(Layer *clone) const; @@ -165,6 +175,7 @@ protected:     bool mVisible;     Map *mMap;     QMap<QString, QString> mProperties;+    CoRenderers mCoRenderers; };  } // namespace Tileddiff --git a/src/tiled/orthogonalrenderer.cpp b/src/tiled/orthogonalrenderer.cppindex 315b779..dbf35a8 100644--- a/src/tiled/orthogonalrenderer.cpp+++ b/src/tiled/orthogonalrenderer.cpp@@ -95,9 +95,11 @@ void OrthogonalRenderer::drawTileLayer(QPainter *painter,     int endX = layer->width();     int endY = layer->height(); +    QRectF rect(layer->x(), layer->y(), layer->width(), layer->height());+     if (!exposed.isNull()) {         const int extraHeight = layer->maxTileHeight() - tileHeight;-        QRectF rect = exposed.adjusted(0, 0, 0, extraHeight);+        rect = exposed.adjusted(0, 0, 0, extraHeight);         rect.translate(-layerPos);          startX = qMax((int) rect.x() / tileWidth, 0);@@ -106,7 +108,26 @@ void OrthogonalRenderer::drawTileLayer(QPainter *painter,         endY = qMin((int) std::ceil(rect.bottom()) / tileHeight + 1, endY);     } +    CoRenderers coreRenderers = layer->coRenderers();+    qSort(coreRenderers);+    QListIterator<CoRenderer*> ci(coreRenderers);++    // Skip CoRenderers above the exposed view+    while (ci.hasNext() && ci.peekNext()->y() <= startY) {+        ci.next();+    }+     for (int y = startY; y < endY; ++y) {+        // Draw all CoRenderers before the tiles in this layer+        while (ci.hasNext() && ci.peekNext()->y() <= y) {+            CoRenderer* cr = ci.next();++            // Only draw CoRenderers in the exposed view+            if (cr->x() >= startX && cr->x() <= endX) {+                cr->draw(painter, rect);+            }+        }+         for (int x = startX; x < endX; ++x) {             const Tile *tile = layer->tileAt(x, y);             if (!tile)diff --git a/src/tiled/tiled.pri b/src/tiled/tiled.priindex 7ee56e1..b002619 100644--- a/src/tiled/tiled.pri+++ b/src/tiled/tiled.pri@@ -10,7 +10,8 @@ SOURCES += $$PWD/layer.cpp \     $$PWD/isometricrenderer.cpp \     $$PWD/orthogonalrenderer.cpp \     $$PWD/compression.cpp \-    $$PWD/tilesetmanager.cpp+    $$PWD/tilesetmanager.cpp \+    tiled/corenderer.cpp HEADERS += $$PWD/layer.h \     $$PWD/map.h \     $$PWD/mapobject.h \@@ -25,4 +26,5 @@ HEADERS += $$PWD/layer.h \     $$PWD/orthogonalrenderer.h \     $$PWD/maprenderer.h \     $$PWD/compression.h \-    $$PWD/tilesetmanager.h+    $$PWD/tilesetmanager.h \+    tiled/corenderer.h