580dd2e1a1162958c1f654b6bade0f7715fb1485
1 from lib
.lib
.gui
import Img
2 from lib
.gameobject
import GameObject
5 class MouseCursorFacade
:
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()
13 class MouseCursor(GameObject
, MouseCursorFacade
):
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
)
29 def show_standard(self
): self
.eng
.lib
.show_std_cursor()
31 def hide_standard(self
): self
.eng
.lib
.hide_std_cursor()
34 self
.cursor_img
.reparent_to(self
.cursor_img
.parent
)
37 mouse
= self
.eng
.lib
.mousepos
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
))
43 if not self
.eng
.pause
.paused
: self
.__on
_frame
()
45 def on_frame_unpausable(self
):
46 if self
.eng
.pause
.paused
: self
.__on
_frame
()