X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..9df06f5b696cde13b1220ae6ec60dc6f32d2ab6f:/wxPython/demo/wxDragImage.py?ds=sidebyside diff --git a/wxPython/demo/wxDragImage.py b/wxPython/demo/wxDragImage.py index 19985b7dd3..d53fb4c67b 100644 --- a/wxPython/demo/wxDragImage.py +++ b/wxPython/demo/wxDragImage.py @@ -1,6 +1,8 @@ from wxPython.wx import * +import images + #---------------------------------------------------------------------- class DragShape: @@ -45,16 +47,15 @@ class DragCanvas(wxScrolledWindow): self.shapes = [] self.dragImage = None self.dragShape = None + self.hiliteShape = None self.SetCursor(wxStockCursor(wxCURSOR_ARROW)) - self.bg_bmp = wxBitmap('bitmaps/backgrnd.png', wxBITMAP_TYPE_PNG) + self.bg_bmp = images.getBackgroundBitmap() # Make a shape from an image and mask. This one will demo # dragging outside the window - bmp = wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG) - mask = wxMaskColour(bmp, wxWHITE) - bmp.SetMask(mask) + bmp = images.getTestStarBitmap() shape = DragShape(bmp) shape.pos = wxPoint(5, 5) shape.fullscreen = true @@ -84,8 +85,9 @@ class DragCanvas(wxScrolledWindow): # Make some shapes from some playing card images. x = 200 - for card in ['01c.gif', '10s.gif', '12h.gif', '13d.gif']: - bmp = wxBitmap('bitmaps/'+card, wxBITMAP_TYPE_GIF) + for card in ['_01c_', '_12h_', '_13d_', '_10s_']: + bmpFunc = getattr(images, "get%sBitmap" % card) + bmp = bmpFunc() shape = DragShape(bmp) shape.pos = wxPoint(x, 5) self.shapes.append(shape) @@ -136,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) @@ -171,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 @@ -191,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)) @@ -205,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) - - - # erase the shape since it will be drawn independently now - dc = wxClientDC(self) - self.dragShape.shown = false - self.EraseShape(self.dragShape, dc) + hotspot = self.dragStartPos - self.dragShape.pos + self.dragImage.BeginDrag(hotspot, self, self.dragShape.fullscreen) - 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() #----------------------------------------------------------------------