show better technique for updating drawing from outside of EVT_PAINT handler
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@44551 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -157,10 +157,8 @@ class MyCanvas(wx.ScrolledWindow):
|
|||||||
self.x, self.y = self.ConvertEventCoords(event)
|
self.x, self.y = self.ConvertEventCoords(event)
|
||||||
|
|
||||||
def ConvertEventCoords(self, event):
|
def ConvertEventCoords(self, event):
|
||||||
xView, yView = self.GetViewStart()
|
newpos = self.CalcUnscrolledPosition(event.GetX(), event.GetY())
|
||||||
xDelta, yDelta = self.GetScrollPixelsPerUnit()
|
return newpos
|
||||||
return (event.GetX() + (xView * xDelta),
|
|
||||||
event.GetY() + (yView * yDelta))
|
|
||||||
|
|
||||||
def OnLeftButtonEvent(self, event):
|
def OnLeftButtonEvent(self, event):
|
||||||
if event.LeftDown():
|
if event.LeftDown():
|
||||||
@@ -172,23 +170,34 @@ class MyCanvas(wx.ScrolledWindow):
|
|||||||
|
|
||||||
elif event.Dragging() and self.drawing:
|
elif event.Dragging() and self.drawing:
|
||||||
if BUFFERED:
|
if BUFFERED:
|
||||||
# If doing buffered drawing, create the buffered DC, giving it
|
# If doing buffered drawing we'll just update the
|
||||||
# it a real DC to blit to when done.
|
# buffer here and then refresh that portion of the
|
||||||
cdc = wx.ClientDC(self)
|
# window, then that portion of the buffer will be
|
||||||
self.PrepareDC(cdc)
|
# redrawn in the EVT_PAINT handler.
|
||||||
dc = wx.BufferedDC(cdc, self.buffer)
|
dc = wx.BufferedDC(None, self.buffer)
|
||||||
else:
|
else:
|
||||||
|
# otherwise we'll draw directly to a wx.ClientDC
|
||||||
dc = wx.ClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
self.PrepareDC(dc)
|
self.PrepareDC(dc)
|
||||||
|
|
||||||
dc.BeginDrawing()
|
|
||||||
dc.SetPen(wx.Pen('MEDIUM FOREST GREEN', 4))
|
dc.SetPen(wx.Pen('MEDIUM FOREST GREEN', 4))
|
||||||
coords = (self.x, self.y) + self.ConvertEventCoords(event)
|
coords = (self.x, self.y) + self.ConvertEventCoords(event)
|
||||||
self.curLine.append(coords)
|
self.curLine.append(coords)
|
||||||
dc.DrawLine(*coords)
|
dc.DrawLine(*coords)
|
||||||
self.SetXY(event)
|
self.SetXY(event)
|
||||||
dc.EndDrawing()
|
|
||||||
|
|
||||||
|
if BUFFERED:
|
||||||
|
# figure out what part of the window to refresh
|
||||||
|
x1,y1, x2,y2 = dc.GetBoundingBox()
|
||||||
|
x1,y1 = self.CalcScrolledPosition(x1, y1)
|
||||||
|
x2,y2 = self.CalcScrolledPosition(x2, y2)
|
||||||
|
# make a rectangle
|
||||||
|
rect = wx.Rect()
|
||||||
|
rect.SetTopLeft((x1,y1))
|
||||||
|
rect.SetBottomRight((x2,y2))
|
||||||
|
rect.Inflate(2,2)
|
||||||
|
# refresh it
|
||||||
|
self.RefreshRect(rect)
|
||||||
|
|
||||||
elif event.LeftUp() and self.drawing:
|
elif event.LeftUp() and self.drawing:
|
||||||
self.lines.append(self.curLine)
|
self.lines.append(self.curLine)
|
||||||
|
Reference in New Issue
Block a user