示例#1
0
 def queryDimensions():
     res = player.getScreenResolution()
     self.assert_(res.x > 0 and res.y > 0 and res.x < 10000 and res.y < 10000)
     ppmm = player.getPixelsPerMM()
     self.assert_(ppmm > 0 and ppmm < 10000)
     mm = player.getPhysicalScreenDimensions()
     self.assert_(mm.x > 0 and mm.y > 0 and mm.x < 10000 and mm.y < 10000)
     player.assumePixelsPerMM(ppmm)
     newPPMM = player.getPixelsPerMM()
     self.assertAlmostEqual(newPPMM, ppmm)
     newMM = player.getPhysicalScreenDimensions()
     self.assertEqual(newMM, mm)
示例#2
0
    def __init__(self, node, direction, numContacts=1, initialEvent=None, 
            directionTolerance=SWIPE_DIRECTION_TOLERANCE, minDist=MIN_SWIPE_DIST, 
            maxContactDist=MAX_SWIPE_CONTACT_DIST,
            possibleHandler=None, failHandler=None, detectedHandler=None):

        self.__numContacts = numContacts
        self.__angleWanted = self.__angleFromDirection(direction)
        self.__directionTolerance = directionTolerance
        self.__minDist = minDist*player.getPixelsPerMM()
        self.__maxInterContactDist = maxContactDist*player.getPixelsPerMM()
        super(SwipeRecognizer, self).__init__(node, False, numContacts, 
                initialEvent, possibleHandler=possibleHandler, failHandler=failHandler, 
                detectedHandler=detectedHandler)
示例#3
0
 def _handleUp(self, event):
     if self.getState() == "POSSIBLE":
         if (event.contact.distancefromstart > 
                 TapRecognizer.MAX_TAP_DIST*player.getPixelsPerMM()):
             self._setFail(event)
         else:
             self._setDetected(event)
示例#4
0
 def _handleUp(self, event):
     if self.getState() == "POSSIBLE":
         if (event.contact.distancefromstart > 
                 self.__maxDist*player.getPixelsPerMM()):
             self._setFail(event)
         else:
             self._setDetected(event)
    def init(self):
        player.showCursor(True)
        self.__minCutoffSlider = LabledSlider(label="Minimum Cutoff", min=0.3, max=8.0,
                formatStr="%.1f", onChange=self.__onSliderMove, 
                pos=(10,10), parent=self._parentNode)
        self.__cutoffSlopeSlider = LabledSlider(label="Cutoff Slope", min=0.0, max=0.05,
                formatStr="%.3f", onChange=self.__onSliderMove, 
                pos=(10,50), parent=self._parentNode)
        self.__onSliderMove()

        self._parentNode.subscribe(avg.Node.CURSOR_DOWN, self.__onDown)
        self.__contact = None
        self.__rawContactCircle = avg.CircleNode(r=7*player.getPixelsPerMM(), 
                color="FF0000", opacity=0, parent=self._parentNode)
        self.__filteredContactCircle = avg.CircleNode(r=7*player.getPixelsPerMM(), 
                color="00FF00", opacity=0, parent=self._parentNode)
        self.__filters = None
示例#6
0
    def __init__(self, event, parent=None, **kwargs):
        avg.DivNode.__init__(self, **kwargs)
        self.registerInstance(self, parent)

        event.contact.subscribe(avg.Contact.CURSOR_MOTION, self._onMotion)
        event.contact.subscribe(avg.Contact.CURSOR_UP, self._onUp)
        self.pos = self.getParent().getRelPos(event.pos)
        self._fingerSize = 7 * player.getPixelsPerMM() # Assume 14mm width for a finger.
        self._radius = self._getRadius(event)
示例#7
0
    def onInit(self):
        self.__minCutoffSlider = LabledSlider(label="Minimum Cutoff", range=(0.3, 8.0),
                formatStr="%.1f", pos=(10,10), parent=self)
        self.__minCutoffSlider.subscribe(widget.Slider.THUMB_POS_CHANGED, 
                self.__onSliderMove)
        self.__cutoffSlopeSlider = LabledSlider(label="Cutoff Slope", range=(0.0, 0.05),
                formatStr="%.3f", pos=(10,50), parent=self)
        self.__minCutoffSlider.subscribe(widget.Slider.THUMB_POS_CHANGED, 
                self.__onSliderMove)
        self.__onSliderMove(avg.Point2D(0,0))

        self.subscribe(avg.Node.CURSOR_DOWN, self.__onDown)
        self.__contact = None
        self.__rawContactCircle = avg.CircleNode(r=7*player.getPixelsPerMM(), 
                color="FF0000", opacity=0, parent=self)
        self.__filteredContactCircle = avg.CircleNode(r=7*player.getPixelsPerMM(), 
                color="00FF00", opacity=0, parent=self)
        self.__filters = None
