Exemple #1
0
 def __init__(self, GameMenue, Field):
     
     self.Field = Field
     self.gameMenue = GameMenue
     
     self.part1 = avg.RectNode(parent = GameMenue.divNodeGameMenue, 
                               pos = (Field.xWertLinksOben+ (6 * GameMenue.blocksize), Field.yWertOben), 
                               fillcolor = "FFFF00", fillopacity = 1, color = "000000", 
                               size = avg.Point2D(GameMenue.blocksize ,GameMenue.blocksize)
                               )
     self.part2 = avg.RectNode(parent = GameMenue.divNodeGameMenue, 
                               pos = (Field.xWertLinksOben+ (7 * GameMenue.blocksize), Field.yWertOben), 
                               fillcolor = "FFFF00", fillopacity = 1, color = "000000", 
                               size = avg.Point2D(GameMenue.blocksize ,GameMenue.blocksize)
                               )
     self.part3 = avg.RectNode(parent = GameMenue.divNodeGameMenue, 
                               pos = (Field.xWertLinksOben+ (8 * GameMenue.blocksize), Field.yWertOben), 
                               fillcolor = "FFFF00", fillopacity = 1, color = "000000", 
                               size = avg.Point2D(GameMenue.blocksize ,GameMenue.blocksize)
                               )
     self.part4 = avg.RectNode(parent = GameMenue.divNodeGameMenue, 
                               pos = (Field.xWertLinksOben+ (9 * GameMenue.blocksize), Field.yWertOben), 
                               fillcolor = "FFFF00", fillopacity = 1, color = "000000", 
                               size = avg.Point2D(GameMenue.blocksize ,GameMenue.blocksize)
                               )
     self.currPos1 = (6,0)
     self.currPos2 = (7,0)
     self.currPos3 = (8,0)
     self.currPos4 = (9,0)
     self.blockType = "I"
     self.rotatingPosition = 0
Exemple #2
0
    def testSetWidth(self):
        root = self.loadEmptyScene()
        text = "42 " * 42
        textNode = avg.WordsNode(
                parent=root,
                fontsize = 10,
                font = "Bitstream Vera Sans",
                text = text)
        
        def testSize(p1, p2):
            self.assert_(abs(p1.x - p2.x) < 5)
            self.assert_(abs(p1.y - p2.y) < 50)
        
        testSize(textNode.size, avg.Point2D(630,13))
        testSize(textNode.getMediaSize(), avg.Point2D(630,13))
        mediaSize = textNode.getMediaSize()

        def changeSize():
            textNode.width = 50
            testSize(textNode.size, avg.Point2D(50,182))
            testSize(textNode.getMediaSize(), avg.Point2D(45,182))
            self.assertNotEqual(mediaSize, textNode.getMediaSize())

        self.start(True, 
                [lambda: changeSize()])
Exemple #3
0
 def testHash():
     ptMap = {}
     ptMap[avg.Point2D(0, 0)] = 0
     ptMap[avg.Point2D(1, 0)] = 1
     ptMap[avg.Point2D(0, 0)] = 2
     self.assertEqual(len(ptMap), 2)
     self.assertEqual(ptMap[avg.Point2D(0, 0)], 2)
Exemple #4
0
 def initFeld(self, startX, endX, oben):
     #linker Rahmen
     avg.RectNode(
         parent=self.divNodeGameMenue,
         sensitive=False,
         pos=(startX - self.rahmenbreite, oben),
         fillcolor="000000",
         fillopacity=1,
         color="000000",
         size=avg.Point2D(
             self.rahmenbreite,
             self.tetrishoehe)  #self.divNodeGameMenue.size[1]* 0.87
     )
     #rechter Rahmen
     avg.RectNode(parent=self.divNodeGameMenue,
                  pos=(endX, oben),
                  sensitive=False,
                  fillcolor="000000",
                  fillopacity=1,
                  color="000000",
                  size=avg.Point2D(self.rahmenbreite, self.tetrishoehe))
     #Boden
     avg.RectNode(
         parent=self.divNodeGameMenue,
         sensitive=False,
         pos=(startX - self.rahmenbreite, self.tetrishoehe + oben),
         fillcolor="000000",
         fillopacity=1,
         color="000000",
         size=avg.Point2D(
             endX - startX + 2 * int(self.divNodeGameMenue.size[0] * 0.025),
             self.rahmenbreite))
