當前位置: 首頁>>代碼示例>>Python>>正文


Python QMap.upperBound方法代碼示例

本文整理匯總了Python中pyqtcore.QMap.upperBound方法的典型用法代碼示例。如果您正苦於以下問題:Python QMap.upperBound方法的具體用法?Python QMap.upperBound怎麽用?Python QMap.upperBound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyqtcore.QMap的用法示例。


在下文中一共展示了QMap.upperBound方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GidMapper

# 需要導入模塊: from pyqtcore import QMap [as 別名]
# 或者: from pyqtcore.QMap import upperBound [as 別名]
class GidMapper():
    ##
    # Default constructor. Use \l insert to initialize the gid mapper
    # incrementally.
    ##
    def __init__(self, *args):
        self.mInvalidTile = None
        self.mTilesetColumnCounts = QMap()
        self.mFirstGidToTileset = QMap()
        if len(args)==1:
            ##
            # Constructor that initializes the gid mapper using the given \a tilesets.
            ##
            firstGid = 1
            tilesets = args[0]
            for tileset in tilesets:
                self.insert(firstGid, tileset)
                firstGid += tileset.tileCount()

    ##
    # Insert the given \a tileset with \a firstGid as its first global ID.
    ##
    def insert(self, firstGid, tileset):
        self.mFirstGidToTileset.insert(firstGid, tileset)

    ##
    # Clears the gid mapper, so that it can be reused.
    ##
    def clear(self):
        self.mFirstGidToTileset.clear()

    ##
    # Returns True when no tilesets are known to this gid mapper.
    ##
    def isEmpty(self):
        return self.mFirstGidToTileset.isEmpty()

    ##
    # Returns the GID of the invalid tile in case decodeLayerData() returns
    # the InvalidTile error.
    ##
    def invalidTile(self):
        return self.mInvalidTile

    ##
    # Returns the cell data matched by the given \a gid. The \a ok parameter
    # indicates whether an error occurred.
    ##
    def gidToCell(self, gid):
        result = Cell()
        # Read out the flags
        result.flippedHorizontally = (gid & FlippedHorizontallyFlag)
        result.flippedVertically = (gid & FlippedVerticallyFlag)
        result.flippedAntiDiagonally = (gid & FlippedAntiDiagonallyFlag)
        # Clear the flags
        gid &= ~(FlippedHorizontallyFlag |
                 FlippedVerticallyFlag |
                 FlippedAntiDiagonallyFlag)
        if (gid == 0):
            ok = True
        elif (self.isEmpty()):
            ok = False
        else:
            # Find the tileset containing this tile
            index = self.mFirstGidToTileset.upperBound(gid)
            if index==0:
                ok = False
            else:
                item = self.mFirstGidToTileset.itemByIndex(index-1)
                # Navigate one tileset back since upper bound finds the next
                tileId = gid - item[0]
                tileset = item[1]

                columnCount = self.mTilesetColumnCounts.value(tileset, 0)
                if (columnCount > 0 and columnCount != tileset.columnCount()):
                    # Correct tile index for changes in image width
                    row = int(tileId / columnCount)
                    column = int(tileId % columnCount)
                    tileId = row * tileset.columnCount() + column
                result.tile = tileset.tileAt(tileId)
                ok = True

        return result, ok

    ##
    # Returns the global tile ID for the given \a cell. Returns 0 when the
    # cell is empty or when its tileset isn't known.
    ##
    def cellToGid(self, cell):
        if (cell.isEmpty()):
            return 0
        tileset = cell.tile.tileset()
        # Find the first GID for the tileset
        for item in self.mFirstGidToTileset:
            if item[1] == tileset:
                gid = item[0] + cell.tile.id()
                if (cell.flippedHorizontally):
                    gid |= FlippedHorizontallyFlag
                if (cell.flippedVertically):
                    gid |= FlippedVerticallyFlag
#.........這裏部分代碼省略.........
開發者ID:theall,項目名稱:Python-Tiled,代碼行數:103,代碼來源:gidmapper.py


注:本文中的pyqtcore.QMap.upperBound方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。