def __init__(self,
              screenRect,
              fullRect,
              absRect,
              zoom=(4, 4),
              pos=None,
              size=None,
              blend=False,
              cropRect=None):
     self.screenRect = screenRect
     self.fullRect = fullRect
     self.absRect = absRect
     if pos:
         self.pos = Vec2(pos[0], pos[1])
     else:
         self.pos = Vec2(0.0, 0.0)
     print "BaseTileDisplayObject, size arg unused"
     """
     if not size:  # if size == None:
         self.size = 100,100
     else:
         self.size = size
     """
     self.blend = blend
     self.cropRect = cropRect
     self.hidden = False
Exemplo n.º 2
0
    def __init__(self,
                 filename,
                 blend=False,
                 screenGeomRect=None,
                 dstRectScale=None):
        self.texture = Texture(filename)
        if blend:
            self.blendFunc = (GL_SRC_ALPHA, GL_ONE)
        else:
            self.blendFunc = (None, None)
        #(GL_SRC_ALPHA, GL_ONE);
        #(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        self.txtrMode = M_REPLACE
        # self.txtrTarget = GL_TEXTURE_2D
        # self.alphaTest = False  # assume this for now
        self.nativeWidth, self.nativeHeight = self.texture.getWidth(
        ), self.texture.getHeight()
        self.width, self.height = self.texture.getWidth(
        ), self.texture.getHeight()
        if screenGeomRect == None:
            self.screenGeomRect = Rect(0, 0, self.width, self.height)
        else:
            self.screenGeomRect = screenGeomRect

        self.texXMinMax = Vec2(0, 1)
        self.texYMinMax = Vec2(0, 1)
        self.color = None

        if dstRectScale == None:
            self.setDstRectScale((1.0, 1.0))
        else:
            self.setDstRectScale(dstRectScale)
Exemplo n.º 3
0
 def addObject(o, offset=None):
     if offset == None:
         currentPos = o.getPos()
         self.children[o] = Vec2(currentPos[0], currentPos[1])
     else:
         self.children[o] = Vec2(offset[0], offset[1])
     o.group = self
     self.resetPosFromChildren()
Exemplo n.º 4
0
    def draw(self, vflipTexture=False):
        glPushAttrib(GL_ENABLE_BIT)
        glDepthMask(GL_FALSE)
        # avoids annoying boxes visible around see through particles
        glEnable(GL_CULL_FACE)

        #if self.alphaTest != None:
        #    #glEnable(GL_ALPHA_TEST);
        #    #glAlphaFunc(GL_GREATER, .5);

        if self.blendFunc == (None, None):
            glDisable(GL_BLEND)
        else:
            glEnable(GL_BLEND)
            #glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glBlendFunc(self.blendFunc[0], self.blendFunc[1])

        if self.texture != None:  # don't have gl textures
            glEnable(GL_TEXTURE_2D)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
                      GLTextureModes[self.txtrMode])
            #    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, self.txtrMode ); # was GL_DECAL, or GL_MODULATE

        self.texture.bind()
        if (self.color != None):
            glColor4f(self.color[0], self.color[1], self.color[2],
                      self.color[3])
        unit_up_vec = Vec2(0.0, 1.0)
        edge_vec = Vec2(1.0, 0.0)
        if self.texture != None:  # have gl textures
            # print "easy texture draw:", self.screenGeomRect.x, self.screenGeomRect.y , self.screenGeomRect.width,self.screenGeomRect.height, self.texXMinMax, self.texYMinMax
            DrawTxtrd2dSquareIn2DFromCorner(Vec2(self.screenGeomRect.x,
                                                 self.screenGeomRect.y),
                                            self.screenGeomRect.width,
                                            self.screenGeomRect.height,
                                            self.texXMinMax,
                                            self.texYMinMax,
                                            vflipTexture=vflipTexture)
        else:
            Draw2dSquareIn2D(Vec2(0, 0), self.width, self.height)
        """
        glBegin(GL_TRIANGLE_STRIP)
        glTexCoord2d(0.0, 1.0);
        glVertex2f(200, 400)
        glTexCoord2d(0.0, 0.0);
        glVertex2f(200, 200)
        glTexCoord2d(1.0, 1.0);
        glVertex2f(400, 400)
        glTexCoord2d(1.0, 0.0);
        glVertex2f(400, 200)
        glEnd()
        """
        self.texture.unbind()

        glPopAttrib()
