+from panda3d.core import GraphicsWindow, WindowProperties
from lib.lib.gui import Img
from lib.gameobject import GameObject
GameObject.__init__(self)
MouseCursorFacade.__init__(self)
if not filepath: return
- self.eng.lib.hide_std_cursor()
+ self.__set_std_cursor(False)
self.cursor_img = Img(filepath, scale=scale, foreground=True)
self.cursor_img.img.set_color(color)
- if self.eng.cfg.dev_cfg.functional_test:
- self.cursor_img.hide()
+ #if self.eng.cfg.dev_cfg.functional_test:
+ # self.cursor_img.hide()
self.hotspot_dx = scale[0] * (1 - 2 * hotspot[0])
self.hotspot_dy = scale[2] * (1 - 2 * hotspot[1])
- self.eng.attach_obs(self.on_frame)
- self.eng.attach_obs(self.on_frame_unpausable)
-
- def show_standard(self): self.eng.lib.show_std_cursor()
-
- def hide_standard(self): self.eng.lib.hide_std_cursor()
-
- def cursor_top(self):
- self.cursor_img.reparent_to(self.cursor_img.parent)
-
- def __on_frame(self):
- mouse = self.eng.lib.mousepos
- if not mouse: return
- h_x = mouse[0] * self.eng.lib.aspect_ratio + self.hotspot_dx
+ #self.eng.attach_obs(self.on_frame)
+ #self.eng.attach_obs(self.on_frame_unpausable)
+ taskMgr.add(self.__on_frame, 'on frame cursor')
+
+ @staticmethod
+ def __set_std_cursor(show):
+ props = WindowProperties()
+ props.set_cursor_hidden(not show)
+ if isinstance(base.win, GraphicsWindow):
+ base.win.requestProperties(props)
+
+ #def show_standard(self): self.eng.lib.show_std_cursor()
+
+ #def hide_standard(self): self.eng.lib.hide_std_cursor()
+
+ #def cursor_top(self):
+ # self.cursor_img.reparent_to(self.cursor_img.parent)
+
+ def __on_frame(self, task):
+ mwn = base.mouseWatcherNode
+ if not mwn: mouse = 0, 0
+ elif not mwn.hasMouse(): mouse = 0, 0
+ else: mouse = mwn.get_mouse_x(), mwn.get_mouse_y()
+ if not mouse: return task.again
+ h_x = mouse[0] * base.getAspectRatio() + self.hotspot_dx
self.cursor_img.set_pos((h_x, mouse[1] - self.hotspot_dy))
+ return task.again
+
+ #def on_frame(self):
+ # if not self.eng.pause.paused: self.__on_frame()
- def on_frame(self):
- if not self.eng.pause.paused: self.__on_frame()
+ #def on_frame_unpausable(self):
+ # if self.eng.pause.paused: self.__on_frame()
- def on_frame_unpausable(self):
- if self.eng.pause.paused: self.__on_frame()
+ def set_image(self, img):
+ self.cursor_img.img.set_texture(loader.load_texture(img), 1)