X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/96bfd05319f9e393843e84ca5274d85ff248bad4..4e1c35f810f574af79e649fa37171dfa7fc775ee:/wxPython/demo/wxDragImage.py?ds=sidebyside diff --git a/wxPython/demo/wxDragImage.py b/wxPython/demo/wxDragImage.py index a74a072699..8814df9c04 100644 --- a/wxPython/demo/wxDragImage.py +++ b/wxPython/demo/wxDragImage.py @@ -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 @@ -65,18 +64,19 @@ class DragCanvas(wxScrolledWindow): # Make a shape from some text text = "Some Text" + bg_colour = wxColour(57, 115, 57) # matches the bg image font = wxFont(15, wxROMAN, wxNORMAL, wxBOLD) textExtent = self.GetFullTextExtent(text, font) bmp = wxEmptyBitmap(textExtent[0], textExtent[1]) dc = wxMemoryDC() dc.SelectObject(bmp) + dc.SetBackground(wxBrush(bg_colour, wxSOLID)) dc.Clear() dc.SetTextForeground(wxRED) dc.SetFont(font) dc.DrawText(text, 0, 0) dc.SelectObject(wxNullBitmap) - del dc - mask = wxMaskColour(bmp, wxWHITE) + mask = wxMaskColour(bmp, bg_colour) bmp.SetMask(mask) shape = DragShape(bmp) shape.pos = wxPoint(5, 100) @@ -139,12 +139,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 +174,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 +194,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 +214,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() #----------------------------------------------------------------------