def draw(self, c, r): c.erase_rect(r) main_image_pos = (10, 10) src_rect = pixmap.bounds dst_rect = offset_rect(src_rect, main_image_pos) pixmap.draw(c, src_rect, dst_rect) src_rect = rect_sized((180, 160), (100, 100)) c.frame_rect(offset_rect(src_rect, main_image_pos)) dst_rect = rect_sized((10, 340), (150, 150)) pixmap.draw(c, src_rect, dst_rect) dst_rect = rect_sized((200, 340), (100, 100)) pixmap.draw(c, src_rect, dst_rect) dst_rect = rect_sized((340, 340), (50, 50)) pixmap.draw(c, src_rect, dst_rect)
def OnPaint(self): if not self._win_paint_broken: try: win = self._win dc, ps = win.BeginPaint() try: win_update_rect = ps[2] if not empty_rect(win_update_rect): #print "DrawableContainer.OnPaint: win_update_rect =", win_update_rect ### scroll_offset = self._win_scroll_offset() view_update_rect = offset_rect(win_update_rect, scroll_offset) if self._double_buffer: dx, dy = rect_topleft(view_update_rect) width, height = rect_size(view_update_rect) buffer = gdi.Bitmap(width, height) canvas = Canvas._from_win_image(buffer) canvas.translate(-dx, -dy) self.draw(canvas, view_update_rect) graphics = gdi.Graphics.from_dc(dc) src_rect = (0, 0, width, height) graphics.DrawImage_rr(buffer, win_update_rect, src_rect) else: self._win_prepare_dc(dc) canvas = Canvas._from_win_dc(dc) self.draw(canvas, view_update_rect) finally: win.EndPaint(ps) except Exception: self._win_paint_broken = True raise
def draw(self, c, r): c.backcolor = rgb(0.94, 0.94, 0.94) c.erase_rect(r) main_image_pos = (int(self.width/2-80), int(self.height/2-90)) src_rect = self.image.bounds #say("Image bounds =", src_rect) dst_rect = offset_rect(src_rect, main_image_pos) #say("Drawing", src_rect, "in", dst_rect) self.image.draw(c, src_rect, dst_rect)
def draw(self, c, r): c.backcolor = skyblue c.erase_rect(r) main_image_pos = (50, 50) src_rect = image.bounds #say("Image bounds =", src_rect) dst_rect = offset_rect(src_rect, main_image_pos) #say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect)
def draw(self, c, r): image = the_image c.backcolor = background c.erase_rect(r) main_image_pos = (10, 10) src_rect = image.bounds #say("Image bounds =", src_rect) dst_rect = offset_rect(src_rect, main_image_pos) #say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect)
def draw(self, c, r): #print "Draw" ### c.forecolor = rgb(0.5, 0.75, 1.0) c.fill_rect(self.viewed_rect()) c.forecolor = black pm = self.pixmap sr = pm.bounds for i in range(3): dr = offset_rect(sr, (10 + i * 50, 10 + i * 60)) pm.draw(c, sr, dr)
def draw(self, c, r): c.backcolor = yellow c.erase_rect(r) main_image_pos = (10, 10) src_rect = image.bounds # say("Image bounds =", src_rect) dst_rect = offset_rect(src_rect, main_image_pos) # say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect) src_rect = rect_sized((180, 160), (100, 100)) c.frame_rect(offset_rect(src_rect, main_image_pos)) dst_rect = rect_sized((10, 340), (150, 150)) # say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect) dst_rect = rect_sized((200, 340), (100, 100)) # say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect) dst_rect = rect_sized((340, 340), (50, 50)) # say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect)
def draw(self, c, r): c.backcolor = yellow c.erase_rect(r) main_image_pos = (10, 10) src_rect = image.bounds #say("Image bounds =", src_rect) dst_rect = offset_rect(src_rect, main_image_pos) #say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect) src_rect = rect_sized((180, 160), (100, 100)) c.frame_rect(offset_rect(src_rect, main_image_pos)) dst_rect = rect_sized((10, 340), (150, 150)) #say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect) dst_rect = rect_sized((200, 340), (100, 100)) #say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect) dst_rect = rect_sized((340, 340), (50, 50)) #say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect)
def draw(self, c, r): here = sys.path[0] image_path = os.path.join(here, "test.png") image = Image(file=image_path) c.backcolor = yellow c.erase_rect(r) main_image_pos = (30, btn1.bottom + 30) src_rect = (0, 0, 571, 416) #say("Image bounds =", src_rect) dst_rect = offset_rect(src_rect, main_image_pos) #say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect)
def OnPaint(self): if not self._win_paint_broken: try: win = self._win dc, ps = win.BeginPaint() try: win_update_rect = ps[2] if not empty_rect(win_update_rect): #print "DrawableContainer.OnPaint: win_update_rect =", win_update_rect ### scroll_offset = self._win_scroll_offset() view_update_rect = offset_rect(win_update_rect, scroll_offset) if self._double_buffer: dx, dy = rect_topleft(view_update_rect) width, height = rect_size(view_update_rect) #GDIPlus draw large image in very bad performance #use GDI instead #buffer = gdi.Bitmap(width, height) #canvas = Canvas._from_win_image(buffer) #canvas.translate(-dx, -dy) #self.draw(canvas, view_update_rect) #graphics = gdi.Graphics.from_dc(dc) #src_rect = (0, 0, width, height) #graphics.DrawImage_rr(buffer, win_update_rect, src_rect) c_dc = dc.CreateCompatibleDC(dc) c_dm = ui.CreateBitmap() c_dm.CreateCompatibleBitmap(dc, width, height) old = c_dc.SelectObject(c_dm) c_dc.SetViewportOrg((-dx, -dy)) canvas = Canvas._from_win_dc(c_dc) self.draw(canvas, view_update_rect) l, t = rect_topleft(win_update_rect) dc.BitBlt((l, t), (width, height), c_dc, (0, 0), win32con.SRCCOPY) c_dc.SelectObject(old) else: self._win_prepare_dc(dc) canvas = Canvas._from_win_dc(dc) self.draw(canvas, view_update_rect) finally: win.EndPaint(ps) except Exception: self._win_paint_broken = True raise
def move(self, dx, dy): self.rect = offset_rect(self.rect, (dx, dy))
def draw(self, canvas, update_rect): canvas.backcolor = backcolor canvas.erase_rect(update_rect) self.pdfrect, im = self.model.pageimage(self.pagenum) if im is None: return self.image = image = MyImage(image = im) self.viewrect = (top_dx + 1, top_dy + 1, top_dx + 1 + image.width, top_dy + 1 + image.height) dest = offset_rect(image.bounds, (top_dx, top_dy)) frame = rect_larger(dest, (1,1)) # draw shadow (XXX draw only lower right part of it) canvas.pencolor = canvas.fillcolor = shadowcolor canvas.fill_frame_rect(offset_rect(frame, (shadow_dx, shadow_dy))) # draw frame canvas.pencolor = bordercolor canvas.frame_rect(frame) self.extent = (image.width + top_dx + shadow_dx + 3, image.height + top_dy + shadow_dy + 3) # draw image print '!', image.draw(canvas, image.bounds, dest) # test alpha-transparency #canvas.fillcolor = rgb(0.0, 0.5, 0.0, 0.5) #canvas.fill_frame_rect((50, 50, 300, 300)) # draw selection if self.selection is not None: # outer darkening # disabled for now - need to work out invalidation and # double-buffering #canvas.forecolor = rgb(0.0, 0.0, 0.0, 0.5) #uleft, utop, uright, ubottom = update_rect #sleft, stop, sright, sbottom = self.selection #canvas.fill_poly([ # (uleft, ubottom), # (uleft, utop), # (uright, utop), # (uright, ubottom), # (sleft, ubottom), # (sleft, sbottom), # (sright, sbottom), # (sright, stop), # (sleft, stop), # (sleft, ubottom), # ]) # frame canvas.pencolor = black canvas.frame_rect(self.selection) self.become_target()