summaryrefslogtreecommitdiff
path: root/plugins/Skins/SkinLib/Size.cpp
blob: 9c2eef5d5d97d9a64f0877b8722ef3fcdd2c019e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
}