-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectutils.odin
More file actions
78 lines (63 loc) · 1.16 KB
/
rectutils.odin
File metadata and controls
78 lines (63 loc) · 1.16 KB
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
package extra
import "core:log"
//This contains procs to help with setting and getting rect parts
import rl "vendor:raylib"
RectPartX :: enum u8 {
None,
Left,
Right,
Center,
}
RectPartY :: enum u8 {
None,
Top,
Bottom,
Center,
}
RectGetPart :: proc(rect: rl.Rectangle, xPart: RectPartX, yPart: RectPartY) -> rl.Vector2 {
position := rl.Vector2{}
switch xPart {
case .None:
case .Left:
position.x = rect.x
case .Right:
position.x = rect.x + rect.width
case .Center:
position.x = (rect.x + rect.width) / 2
}
switch yPart {
case .None:
case .Top:
position.y = rect.y
case .Bottom:
position.y = rect.y + rect.height
case .Center:
position.y = (rect.y + rect.height) / 2
}
return position
}
RectSetPart :: proc(
rect: ^rl.Rectangle,
xPart: RectPartX,
yPart: RectPartY,
position: rl.Vector2,
) {
switch xPart {
case .None:
case .Left:
rect.x = position.x
case .Right:
rect.x = position.x - rect.width
case .Center:
rect.x = position.x - (rect.width / 2)
}
switch yPart {
case .None:
case .Top:
rect.y = position.y
case .Bottom:
rect.y = position.y - rect.height
case .Center:
rect.y = position.y - (rect.height / 2)
}
}