summaryrefslogtreecommitdiffstats
path: root/ktuberling/todraw.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /ktuberling/todraw.cpp
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ktuberling/todraw.cpp')
-rw-r--r--ktuberling/todraw.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/ktuberling/todraw.cpp b/ktuberling/todraw.cpp
new file mode 100644
index 00000000..e12c9e1b
--- /dev/null
+++ b/ktuberling/todraw.cpp
@@ -0,0 +1,90 @@
+/* -------------------------------------------------------------
+ KDE Tuberling
+ Object to draw on the game board
+ mailto:e.bischoff@noos.fr
+ ------------------------------------------------------------- */
+
+#include <qbitmap.h>
+#include <qpainter.h>
+
+#include "todraw.h"
+
+// Constructor with no arguments
+ToDraw::ToDraw()
+ : position()
+{
+ number = -1;
+}
+
+// Copy constructor
+ToDraw::ToDraw(const ToDraw &model)
+ : position(model.position)
+{
+ number = model.number;
+}
+
+// Constructor with arguments
+ToDraw::ToDraw(int declaredNumber, const QRect &declaredPosition)
+ : position(declaredPosition)
+{
+ number = declaredNumber;
+}
+
+// Affectation operator
+ToDraw &ToDraw::operator=(const ToDraw &model)
+{
+ if (&model == this) return *this;
+
+ position = model.position;
+ number = model.number;
+
+ return *this;
+}
+
+// Draw an object previously laid down on the game board
+void ToDraw::draw(QPainter &artist, const QRect &area,
+ const QRect *objectsLayout,
+ const QPixmap *gameboard, const QBitmap *masks) const
+{
+ if (!position.intersects(area)) return;
+
+ QPixmap objectPixmap(objectsLayout[number].size());
+ QBitmap shapeBitmap(objectsLayout[number].size());
+
+ bitBlt(&objectPixmap, QPoint(0, 0), gameboard, objectsLayout[number], Qt::CopyROP);
+ bitBlt(&shapeBitmap, QPoint(0, 0), masks, objectsLayout[number], Qt::CopyROP);
+ objectPixmap.setMask(shapeBitmap);
+ artist.drawPixmap(position.topLeft(), objectPixmap);
+}
+
+// Load an object from a file
+bool ToDraw::load(FILE *fp, int decorations, bool &eof)
+{
+ int nitems;
+ int pl, pt, pr, pb;
+
+ nitems = fscanf(fp, "%d\t%d %d %d %d\n", &number, &pl, &pt, &pr, &pb);
+
+ if (nitems == EOF)
+ {
+ eof = true;
+ return true;
+ }
+ eof = false;
+ if (nitems != 5) return false;
+
+ if (number < 0 || number >= decorations) return false;
+
+ position.setCoords(pl, pt, pr, pb);
+
+ return true;
+}
+
+// Save an object to a file
+void ToDraw::save(FILE *fp) const
+{
+ fprintf(fp, "%d\t%d %d %d %d\n",
+ number,
+ position.left(), position.top(), position.right(), position.bottom());
+}
+