summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/editorui.py133
-rw-r--r--src/mapdata.py6
2 files changed, 34 insertions, 105 deletions
diff --git a/src/editorui.py b/src/editorui.py
index 505af08..58b0456 100644
--- a/src/editorui.py
+++ b/src/editorui.py
@@ -50,15 +50,6 @@ class KPEditorItem(QtGui.QGraphicsItem):
return self._boundingRect
- RESIZER_TOP_LEFT = 1
- RESIZER_TOP_RIGHT = 2
- RESIZER_BOTTOM_LEFT = 3
- RESIZER_BOTTOM_RIGHT = 4
- RESIZER_TOP = 5
- RESIZER_BOTTOM = 6
- RESIZER_LEFT = 7
- RESIZER_RIGHT = 8
-
def resizerPortionAt(self, x, y, originX=0, originY=0):
try:
leftBound, topBound = originX+5, originY+5
@@ -68,7 +59,6 @@ class KPEditorItem(QtGui.QGraphicsItem):
leftBound, topBound = rect.x() + 5, rect.y() + 5
rightBound, bottomBound = rect.right() - 5, rect.bottom() - 5
- print "Testing %f,%f against (%f,%f) - (%f,%f)" % (x, y, leftBound, topBound, rightBound, bottomBound)
if y < topBound:
if x < leftBound: return 1 # TOP_LEFT
elif x >= rightBound: return 2 # TOP_RIGHT
@@ -289,10 +279,6 @@ class KPEditorDoodad(KPEditorItem):
self._updatePixmap()
self._updatePosition()
self._updateSize()
- self._updateTransform()
-
- global BULLSHIT
- BULLSHIT = self.bullshit
self.setAcceptHoverEvents(True)
@@ -306,61 +292,45 @@ class KPEditorDoodad(KPEditorItem):
self.pixmap = pixmap
+
def _updatePosition(self):
# NOTE: EditorDoodads originate at the centre, not the top left like the others
- self.ignoreMovement = True
doodad = self._doodadRef()
x,y = doodad.position
w,h = doodad.size
self.setPos(x+floor(w/2.0), y+floor(h/2.0))
- self.ignoreMovement = False
+
def _updateSize(self):
self.prepareGeometryChange()
w,h = self._doodadRef().size
- #self.setTransformOriginPoint(w/2, h/2)
self._boundingRect = QtCore.QRectF(-w/2, -h/2, w, h)
self._selectionRect = self._boundingRect.adjusted(0, 0, -1, -1)
+
def _updateTransform(self):
doodad = self._doodadRef()
- transform = QtGui.QTransform()
- transform.rotate(doodad.angle)
- self.setTransform(transform)
+ self.setRotation(doodad.angle)
- itransform = QtGui.QTransform()
- itransform.rotate(-doodad.angle)
- self.invertedTransform = itransform
-
- print "----"
- self._pt(transform)
- print "~~"
- self._pt(itransform)
- #self.invertedTransform, invertible = transform.inverted()
- #self.setRotation(doodad.angle)
- #self.invertedTransform, invertible = self.transform().inverted()
- def _pt(self, t):
- print t.m11(), t.m12(), t.m13()
- print t.m21(), t.m22(), t.m23()
- print t.m31(), t.m32(), t.m33()
+ def itemChange(self, change, value):
+ return QtGui.QGraphicsItem.itemChange(self, change, value)
def paint(self, painter, option, widget):
if self.isSelected():
- painter.setPen(QtGui.QPen(Qt.white, 1, Qt.DotLine))
+ painter.setPen(QtGui.QPen(Qt.red, 1, Qt.DotLine))
painter.drawRect(self._selectionRect)
def _itemMoved(self, oldX, oldY, newX, newY):
doodad = self._doodadRef()
w,h = doodad.size
- print "Moved to", newX, newY, "size", w, h
- doodad.position = (newX-floor(w/2.0), newY-floor(h/2.0))
+ doodad.position = [newX-floor(w/2.0), newY-floor(h/2.0)]
def hoverMoveEvent(self, event):
@@ -408,19 +378,21 @@ class KPEditorDoodad(KPEditorItem):
else:
x, xSide, y, ySide = False, None, False, None
-
- if bit == 1 or bit == 7 or bit == 3:
+
+ if bit == 1 or bit == 7 or bit == 3: # left
x, xSide = True, 1
- elif bit == 2 or bit == 4 or bit == 8:
+
+ elif bit == 2 or bit == 4 or bit == 8: # right
x, xSide = True, 0
- if bit == 1 or bit == 2 or bit == 5:
+ if bit == 1 or bit == 2 or bit == 5: # top
y, ySide = True, 1
- elif bit == 3 or bit == 4 or bit == 6:
+
+ elif bit == 3 or bit == 4 or bit == 6: # bottom
y, ySide = True, 0
+ self._updateSize()
self.resizing = (x, xSide, y, ySide)
- print self.resizing
return
@@ -428,35 +400,15 @@ class KPEditorDoodad(KPEditorItem):
def _tryAndResize(self, obj, axisIndex, mousePosition, stationarySide):
- objPosition = obj.position[axisIndex]
- objSize = obj.size[axisIndex]
-
- currentCentre = objPosition + (objSize / 2)
-
- lowerSide = objPosition
- upperSide = lowerSide + objSize
- if stationarySide == 0:
- upperSide = mousePosition
- else:
- lowerSide = mousePosition
-
- newSize = upperSide - lowerSide
- newPosition = lowerSide
- #newPosition = currentCentre - (newSize / 2)
+ newSize = abs(mousePosition) * 2
- if newPosition == objPosition and newSize == objSize:
+ if newSize < 10:
return False
- elif newSize < 1:
- return False
-
- if axisIndex == 1:
- obj.position = (obj.position[0], newPosition)
- obj.size = (obj.size[0], newSize)
- else:
- obj.position = (newPosition, obj.position[1])
- obj.size = (newSize, obj.size[1])
-
+
+ obj.size[axisIndex] = newSize
+
+ print obj.position
return True
@@ -495,41 +447,24 @@ class KPEditorDoodad(KPEditorItem):
def mouseMoveEvent(self, event):
if self.resizing:
obj = self._doodadRef()
- scenePos = event.scenePos()
- #mappedPos = self.transform().map(scenePos)
- #mappedPos = self.invertedTransform.map(scenePos)
-
- x = event.pos().x() + self.x()
- y = event.pos().y() + self.y()
- mappedPos = QtCore.QPointF(x, y)
hasChanged = False
resizeX, xSide, resizeY, ySide = self.resizing
- print "Scene Position: %f,%f" % (scenePos.x(), scenePos.y())
- print "Mapped Position: %f,%f" % (mappedPos.x(), mappedPos.y())
- print "Current X/Y: %r; Size: %r" % (obj.position, obj.size)
-
if resizeX:
- hasChanged |= self._tryAndResize(obj, 0, mappedPos.x(), xSide)
+ hasChanged |= self._tryAndResize(obj, 0, event.pos().x(), xSide)
if resizeY:
- hasChanged |= self._tryAndResize(obj, 1, mappedPos.y(), ySide)
+ hasChanged |= self._tryAndResize(obj, 1, event.pos().y(), ySide)
- print "New X/Y: %r; Size: %r" % (obj.position, obj.size)
if hasChanged:
- # TODO: move overrides into updatePosition?
- # TODO: snapping for resizing
- self.overrideSnap = True
- self._updatePosition()
+ # Doodads aren't supposed to snap, they're all free flowing like the wind.
self._updateSize()
- self._updateTransform()
- self.overrideSnap = False
- print "New Rect: (%f,%f) %f x %f" % (self._boundingRect.x(), self._boundingRect.y(), self._boundingRect.width(), self._boundingRect.height())
elif self.rotating:
obj = self._doodadRef()
scenePos = event.scenePos()
+ self.setTransformOriginPoint(self.boundingRect().center())
hasChanged = False
@@ -544,14 +479,11 @@ class KPEditorDoodad(KPEditorItem):
KPEditorItem.mouseMoveEvent(self, event)
- def bullshit(self):
- obj = self._doodadRef()
- print "Current X/Y: %r; Size: %r" % (obj.position, obj.size)
-
-
def mouseReleaseEvent(self, event):
if self.resizing and event.button() == Qt.LeftButton:
self.resizing = None
+ # self._doodadRef().position = [self.x(), self.y()]
+
elif self.rotating and event.button() == Qt.LeftButton:
self.rotating = None
@@ -704,16 +636,13 @@ class KPMapScene(QtGui.QGraphicsScene):
except KeyError:
continue
- painter.setPen(Qt.red)
for item in reversed(toDraw):
painter.save()
painter.setWorldTransform(item.sceneTransform(), True)
w, h = item._doodadRef().size
- painter.drawPixmap(-w/2, -h/2, w, h, item.pixmap)
+ p = item._boundingRect
+ painter.drawPixmap(p.x(), p.y(), p.width(), p.height(), item.pixmap)
painter.restore()
- x, y = item._doodadRef().position
- #painter.drawPoint(x, y)
- painter.drawRect(x, y, w, h)
elif isinstance(layer, KPTileLayer):
left, top = layer.cacheBasePos
@@ -850,7 +779,7 @@ class KPEditorWidget(QtGui.QGraphicsView):
if not isinstance(layer, KPDoodadLayer): return
obj = KPDoodad()
- obj.position = (x,y)
+ obj.position = [x,y]
obj.index = self.paintNextID
obj.setDefaultSize()
layer.objects.append(obj)
diff --git a/src/mapdata.py b/src/mapdata.py
index 8671430..85549e2 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -113,15 +113,15 @@ class KPTileLayer(KPLayer):
class KPDoodad(object):
def __init__(self):
- self.position = (0,0)
- self.size = (0,0)
+ self.position = [0,0]
+ self.size = [0,0]
self.angle = 0
self.index = 0
def setDefaultSize(self):
source = KP.mainWindow.doodadSelector.getDoodad(self.index)
pixmap = source.icon().pixmap(source.icon().availableSizes()[0])
- self.size = pixmap.width(), pixmap.height()
+ self.size = [pixmap.width(), pixmap.height()]