summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-11-09 02:23:21 +0100
committerTreeki <treeki@gmail.com>2011-11-09 02:23:21 +0100
commit39d905c4684b474e13ab3298fca08453f4c14834 (patch)
treee8740e8637c5c0187322f8b895689234682c265f
parent258ea63e0629df5a398fe540059c4d1f6105bf08 (diff)
downloadkoopatlas-39d905c4684b474e13ab3298fca08453f4c14834.tar.gz
koopatlas-39d905c4684b474e13ab3298fca08453f4c14834.zip
starting work on tile drawing
-rw-r--r--src/editorui.py58
-rw-r--r--src/mapdata.py10
-rw-r--r--src/ui.py3
3 files changed, 70 insertions, 1 deletions
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
diff --git a/src/mapdata.py b/src/mapdata.py
index ad0bef2..550d710 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -25,9 +25,17 @@ class KPLayer(object):
self.tileset = ''
self.objects = []
self.visible = True
- self.cache = []
+ self.cache = ['DUMMY_FLAG']
+ self.updateCache()
def updateCache(self):
+ if len(self.objects) == 0:
+ if len(self.cache) != 0:
+ self.cache = []
+ self.cacheBasePos = (0,0)
+ self.cacheSize = (0,0)
+ return
+
x1, x2 = MAP_SIZE_IN_TILES[0] - 1, 0
y1, y2 = MAP_SIZE_IN_TILES[1] - 1, 0
diff --git a/src/ui.py b/src/ui.py
index 9536206..cc3d4be 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -141,6 +141,9 @@ class KPMainWindow(QtGui.QMainWindow):
self.editor = KPEditorWidget()
self.setCentralWidget(self.editor)
+ self.scene = KPMapScene()
+ self.editor.setScene(self.scene)
+
self.setupMenuBar()
self.setupDocks()