from __future__ import annotations
from .function import *
import math
from enum import Enum
from .src.types import *
from .src.draw import *
from .src._3d import *

def quit():
    lib.finalization()

def now_time():
    return lib.get_time()

_last_time = 0
_delta_time = 0
def start_frame():
    global _last_time, _delta_time
    current_time = now_time()
    _delta_time = current_time - _last_time
    _last_time = current_time
    lib.start_frame()

def delta_time():
    return _delta_time

def load_texture(*args):
    if len(args) == 1:
        # Only the path was passed
        tex = Texture(0, 0)
        path = args[0]
    elif len(args) == 2:
        tex = args[0]
        path = args[1]
    else:
        raise TypeError(
            "load_texture(str) or load_texture(Texture, str)"
        )
    if isinstance(tex, Texture) and isinstance(path, str):
        lib.load_texture(tex._id, path.encode("utf-8"), False)
    return tex

def load_image(*args):
    if len(args) == 1:
        # Only the path was passed
        img = Image(0, 0)
        path = args[0]
    elif len(args) == 2:
        img = args[0]
        path = args[1]
    else:
        raise TypeError(
            "load_image(str) or load_image(Image, str)"
        )
    if isinstance(img, Image) and isinstance(path, str):
        lib.load_image(img._id, path.encode("utf-8"))
    return img

def load_font(path: str, scale: float = 1):
    f = Font()
    f._id = lib.load_font(path.encode("utf-8"), 1500 * scale)
    return f
