]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/ScrolledWindow.py
added inline plural form of wxGetTranslation to wxUSE_INTL=0 case for use with non...
[wxWidgets.git] / wxPython / demo / ScrolledWindow.py
index 153ceab617836e90b15a0dbab2e6090420c9dceb..d5b0728be2e4607ab67de85263b22697f286e115 100644 (file)
@@ -24,7 +24,8 @@ class MyCanvas(wx.ScrolledWindow):
         bmp.SetMask(mask)
         self.bmp = bmp
 
-        self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20)
+        self.SetVirtualSize((self.maxWidth, self.maxHeight))
+        self.SetScrollRate(20,20)
 
         if BUFFERED:
             # Initialize the buffer bitmap.  No real DC is needed at this point.
@@ -53,7 +54,7 @@ class MyCanvas(wx.ScrolledWindow):
             # wx.PaintDC and then blit the bitmap to it when dc is
             # deleted.  Since we don't need to draw anything else
             # here that's all there is to it.
-            dc = wx.BufferedPaintDC(self, self.buffer)
+            dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)
         else:
             dc = wx.PaintDC(self)
             self.PrepareDC(dc)
@@ -136,6 +137,10 @@ class MyCanvas(wx.ScrolledWindow):
         dc.SetPen(old_pen)
         dc.DrawRectangle(490,90, 20,20)
 
+        dc.GradientFillLinear((20, 260, 50, 50),
+                              "red", "blue")
+        dc.GradientFillConcentric((20, 325, 50, 50),
+                                  "red", "blue", (25,25))
         self.DrawSavedLines(dc)
         dc.EndDrawing()
 
@@ -152,10 +157,8 @@ class MyCanvas(wx.ScrolledWindow):
         self.x, self.y = self.ConvertEventCoords(event)
 
     def ConvertEventCoords(self, event):
-        xView, yView = self.GetViewStart()
-        xDelta, yDelta = self.GetScrollPixelsPerUnit()
-        return (event.GetX() + (xView * xDelta),
-                event.GetY() + (yView * yDelta))
+        newpos = self.CalcUnscrolledPosition(event.GetX(), event.GetY())
+        return newpos
 
     def OnLeftButtonEvent(self, event):
         if event.LeftDown():
@@ -167,23 +170,34 @@ class MyCanvas(wx.ScrolledWindow):
 
         elif event.Dragging() and self.drawing:
             if BUFFERED:
-                # If doing buffered drawing, create the buffered DC, giving it
-                # it a real DC to blit to when done.
-                cdc = wx.ClientDC(self)
-                self.PrepareDC(cdc)
-                dc = wx.BufferedDC(cdc, self.buffer)
+                # If doing buffered drawing we'll just update the
+                # buffer here and then refresh that portion of the
+                # window, then that portion of the buffer will be
+                # redrawn in the EVT_PAINT handler.
+                dc = wx.BufferedDC(None, self.buffer)
             else:
+                # otherwise we'll draw directly to a wx.ClientDC
                 dc = wx.ClientDC(self)
                 self.PrepareDC(dc)
 
-            dc.BeginDrawing()
             dc.SetPen(wx.Pen('MEDIUM FOREST GREEN', 4))
             coords = (self.x, self.y) + self.ConvertEventCoords(event)
             self.curLine.append(coords)
             dc.DrawLine(*coords)
             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:
             self.lines.append(self.curLine)