diff options
author | pescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7> | 2008-12-31 21:12:58 +0000 |
---|---|---|
committer | pescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7> | 2008-12-31 21:12:58 +0000 |
commit | bb6784e0e1a385cdd20b41d3254093e89a210332 (patch) | |
tree | c5d9c91b42a74baa30682fcbb717116a1df9c126 /Plugins/skins/SkinLib/Size.cpp | |
parent | 204a27b2f949cababbc13aff26755756987789a0 (diff) |
skins: Added SkinLib
git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@120 c086bb3d-8645-0410-b8da-73a8550f86e7
Diffstat (limited to 'Plugins/skins/SkinLib/Size.cpp')
-rw-r--r-- | Plugins/skins/SkinLib/Size.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Plugins/skins/SkinLib/Size.cpp b/Plugins/skins/SkinLib/Size.cpp new file mode 100644 index 0000000..9c2eef5 --- /dev/null +++ b/Plugins/skins/SkinLib/Size.cpp @@ -0,0 +1,84 @@ +#include "globals.h"
+#include "Size.h"
+
+Size::Size() : x(0), y(0)
+{
+}
+
+Size::Size(int aX, int aY) : x(aX), y(aY)
+{
+
+}
+
+int Size::resizeTo(int newX, int newY)
+{
+ if (newX < 0 && newY < 0)
+ return -1;
+
+ if (newY < 0)
+ {
+ if (x < 0 || y < 0)
+ return -2;
+
+ y = (int) (y * (newX / (float) x));
+ x = newX;
+ }
+ else if (newX < 0)
+ {
+ if (x < 0 || y < 0)
+ return -2;
+
+ x = (int) (x * (newY / (float) y));
+ y = newY;
+ }
+ else
+ {
+ x = newX;
+ y = newY;
+ }
+ return 0;
+}
+
+int Size::fitInside(int maxSize)
+{
+ if (x < 0 || y < 0)
+ return -2;
+ if (x <= maxSize && y <= maxSize)
+ return 0;
+
+ if (x >= y)
+ {
+ y = (int) (y * (maxSize / (float) x));
+ x = maxSize;
+ }
+ else
+ {
+ x = (int) (x * (maxSize / (float) y));
+ y = maxSize;
+ }
+ return 0;
+}
+
+int Size::scaleTo(int size)
+{
+ if (x < 0 || y < 0)
+ return -2;
+
+ if (x >= y)
+ {
+ y = (int) (y * (size / (float) x));
+ x = size;
+ }
+ else
+ {
+ x = (int) (x * (size / (float) y));
+ y = size;
+ }
+
+ return 0;
+}
+
+bool Size::operator==(const Size &other) const
+{
+ return x == other.x && y == other.y;
+}
\ No newline at end of file |