Exemple #5
0
 def __init__(self, size, radius, pos=(0, 0), parent=None, **kwargs):
     super(RoundedRect, self).__init__(**kwargs)
     self.__pos = avg.Point2D(pos)
     self.__size = avg.Point2D(size)
     self.__radius = radius
     self.__calcPolygon()
     self.registerInstance(self, parent)
Exemple #6
0
    def __init__(self,
                 keyDef,
                 downBmp,
                 feedbackBmp,
                 sticky=False,
                 parent=None,
                 **kwargs):
        self.__keyCode = keyDef[0]
        if not (isinstance(self.__keyCode, tuple)):
            self.__keyCode = (self.__keyCode, )
        kwargs['pos'] = avg.Point2D(keyDef[1])
        kwargs['size'] = avg.Point2D(keyDef[2])
        if len(keyDef) == 4:
            self.__isCommand = keyDef[3]
        else:
            self.__isCommand = False
        super(Key, self).__init__(**kwargs)
        self.registerInstance(self, parent)

        self.__sticky = sticky
        self.__stickyIsDown = False
        self.__cursorID = None
        if downBmp:
            if player.isPlaying():
                self.__createImages(downBmp, feedbackBmp)
            else:
                player.subscribe(
                    avg.Player.PLAYBACK_START,
                    lambda: self.__createImages(downBmp, feedbackBmp))
Exemple #7
0
 def testHash():
     ptMap = {
         avg.Point2D(0, 0): 0,
         avg.Point2D(1, 0): 1,
         avg.Point2D(0, 0): 2
     }
     self.assertEqual(len(ptMap), 2)
     self.assertEqual(ptMap[avg.Point2D(0, 0)], 2)
Exemple #8
0
def scaleMin(srcSize, minSize):
    """
    Returns scrSize aspect correct scaled to completely fill minSize.
    """
    aspect = srcSize.x / srcSize.y
    if aspect < minSize.x / minSize.y:
        return avg.Point2D(minSize.x, minSize.x / aspect)
    return avg.Point2D(minSize.y * aspect, minSize.y)
Exemple #9
0
def scaleMax(srcSize, maxSize):
    """
    Returns scrSize aspect correct scaled to fit right into maxSize.
    """
    aspect = srcSize.x / srcSize.y
    if aspect < maxSize.x / maxSize.y:
        return avg.Point2D(maxSize.y * aspect, maxSize.y)
    return avg.Point2D(maxSize.x, maxSize.x / aspect)
Exemple #10
0
 def setNodeTransform(self, node):
     v = self.applyVec([1,0,0])
     rot = avg.Point2D(v[0], v[1]).getAngle()
     node.angle = rot
     node.size = self.getScale()
     node.pivot = node.size/2
     v = self.applyVec([0,0,1])
     node.pos = (avg.Point2D(v[0], v[1]) + (node.pivot).getRotated(node.angle) -
             node.pivot)
Exemple #11
0
    def __init__(self, friction, moveHandler, stopHandler):
        self.__friction = friction
        self.__moveHandler = moveHandler
        self.__stopHandler = stopHandler

        self.__transVel = avg.Point2D(0, 0)
        self.__curPivot = avg.Point2D(0, 0)
        self.__angVel = 0
        self.__sizeVel = avg.Point2D(0, 0)
        self.__frameHandlerID = player.subscribe(player.ON_FRAME, self.__onDragFrame)
