EG/QMeta3D/QMouseWatcherNode.py
2025-10-29 10:35:38 +08:00

28 lines
618 B
Python

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from panda3d.core import *
__all__ = ["QMouseWatcherNode"]
class QMouseWatcherNode(MouseWatcher):
def __init__(self, parent):
super().__init__()
self.parent = parent
def getMouse(self, *args, **kwargs):
pos = self.parent.mapFromGlobal(QCursor.pos())
rel_x = -1 + 2 * pos.x() / self.parent.width()
rel_y = -1 + 2 * pos.y() / self.parent.height()
rel_y = -rel_y
return LPoint2(rel_x, rel_y)
def hasMouse(self):
return isinstance(self.parent, QWidget)