1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
from common import *
class KPMapScene(QtGui.QGraphicsScene):
def __init__(self):
QtGui.QGraphicsScene.__init__(self)
self.currentLayer = None
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 = min(areaBottomT, bottom)
srcY = drawTop - top
destY = drawTop * 24
baseSrcX = drawLeft - left
baseDestX = drawLeft * 24
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 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
def setCurrentLayer(self, layer):
if self.currentLayer is not None:
self.setLayerObjectsFlag(self.currentLayer, QtGui.QGraphicsItem.ItemIsSelectable, False)
self.currentLayer = layer
self.setLayerObjectsFlag(layer, QtGui.QGraphicsItem.ItemIsSelectable, True)
def setLayerObjectsFlag(self, layer, flag, value):
for obj in layer.objects:
item = obj.qtItem
if item:
item.setFlag(flag, value)
class KPEditorWidget(QtGui.QGraphicsView):
pass
|