1 from panda3d
.core
import GraphicsWindow
, WindowProperties
2 from lib
.lib
.gui
import Img
3 from lib
.gameobject
import GameObject
6 class MouseCursorFacade
:
9 if not self
.eng
.cfg
.dev_cfg
.functional_test
:
10 return self
.cursor_img
.show()
11 def hide(self
): return self
.cursor_img
.hide()
14 class MouseCursor(GameObject
, MouseCursorFacade
):
16 def __init__(self
, filepath
, scale
, color
, hotspot
):
17 GameObject
.__init
__(self
)
18 MouseCursorFacade
.__init
__(self
)
19 if not filepath
: return
20 self
.__set
_std
_cursor
(False)
21 self
.cursor_img
= Img(filepath
, scale
=scale
, foreground
=True)
22 self
.cursor_img
.img
.set_color(color
)
23 #if self.eng.cfg.dev_cfg.functional_test:
24 # self.cursor_img.hide()
25 self
.hotspot_dx
= scale
[0] * (1 - 2 * hotspot
[0])
26 self
.hotspot_dy
= scale
[2] * (1 - 2 * hotspot
[1])
27 #self.eng.attach_obs(self.on_frame)
28 #self.eng.attach_obs(self.on_frame_unpausable)
29 taskMgr
.add(self
.__on
_frame
, 'on frame cursor')
32 def __set_std_cursor(show
):
33 props
= WindowProperties()
34 props
.set_cursor_hidden(not show
)
35 if isinstance(base
.win
, GraphicsWindow
):
36 base
.win
.requestProperties(props
)
38 #def show_standard(self): self.eng.lib.show_std_cursor()
40 #def hide_standard(self): self.eng.lib.hide_std_cursor()
42 #def cursor_top(self):
43 # self.cursor_img.reparent_to(self.cursor_img.parent)
45 def __on_frame(self
, task
):
46 mwn
= base
.mouseWatcherNode
47 if not mwn
: mouse
= 0, 0
48 elif not mwn
.hasMouse(): mouse
= 0, 0
49 else: mouse
= mwn
.get_mouse_x(), mwn
.get_mouse_y()
50 if not mouse
: return task
.again
51 h_x
= mouse
[0] * base
.getAspectRatio() + self
.hotspot_dx
52 self
.cursor_img
.set_pos((h_x
, mouse
[1] - self
.hotspot_dy
))
56 # if not self.eng.pause.paused: self.__on_frame()
58 #def on_frame_unpausable(self):
59 # if self.eng.pause.paused: self.__on_frame()
61 def set_image(self
, img
):
62 self
.cursor_img
.img
.set_texture(loader
.load_texture(img
), 1)