wxDragImage fixes and cleanup
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10224 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -47,6 +47,7 @@ class DragCanvas(wxScrolledWindow):
|
||||
self.shapes = []
|
||||
self.dragImage = None
|
||||
self.dragShape = None
|
||||
self.hiliteShape = None
|
||||
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
|
||||
self.bg_bmp = images.getBackgroundBitmap()
|
||||
@@ -55,8 +56,6 @@ class DragCanvas(wxScrolledWindow):
|
||||
# Make a shape from an image and mask. This one will demo
|
||||
# dragging outside the window
|
||||
bmp = images.getTestStarBitmap()
|
||||
#mask = wxMaskColour(bmp, wxWHITE)
|
||||
#bmp.SetMask(mask)
|
||||
shape = DragShape(bmp)
|
||||
shape.pos = wxPoint(5, 5)
|
||||
shape.fullscreen = true
|
||||
@@ -174,13 +173,13 @@ class DragCanvas(wxScrolledWindow):
|
||||
self.dragImage.EndDrag()
|
||||
self.dragImage = None
|
||||
|
||||
# reposition and draw the shape
|
||||
pt = evt.GetPosition()
|
||||
newPos = wxPoint(self.dragShape.pos.x + (pt.x - self.dragStartPos.x),
|
||||
self.dragShape.pos.y + (pt.y - self.dragStartPos.y))
|
||||
|
||||
dc = wxClientDC(self)
|
||||
self.dragShape.pos = newPos
|
||||
if self.hiliteShape:
|
||||
self.hiliteShape.Draw(dc)
|
||||
self.hiliteShape = None
|
||||
|
||||
# reposition and draw the shape
|
||||
self.dragShape.pos = self.dragShape.pos + evt.GetPosition() - self.dragStartPos
|
||||
self.dragShape.shown = true
|
||||
self.dragShape.Draw(dc)
|
||||
self.dragShape = None
|
||||
@@ -194,13 +193,19 @@ class DragCanvas(wxScrolledWindow):
|
||||
if self.dragShape and not self.dragImage:
|
||||
|
||||
# only start the drag after having moved a couple pixels
|
||||
tolerance = 4
|
||||
tolerance = 2
|
||||
pt = evt.GetPosition()
|
||||
dx = abs(pt.x - self.dragStartPos.x)
|
||||
dy = abs(pt.y - self.dragStartPos.y)
|
||||
if dx <= tolerance and dy <= tolerance:
|
||||
return
|
||||
|
||||
# erase the shape since it will be drawn independently now
|
||||
dc = wxClientDC(self)
|
||||
self.dragShape.shown = false
|
||||
self.EraseShape(self.dragShape, dc)
|
||||
|
||||
|
||||
if self.dragShape.text:
|
||||
self.dragImage = wxDragString(self.dragShape.text,
|
||||
wxStockCursor(wxCURSOR_HAND))
|
||||
@@ -208,34 +213,45 @@ class DragCanvas(wxScrolledWindow):
|
||||
self.dragImage = wxDragImage(self.dragShape.bmp,
|
||||
wxStockCursor(wxCURSOR_HAND))
|
||||
|
||||
newPos = wxPoint(self.dragShape.pos.x + (pt.x - self.dragStartPos.x),
|
||||
self.dragShape.pos.y + (pt.y - self.dragStartPos.y))
|
||||
hotspot = self.dragStartPos - self.dragShape.pos
|
||||
self.dragImage.BeginDrag(hotspot, self, self.dragShape.fullscreen)
|
||||
|
||||
if self.dragShape.fullscreen:
|
||||
newPos = self.ClientToScreen(newPos)
|
||||
self.dragImage.BeginDrag((0,0), self, true)
|
||||
else:
|
||||
self.dragImage.BeginDrag((0,0), self)
|
||||
|
||||
|
||||
# erase the shape since it will be drawn independently now
|
||||
dc = wxClientDC(self)
|
||||
self.dragShape.shown = false
|
||||
self.EraseShape(self.dragShape, dc)
|
||||
|
||||
self.dragImage.Move(newPos)
|
||||
self.dragImage.Move(pt)
|
||||
self.dragImage.Show()
|
||||
|
||||
|
||||
# if we have shape and image then move it.
|
||||
# if we have shape and image then move it, posibly highlighting another shape.
|
||||
elif self.dragShape and self.dragImage:
|
||||
pt = evt.GetPosition()
|
||||
newPos = wxPoint(self.dragShape.pos.x + (pt.x - self.dragStartPos.x),
|
||||
self.dragShape.pos.y + (pt.y - self.dragStartPos.y))
|
||||
if self.dragShape.fullscreen:
|
||||
newPos = self.ClientToScreen(newPos)
|
||||
onShape = self.FindShape(evt.GetPosition())
|
||||
unhiliteOld = false
|
||||
hiliteNew = false
|
||||
|
||||
self.dragImage.Move(newPos)
|
||||
# figure out what to hilite and what to unhilite
|
||||
if self.hiliteShape:
|
||||
if onShape is None or self.hiliteShape is not onShape:
|
||||
unhiliteOld = true
|
||||
|
||||
if onShape and onShape is not self.hiliteShape and onShape.shown:
|
||||
hiliteNew = TRUE
|
||||
|
||||
# if needed, hide the drag image so we can update the window
|
||||
if unhiliteOld or hiliteNew:
|
||||
self.dragImage.Hide()
|
||||
|
||||
if unhiliteOld:
|
||||
dc = wxClientDC(self)
|
||||
self.hiliteShape.Draw(dc)
|
||||
self.hiliteShape = None
|
||||
|
||||
if hiliteNew:
|
||||
dc = wxClientDC(self)
|
||||
self.hiliteShape = onShape
|
||||
self.hiliteShape.Draw(dc, wxINVERT)
|
||||
|
||||
# now move it and show it again if needed
|
||||
self.dragImage.Move(evt.GetPosition())
|
||||
if unhiliteOld or hiliteNew:
|
||||
self.dragImage.Show()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user