From 39d905c4684b474e13ab3298fca08453f4c14834 Mon Sep 17 00:00:00 2001 From: Treeki Date: Wed, 9 Nov 2011 02:23:21 +0100 Subject: starting work on tile drawing --- src/editorui.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/editorui.py') diff --git a/src/editorui.py b/src/editorui.py index 5055f69..7f2a7f7 100644 --- a/src/editorui.py +++ b/src/editorui.py @@ -1,5 +1,63 @@ from common import * +class KPMapScene(QtGui.QGraphicsScene): + def drawBackground(self, painter, rect): + painter.fillRect(rect, Qt.white) + + areaLeft, areaTop = rect.x(), rect.y() + areaWidth, areaHeight = rect.width(), rect.height() + areaRight, areaBottom = areaLeft+areaWidth, areaTop+areaHeight + + areaLeftT = areaLeft / 24 + areaTopT = areaTop / 24 + areaRightT = areaRight / 24 + areaBottomT = areaBottom / 24 + + for layer in KP.map.layers: + left, top = layer.cacheBasePos + width, height = layer.cacheSize + right, bottom = left+width, top+height + + if width == 0 and height == 0: continue + + if right < areaLeftT: continue + if left > areaRightT: continue + + if bottom < areaTopT: continue + if top > areaBottomT: continue + + # decide how much of the layer we'll actually draw + drawLeft = max(areaLeftT, left) + drawRight = min(areaRightT, right) + + drawTop = max(areaTopT, top) + drawBottom = max(areaBottomT, bottom) + + srcY = drawTop - top + destY = drawTop * 24 + + baseSrcX = drawLeft - left + baseDestX = drawLeft * 24 + + rows = layer.cache + tileset = KP.map.tilesets[layer.tileset] + tileList = tileset.tiles + + 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 + + srcY += 1 + destY += 24 class KPEditorWidget(QtGui.QGraphicsView): pass -- cgit v1.2.3