Exemple #12
0
    def __init__(self, endsExtent, minExtent=(-1,-1), **kwargs):
        super(HVStretchNode, self).__init__(**kwargs)

        (hEndsExtent, hMinExtent) = self._checkExtents(endsExtent[0], minExtent[0])
        (vEndsExtent, vMinExtent) = self._checkExtents(endsExtent[1], minExtent[1])
        self.__endsExtent = avg.Point2D(hEndsExtent, vEndsExtent)
        self.__minExtent = avg.Point2D(hMinExtent, vMinExtent)
        
        self.__createNodes()

        self._initNodes()
Exemple #13
0
 def addNodes(y):
     xmlNode = createXmlNode((16, y))
     root.appendChild(xmlNode)
     createDictNode(root, (48, y))
     noAttachNode = createXmlNode((0, 0))
     noAttachNode.pos = avg.Point2D(80, y)
     illegalMove(noAttachNode)
     root.appendChild(noAttachNode)
     attachNode = createXmlNode((0, 0))
     root.appendChild(attachNode)
     attachNode.pos = avg.Point2D(112, y)
     illegalMove(attachNode)
Exemple #14
0
 def onTransform(self, tr):
     if self.bat is not None:
         vert = [(tr.scale * v[0], tr.scale * v[1]) for v in self.bat.body.fixtures[0].shape.vertices]
         pos1, pos2 = avg.Point2D(vert[0]), avg.Point2D(vert[1])
         length = (pos2 - pos1).getNorm()
         self.bat.body.active = self.bat.node.active = length <= maxBatSize 
         width = max(1 / PPM, (maxBatSize - length) / 10)
         self.bat.body.fixtures[0].shape.SetAsBox(length / 2, width / 2)
         self.bat.body.position = tr.pivot / PPM 
         self.bat.body.position += tr.trans / PPM
         self.bat.body.angle += tr.rot         
         res = 1.65 - (length / maxBatSize)
         self.bat.body.fixtures[0].restitution = res
Exemple #15
0
        def calc_wall_viewpoint(de):
            yaw_quat = pyglm.quat.fromAxisAngle((0, 1, 0), de.orientation[0])
            pitch_quat = pyglm.quat.fromAxisAngle((1, 0, 0), de.orientation[1])
            roll_quat = pyglm.quat.fromAxisAngle((0, 0, 1), de.orientation[2])
            q = yaw_quat * pitch_quat * roll_quat
            device_dir = q * pyglm.vec3(0, 0, 1)

            viewpt3d = line_plane_intersect(de.spacePos, device_dir, (0, 0, 0),
                                            (0, 0, 1))
            if viewpt3d is not None:
                de.setWallViewpoint(avg.Point2D(viewpt3d.x, viewpt3d.y))
            else:
                de.setWallViewpoint(avg.Point2D(0, 0))
Exemple #16
0
        def calc_wall_viewpoint(hd):
            yaw_quat = pyglm.quat.fromAxisAngle((0, 1, 0), hd.rot[0])
            pitch_quat = pyglm.quat.fromAxisAngle((1, 0, 0), hd.rot[1])
            roll_quat = pyglm.quat.fromAxisAngle((0, 0, 1), hd.rot[2])
            q = yaw_quat * pitch_quat * roll_quat
            head_dir = q * pyglm.vec3(0, 0, 1)

            viewpt3d = line_plane_intersect(hd.pos, head_dir, (0, 0, 0),
                                            (0, 0, 1))
            if viewpt3d is not None:
                hd.setWallViewpoint(avg.Point2D(viewpt3d.x, viewpt3d.y))
            else:
                hd.setWallViewpoint(avg.Point2D(0, 0))
Exemple #17
0
 def _renderImages(self):
     bmpSize = self._bmp.getSize()
     xPosns = (0, self.__endsExtent[0], bmpSize.x-self.__endsExtent[0], bmpSize.x)
     yPosns = (0, self.__endsExtent[1], bmpSize.y-self.__endsExtent[1], bmpSize.y)
     for y in range(3):
         for x in range(3):
             node = self.__nodes[y][x]
             pos = avg.Point2D(xPosns[x], yPosns[y])
             size = avg.Point2D(xPosns[x+1], yPosns[y+1]) - pos
             if x == 1:
                 size.x = 1
             if y == 1:
                 size.y = 1
             self._renderImage(self._bmp, node, -pos, size)
