/
window.py
59 lines (43 loc) · 1.37 KB
/
window.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
from numpy import ndarray
from canvas import Canvas
from mesh import Mesh
class Window(object):
def __init__(self, width: int, height: int, pixels: ndarray):
self.pixels = pixels
self.width = width
self.height = height
self.canvas = Canvas(width, height, pixels)
# setup key handlers
key_esc = 27
self.handlers = {
key_esc: self.exit
}
# self.v1 = Vertex(Vector(0, 0), Color.cyan())
# self.v2 = Vertex(Vector(300, 100), Color.red())
# self.v3 = Vertex(Vector(200, 300), Color.green())
model_path = "illidan.model"
texture_path = "illidan.texture"
self.mesh = Mesh(model_path, texture_path)
def clear(self):
self.canvas.clear()
pass
def update(self, dt):
pass
def draw(self):
# self.canvas.draw_triangle(self.v1, self.v2, self.v3)
self.canvas.draw_mesh(self.mesh)
def mouse_event(self, button, state, x, y):
print('mouse event', button, state, x, y)
# 0, left button
# 2, right button
# 0, state press
# 1, state release
def exit(self):
sys.exit(0)
def cmd404(self):
pass
def key_event(self, key, key_is_down):
print('key event', key, key_is_down)
cmd = self.handlers.get(key, self.cmd404)
cmd()