Commit | Line | Data |
---|---|---|
8ee66edd FC |
1 | from lib.lib.gui import Img |
2 | from lib.gameobject import GameObject | |
3 | ||
4 | ||
5 | class MouseCursorFacade: | |
6 | ||
7 | def show(self): | |
8 | if not self.eng.cfg.dev_cfg.functional_test: | |
9 | return self.cursor_img.show() | |
10 | def hide(self): return self.cursor_img.hide() | |
11 | ||
12 | ||
13 | class MouseCursor(GameObject, MouseCursorFacade): | |
14 | ||
15 | def __init__(self, filepath, scale, color, hotspot): | |
16 | GameObject.__init__(self) | |
17 | MouseCursorFacade.__init__(self) | |
18 | if not filepath: return | |
19 | self.eng.lib.hide_std_cursor() | |
20 | self.cursor_img = Img(filepath, scale=scale, foreground=True) | |
21 | self.cursor_img.img.set_color(color) | |
22 | if self.eng.cfg.dev_cfg.functional_test: | |
23 | self.cursor_img.hide() | |
24 | self.hotspot_dx = scale[0] * (1 - 2 * hotspot[0]) | |
25 | self.hotspot_dy = scale[2] * (1 - 2 * hotspot[1]) | |
26 | self.eng.attach_obs(self.on_frame) | |
27 | self.eng.attach_obs(self.on_frame_unpausable) | |
28 | ||
29 | def show_standard(self): self.eng.lib.show_std_cursor() | |
30 | ||
31 | def hide_standard(self): self.eng.lib.hide_std_cursor() | |
32 | ||
33 | def cursor_top(self): | |
34 | self.cursor_img.reparent_to(self.cursor_img.parent) | |
35 | ||
36 | def __on_frame(self): | |
37 | mouse = self.eng.lib.mousepos | |
38 | if not mouse: return | |
39 | h_x = mouse[0] * self.eng.lib.aspect_ratio + self.hotspot_dx | |
40 | self.cursor_img.set_pos((h_x, mouse[1] - self.hotspot_dy)) | |
41 | ||
42 | def on_frame(self): | |
43 | if not self.eng.pause.paused: self.__on_frame() | |
44 | ||
45 | def on_frame_unpausable(self): | |
46 | if self.eng.pause.paused: self.__on_frame() |