Exemplo n.º 5
0
    def __init__(self, address, objDesc, screenRect, fullRect, absRect, zoom=(4,4), pos=None, size=None, blend=False, cropRect=None, fps=None, scale=None, allowFrameSkip=True, gridColsRows=None, doCenter=True):
        BaseTileDisplayObject.__init__(self, screenRect=screenRect, fullRect=fullRect, absRect=absRect, zoom=zoom, pos=pos, size=size, blend=blend, cropRect=cropRect)
        self.address = address
        if gridColsRows == None:
            self.streamCols = 1
            self.streamRows = 1
        else:
            self.streamCols = gridColsRows[0]
            self.streamRows = gridColsRows[1]
        #self.streamWidth = 352
        #self.streamHeight = 288
        self.streamWidth = objDesc.streamWidth
        self.streamHeight = objDesc.streamHeight
        if scale != None:
            self.streamWidth *= scale[0]
            self.streamHeight *= scale[1]
        addVisibleSeparation = False
        if addVisibleSeparation:
            self.streamWidth += 3
            self.streamHeight += 3
        self.size = self.streamCols * self.streamWidth, self.streamRows * self.streamHeight
        self.streamObjs = []

        # print "GROUP:", self.pos, self.size
        if doCenter:
            # center on pos
            self.setPos(pos[0] -self.size[0]/2, pos[1] - self.size[1]/2)


        for r in range(self.streamRows):
            for c in range(self.streamCols):
                objOffset = Vec2(c * self.streamWidth, r * self.streamHeight)
                #objPos = (self.pos[0] + c * self.streamWidth, self.pos[1] + r * self.streamHeight)
                objPos = Vec2(self.pos[0] + objOffset[0], self.pos[1] + objOffset[1])
                streamObj = glStreamedTxtrBox(address, screenRect=screenRect, imagePos=objPos, absRect= absRect, fullRect=fullRect, blend=blend, scale=scale, streamState=StreamState(), streamWidth=objDesc.streamWidth, streamHeight=objDesc.streamHeight, vflip=objDesc.vflip)
                streamObj.groupOffset = objOffset
                self.streamObjs.append(streamObj)

        # information for sorting and aligning tiles
        self.targetLocationOrder = []
        self.locations = []
        for r in range(self.streamRows):
            for c in range(self.streamCols):
                self.locations.append(Vec2(c * self.streamWidth, r * self.streamHeight))
                #nC = self.streamCols-c
                #self.targetLocationOrder.append(r*self.streamCols+c)
        self.initialObjOrder = list(self.streamObjs)

        # DEBUG
        #self.targetLocationOrder = [ 0, 1, 2, 3]  # numbers for the location
        self.targetLocationOrder = range(self.streamRows*self.streamCols)
Exemplo n.º 6
0
 def __init__(self,
              imageFilename,
              screenRect,
              fullRect,
              absRect,
              initialOffset=(0, 0),
              zoom=(4, 4),
              imagePos=(0, 0),
              imageSize=None):
     self.hasDrawFunc = True
     self.hasEraseDrawFunc = True
     self.visible = True
     self.texture = Texture(imageFilename)
     #self.easyTexture = EasyTexture(imageFilename, screenGeomRect=screenRect, blend=False)
     #self.easyTexture.width = renderer.width * 0.8
     #self.easyTexture.height = renderer.height * 0.8
     #self.easyTexture.width = renderer.width
     #self.easyTexture.height = renderer.height
     self.useDrawPixel = False  # For comparison debugging
     self.xvel = 0.1
     self.yvel = 0.1
     self.zoom = zoom
     #self.easyTexture.zoom(zoom[0], zoom[1])
     #self.easyTexture.setOffset(initialOffset[0], initialOffset[1])
     self.autoPan = True
     self.imagePos = Vec2(imagePos[0], imagePos[1])
     if imageSize == None:
         self.imageSize = self.texture.getWidth(
         ), self.texture.getHeight()
     else:
         self.imageSize = imageSize
     self.fullRect = fullRect
     self.absRect = absRect
     self.screenRect = screenRect
