From: Thomas H. <tho...@io...> - 2002-08-29 13:12:17
|
While steal^H^H^H^H^Hreusing code from resourceEditor, I refactored the resizing handle code. Here is the patch against the current CVS version. Thomas ----- Index: resourceEditor.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCardPrototype/tools/resourceEditor/resourceEditor.py,v retrieving revision 1.132 diff -c -r1.132 resourceEditor.py *** resourceEditor.py 16 Aug 2002 00:26:30 -0000 1.132 --- resourceEditor.py 29 Aug 2002 13:08:26 -0000 *************** *** 371,504 **** # I need to refactor the common elements of the resizing handle code # I also want to add a Component info window to show the component # name, position, size as the component is moved and resized ! def doTopLeftResize(self, event): xOffset = event.x - self.offset[0] yOffset = event.y - self.offset[1] ! xStartOffset = self.startPosition[0] + event.x - self.offset[0] ! yStartOffset = self.startPosition[1] + event.y - self.offset[1] if self.alignToGrid: xOffset = xOffset / self.xGridSize * self.xGridSize yOffset = yOffset / self.yGridSize * self.yGridSize xStartOffset = xStartOffset / self.xGridSize * self.xGridSize yStartOffset = yStartOffset / self.yGridSize * self.yGridSize ! width = self.startSize[0] - xOffset ! height = self.startSize[1] - yOffset self.components[self.startName].position = (xStartOffset, yStartOffset) self.components[self.startName].size = (width, height) self.setToolTip(self.components[self.startName]) def on_topLeft_mouseDrag(self, event): ! self.doTopLeftResize(event) - - def doTopMiddleResize(self, event): - yOffset = event.y - self.offset[1] - yStartOffset = self.startPosition[1] + event.y - self.offset[1] - if self.alignToGrid: - yOffset = yOffset / self.yGridSize * self.yGridSize - yStartOffset = yStartOffset / self.yGridSize * self.yGridSize - width = self.startSize[0] - height = self.startSize[1] - yOffset - self.components[self.startName].position = (self.startPosition[0], yStartOffset) - self.components[self.startName].size = (width, height) - self.setToolTip(self.components[self.startName]) - def on_topMiddle_mouseDrag(self, event): ! self.doTopMiddleResize(event) ! ! ! def doTopRightResize(self, event): ! xOffset = event.x - self.offset[0] ! yOffset = event.y - self.offset[1] ! yStartOffset = self.startPosition[1] + event.y - self.offset[1] ! if self.alignToGrid: ! xOffset = xOffset / self.xGridSize * self.xGridSize ! yOffset = yOffset / self.yGridSize * self.yGridSize ! yStartOffset = yStartOffset / self.yGridSize * self.yGridSize ! width = self.startSize[0] + xOffset ! height = self.startSize[1] - yOffset ! self.components[self.startName].position = (self.startPosition[0], yStartOffset) ! self.components[self.startName].size = (width, height) ! self.setToolTip(self.components[self.startName]) def on_topRight_mouseDrag(self, event): ! self.doTopRightResize(event) ! ! ! def doMiddleLeftResize(self, event): ! xOffset = event.x - self.offset[0] ! xStartOffset = self.startPosition[0] + event.x - self.offset[0] ! if self.alignToGrid: ! xOffset = xOffset / self.xGridSize * self.xGridSize ! xStartOffset = xStartOffset / self.xGridSize * self.xGridSize ! width = self.startSize[0] - xOffset ! height = self.startSize[1] ! self.components[self.startName].position = (xStartOffset, self.startPosition[1]) ! self.components[self.startName].size = (width, height) ! self.setToolTip(self.components[self.startName]) def on_middleLeft_mouseDrag(self, event): ! self.doMiddleLeftResize(event) ! ! def doMiddleRightResize(self, event): ! xOffset = event.x - self.offset[0] ! if self.alignToGrid: ! xOffset = xOffset / self.xGridSize * self.xGridSize ! width = self.startSize[0] + xOffset ! height = self.startSize[1] ! self.components[self.startName].size = (width, height) ! self.setToolTip(self.components[self.startName]) def on_middleRight_mouseDrag(self, event): ! self.doMiddleRightResize(event) - - def doBottomLeftResize(self, event): - xOffset = event.x - self.offset[0] - yOffset = event.y - self.offset[1] - xStartOffset = self.startPosition[0] + event.x - self.offset[0] - if self.alignToGrid: - xOffset = xOffset / self.xGridSize * self.xGridSize - yOffset = yOffset / self.yGridSize * self.yGridSize - xStartOffset = xStartOffset / self.xGridSize * self.xGridSize - width = self.startSize[0] - xOffset - height = self.startSize[1] + yOffset - self.components[self.startName].position = (xStartOffset, self.startPosition[1]) - self.components[self.startName].size = (width, height) - self.setToolTip(self.components[self.startName]) - def on_bottomLeft_mouseDrag(self, event): ! self.doBottomLeftResize(event) ! ! ! def doBottomMiddleResize(self, event): ! yOffset = event.y - self.offset[1] ! if self.alignToGrid: ! yOffset = yOffset / self.yGridSize * self.yGridSize ! width = self.startSize[0] ! height = self.startSize[1] + yOffset ! self.components[self.startName].position = (self.startPosition[0], self.startPosition[1]) ! self.components[self.startName].size = (width, height) ! self.setToolTip(self.components[self.startName]) def on_bottomMiddle_mouseDrag(self, event): ! self.doBottomMiddleResize(event) - - def doBottomRightResize(self, event): - xOffset = event.x - self.offset[0] - yOffset = event.y - self.offset[1] - if self.alignToGrid: - xOffset = xOffset / self.xGridSize * self.xGridSize - yOffset = yOffset / self.yGridSize * self.yGridSize - width = self.startSize[0] + xOffset - height = self.startSize[1] + yOffset - self.components[self.startName].size = (width, height) - self.setToolTip(self.components[self.startName]) - def on_bottomRight_mouseDrag(self, event): ! self.doBottomRightResize(event) def saveChanges(self): if self.filename == None: --- 371,419 ---- # I need to refactor the common elements of the resizing handle code # I also want to add a Component info window to show the component # name, position, size as the component is moved and resized + # THe 2002-08-29 + # Refactored the common elements of resizing handle code. ! def doResize(self, event, (n, w, s, e)): xOffset = event.x - self.offset[0] yOffset = event.y - self.offset[1] ! xStartOffset = self.startPosition[0] + e * xOffset ! yStartOffset = self.startPosition[1] + n * yOffset if self.alignToGrid: xOffset = xOffset / self.xGridSize * self.xGridSize yOffset = yOffset / self.yGridSize * self.yGridSize xStartOffset = xStartOffset / self.xGridSize * self.xGridSize yStartOffset = yStartOffset / self.yGridSize * self.yGridSize ! ! width = self.startSize[0] + (w - e) * xOffset ! height = self.startSize[1] + (s - n) * yOffset self.components[self.startName].position = (xStartOffset, yStartOffset) self.components[self.startName].size = (width, height) self.setToolTip(self.components[self.startName]) def on_topLeft_mouseDrag(self, event): ! self.doResize(event, (1, 0, 0, 1)) def on_topMiddle_mouseDrag(self, event): ! self.doResize(event, (1, 0, 0, 0)) def on_topRight_mouseDrag(self, event): ! self.doResize(event, (1, 1, 0, 0)) def on_middleLeft_mouseDrag(self, event): ! self.doResize(event, (0, 0, 0, 1)) def on_middleRight_mouseDrag(self, event): ! self.doResize(event, (0, 1, 0, 0)) def on_bottomLeft_mouseDrag(self, event): ! self.doResize(event, (0, 0, 1, 1)) def on_bottomMiddle_mouseDrag(self, event): ! self.doResize(event, (0, 0, 1, 0)) def on_bottomRight_mouseDrag(self, event): ! self.doResize(event, (0, 1, 1, 0)) def saveChanges(self): if self.filename == None: |