summaryrefslogtreecommitdiffstats
path: root/ktux/spritemisc.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
commitae2a03c2941bf92573f89b88ef73f8aa842bea0a (patch)
tree3566563f3fb6ac3cb3496669d8f233062d3091bc /ktux/spritemisc.cpp
downloadtdetoys-ae2a03c2941bf92573f89b88ef73f8aa842bea0a.tar.gz
tdetoys-ae2a03c2941bf92573f89b88ef73f8aa842bea0a.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/kdetoys@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ktux/spritemisc.cpp')
-rw-r--r--ktux/spritemisc.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/ktux/spritemisc.cpp b/ktux/spritemisc.cpp
new file mode 100644
index 0000000..f3a9a73
--- /dev/null
+++ b/ktux/spritemisc.cpp
@@ -0,0 +1,69 @@
+//-----------------------------------------------------------------------------
+//
+// spritemisc
+//
+// Copyright (c) Martin R. Jones 1999
+//
+
+#include <kapplication.h>
+#include "spritemisc.h"
+
+QSize SpriteRange::mFieldSize;
+
+SpriteRange::SpriteRange(const QString &str)
+{
+ set(str);
+}
+
+int SpriteRange::random() const
+{
+ int val = mMin;
+
+ if (mMax != mMin)
+ {
+ val = (KApplication::random()%(mMax-mMin)) + mMin;
+ }
+
+ return val;
+}
+
+void SpriteRange::set(const QString &str)
+{
+ int r = str.find("..");
+
+ if (r > 0)
+ {
+ mMin = parse(str.left(r));
+ mMax = parse(str.mid(r+2, 10));
+ }
+ else
+ {
+ mMin = mMax = parse(str);
+ }
+}
+
+void SpriteRange::setFieldSize(const QSize &size)
+{
+ mFieldSize = size;
+}
+
+int SpriteRange::parse(const QString &str)
+{
+ int val = 0;
+
+ if (str == "WIDTH")
+ {
+ val = mFieldSize.width();
+ }
+ else if (str == "HEIGHT")
+ {
+ val = mFieldSize.height();
+ }
+ else
+ {
+ val = str.toInt();
+ }
+
+ return val;
+}
+