Exemplo n.º 7
0
 def resetPosFromChildren(self):
     rect = self.getChildrenRect() # the rect origin is the new group origin
     if rect:
         difference = Vec2(rect.x, rect.y) - self.getPos()
         for child, offset in self.childrenAndOffsets.items(): 
             self.childrenAndOffsets[child] = offset - difference
     self.setPos(rect.x, rect.y)
     print "Group Object pos (after reset pos from children:", self.getPos()
Exemplo n.º 8
0
 def isPixelTransparent(self, imagecoords):
     for child,offset in self.childrenAndOffsets.items():
         # need to adjust image coords to match individual image instead of group rect
         #print "orig imagecoords:", imagecoords
         #print "child coords:", child.getPos(), "group coords:", self.getPos()
         offset = child.getPos() - self.getPos()
         tileImagecoords =  Vec2(imagecoords[0] - offset.x, imagecoords[1] - offset.y)
         #print "modified imagecoords:", tileImagecoords
         if ( Rect(0,0,child.getWidth(), child.getHeight()).containsPoint(*tileImagecoords) and
             not child.isPixelTransparent(tileImagecoords) ):
             return False
     return True
Exemplo n.º 9
0
        def update(self, secs, app):
            posTuple = self.target.getPos()
            pos = Vec2(posTuple[0], posTuple[1])
            pos.x = pos.x + self.xvel * secs
            pos.y = pos.y + self.yvel * secs
            if pos.x > self.xrange[1]:
                self.xvel = -abs(self.xvel)
            if pos.y > self.yrange[1]:
                self.yvel = -abs(self.yvel)

            if pos.x < self.xrange[0]:
                self.xvel = abs(self.xvel)
            if pos.y < self.xrange[0]:
                self.yvel = abs(self.yvel)

            self.target.setPos(pos.x, pos.y)
Exemplo n.º 10
0
        def draw(self, renderer):
            #glClearColor(.8, .8, .8, 1.0)
            #glClear(GL_COLOR_BUFFER_BIT)
            # glPixelStoref(GL_UNPACK_ALIGNMENT, 1)

            # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) )
            # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) )
            # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True)
            #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) )

            # convert to local coords
            localBtmLeft = Vec2(self.imagePos.x - self.absRect.x,
                                self.imagePos.y - self.absRect.y)
            localTopRight = Vec2(localBtmLeft.x + self.imageSize[0],
                                 localBtmLeft.y + self.imageSize[1])
            # clip to max/min of local display
            localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0))
            #if mpi.rank == 3:
            #    print "clip top right y:", localTopRight.y, self.screenRect.height
            localTopRight = Vec2(min(localTopRight.x, self.screenRect.width),
                                 min(localTopRight.y, self.screenRect.height))
            #if mpi.rank == 3:
            #    print "clip top right y:", localTopRight.y
            blitSize = Vec2(localTopRight.x - localBtmLeft.x,
                            localTopRight.y - localBtmLeft.y)

            # convert clipped local coords back to global coords find the source rect
            globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x,
                                 localBtmLeft.y + self.absRect.y)
            globalTopRight = Vec2(localTopRight.x + self.absRect.x,
                                  localTopRight.y + self.absRect.y)

            # convert global coords to txtr coords
            offset = Vec2(globalBtmLeft.x - self.imagePos.x,
                          globalBtmLeft.y - self.imagePos.y)
            #size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y + 80)
            size = (globalTopRight.x - globalBtmLeft.x,
                    localTopRight.y - localBtmLeft.y)
            if size[0] > 0 and size[1] > 0:
                #if mpi.rank == 3:
                #    print "renderer height:", renderer.height
                self.texture.blit(localBtmLeft,
                                  Rect(offset.x, offset.y, size[0], size[1]),
                                  (renderer.width, renderer.height))
