1 from panda3d
.core
import GraphicsWindow
, WindowProperties
2 from ya2
.p3d
.gui
import P3dImg
as Img
3 from ya2
.patterns
.gameobject
import GameObject
6 class MouseCursorFacade
:
9 if not self
.eng
.cfg
.dev_cfg
.functional_test
:
10 return self
.cursor_img
.show()
13 return self
.cursor_img
.hide()
16 class MouseCursor(GameObject
, MouseCursorFacade
):
18 def __init__(self
, filepath
, scale
, color
, hotspot
):
19 GameObject
.__init
__(self
)
20 MouseCursorFacade
.__init
__(self
)
23 self
.__set
_std
_cursor
(False)
24 self
.cursor_img
= Img(filepath
, scale
=scale
, foreground
=True)
25 self
.cursor_img
.img
.set_color(color
)
26 # if self.eng.cfg.dev_cfg.functional_test:
27 # self.cursor_img.hide()
28 self
.hotspot_dx
= scale
[0] * (1 - 2 * hotspot
[0])
29 self
.hotspot_dy
= scale
[2] * (1 - 2 * hotspot
[1])
30 # self.eng.attach_obs(self.on_frame)
31 # self.eng.attach_obs(self.on_frame_unpausable)
32 self
._tsk
= taskMgr
.add(self
.__on
_frame
, 'on frame cursor')
35 def __set_std_cursor(show
):
36 props
= WindowProperties()
37 props
.set_cursor_hidden(not show
)
38 if isinstance(base
.win
, GraphicsWindow
):
39 base
.win
.requestProperties(props
)
41 # def show_standard(self): self.eng.lib.show_std_cursor()
43 # def hide_standard(self): self.eng.lib.hide_std_cursor()
45 # def cursor_top(self):
46 # self.cursor_img.reparent_to(self.cursor_img.parent)
48 def __on_frame(self
, task
):
49 mwn
= base
.mouseWatcherNode
50 if not mwn
or not mwn
.hasMouse():
52 mouse
= mwn
.get_mouse_x(), mwn
.get_mouse_y()
53 h_x
= mouse
[0] * base
.getAspectRatio() + self
.hotspot_dx
54 self
.cursor_img
.set_pos((h_x
, mouse
[1] - self
.hotspot_dy
))
58 # if not self.eng.pause.paused: self.__on_frame()
60 # def on_frame_unpausable(self):
61 # if self.eng.pause.paused: self.__on_frame()
63 def set_image(self
, img
):
64 self
.cursor_img
.img
.set_texture(loader
.load_texture(img
), 1)
67 taskMgr
.remove(self
._tsk
)
68 self
.cursor_img
.destroy()