+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)
from direct.showbase.DirectObject import DirectObject
from pmachines.items.background import Background
from pmachines.items.box import Box
+from lib.engine.gui.cursor import MouseCursor
class Scene(DirectObject):
super().__init__()
self._world = world
self._set_camera()
+ self._cursor = MouseCursor(
+ 'assets/buttons/arrowUpLeft.png', (.04, 1, .04), (.5, .5, .5, 1),
+ (.01, .01))
self._set_gui()
self._set_lights()
self._set_input()
for hit in self._get_hits():
for item in [i for i in self.items if hit.get_node() == i.node]:
getattr(item, method)(pos)
+ img = 'move' if method == 'on_click_l' else 'rotate'
+ self._cursor.set_image('assets/buttons/%s.png' % img)
def on_click_l(self):
self._on_click('on_click_l')
def on_release(self):
[item.on_release() for item in self.items]
+ self._cursor.set_image('assets/buttons/arrowUpLeft.png')
def on_frame(self, task):
hits = self._get_hits()