summaryrefslogtreecommitdiffstats
path: root/Function/createText.py
blob: 17c7ba0e99a6ef05927a62d6ae2a43ba9372df37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pygame import font
from functools import lru_cache

@lru_cache
def get_font(weight, size):
    return font.Font(f"./Font/Exo2-{weight}.ttf", size)


def createText(X, Y, size, textColour, weight, textInfo, alignment="l"):
    fontx = get_font(weight,size)

    text = fontx.render(textInfo, True, textColour)
    textRect = text.get_rect()
    if (alignment == "left" or alignment == "l"):
        textRect = (X // 2, Y // 2)  # Left aligned text
    elif (alignment == "center" or alignment == "c"):
        textRect.center = (X // 2, Y // 2)  # Centered text
    elif (alignment == "right" or alignment == "r"):
        textRect.right = (X // 2, Y // 2)  # Right aligned text

    return text, textRect;