X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8eca4fef106b8327e2e55636de3f68a511a4c392..d38f70b2494626c4c04dbec17b48d1029b7bcd10:/wxPython/demo/DragImage.py diff --git a/wxPython/demo/DragImage.py b/wxPython/demo/DragImage.py index f686421b63..d0173caf03 100644 --- a/wxPython/demo/DragImage.py +++ b/wxPython/demo/DragImage.py @@ -25,9 +25,9 @@ class DragShape: memDC = wx.MemoryDC() memDC.SelectObject(self.bmp) - dc.Blit((self.pos[0], self.pos[1]), - (self.bmp.GetWidth(), self.bmp.GetHeight()), - memDC, (0, 0), op, True) + dc.Blit(self.pos[0], self.pos[1], + self.bmp.GetWidth(), self.bmp.GetHeight(), + memDC, 0, 0, op, True) return True else: @@ -47,15 +47,22 @@ class DragCanvas(wx.ScrolledWindow): self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) self.bg_bmp = images.getBackgroundBitmap() + self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) # Make a shape from an image and mask. This one will demo # dragging outside the window bmp = images.getTestStarBitmap() + #bmp = wx.Bitmap('bitmaps/toucan.png') shape = DragShape(bmp) shape.pos = (5, 5) shape.fullscreen = True self.shapes.append(shape) + bmp = images.getTheKidBitmap() + shape = DragShape(bmp) + shape.pos = (200, 5) + self.shapes.append(shape) + # Make a shape from some text text = "Some Text" bg_colour = wx.Colour(57, 115, 57) # matches the bg image @@ -72,9 +79,9 @@ class DragCanvas(wx.ScrolledWindow): dc.Clear() dc.SetTextForeground(wx.RED) dc.SetFont(font) - dc.DrawText(text, (0, 0)) + dc.DrawText(text, 0, 0) dc.SelectObject(wx.NullBitmap) - mask = wx.MaskColour(bmp, bg_colour) + mask = wx.Mask(bmp, bg_colour) bmp.SetMask(mask) shape = DragShape(bmp) shape.pos = (5, 100) @@ -82,18 +89,6 @@ class DragCanvas(wx.ScrolledWindow): self.shapes.append(shape) - # Make some shapes from some playing card images. - x = 200 - - for card in ['_01c_', '_12h_', '_13d_', '_10s_']: - bmpFunc = getattr(images, "get%sBitmap" % card) - bmp = bmpFunc() - shape = DragShape(bmp) - shape.pos = (x, 5) - self.shapes.append(shape) - x = x + 80 - - self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) @@ -121,7 +116,7 @@ class DragCanvas(wx.ScrolledWindow): y = 0 while y < sz.height: - dc.DrawBitmap(self.bg_bmp, (x, y)) + dc.DrawBitmap(self.bg_bmp, x, y) y = y + h x = x + w @@ -141,21 +136,13 @@ class DragCanvas(wx.ScrolledWindow): return shape return None - # Remove a shape from the display - def EraseShape(self, shape, dc): - r = shape.GetRect() - dc.SetClippingRect(r) - self.TileBackground(dc) - self.DrawShapes(dc) - dc.DestroyClippingRegion() # Clears the background, then redraws it. If the DC is passed, then # we only do so in the area so designated. Otherwise, it's the whole thing. def OnEraseBackground(self, evt): dc = evt.GetDC() - if not dc: - dc = wxClientDC(self) + dc = wx.ClientDC(self) rect = self.GetUpdateRegion().GetBox() dc.SetClippingRect(rect) self.TileBackground(dc) @@ -190,10 +177,8 @@ class DragCanvas(wx.ScrolledWindow): self.dragImage.EndDrag() self.dragImage = None - dc = wx.ClientDC(self) - if self.hiliteShape: - self.hiliteShape.Draw(dc) + self.RefreshRect(self.hiliteShape.GetRect()) self.hiliteShape = None # reposition and draw the shape @@ -217,9 +202,10 @@ class DragCanvas(wx.ScrolledWindow): ) self.dragShape.shown = True - self.dragShape.Draw(dc) + self.RefreshRect(self.dragShape.GetRect()) self.dragShape = None + # The mouse is moving def OnMotion(self, evt): # Ignore mouse movement if we're not dragging. @@ -237,11 +223,11 @@ class DragCanvas(wx.ScrolledWindow): if dx <= tolerance and dy <= tolerance: return - # erase the shape since it will be drawn independently now - dc = wx.ClientDC(self) + # refresh the area of the window where the shape was so it + # will get erased. self.dragShape.shown = False - self.EraseShape(self.dragShape, dc) - + self.RefreshRect(self.dragShape.GetRect(), True) + self.Update() if self.dragShape.text: self.dragImage = wx.DragString(self.dragShape.text,