def copyBuffer(self, dc, regions): origin = dc.GetDeviceOrigin() copydc = wx.MemoryDC() copydc.SelectObject(self.buffer) copydc.SetDeviceOrigin(-self.rect.x, -self.rect.y) for offset, region in regions.items(): dc.SetDeviceOrigin(*(origin + offset)) regioniterator = wx.RegionIterator(region) while (regioniterator): r = regioniterator.GetRect() dc.Blit(r.x, r.y, r.width, r.height, copydc, r.x, r.y) regioniterator.Next() ''' dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(wx.GREEN_BRUSH) regioniterator = wx.RegionIterator(region) while(regioniterator): r = regioniterator.GetRect() dc.DrawRectangle(r.x, r.y, r.width, r.height) regioniterator.Next() dc.SetBrush(wx.NullBrush) dc.SetPen(wx.NullPen) ''' copydc.SelectObject(wx.NullBitmap) dc.SetDeviceOrigin(*origin)
def OnPaint(self, event): dc = wx.PaintDC(self) #self.parentPanel.PrepareDC(dc) size = self.GetVirtualSize() s = "Size: %d x %d"%(size.x, size.y) vbX, vbY = self.parentPanel.GetViewStart() posX, posY = self.parentPanel.CalcUnscrolledPosition (0, 0) vbX, vbY = vbX * self.use_x, vbY * self.use_y posX, posY = posX * self.use_x, posY * self.use_y # vbX, vbY = self.GetViewStart() # posX, posY = self.CalcUnscrolledPosition (0, 0) upd = wx.RegionIterator(self.GetUpdateRegion()) # get the update rect list r = [] while upd.HaveRects(): rect = upd.GetRect() # Repaint this rectangle #PaintRectangle(rect, dc) r.append("rect: %s" % str(rect)) upd.Next() print(s, (posX, posY), (vbX, vbY), " ".join(r)) dc.SetLogicalOrigin(posX, posY) dc.SetFont(wx.NORMAL_FONT) w, height = dc.GetTextExtent(s) height += 3 dc.SetBrush(wx.WHITE_BRUSH) dc.SetPen(wx.WHITE_PEN) dc.DrawRectangle(0, 0, size.x, size.y) dc.SetPen(wx.LIGHT_GREY_PEN) dc.DrawLine(0, 0, size.x, size.y) dc.DrawLine(0, size.y, size.x, 0) dc.DrawText(s, (size.x-w)/2, (size.y-height*5)/2)
def do_paint(self, dc): source = wx.MemoryDC() source.SelectObject(self.bitmap) r = wx.RegionIterator(self.UpdateRegion) while r.HaveRects(): dc.Blit(r.X, r.Y, r.W, r.H, source, r.X, r.Y) r.Next() source.SelectObject(wx.NullBitmap)
def on_paint(self, event): dc = wx.PaintDC(self) x_origin = self.width_border y_origin = self.height_border vbX, vbY = self.GetViewStart() posX, posY = self.CalcUnscrolledPosition(0, 0) s = "Size: %d x %d" % (self.virtual_width, self.virtual_height) upd = wx.RegionIterator( self.GetUpdateRegion()) # get the update rect list r = [] while upd.HaveRects(): rect = upd.GetRect() # Repaint this rectangle #PaintRectangle(rect, dc) r.append("rect: %s" % str(rect)) upd.Next() print("on_paint", s, (posX, posY), (vbX, vbY), " ".join(r)) dc.SetLogicalOrigin(posX, posY) dc.SetFont(wx.NORMAL_FONT) w, height = dc.GetTextExtent(s) height += 3 dc.SetBrush(wx.WHITE_BRUSH) dc.SetPen(wx.WHITE_PEN) dc.DrawRectangle(0, 0, self.virtual_width, self.virtual_height) dc.SetPen(wx.LIGHT_GREY_PEN) dc.DrawLine(0, 0, self.virtual_width, self.virtual_height) dc.DrawLine(0, self.virtual_height, self.virtual_width, 0) dc.DrawText(s, (self.virtual_width - w) / 2, (self.virtual_height - height * 5) / 2) dc.SetPen(self.pen) for line in self.restart_lines: x1 = self.frame_to_x(line.start_frame) x2 = self.frame_to_x(line.end_frame) y = self.level_to_y(line.level) if line == self.over_line: dc.SetPen(self.hover_pen) dc.DrawLine(x1, y, x2, y) else: dc.SetPen(self.pen) dc.DrawLine(x1, y, x2, y) dc.SetPen(self.marker_pen) dc.SetBrush(self.marker_brush) for interesting_frame in line.interesting_frames.keys(): xi = self.frame_to_x(interesting_frame) dc.DrawCircle(xi, y, self.marker_size) if line.restart_number == 0: continue # draw vertical line connecting to parent restart parent_line = self.restart_lines[line.parent] parent_y = self.level_to_y(parent_line.level) dc.SetPen(self.pen) dc.DrawLine(x1, y, x1, parent_y)
def OnPaint(self, e): dc = wx.PaintDC( self.scroll) #We must create a PaintDC even if we don't use it. i = wx.RegionIterator(self.scroll.GetUpdateRegion()) while i: win = reverse_frames[self] x, y = scrolls[win].CalcUnscrolledPosition((i.GetX(), i.GetY())) send(["PaintRect", win, x, y, i.GetWidth(), i.GetHeight()]) i.Next()
def onPaint(self, dc): dc = wx.PaintDC(self) memorydc = wx.MemoryDC() memorydc.SelectObject(self.buffer) regioniterator = wx.RegionIterator(self.GetUpdateRegion()) while(regioniterator): r = regioniterator.GetRect() dc.Blit(r.x, r.y, r.width, r.height, memorydc, r.x, r.y) regioniterator.Next() memorydc.SelectObject(wx.NullBitmap)
def _onPaint(self, dc): memorydc = wx.MemoryDC() memorydc.SelectObject(self._buffer) regioniterator = wx.RegionIterator(self.GetUpdateRegion()) while (regioniterator): rect = regioniterator.GetRect() self._onPaintRegion(dc, rect.x, rect.y, rect.width, rect.height, memorydc) regioniterator.Next() memorydc.SelectObject(wx.NullBitmap)
def test_regionIterator1(self): region = wx.Region([(10, 10), (100, 100), (10, 100)]) iterator = wx.RegionIterator(region) count = 0 while iterator: rect = iterator.GetRect() self.assertTrue(isinstance(rect, wx.Rect)) iterator.Next() count += 1 self.assertTrue(count > 0)
def draw(self, dc, region): dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(self.brush) regioniterator = wx.RegionIterator(region) while(regioniterator): r = regioniterator.GetRect() dc.DrawRectangle(r.x, r.y, r.width, r.height) regioniterator.Next() dc.SetBrush(wx.NullBrush) dc.SetPen(wx.NullPen)
def draw(self, dc, region): if self.bitmap is None: return regioniterator = wx.RegionIterator(region) while (regioniterator): r = regioniterator.GetRect() sourcedc = wx.MemoryDC() sourcedc.SelectObject(self.bitmap) dc.Blit(r.x, r.y, r.width, r.height, sourcedc, 0, 0) sourcedc.SelectObject(wx.NullBitmap) regioniterator.Next()
def ClipRegion(self, region): """ Adds the wx.Region to the current clipping region. """ p = GraphicsPath() ri = wx.RegionIterator(region) while ri: rect = ri.GetRect() p.AddRectangle(*rect) ri.Next() self._context.append_path(p.GetNativePath()) self._context.clip()
def OnPaint2(self, ev): dc = wx.PaintDC(self) self.DoPrepareDC(dc) it = wx.RegionIterator(self.GetUpdateRegion()) while it.HaveRects(): x = it.GetX() y = it.GetY() w = it.GetW() h = it.GetH() (x, y) = self.CalcUnscrolledPosition(x, y) self.paint_rect(dc, x, y, w, h) it.Next()
def draw(self, dc, region): regioniterator = wx.RegionIterator(region) while (regioniterator): r = regioniterator.GetRect() bitmap = numpyimage.numpy2wxBitmap(self.array, r.x - self.rect.x, r.y - self.rect.y, r.width, r.height, self.rect.width, self.rect.height, self.valuerange) sourcedc = wx.MemoryDC() sourcedc.SelectObject(bitmap) dc.Blit(r.x, r.y, r.width, r.height, sourcedc, 0, 0) sourcedc.SelectObject(wx.NullBitmap) regioniterator.Next()
def draw(self, dc, region): regioniterator = wx.RegionIterator(region) while (regioniterator): r = regioniterator.GetRect() for tr in self.targetoffsets: if not r.Intersects(tr): continue x = r.x - tr.x y = r.y - tr.y w = min(tr.width - x, r.width) h = min(tr.height - y, r.height) sourcedc = wx.MemoryDC() sourcedc.SelectObject(self.bitmap) dc.Blit(r.x, r.y, w, h, sourcedc, x, y) sourcedc.SelectObject(wx.NullBitmap) regioniterator.Next()
def draw(self, dc, region): regioniterator = wx.RegionIterator(region) while(regioniterator): r = regioniterator.GetRect() dc.SetPen(self.pen) start = (r.x - 1) + self.spacing - (r.x - 1) % self.spacing stop = r.x + r.width for i in range(start, stop, self.spacing): dc.DrawLine(i, r.y, i, r.y + r.height) start = (r.y - 1) + self.spacing - (r.y - 1) % self.spacing stop = r.y + r.height for i in range(start, stop, self.spacing): dc.DrawLine(r.x, i, r.x + r.width, i) dc.SetPen(wx.NullPen) regioniterator.Next()
def _PaintPreview(self, event: wx.PaintEvent): dc = wx.PaintDC(self._preview) gc = wx.GraphicsContext.Create(dc) if not gc: return gc.SetBrush(GetPatternBrush()) it = wx.RegionIterator(self._preview.GetUpdateRegion()) while it.HaveRects(): rect = it.GetRect() gc.DrawRectangle(rect.x, rect.y, rect.width, rect.height) it.Next() rect = self._preview.GetClientRect() asStops = self.GetGradientAsStops() stops = wx.GraphicsGradientStops(asStops[0][0], asStops[-1][0]) for col, pos in asStops[1:-1]: stops.Add(col, pos) brush = gc.CreateLinearGradientBrush(0, 0, rect.GetWidth() - 1, 0, stops) gc.SetBrush(brush) gc.DrawRectangle(0, 0, rect.GetWidth(), rect.GetHeight())
def redraw(self, evt): DC = wx.PaintDC(self) self.PrepareDC(DC) extent = DC.GetFullTextExtent('x' * self.longest_line) lineheight = extent[1] vs = self.GetViewStart() ppu = self.GetScrollPixelsPerUnit() ri = wx.RegionIterator(self.GetUpdateRegion()) mmin, mmax = len(self.text), 0 while ri: rect = ri.GetRect() # find the lines that need rendering min_y = rect[1] + vs[1] * ppu[1] max_y = rect[1] + rect[3] + vs[1] * ppu[1] min_line = int(min_y / lineheight) - 1 max_line = int(max_y / lineheight) + 2 mmin = min(min_line, mmin) mmax = max(max_line, mmax) ri.Next() self.draw_lines(DC, mmin, mmax, lineheight)
def OnPaint(self, event: wx.PaintEvent): dc = wx.PaintDC(self) gc = wx.GraphicsContext.Create(dc) upd = wx.RegionIterator(self.GetUpdateRegion()) while upd.HaveRects(): rect = upd.GetRect() if self._colour.alpha < wx.ALPHA_OPAQUE: gc.SetBrush(GetPatternBrush()) gc.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height) gc.SetBrush(wx.TheBrushList.FindOrCreateBrush(self._colour)) gc.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height) upd.Next() gc.SetBrush(wx.TRANSPARENT_BRUSH) gc.SetPen(wx.BLACK_PEN) rect = self.GetClientRect() gc.DrawRectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1) if self.HasFocus(): rect.Deflate(2) renderer = wx.RendererNative.Get() renderer.DrawFocusRect(self, dc, rect)
def OnPaint(self, event: wx.PaintEvent): dc = wx.PaintDC(self) if self._image == None: dc.SetBrush(wx.GREY_BRUSH) it = wx.RegionIterator(self.GetUpdateRegion()) while it.HaveRects(): rect = it.GetRect() dc.DrawRectangle(rect) it.Next() return clientRect = self.GetClientRect() bmp = wx.Bitmap(clientRect.Size) dc2 = wx.MemoryDC() dc2.SelectObject(bmp) gc = wx.GraphicsContext.Create(dc2) if not gc: return gc.SetBrush(wx.GREY_BRUSH) gc.DrawRectangle(clientRect.x, clientRect.y, clientRect.width, clientRect.height) rect = wx.Rect(self._image.Size) ratio = rect.width / rect.height if rect.width > rect.height: if rect.width > clientRect.width: rect.width = clientRect.width rect.height = clientRect.width / ratio elif rect.height > clientRect.height: rect.height = clientRect.height rect.width = clientRect.height * ratio else: if rect.height > clientRect.height: rect.height = clientRect.height rect.width = clientRect.height * ratio elif rect.width > clientRect.width: rect.width = clientRect.width rect.height = clientRect.width / ratio rect = rect.CenterIn(clientRect) gc.SetBrush(GetPatternBrush()) gc.DrawRectangle(rect.x, rect.y, rect.width, rect.height) gc.DrawBitmap(self._image, rect.x, rect.y, rect.width, rect.height) dc.Blit(0, 0, clientRect.width, clientRect.height, dc2, 0, 0)
def iter_rects_of_region(region): '''Iterate over the rects of a region.''' i = wx.RegionIterator(region) while i.HaveRects(): yield i.GetRect() i.Next()
def getRegionInfo(self, evt): upd = wx.RegionIterator(self.GetUpdateRegion()) print('pos: {}, {}'.format(upd.GetX(), upd.GetY())) print('size: {}, {}'.format(upd.GetWidth(), upd.GetHeight()))