1 from panda3d
.core
import GraphicsWindow
, WindowProperties
2 from direct
.gui
.OnscreenImage
import OnscreenImage
5 class MouseCursorFacade
:
8 if not self
.eng
.cfg
.dev_cfg
.functional_test
:
9 return self
.cursor_img
.show()
12 return self
.cursor_img
.hide()
15 class MouseCursor(MouseCursorFacade
):
17 def __init__(self
, filepath
, scale
, color
, hotspot
):
18 MouseCursorFacade
.__init
__(self
)
21 self
.__set
_std
_cursor
(False)
22 self
.cursor_img
= OnscreenImage(filepath
, scale
=scale
)
23 self
.cursor_img
.set_color(color
)
24 self
.cursor_img
.set_bin('gui-popup', 50)
25 alpha_formats
= [12] # panda3d.core.texture.Frgba
26 if self
.cursor_img
.get_texture().get_format() in alpha_formats
:
27 self
.cursor_img
.set_transparency(True)
28 # if self.eng.cfg.dev_cfg.functional_test:
29 # self.cursor_img.hide()
30 self
.hotspot_dx
= scale
[0] * (1 - 2 * hotspot
[0])
31 self
.hotspot_dy
= scale
[2] * (1 - 2 * hotspot
[1])
32 # self.eng.attach_obs(self.on_frame)
33 # self.eng.attach_obs(self.on_frame_unpausable)
34 self
._tsk
= taskMgr
.add(self
.__on
_frame
, 'on frame cursor')
37 def __set_std_cursor(show
):
38 props
= WindowProperties()
39 props
.set_cursor_hidden(not show
)
40 if isinstance(base
.win
, GraphicsWindow
):
41 base
.win
.requestProperties(props
)
43 # def show_standard(self): self.eng.lib.show_std_cursor()
45 # def hide_standard(self): self.eng.lib.hide_std_cursor()
47 # def cursor_top(self):
48 # self.cursor_img.reparent_to(self.cursor_img.parent)
50 def __on_frame(self
, task
):
51 mwn
= base
.mouseWatcherNode
52 if not mwn
or not mwn
.hasMouse():
54 mouse
= mwn
.get_mouse_x(), mwn
.get_mouse_y()
55 h_x
= mouse
[0] * base
.getAspectRatio() + self
.hotspot_dx
56 self
.cursor_img
.set_pos((h_x
, 1, mouse
[1] - self
.hotspot_dy
))
60 # if not self.eng.pause.paused: self.__on_frame()
62 # def on_frame_unpausable(self):
63 # if self.eng.pause.paused: self.__on_frame()
65 def set_image(self
, img
):
66 self
.cursor_img
.set_texture(loader
.load_texture(img
), 1)
69 taskMgr
.remove(self
._tsk
)
70 self
.cursor_img
.destroy()