From ffc9daf57c6a3ad8377c82d811cb3bcad2421bea Mon Sep 17 00:00:00 2001 From: Treeki Date: Mon, 14 Nov 2011 22:32:47 +0100 Subject: created a generic KPLayer class --- src/editorui.py | 67 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'src/editorui.py') diff --git a/src/editorui.py b/src/editorui.py index 05cb77f..7969100 100644 --- a/src/editorui.py +++ b/src/editorui.py @@ -262,50 +262,51 @@ class KPMapScene(QtGui.QGraphicsScene): for layer in reversed(KP.map.layers): if not layer.visible: continue - left, top = layer.cacheBasePos - width, height = layer.cacheSize - right, bottom = left+width, top+height + if isinstance(layer, KPTileLayer): + left, top = layer.cacheBasePos + width, height = layer.cacheSize + right, bottom = left+width, top+height - if width == 0 and height == 0: continue + if width == 0 and height == 0: continue - if right < areaLeftT: continue - if left > areaRightT: continue + if right < areaLeftT: continue + if left > areaRightT: continue - if bottom < areaTopT: continue - if top > areaBottomT: continue + if bottom < areaTopT: continue + if top > areaBottomT: continue - # decide how much of the layer we'll actually draw - drawLeft = int(max(areaLeftT, left)) - drawRight = int(min(areaRightT, right)) + # decide how much of the layer we'll actually draw + drawLeft = int(max(areaLeftT, left)) + drawRight = int(min(areaRightT, right)) - drawTop = int(max(areaTopT, top)) - drawBottom = int(min(areaBottomT, bottom)) + drawTop = int(max(areaTopT, top)) + drawBottom = int(min(areaBottomT, bottom)) - srcY = drawTop - top - destY = drawTop * 24 + srcY = drawTop - top + destY = drawTop * 24 - baseSrcX = drawLeft - left - baseDestX = drawLeft * 24 + baseSrcX = drawLeft - left + baseDestX = drawLeft * 24 - rows = layer.cache - tileset = KP.map.loadedTilesets[layer.tileset] - tileList = tileset.tiles + rows = layer.cache + tileset = KP.map.loadedTilesets[layer.tileset] + tileList = tileset.tiles - for y in xrange(drawTop, drawBottom): - srcX = baseSrcX - destX = baseDestX - row = rows[srcY] + for y in xrange(drawTop, drawBottom): + srcX = baseSrcX + destX = baseDestX + row = rows[srcY] - for x in xrange(drawLeft, drawRight): - tile = row[srcX] - if tile != -1: - painter.drawPixmap(destX, destY, tileList[tile]) - - srcX += 1 - destX += 24 + for x in xrange(drawLeft, drawRight): + tile = row[srcX] + if tile != -1: + painter.drawPixmap(destX, destY, tileList[tile]) + + srcX += 1 + destX += 24 - srcY += 1 - destY += 24 + srcY += 1 + destY += 24 def setCurrentLayer(self, layer): -- cgit v1.2.3