Exemplo n.º 11
0
    def getLocalRectTxtrRectBL(self):
        # convert to local coords, BL means 0,0 is in the Bottom Left
        localBtmLeft = Vec2(self.pos.x - self.absRect.x,
                            self.pos.y - self.absRect.y)
        # print "CALC LOCAL TR1:", localBtmLeft.x, self.getSize()[0], localBtmLeft.y, self.getSize()[1]
        localTopRight = Vec2(localBtmLeft.x + self.getSize()[0],
                             localBtmLeft.y + self.getSize()[1])
        # clip to max/min of local display
        localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0))
        #if mpi.rank == 3:
        #    print "clip top right y:", localTopRight.y, self.screenRect.height
        # print "CALC LOCAL TR:", localTopRight.x, self.screenRect.width, localTopRight.y, self.screenRect.height
        localTopRight = Vec2(min(localTopRight.x, self.screenRect.width),
                             min(localTopRight.y, self.screenRect.height))
        #if mpi.rank == 3:
        #    print "clip top right y:", localTopRight.y
        blitSize = Vec2(localTopRight.x - localBtmLeft.x,
                        localTopRight.y - localBtmLeft.y)

        # convert clipped local coords back to global coords find the source rect
        globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x,
                             localBtmLeft.y + self.absRect.y)
        globalTopRight = Vec2(localTopRight.x + self.absRect.x,
                              localTopRight.y + self.absRect.y)

        # convert global coords to txtr coords
        offset = Vec2(globalBtmLeft.x - self.pos.x,
                      globalBtmLeft.y - self.pos.y)
        #size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y + 80)
        size = (globalTopRight.x - globalBtmLeft.x,
                localTopRight.y - localBtmLeft.y)

        # print "CALC LOCALRECTSIZE:", localTopRight, localBtmLeft
        localRectSize = localTopRight - localBtmLeft
        return Rect(localBtmLeft.x, localBtmLeft.y, localRectSize[0],
                    localRectSize[1]), Rect(offset.x, offset.y, size[0],
                                            size[1])
    def draw(self, renderer):
        if self.hidden:
            return
        localRectBL, txtrRectBL = self.getLocalRectTxtrRectBL()
        # print "pos:", self.pos, "absRect:", self.absRect
        # print "movie LOCAL RECT:", localRectBL, "TXTR RECTBL:", txtrRectBL
        localBtmLeftBL = Vec2(
            localRectBL.x, localRectBL.y)  # probably top and btm are flipped
        #localTopRightTL = Vec2(localRect.x, localRect.y)
        #localBtmLeftBL = Vec2(localRectBL.x, self.screenRect.height-localRectBL.y)
        #localBtmRightBL = Vec2(localRectBL.x, localBtmLeftBL.y + localRectBL.height)
        #print "Drawing at:", localBtmLeft
        if abs(localRectBL.width) > 0 and abs(localRectBL.height) > 0:
            #self.texture.blit( localBtmLeft, Rect(offset.x,offset.y, size[0], size[1]), (renderer.width, renderer.height) , blend=self.blend)
            #self.texture.blit( localBtmLeft, localRectBL, (renderer.width, renderer.height) , blend=self.blend)
            # use GL coords (bottom left is 0,0)
            #print "Setting movie pos to: ", localBtmLeftBL
            #self.moviePlayer.setPos(*(txtrBtmLeftBL))
            #self.moviePlayer.setPos(10,-340)
            # self.moviePlayer.setPos(30,10)
            #self.moviePlayer.setPos(*(localBtmLeft - Vec2(txtrRect.x, -txtrRect.y)))
            blend = False
            # print "movieplayer blit:", localBtmLeftBL, txtrRectBL, (renderer.width, renderer.height) , blend

            # Do simple blit for now instead of using easyTexture features.
            if self.scale == None:
                self.moviePlayer.easyTexture.texture.blit(
                    localBtmLeftBL,
                    txtrRectBL, (renderer.width, renderer.height),
                    blend=blend)
            else:
                self.moviePlayer.easyTexture.texture.blitWithTexScale(
                    localBtmLeftBL,
                    txtrRectBL, (renderer.width, renderer.height),
                    self.scale,
                    blend=blend)
            """
Exemplo n.º 13
0
def CreateTiledMovieObject(filename,
                           screenRect,
                           pos,
                           absRect,
                           fullRect,
                           loadAllMovieTiles=False,
                           scale=None,
                           allowFrameSkip=None):
    # A tiled movie object has a mostly frozen position on the display (for now)
    #   Each tile only loads the movie tiles that it will display at the
    #   movie's current position.
    # Find the tiles that are located on the current display, load them, and
    #   position them.

    print "CreateTiledMovieObject"

    objectsToGroup = []

    # Load info from description
    des = ReadTiledMovieDescription(filename)
    tileFilenames = os.listdir(filename)
    print "tileFilenames:", tileFilenames

    # calculate adjustment in case full movie width and height are not
    # evenly divisible by tile width and height.
    adjustment = (des["tileColsRows"][0] * des["tileRes"][0] -
                  des["fullRes"][0],
                  des["tileColsRows"][1] * des["tileRes"][1] -
                  des["fullRes"][1])

    imageBased = False
    if IsTiledMovieChunkImageBased(os.path.join(filename, tileFilenames[0])):
        imageBased = True

    for xIndex in range(des["tileColsRows"][0]):
        for yIndex in range(des["tileColsRows"][1]):  # TZ==TopZero
            yIndexBZ = des["tileColsRows"][1] - 1 - yIndex  # BZ==BottomZero

            movieTileFilename = ""
            for f in tileFilenames:
                tileYIndex = yIndexBZ
                if imageBased:  # The 0th row for our movie and image loaders is different.
                    tileYIndex = yIndex
                if f.startswith("%s_%s." % (xIndex, tileYIndex)
                                ) or f == "%s_%s" % (xIndex, tileYIndex):
                    movieTileFilename = f
            fullMovieTilePath = os.path.join(filename, movieTileFilename)

            tileObject = None

            # full movie width and height are not evenly divisible by
            #   tile width and tile height, so adjust offset
            xSrcOffset = xIndex * des["tileRes"][0] - adjustment[0]
            ySrcOffset = yIndex * des["tileRes"][1] - adjustment[1]

            srcWidth, srcHeight = (des["tileRes"][0], des["tileRes"][1])

            # adjust a possibly small row or column's offset and size
            #   might only be necessary for y, since y is flipped (x untested).
            #if xIndex == 0:
            #    xOffset -= adjustment[0]
            #    width -= adjustment[0]

            if scale != None:
                xRenderOffset = xIndex * des["tileRes"][0] * scale[
                    0] - adjustment[0]
                yRenderOffset = yIndex * des["tileRes"][1] * scale[
                    1] - adjustment[1] * scale[1]
                # remove the adjustment when yIndex == 0
                if yIndex == 0:
                    yRenderOffset = yIndex * des["tileRes"][1] * scale[1]
                    srcHeight -= adjustment[1]
                renderWidth, renderHeight = srcWidth * scale[
                    0], srcHeight * scale[1]
            else:
                # remove the adjustment when yIndex == 0
                if yIndex == 0:  # FIXME, if we ever use imagebased (slow, movies
                    #  from image files, this may have to be adjusted
                    #  to use tileYIndex and maybe flip signs below.
                    ySrcOffset += adjustment[1]
                    srcHeight -= adjustment[1]
                xRenderOffset, yRenderOffset = xSrcOffset, ySrcOffset
                renderWidth, renderHeight = srcWidth, srcHeight

            #xSrcOffset = xIndex * des["tileRes"][0]
            #ySrcOffset = yIndex * des["tileRes"][1]

            #moviePos = Vec2(pos[0] + xSrcOffset, pos[1] + ySrcOffset)
            moviePos = Vec2(pos[0] + xRenderOffset, pos[1] + yRenderOffset)

            #movieRect = Rect(pos[0] + xSrcOffset, pos[1] + ySrcOffset, srcWidth, srcHeight)
            movieRenderRect = Rect(pos[0] + xRenderOffset,
                                   pos[1] + yRenderOffset, renderWidth,
                                   renderHeight)
            # print "Checking colliderects to see if movie tile is on this display tile:", movieRenderRect.colliderect(absRect), movieRenderRect, absRect, movieRenderRect.colliderect(absRect), "indexes:", xIndex, yIndex, "flipped indexes:", xIndex,yIndexBZ

            if loadAllMovieTiles or movieRenderRect.colliderect(absRect):
                movieTileFilename = ""
                for f in tileFilenames:
                    if f.startswith("%s_%s." % (xIndex, yIndexBZ)
                                    ) or f == "%s_%s" % (xIndex, yIndexBZ):
                        movieTileFilename = f
                print "movieTileFilename:", movieTileFilename, len(
                    movieTileFilename)
                if len(movieTileFilename.strip()) > 0:
                    print "movieTileFilename:", movieTileFilename, len(
                        movieTileFilename)
                    print "TiledMovie: loading tile: ", fullMovieTilePath
                    # obj.pos and obj.size will be used to group movie tiles.
                    tileObject = CreateMovieObject(
                        fullMovieTilePath,
                        screenRect,
                        moviePos,
                        absRect,
                        fullRect,
                        fps=des["FPS"],
                        scale=scale,
                        allowFrameSkip=allowFrameSkip)
                else:
                    print "Warning movieTile not found for:", xIndex, yIndex

            if not tileObject:
                tileObject = NullTileDisplayObject(
                    pos=moviePos,
                    size=(movieRenderRect.width,
                          movieRenderRect.height))  # Empty object to represent
                # objects on other nodes
                # and keep object list synced.
            objectsToGroup.append(tileObject)

    shortName = os.path.basename(filename.strip(os.path.sep))
    groupObject = TiledMovieGroupObject(shortName,
                                        objectsToGroup,
                                        duration=des["duration"],
                                        fps=des["FPS"])

    groupObject.doChildUpdates = True
    returnObj = groupObject
    return returnObj
Exemplo n.º 14
0
 def setPos(self, x, y):
     self.imagePos = Vec2(x, y)
Exemplo n.º 15
0
 def getSize(self):
     rect = self.getChildrenRect()
     return Vec2(rect.width, rect.height)
Exemplo n.º 16
0
 def __init__(self):
     self.pos = Vec2(0.0,0.0)
Exemplo n.º 17
0
def CreateTileImageObject(imageFilename,
                          screenRect,
                          pos,
                          absRect,
                          fullRect,
                          blend=True,
                          scale=None):
    print "CreateTileImageObject", imageFilename, "at", pos
    imageSize = Image.open(imageFilename).size
    maxTextureSize = GetMaxTextureSize()
    numTiles = (int(math.ceil(float(imageSize[0]) / maxTextureSize)),
                int(math.ceil(float(imageSize[1]) / maxTextureSize)))
    print "NUMTILES:", numTiles

    if numTiles[0] == 1 and numTiles[1] == 1:
        returnObj = glTxtrBox(imageFilename,
                              screenRect=screenRect,
                              imagePos=pos,
                              absRect=absRect,
                              fullRect=fullRect,
                              blend=blend,
                              scale=scale)

    else:
        objectsToGroup = []

        # Create a group object
        xSrcOffset = 0
        xRenderOffset = 0
        subImageWidth = imageSize[0] / numTiles[0]
        subImageHeight = imageSize[1] / numTiles[1]
        for xIndex in range(numTiles[0]):
            ySrcOffset = 0
            yRenderOffset = 0

            if xIndex == numTiles[0] - 1:
                # make sure we don't cut off any
                # pixels if it's not evenly divisible.
                width = imageSize[0] - xSrcOffset
            else:
                width = subImageWidth

            for yIndex in range(numTiles[1]):

                if yIndex == numTiles[1] - 1:
                    # make sure we don't cut off any
                    # pixels if it's not evenly divisible.
                    height = imageSize[1] - ySrcOffset
                else:
                    height = subImageHeight

                pos = Vec2(xRenderOffset, -yRenderOffset)  # flip y coord
                # cropRect is for cropping a subsection out of the source image
                cropRect = Rect(xSrcOffset, ySrcOffset, width, height)
                print "Loading with crop rect:", cropRect
                obj = glTxtrBox(imageFilename,
                                screenRect=screenRect,
                                imagePos=pos,
                                absRect=absRect,
                                fullRect=fullRect,
                                blend=blend,
                                cropRect=cropRect,
                                scale=scale)
                objectsToGroup.append(obj)

                ySrcOffset += obj.getSrcSize()[1]
                yRenderOffset += obj.getRenderSize()[1]
            xSrcOffset += obj.getSrcSize()[0]
            xRenderOffset += obj.getRenderSize()[0]

        shortName = os.path.basename(imageFilename.strip(os.path.sep))
        groupObject = GroupObject(shortName, objectsToGroup)
        returnObj = groupObject
    print "************* CreateTileDisplayObject finished", returnObj
    return returnObj
Exemplo n.º 18
0
def CreateTiledMovieObjectFromLayout(layoutFile,
                                     screenRect,
                                     pos,
                                     absRect,
                                     fullRect,
                                     loadAllMovieTiles=False,
                                     scale=None,
                                     allowFrameSkip=None):
    print "CreateTiledMovieObjectFromLayout"

    objectsToGroup = []
    if None == pos:
        pos = (0, 0)

    layoutEntries = ReadLayout(layoutFile)
    for entry in layoutEntries:
        moviePos = Vec2(pos[0] + entry.pos[0], pos[1] + entry.pos[1])

        movieRenderRect = Rect(moviePos[0], moviePos[1], entry.getWidth(),
                               entry.getHeight())
        tileObject = None

        # same code as below func
        if loadAllMovieTiles or movieRenderRect.colliderect(absRect):
            movieTileFilename = entry.path
            fullMovieTilePath = movieTileFilename  # for now has absolute paths

            # same code as below function
            print "movieTileFilename:", movieTileFilename, len(
                movieTileFilename)
            if len(movieTileFilename.strip()) > 0:
                print "movieTileFilename:", movieTileFilename, len(
                    movieTileFilename)
                print "TiledMovie: loading tile: ", fullMovieTilePath
                # obj.pos and obj.size will be used to group movie tiles.
                fps = fps = entry.getProperty("fps")
                tileObject = CreateMovieObject(fullMovieTilePath,
                                               screenRect,
                                               moviePos,
                                               absRect,
                                               fullRect,
                                               fps=fps,
                                               scale=scale,
                                               allowFrameSkip=allowFrameSkip)
            else:
                print "Warning movieTile not found for:", xIndex, yIndex

        if not tileObject:
            tileObject = NullTileDisplayObject(
                pos=moviePos,
                size=(movieRenderRect.width,
                      movieRenderRect.height))  # Empty object to represent
            # objects on other nodes
            # and keep object list synced.
        objectsToGroup.append(tileObject)

    shortName = os.path.basename(layoutFile.strip(os.path.sep))
    duration = layoutEntries[0].getProperty("duration")
    fps = fps = layoutEntries[0].getProperty("fps")
    groupObject = TiledMovieGroupObject(shortName,
                                        objectsToGroup,
                                        duration=duration,
                                        fps=fps)

    groupObject.doChildUpdates = True
    returnObj = groupObject
    return returnObj
Exemplo n.º 19
0
def CreateMultiNetGroupTileDisplayStreamObject(addresses,
                                               objDesc,
                                               screenRect,
                                               pos,
                                               absRect,
                                               fullRect,
                                               gridColsRows,
                                               netGridColsRows,
                                               blend=True,
                                               scale=None,
                                               doCenter=True,
                                               plant=False):
    #from streamView import StreamView
    objectsToGroup = []
    if len(addresses) != netGridColsRows[0] * netGridColsRows[1]:
        raise Exception(
            "Number of addresses should match number of net grid tiles (e.g. use: --streamGroupsColsRows=3x2). currently: %d, %s"
            % (len(addresses), netGridColsRows))
    #for address in addresses:

    gridCols = gridColsRows[0]
    gridRows = gridColsRows[1]
    bigTileWidth = gridCols * objDesc.streamWidth  # 352
    bigTileHeight = gridRows * objDesc.streamHeight  # 288
    if scale != None:
        bigTileWidth *= scale[0]
        bigTileHeight *= scale[1]
    netGridCols = netGridColsRows[0]
    netGridRows = netGridColsRows[1]
    print "BIGTILESIZE:", bigTileWidth, bigTileHeight

    basePos = pos
    if doCenter:
        centeredPos = Vec2(pos[0], pos[1]) - Vec2(
            netGridCols * bigTileWidth / 2, netGridRows * bigTileHeight / 2)
        basePos = centeredPos

    # for xcol in range(1,2):
    print "grid within network stream:", gridCols, gridRows
    print "bigTile width,height:", bigTileWidth, bigTileHeight
    for xcol in range(netGridCols):
        for yrow in range(netGridRows):
            streamAddressIndex = netGridCols * yrow + xcol  # btm left to right, to top
            address = addresses[streamAddressIndex]
            yOffset = yrow * bigTileHeight
            xOffset = xcol * bigTileWidth
            singlePos = Vec2(xOffset + basePos[0], yOffset + basePos[1])

            loadTile = True
            if plant:  # only load if it's on this machine
                streamTileRenderRect = Rect(singlePos[0], singlePos[1],
                                            bigTileWidth, bigTileHeight)
                # print "Checking colliderects to see if stream tile is on this display tile:", movieRenderRect.colliderect(absRect), movieRenderRect, absRect, movieRenderRect.colliderect(absRect), "indexes:", xIndex, yIndex, "flipped indexes:", xIndex,yIndexBZ
                if streamTileRenderRect.colliderect(absRect):
                    loadTile = True
                    # Debug
                    import mpi
                    print mpi.rank, " Loading stream with rect: ", streamTileRenderRect, "me:", (
                        absRect.x, absRect.y, absRect.width,
                        absRect.height), address
                else:
                    import mpi
                    print mpi.rank, " Not loading stream with rect: ", streamTileRenderRect, "me:", (
                        absRect.x, absRect.y, absRect.width,
                        absRect.height), address
                    loadTile = False

            if loadTile:
                groupStreamObj = GroupTiledStreamObject(
                    address,
                    objDesc,
                    screenRect=screenRect,
                    pos=singlePos,
                    absRect=absRect,
                    fullRect=fullRect,
                    blend=blend,
                    scale=scale,
                    gridColsRows=gridColsRows,
                    doCenter=False)
                objectsToGroup.append(groupStreamObj)
            else:
                groupStreamObj = NullTileDisplayObject(
                    pos=singlePos, size=(bigTileWidth, bigTileHeight)
                )  # Empty object to represent objects on other nodes and help describe large object on this node .
                objectsToGroup.append(groupStreamObj)

    shortName = "_".join(addresses)
    largeGroupObject = GroupObject(shortName,
                                   objectsToGroup,
                                   doChildUpdates=True)

    return largeGroupObject