--- a/graphics/GraphicCommons.py Fri Jul 27 10:03:24 2007 +0200
+++ b/graphics/GraphicCommons.py Thu Aug 02 16:51:58 2007 +0200
@@ -4,7 +4,7 @@
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
#based on the plcopen standard.
#
-#Copyright (C): Edouard TISSERANT and Laurent BESSARD
+#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
#
#See COPYING file for copyrights details.
#
@@ -16,7 +16,7 @@
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-#Lesser General Public License for more details.
+#General Public License for more details.
#
#You should have received a copy of the GNU General Public
#License along with this library; if not, write to the Free Software
@@ -86,6 +86,28 @@
# Contants for defining which drawing mode is selected for app
[FREEDRAWING_MODE, DRIVENDRAWING_MODE] = [1, 2]
+CURSORS = None
+
+def ResetCursors():
+ global CURSORS
+ if CURSORS == None:
+ CURSORS = [wxNullCursor,
+ wxStockCursor(wxCURSOR_HAND),
+ wxStockCursor(wxCURSOR_SIZENWSE),
+ wxStockCursor(wxCURSOR_SIZENESW),
+ wxStockCursor(wxCURSOR_SIZEWE),
+ wxStockCursor(wxCURSOR_SIZENS)]
+
+HANDLE_CURSORS = {
+ (1, 1) : 2,
+ (3, 3) : 2,
+ (1, 3) : 3,
+ (3, 1) : 3,
+ (1, 2) : 4,
+ (3, 2) : 4,
+ (2, 1) : 5,
+ (2, 3) : 5
+}
"""
Basic vector operations for calculate wire points
@@ -265,6 +287,8 @@
self.Pos = wxPoint(0, 0)
self.Size = wxSize(0, 0)
self.BoundingBox = wxRect(0, 0, 0, 0)
+ self.CurrentCursor = 0
+ ResetCursors()
# Make a clone of this element
def Clone(self):
@@ -339,8 +363,12 @@
# Test if the point is on a handle of this element
def TestHandle(self, pt):
+ extern_rect = wxRect(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2,
+ self.BoundingBox.width + 2 * HANDLE_SIZE + 4, self.BoundingBox.height + 2 * HANDLE_SIZE + 4)
+ intern_rect = wxRect(self.BoundingBox.x - 2, self.BoundingBox.y - 2,
+ self.BoundingBox.width + 4, self.BoundingBox.height + 4)
# Verify that this element is selected
- if self.Selected:
+ if self.Selected and extern_rect.InsideXY(pt.x, pt.y) and not intern_rect.InsideXY(pt.x, pt.y):
# Find if point is on a handle horizontally
if self.BoundingBox.x - HANDLE_SIZE - 2 <= pt.x < self.BoundingBox.x - 2:
handle_x = 1
@@ -368,25 +396,17 @@
def OnLeftDown(self, event, dc, scaling):
pos = event.GetLogicalPosition(dc)
# Test if an handle have been clicked
- result = self.TestHandle(pos)
+ handle = self.TestHandle(pos)
# Find which type of handle have been clicked,
# Save a resize event and change the cursor
- if result == (1, 1) or result == (3, 3):
- self.Handle = (HANDLE_RESIZE, result)
- self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZENWSE))
- elif result == (1, 3) or result == (3, 1):
- self.Handle = (HANDLE_RESIZE, result)
- self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZENESW))
- elif result == (1, 2) or result == (3, 2):
- self.Handle = (HANDLE_RESIZE, result)
- self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZEWE))
- elif result == (2, 1) or result == (2, 3):
- self.Handle = (HANDLE_RESIZE, result)
- self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZENS))
- # If no handle have been clicked, save a move event, and change the cursor
+ cursor = HANDLE_CURSORS.get(handle, 1)
+ if cursor != self.CurrentCursor:
+ self.Parent.SetCursor(CURSORS[cursor])
+ self.CurrentCursor = cursor
+ if cursor > 1:
+ self.Handle = (HANDLE_RESIZE, handle)
else:
self.Handle = (HANDLE_MOVE, None)
- self.Parent.SetCursor(wxStockCursor(wxCURSOR_HAND))
self.SetSelected(False)
# Initializes the last position
self.oldPos = GetScaledEventPosition(event, dc, scaling)
@@ -402,6 +422,9 @@
self.ProcessDragging(movex, movey)
self.RefreshModel()
self.Parent.RefreshBuffer()
+ if self.CurrentCursor != 0:
+ self.Parent.SetCursor(CURSORS[0])
+ self.CurrentCursor = 0
self.SetSelected(True)
self.oldPos = None
@@ -433,17 +456,13 @@
else:
pos = event.GetLogicalPosition(dc)
handle = self.TestHandle(pos)
- if handle == (1, 1) or handle == (3, 3):
- wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZENWSE))
- elif handle == (1, 3) or handle == (3, 1):
- wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZENESW))
- elif handle == (1, 2) or handle == (3, 2):
- wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZEWE))
- elif handle == (2, 1) or handle == (2, 3):
- wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZENS))
- else:
- wxCallAfter(self.Parent.SetCursor, wxNullCursor)
-
+ # Find which type of handle have been clicked,
+ # Save a resize event and change the cursor
+ cursor = HANDLE_CURSORS.get(handle, 0)
+ if cursor != self.CurrentCursor:
+ self.Parent.SetCursor(CURSORS[cursor])
+ self.CurrentCursor = cursor
+
# Moves the element
def Move(self, dx, dy, exclude = []):
self.Pos.x += dx