-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.py
45 lines (35 loc) · 1.54 KB
/
draw.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from numpy.core.arrayprint import BoolFormat
import math
from board import Board
from ui.element_picker import ElementPicker
import numpy as np
import pygame
class UserInterface():
def __init__(self, width: int, height: int, zoom_factor: int, display: pygame.Surface):
self.game_surface = pygame.Surface(
(width * zoom_factor, height * zoom_factor))
self.ui_surface = pygame.Surface((width * zoom_factor, 200))
self.picker = ElementPicker()
self.display = display
def frame(self, board: Board):
board.render()
self.display.blit(self.game_surface, (0, 0))
def draw_ui(self, board: Board):
# Render UI
self.picker.draw(board, self.ui_surface)
self.display.blit(
self.ui_surface, (0, board.height * board.zoom_factor))
def mouse_up(self, board: Board, x: float, y: float) -> None:
if y >= board.height * board.zoom_factor:
if self.picker.process_click(board, x, y - (board.height * board.zoom_factor)):
self.draw_ui(board)
else:
pass
def mouse_down(self, board: Board, x: float, y: float) -> None:
if y < board.height * board.zoom_factor:
board.paint(math.floor(y / board.zoom_factor),
math.floor(x / board.zoom_factor))
def mouse_drag(self, board: Board, x: float, y: float) -> None:
if y < board.height * board.zoom_factor:
board.paint(math.floor(y / board.zoom_factor),
math.floor(x / board.zoom_factor))