2020-11-14 10:15:47 -07:00
|
|
|
import pygame
|
|
|
|
from pygame import gfxdraw
|
|
|
|
from pygame import freetype
|
|
|
|
from . import HEIGHT, WIDTH
|
|
|
|
from .math import add
|
|
|
|
|
|
|
|
OFFSET = (WIDTH/2, HEIGHT/2)
|
|
|
|
FONT = None
|
|
|
|
|
|
|
|
def init():
|
|
|
|
global FONT
|
|
|
|
freetype.init()
|
|
|
|
FONT = freetype.SysFont('Arial', 16)
|
|
|
|
|
2020-11-14 11:10:22 -07:00
|
|
|
def line(surface, color, start, end, width=1):
|
2020-11-14 10:15:47 -07:00
|
|
|
pygame.draw.line(surface, color,
|
|
|
|
add(*OFFSET, *start), add(*OFFSET, *end), width)
|
|
|
|
|
|
|
|
|
|
|
|
def polygon(surface, color, vertices, width):
|
|
|
|
translated = [add(*OFFSET, *vertex) for vertex in vertices]
|
|
|
|
pygame.draw.polygon(surface, color, translated, width)
|
|
|
|
|
|
|
|
|
|
|
|
def rect(surface, color, x, y, height, width, stroke_width):
|
|
|
|
pygame.draw.rect(surface, color,
|
2020-11-15 02:26:57 -07:00
|
|
|
pygame.Rect(*add(*OFFSET, x, y), height, width),
|
2020-11-14 10:15:47 -07:00
|
|
|
stroke_width)
|
|
|
|
|
|
|
|
|
|
|
|
def pixel(surface, color, x, y):
|
|
|
|
gfxdraw.pixel(surface,
|
|
|
|
int(OFFSET[0] + x),
|
|
|
|
int(OFFSET[1] + y),
|
|
|
|
color)
|
|
|
|
|
|
|
|
def text(surface, color, position, text):
|
|
|
|
FONT.render_to(surface, add(*OFFSET, *position), text, color)
|
|
|
|
|
|
|
|
def text_screen(surface, color, position, text):
|
|
|
|
FONT.render_to(surface, position, text, color)
|