示例#8
0
 def _handleUp(self, event):
     if self.__stateMachine.state == "DOWN1":
         self.__startTime = player.getFrameTime()
         self.__stateMachine.changeState("UP1")
     elif self.__stateMachine.state == "DOWN2":
         if ((event.pos - self.__startPos).getNorm() >
                 self.__maxDist*player.getPixelsPerMM()):
             self._setFail(event)
         else:
             self._setDetected(event)
         self.__stateMachine.changeState("IDLE")
     elif self.__stateMachine.state == "IDLE":
         pass
     else:
         assert(False), self.__stateMachine.state
示例#9
0
 def _handleDown(self, event):
     self.__startTime = player.getFrameTime()
     if self.__stateMachine.state == "IDLE":
         self.__frameHandlerID = player.subscribe(player.ON_FRAME, self.__onFrame)
         self.__stateMachine.changeState("DOWN1")
         self.__startPos = event.pos
         self._setPossible(event)
     elif self.__stateMachine.state == "UP1":
         if ((event.pos - self.__startPos).getNorm() > 
                 self.__maxDist*player.getPixelsPerMM()):
             self.__stateMachine.changeState("IDLE")
             self._setFail(event)
         else:
             self.__stateMachine.changeState("DOWN2")
     else:
         assert(False), self.__stateMachine.state
示例#10
0
 def _handleMove(self, event):
     if self.getState() != "IDLE":
         pos = self.__relEventPos(event)
         offset = pos - self.__dragStartPos
         if self.getState() == "RUNNING":
             self.notifySubscribers(Recognizer.MOTION, [offset]);
         else:
             if offset.getNorm() > self.__minDragDist*player.getPixelsPerMM():
                 if self.__angleFits(offset):
                     self._setDetected(event)
                     self.notifySubscribers(Recognizer.MOTION, [offset]);
                 else:
                     self.__fail(event)
         if self.__inertiaHandler:
             self.__inertiaHandler.onDrag(Transform(pos - self.__lastPos))
         self.__lastPos = pos
示例#11
0
    def _setActiveArea(self, upNode, activeAreaNode, fatFingerEnlarge):
        if fatFingerEnlarge:
            if activeAreaNode:
                raise (RuntimeError("Button: Can't specify both fatFingerEnlarge and activeAreaNode"))
            size = upNode.size
            minSize = 20 * player.getPixelsPerMM()
            size = avg.Point2D(max(minSize, size.x), max(minSize, size.y))
            activeAreaNode = avg.RectNode(size=size, opacity=0, parent=self)
            # Here we need to store a 'hard' reference to the active area node
            # because the tap recognizer won't keep it
            self.__activeAreaNode = activeAreaNode
        else:
            if activeAreaNode == None:
                activeAreaNode = self
            else:
                self.appendChild(activeAreaNode)

        self._tapRecognizer = gesture.TapRecognizer(
            activeAreaNode, possibleHandler=self._onDown, detectedHandler=self._onTap, failHandler=self._onTapFail
        )
示例#12
0
    def _setActiveArea(self, upNode, activeAreaNode, fatFingerEnlarge):
        self.__activeAreaNode = activeAreaNode

        if fatFingerEnlarge:
            if self.__activeAreaNode != None:
                raise(RuntimeError(
                    "Button: Can't specify both fatFingerEnlarge and activeAreaNode"))
            size = upNode.size
            minSize = 20*player.getPixelsPerMM()
            size = avg.Point2D(max(minSize, size.x), max(minSize, size.y))
            self.__activeAreaNode = avg.RectNode(size=size, opacity=0, parent=self)
        else:
            if self.__activeAreaNode == None:
                self.__activeAreaNode = self
            else:
                self.appendChild(self.__activeAreaNode)

        self._tapRecognizer = gesture.TapRecognizer(self.__activeAreaNode,
                possibleHandler=self._onDown, 
                detectedHandler=self._onTap, 
                failHandler=self._onTapFail)
示例#13
0
 def _handleMove(self, event):
     if self.__stateMachine.state != "IDLE": 
         if ((event.pos - self.__startPos).getNorm() > 
                 TapRecognizer.MAX_TAP_DIST*player.getPixelsPerMM()):
             self.__stateMachine.changeState("IDLE")
             self._setFail(event)
示例#14
0
 def _handleMove(self, event):
     self.__lastEvent = event
     if self.getState() == "POSSIBLE": 
         if (event.contact.distancefromstart > 
                 TapRecognizer.MAX_TAP_DIST*player.getPixelsPerMM()):
             self._setFail(event)
示例#15
0
 def _handleMove(self, event):
     self.__lastEvent = event
     if self.getState() == "POSSIBLE": 
         if (event.contact.distancefromstart > 
                 self.__maxDist*player.getPixelsPerMM()):
             self._setFail(event)
示例#16
0
 def _handleMove(self, event):
     if self.__stateMachine.state != "IDLE": 
         if ((event.pos - self.__startPos).getNorm() > 
                 self.__maxDist*player.getPixelsPerMM()):
             self.__stateMachine.changeState("IDLE")
             self._setFail(event)
示例#17
0
 def _handleMove(self, event):
     if self.getState() != "IDLE": 
         if (event.contact.distancefromstart > 
                 self.__maxDist*player.getPixelsPerMM()):
             self._setFail(event)