Exemple #18
0
    def onArgvParsed(self, options, args, parser):
        if len(args) != 1:
            parser.print_help()
            sys.exit(1)

        self.node = avg.VideoNode(href=args[0],
                                  accelerated=not (options.disableAccel))
        self.node.pause()

        mediaSize = self.node.getMediaSize()
        size = avg.Point2D(max(mediaSize.x, 320), max(mediaSize.y, 120))
        screenSize = player.getScreenResolution()
        size = avg.Point2D(min(size.x, screenSize.x),
                           min(size.y, screenSize.y - 80))
        self.settings.set("app_resolution", "%dx%d" % (size.x, size.y))
Exemple #19
0
 def testIntAnim(self):
     self.initScene()
     self.__doubleAnim = avg.LinearAnim(self.__node, "x", 300, 0, 100, True)
     self.__pointAnim = avg.LinearAnim(self.__node, "pos", 200,
                                       avg.Point2D(0, 0),
                                       avg.Point2D(100, 40), True)
     self.start(False, (
         self.__doubleAnim.start,
         lambda: self.delay(100),
         lambda: self.compareImage("testIntAnim1"),
         self.__doubleAnim.abort,
         self.__pointAnim.start,
         lambda: self.delay(100),
         lambda: self.compareImage("testIntAnim2"),
     ))
Exemple #20
0
 def createImageNode():
     # Node is not in tree; mediadir should be root node dir.
     node = avg.ImageNode(href="rgb24-64x64a.png")
     self.assertEqual(node.size, avg.Point2D(0, 0))  # File not found
     node.href = "rgb24-64x64.png"
     self.assertEqual(node.size, avg.Point2D(64, 64))  # File found
     node = avg.ImageNode(href="rgb24-64x64a.png", width=23, height=42)
     # File not found, but custom size
     self.assertEqual(node.size, avg.Point2D(23, 42))
     node.href = "rgb24-64x64.png"
     # File found, custom size stays
     self.assertEqual(node.size, avg.Point2D(23, 42))
     node.size = (0, 0)
     # File found, custom size cleared. Media size should be used.
     self.assertEqual(node.size, avg.Point2D(64, 64))
Exemple #21
0
 def __moveContact(self):
     time = player.getFrameTime()
     rawPos = self.__contact.events[-1].pos
     self.__rawContactCircle.pos = rawPos
     filteredPos = avg.Point2D(self.__filters[0].apply(rawPos.x, time),
                               self.__filters[1].apply(rawPos.y, time))
     self.__filteredContactCircle.pos = filteredPos
Exemple #22
0
    def onInit(self):
        avg.RectNode(size=(1024, 768),
                     fillopacity=1,
                     fillcolor="FFFFFF",
                     parent=self)

        hScrollBar = widget.ScrollBar(pos=(10, 10), width=150, parent=self)
        self.__addValueDisplay(hScrollBar, (175, 12))

        vScrollBar = widget.ScrollBar(pos=(15, 60),
                                      height=150,
                                      orientation=widget.Orientation.VERTICAL,
                                      parent=self)
        vScrollBar.thumbExtent = 5
        vScrollBar.range = (10, 0)
        self.__addValueDisplay(vScrollBar, (10, 220))

        hSlider = widget.Slider(pos=(10, 35), width=150, parent=self)
        self.__addValueDisplay(hSlider, (175, 33))

        vSlider = widget.Slider(pos=(60.5, 60),
                                height=150,
                                orientation=widget.Orientation.VERTICAL,
                                parent=self)
        vSlider.range = (1, 0)
        self.__addValueDisplay(vSlider, (55, 220))
        self.controls = [hScrollBar, vScrollBar, hSlider, vSlider]

        self.createScrollArea(avg.Point2D(220, 10))

        checkBox = widget.CheckBox(pos=(10, 270),
                                   text="Disable everything",
                                   parent=self)
        checkBox.subscribe(widget.CheckBox.TOGGLED, self.onCheck)
