]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/wxDragImage.py
Fixed compilation error
[wxWidgets.git] / wxPython / demo / wxDragImage.py
index a74a072699f6e61277abd500eef3ca577ff440a4..d53fb4c67bc7c451c80dadfbc388cf748d9dd0e3 100644 (file)
@@ -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
@@ -139,12 +138,12 @@ class DragCanvas(wxScrolledWindow):
         dc.DestroyClippingRegion()
 
 
-
-
     def OnEraseBackground(self, evt):
         dc = evt.GetDC()
         if not dc:
             dc = wxClientDC(self)
+            rect = self.GetUpdateRegion().GetBox()
+            dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height)
         self.TileBackground(dc)
 
 
@@ -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))
-
-            if self.dragShape.fullscreen:
-                newPos = self.ClientToScreen(newPos)
-                self.dragImage.BeginDrag((0,0), self, true)
-            else:
-                self.dragImage.BeginDrag((0,0), self)
-
+            hotspot = self.dragStartPos - self.dragShape.pos
+            self.dragImage.BeginDrag(hotspot, self, self.dragShape.fullscreen)
 
-            # 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)
-
-            self.dragImage.Move(newPos)
+            onShape = self.FindShape(evt.GetPosition())
+            unhiliteOld = false
+            hiliteNew = false
+
+            # 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()
 
 
 #----------------------------------------------------------------------