-
Notifications
You must be signed in to change notification settings - Fork 3
/
JPExtraCGRectFunctions.h
executable file
·101 lines (97 loc) · 2.04 KB
/
JPExtraCGRectFunctions.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Part of JPGeneral repository, Jon889: https://github.com/Jon889/JPGeneral
Copyright (c) 2011 Jonathan Bailey
May be modified and used in any project as long this comment remains.*/
CG_INLINE CGRect
CGRectSetSize(CGRect rect, CGFloat width, CGFloat height)
{
rect.size.width = width;
rect.size.height = height;
return rect;
}
CG_INLINE CGRect
CGRectSetOrigin(CGRect rect, CGFloat x, CGFloat y)
{
rect.origin.x = x;
rect.origin.y = y;
return rect;
}
CG_INLINE CGRect
CGRectAdjustSize(CGRect rect, CGFloat awidth, CGFloat aheight)
{
rect.size.width += awidth;
rect.size.height += aheight;
return rect;
}
CG_INLINE CGRect
CGRectSetWidth(CGRect rect, CGFloat width)
{
rect.size.width = width;
return rect;
}
CG_INLINE CGRect
CGRectSetHeight(CGRect rect, CGFloat height)
{
rect.size.height = height;
return rect;
}
CG_INLINE CGRect
CGRectSetX(CGRect rect, CGFloat x)
{
rect.origin.x = x;
return rect;
}
CG_INLINE CGRect
CGRectSetY(CGRect rect, CGFloat y)
{
rect.origin.y = y;
return rect;
}
CGRectAdjustWidth(CGRect rect, CGFloat awidth)
{
rect.size.width += awidth;
return rect;
}
CG_INLINE CGRect
CGRectAdjustHeight(CGRect rect, CGFloat aheight)
{
rect.size.height += aheight;
return rect;
}
CG_INLINE CGRect
CGRectOffsetX(CGRect rect, CGFloat dx)
{
rect.origin.x += dx;
return rect;
}
CG_INLINE CGRect
CGRectOffsetY(CGRect rect, CGFloat dy)
{
rect.origin.y += dy;
return rect;
}
CG_INLINE CGRect
CGRectMathRounded(CGRect rect)
{
rect.origin.x = roundf(rect.origin.x);
rect.origin.y = roundf(rect.origin.y);
rect.size.width = roundf(rect.size.width);
rect.size.height = roundf(rect.size.height);
return rect;
}
CG_INLINE CGRect
CGRectMakeForSizeAroundCenter(CGSize size, CGPoint center)
{
CGRect rect;
rect.size.width = size.width;
rect.size.height = size.height;
rect.origin.x = center.x - (size.width / 2);
rect.origin.y = center.y - (size.height / 2);
return rect;
}
CG_INLINE CGRect
CGRectSetWidthKeepRightFixed(CGRect rect, CGFloat width)
{
rect.origin.x = (rect.origin.x + rect.size.width) - width;
rect.size.width = width;
return rect;
}