Exemple #23
0
    def testSVG(self):
        svgFile = avg.SVG("media/rect.svg", False)

        # renderElement
        bmp = svgFile.renderElement("rect")
        self.compareBitmapToFile(bmp, "testSvgBmp")
        self.assertEqual(svgFile.getElementSize("rect"), avg.Point2D(22,12))
        bmp = svgFile.renderElement("pos_rect")
        self.compareBitmapToFile(bmp, "testSvgPosBmp")
        bmp = svgFile.renderElement("rect", 5)
        self.compareBitmapToFile(bmp, "testSvgScaleBmp1")
        bmp = svgFile.renderElement("rect", (20,20))
        self.compareBitmapToFile(bmp, "testSvgScaleBmp2")

        # error handling
        self.assertException(lambda: avg.SVG("filedoesntexist.svg", False))
        self.assertException(lambda: svgFile.renderElement("missing_id"))

        # unescapeIllustratorIDs
        svgIllustratorFile = avg.SVG("illustratorRect.svg", True)
        svgIllustratorFile.getElementSize("pos_rect")

        # createImageNode
        root = self.loadEmptyScene()
        self.start(False,
                (lambda: svgFile.createImageNode("rect", {"pos":(10,10), "parent":root}),
                 lambda: self.compareImage("testSvgNode"),
                 lambda: svgFile.createImageNode("rect", {"pos":(5,5), "parent":root},
                        5),
                 lambda: self.compareImage("testSvgScaledNode1"),
                 lambda: svgFile.createImageNode("rect", {"pos":(1,1), "parent":root},
                        (40,40)),
                 lambda: self.compareImage("testSvgScaledNode2")
                ))
Exemple #24
0
    def __device_entry_from_list(self, device_list, pitch_offset):
        def calc_wall_viewpoint(de):
            yaw_quat = pyglm.quat.fromAxisAngle((0, 1, 0), de.orientation[0])
            pitch_quat = pyglm.quat.fromAxisAngle((1, 0, 0), de.orientation[1])
            roll_quat = pyglm.quat.fromAxisAngle((0, 0, 1), de.orientation[2])
            q = yaw_quat * pitch_quat * roll_quat
            device_dir = q * pyglm.vec3(0, 0, 1)

            viewpt3d = line_plane_intersect(de.spacePos, device_dir, (0, 0, 0),
                                            (0, 0, 1))
            if viewpt3d is not None:
                de.setWallViewpoint(avg.Point2D(viewpt3d.x, viewpt3d.y))
            else:
                de.setWallViewpoint(avg.Point2D(0, 0))

        timestamp = device_list[1]
        if timestamp < self.start_time or self.start_time + self.duration < timestamp:
            return None

        user_id = device_list[0]
        screen_pos = avg.Point2D(device_list[2], device_list[3])
        space_pos = [device_list[4], device_list[5], device_list[6]]
        orientation = [
            device_list[7] + pitch_offset, device_list[8], device_list[9]
        ]

        device_entry = plots.DeviceEntry(user_id, screen_pos, space_pos,
                                         orientation, timestamp)
        calc_wall_viewpoint(device_entry)
        return device_entry
Exemple #25
0
    def __init__(self, userid, pos, viewpt, parent, **kwargs):
        super(UserNode, self).__init__(**kwargs)
        self.registerInstance(self, parent)

        color = vis_params.VisParams.get_user_color(userid)

        end_pos = avg.Point2D(viewpt)
        if (end_pos-pos).getNorm() > 200:
            dir = (end_pos-pos).getNormalized()
            end_pos = pos + dir*200
        avg.LineNode(
            pos1=pos,
            pos2=end_pos,
            color=color,
            parent=self,
            strokewidth=2
        )
        avg.CircleNode(
            pos=pos,
            r=6,
            fillopacity=1,
            color=color,
            fillcolor="000000",
            parent=self
        )
        avg.WordsNode(
            parent=self,
            pos=(pos[0], pos[1] + 6 + 2),
            fontsize=11,
            color=color,
            rawtextmode=True,
            text=str(userid),
            alignment='center'
        )
