forked from nyaoouo/FFDraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.py
27 lines (23 loc) · 775 Bytes
/
text.py
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
import glm
class TextPosition:
left_top = 0
left_bottom = 1
center_top = 2
center_bottom = 3
right_top = 4
right_bottom = 5
def adjust(key, pos: glm.vec2, text_size: glm.vec2):
if key < 3:
if key == 0: # left_top
return glm.vec2(*pos)
elif key == 1: # left_bottom
return glm.vec2(pos.x, pos.y - text_size.y)
else: # center_top
return glm.vec2(pos.x - text_size.x / 2, pos.y)
elif key > 3:
if key == 4: # right_top
return glm.vec2(pos.x - text_size.x, pos.y)
else: # right_bottom
return glm.vec2(pos.x - text_size.x, pos.y - text_size.y)
else: # center_bottom
return glm.vec2(pos.x - text_size.x / 2, pos.y - text_size.y)