forked from sanskarchand/bone-animator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (67 loc) · 2.7 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
import pygame as pg
import Bone
import const
import os
from gui.gui import GUI, Orientation
from gui.const import POS_UNDEF
# last change: 2020-11-22
class MainApplication:
def __init__(self):
self.running = True
self.current_frame = 0
self.mouse_pos = (0, 0)
self.figure_def = Bone.Figure.fromFile("man_figure.xml")
self.current_figure = self.figure_def
self.ctrl_rect: pg.Rect | None = None
self.init_pg()
self.init_gui()
def init_pg(self):
pg.init()
pg.font.init()
self.main_screen = pg.display.set_mode(const.TOTAL_DIM)
pg.display.set_caption("Pivot Clone")
self.clock = pg.time.Clock()
def init_gui(self):
self.gui = GUI(self.main_screen)
## make rect
self.ctrl_rect = pg.Rect(*const.RIGHT_CTRL_RECT_PARAMS)
self.ctrl_container = self.gui.make_container_from_rect(
self.ctrl_rect,
Orientation.VERTICAL
)
but_frame = self.gui.make_text_button(POS_UNDEF, 160, 20, "Add Frame", self.addFrame, ())
self.ctrl_container.push_item(but_frame)
self.surf_canvas = pg.Surface(list(const.CANVAS_DIM), pg.SRCALPHA, 32)
self.surf_canvas = self.surf_canvas.convert_alpha()
self.gui.add_elem(self.ctrl_container)
def addFrame(self):
self.current_figure.addFrame()
self.current_frame += 1
print("FRAMESSSSS")
def mainloop (self):
while self.running:
self.mouse_pos = pg.mouse.get_pos()
for event in pg.event.get():
if event.type == pg.QUIT:
self.running = False
break
else:
self.gui.update(event, self.mouse_pos)
## TODO: replace this with a scene manager or soemthing
if event.type == pg.MOUSEBUTTONDOWN:
self.figure_def.checkPressed(self.mouse_pos)
if event.type == pg.MOUSEBUTTONUP:
self.figure_def.root.unselectGimbals()
### Wipe/Fill screen, and draw GUI
self.main_screen.fill(const.BGCOLOR)
pg.draw.rect(self.main_screen, const.GREY, self.ctrl_rect)
self.gui.draw()
self.figure_def.update()
print("UPDATE FIN===================")
self.figure_def.draw(self.main_screen)
pg.display.update()
self.clock.tick(const.FPS)
m_app = MainApplication()
if __name__ == "__main__":
m_app.mainloop()