import pygame,sys,threading,pygame.locals,pygame.font

pygame.init()

def New_window(window_x,window_y,window_name,background):
    screen = pygame.display.set_mode((window_x,window_y),0,32)
    pygame.display.set_caption(window_name)
    background_imarges = pygame.image.load(f'./imarges/background/{background}.png').convert()
    return screen,background_imarges

def New_file(screen,file_imarge,file_x,file_y,file_text,text_x,text_y,text_color,text_S,text_font,text_bold,text_italic):
    file_imarge = pygame.image.load(f'./imarges/{file_imarge}.png').convert()
    font = pygame.font.Font(text_font,text_S)
    font.set_bold(text_bold)
    font.set_italic(text_italic)
    file_text = font.render(file_text,True,text_color)
    screen.blit(file_imarge,(file_x,file_y))
    screen.blit(file_text,((text_x+file_x),(text_y+file_y)))
    return None

def New_button(function,screen,event,button_imarge,button_down_imarge,button_x,button_y,text,text_x,text_y,text_color,text_S,text_font,text_bold,text_italic):
    if event == MOUSEBUTTONDOWN:
        mouse_x, mouse_y = pygame.mouse.get_pos()
        New_file(screen,button_down_imarge,button_x,button_y,text,text_x,text_y,text_color,text_S,text_font,text_bold,text_italic)
        function()
    else:
        New_file(screen,button_imarge,button_x,button_y,text,text_x,text_y,text_color,text_S,text_font,text_bold,text_italic)
    
def first_window():
    with open('./sys/first_window/window.txt',encoding='UTF-8') as files:
        file = files.readlines()
        window_x,window_y = int(file[0].rstrip()),int(file[1].rstrip())

    first_window,first_window_background = New_window(window_x,window_y,'说我(TAM) ——定义你自己','first_window')
    
    with open('./sys/first_window/title.txt',encoding='UTF-8') as files:
        file = files.readlines()
        title = file[0].rstrip()
        title_x,title_y = int(file[1].rstrip()),int(file[2].rstrip())
        title_S,title_color = int(file[3].rstrip()),(int(file[4].rstrip()),int(file[5].rstrip()),int(file[6].rstrip()))
        title_bold,title_italic = bool(file[6].rstrip()),bool(file[7].rstrip())

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.VIDEORESIZE:
                size = (event.size[0], event.size[1])
        first_window.blit(first_window_background,(0,0))
        New_file(first_window,"title_box/first_window",0,0,title,title_x,title_y,title_color,title_S,'./sys/first_window/title.ttf',title_bold,title_italic)

        pygame.display.flip()

    return None

t_First = threading.Thread(target = first_window)
t_First.start()
t_First.join()
pygame.quit()