Exemple #26
0
 def getMaxContentPos(self):
     maxPos = avg.Point2D(self._contentNode.size - self.size)
     if maxPos.x < 0:
         maxPos.x = 0
     if maxPos.y < 0:
         maxPos.y = 0
     return maxPos
Exemple #27
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
Exemple #28
0
 def calcQuarterCircle(center, r, startAngle):
     pos = []
     for i in xrange(int(r) + 1):
         angle = i * (1.57 / r) + startAngle
         p = avg.Point2D(center) + avg.Point2D.fromPolar(angle, r)
         pos.append(p)
     return pos
Exemple #29
0
 def reset(self):
     # Reset der Frage
     self.solved = False
     self.qFalse = 0
     for answer in self.a:
         answer.reset()
     self.sidebar.sensitive = True
     self.close.opacity = 0
     self.captureHolder2 = None
     if self.current_event != None:
         self.current_event.sensitive = True
     py = 0
     for p in self.picture:                  # alle Bilder werden in die Seitenleiste gesetzt, falls (eins) vergroessert ist
         p.pos = avg.Point2D(0,py)
         p.size = avg.Point2D(550,406)
         py = py + 410
    def __init__(self, event, **kwargs):
        BaseTouchVisualization.__init__(self, event, **kwargs)
        self.positions = [event.pos]

        if event.source == avg.Event.TOUCH:
            color = 'e5d8d8'
        elif event.source == avg.Event.TANGIBLE:
            color = 'ffe0e0'
        else:
            color = 'd8e5e5'
            self.opacity = 0.5

        self.__transparentCircle = avg.CircleNode(r=self._radius + 20,
                                                  fillcolor=color,
                                                  fillopacity=0.2,
                                                  opacity=0.0,
                                                  strokewidth=1,
                                                  sensitive=False,
                                                  parent=self)
        self.__pulsecircle = avg.CircleNode(r=self._radius,
                                            fillcolor=color,
                                            color=color,
                                            fillopacity=0.5,
                                            opacity=0.5,
                                            strokewidth=1,
                                            sensitive=False,
                                            parent=self)
        if event.source in [avg.Event.TOUCH, avg.Event.TRACK]:
            self.__majorAxis = avg.LineNode(pos1=(0, 0),
                                            pos2=event.majoraxis,
                                            color='FFFFFF',
                                            sensitive=False,
                                            parent=self)
            self.__minorAxis = avg.LineNode(pos1=(0, 0),
                                            pos2=event.minoraxis,
                                            color='FFFFFF',
                                            sensitive=False,
                                            parent=self)
        if event.source == avg.Event.TOUCH:
            self.__handAxis = avg.LineNode(pos1=(0, 0),
                                           pos2=self.__getHandVector(event),
                                           opacity=0.5,
                                           color='A0FFA0',
                                           sensitive=False,
                                           parent=self)
        fontPos = avg.Point2D(self.__pulsecircle.r, 0)

        self.__textNode = avg.WordsNode(pos=fontPos, fontsize=9, parent=self)
        self.motionPath = avg.PolyLineNode(pos=self.positions,
                                           opacity=0.7,
                                           color=color,
                                           parent=kwargs['parent'])
        self.motionVector = avg.LineNode(pos1=(0, 0),
                                         pos2=-event.contact.motionvec,
                                         opacity=0.4,
                                         parent=self)
        pulseCircleAnim = avg.LinearAnim(self.__pulsecircle, 'r', 200, 50,
                                         self._radius)
        pulseCircleAnim.start()