def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn): value = parameters rgb = int(value * 0xffff), int(value * 0xffff), int(value * 0xffff) Qd.OpColor(rgb) Qd.CopyBits(src2, tmp, self.ltrb, self.ltrb, QuickDraw.srcCopy, dstrgn) Qd.CopyBits(src1, tmp, self.ltrb, self.ltrb, QuickDraw.blend, dstrgn) Qd.CopyBits(tmp, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, dstrgn)
def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn): pointlist, rect2 = parameters Qd.CopyBits(src2, tmp, rect2, rect2, QuickDraw.srcCopy, None) if pointlist: rgn = _mkpolyrgn(pointlist) Qd.CopyBits(src1, tmp, self.ltrb, self.ltrb, QuickDraw.srcCopy, rgn) Qd.DisposeRgn(rgn) Qd.CopyBits(tmp, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, dstrgn)
def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn): pointlist, rect2 = parameters Qd.CopyBits(src2, tmp, rect2, rect2, QuickDraw.srcCopy, None) if pointlist: rgn = _mkpolyrgn(pointlist[0]) for pl in pointlist[1:]: newrgn = _mkpolyrgn(pl) Qd.UnionRgn(rgn, newrgn, rgn) Qd.DisposeRgn(newrgn) Qd.CopyBits(src1, tmp, self.ltrb, self.ltrb, QuickDraw.srcCopy, rgn) Qd.DisposeRgn(rgn) Qd.CopyBits(tmp, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, dstrgn)
def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn): rectlist, rect2 = parameters Qd.CopyBits(src2, tmp, rect2, rect2, QuickDraw.srcCopy, None) x0, y0, x1, y1 = self.ltrb rgn = Qd.NewRgn() for rect in rectlist: rgn2 = Qd.NewRgn() Qd.RectRgn(rgn2, rect) Qd.UnionRgn(rgn, rgn2, rgn) Qd.DisposeRgn(rgn2) Qd.CopyBits(src1, tmp, self.ltrb, self.ltrb, QuickDraw.srcCopy, rgn) Qd.DisposeRgn(rgn) Qd.CopyBits(tmp, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, dstrgn)
def _doredraw(self, mustredraw): """Internal: do the actual computation, iff anything has changed since last time""" oldparameters = self.currentparameters self.currentparameters = self.transitiontype.computeparameters( self.value) if self.currentparameters == oldparameters and not mustredraw: return # All windows in the transition share their bitmaps, so we can pick any of them w = self.windows[0] dst = w._mac_getoswindowpixmap(mw_globals.BM_ONSCREEN) src_active = w._mac_getoswindowpixmap(mw_globals.BM_DRAWING) src_passive = w._mac_getoswindowpixmap(mw_globals.BM_PASSIVE) tmp = w._mac_getoswindowpixmap(mw_globals.BM_TEMP) if self.outtransition: src_old = src_active src_new = src_passive else: src_old = src_passive src_new = src_active w._mac_setwin(mw_globals.BM_ONSCREEN) Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) Qd.RGBForeColor((0, 0, 0)) self.transitiontype.updatebitmap(self.currentparameters, src_new, src_old, tmp, dst, self.dstrgn) if self.verbatimrgn: Qd.CopyBits(src_active, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, self.verbatimrgn)
def _redrawimage(self, rect, image_data): w, h, (pixmap, dataref) = image_data dl, dt, dr, db = rect # # If there is enough room center the image # if dr - dl > w: dl = dl + ((dr - dl) - w) / 2 dr = dl + w if db - dt > h: dt = dt + ((db - dt) - h) / 2 db = dt + h srcrect = 0, 0, w, h dstrect = dl, dt, dr, db fgcolor = self.wid.GetWindowPort().rgbFgColor bgcolor = self.wid.GetWindowPort().rgbBkColor Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) Qd.RGBForeColor((0, 0, 0)) Qd.CopyBits(pixmap, self.wid.GetWindowPort().GetPortBitMapForCopyBits(), srcrect, dstrect, QuickDraw.srcCopy + QuickDraw.ditherCopy, None) Qd.RGBBackColor(bgcolor) Qd.RGBForeColor(fgcolor)
def do_update(self, *args): pass currect = self.fitrect() print 'PICT:', self.pictrect print 'WIND:', currect print 'ARGS:', (self.pixmap, self.wid.GetWindowPort().GetPortBitMapForCopyBits(), self.pictrect, currect, QuickDraw.srcCopy, None) self.info() Qd.CopyBits(self.pixmap, self.wid.GetWindowPort().GetPortBitMapForCopyBits(), self.pictrect, currect, QuickDraw.srcCopy, None)
def blit(self, x1=0, y1=0, x2=None, y2=None, port=None): """Draw this pixmap into the given (default current) grafport.""" src = self.bounds dest = [x1, y1, x2, y2] if x2 == None: dest[2] = x1 + src[2] - src[0] if y2 == None: dest[3] = y1 + src[3] - src[1] if not port: port = Qd.GetPort() Qd.CopyBits(self.PixMap(), port.GetPortBitMapForCopyBits(), src, tuple(dest), QuickDraw.srcCopy, None)
def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn): """Called by the engine when the parameters have changed and the destination bitmap has to be recomputed. Also called for other redraw reasons.""" Qd.CopyBits(src1, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, dstrgn) if self.SHOW_UNIMPLEMENTED_TRANSITION_NAME: x0, y0, x1, y1 = self.ltrb Qd.MoveTo(x0, y0) Qd.LineTo(x1, y1) Qd.MoveTo(x0, y1) Qd.LineTo(x1, y0) Qd.MoveTo(x0, (y0 + y1) / 2) Qd.DrawString( "%s %s" % (self.dict.get('trtype', '???'), self.dict.get('subtype', '')))
def blit(self, x1=0, y1=0, x2=None, y2=None, port=None): src = self.bounds dest = [x1, y1, x2, y2] if x2 is None: dest[2] = x1 + src[2] - src[0] if y2 is None: dest[3] = y1 + src[3] - src[1] if not port: port = Qd.GetPort() Qd.CopyBits(self.PixMap(), port.GetPortBitMapForCopyBits(), src, tuple(dest), QuickDraw.srcCopy, None) return
def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn): rect1, rect2 = parameters Qd.CopyBits(src2, tmp, rect2, rect2, QuickDraw.srcCopy, dstrgn) Qd.CopyBits(src1, tmp, rect1, rect1, QuickDraw.srcCopy, dstrgn) Qd.CopyBits(tmp, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, dstrgn)
def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn): srcrect1, dstrect1, srcrect2, dstrect2 = parameters Qd.CopyBits(src2, dst, srcrect2, dstrect2, QuickDraw.srcCopy, dstrgn) Qd.CopyBits(src1, dst, srcrect1, dstrect1, QuickDraw.srcCopy, dstrgn)
def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn): rect1, rect2 = parameters rect1 = self._convertrect(rect1) rect2 = self._convertrect(rect2) Qd.CopyBits(src2, dst, rect2, rect2, QuickDraw.srcCopy, dstrgn) Qd.CopyBits(src1, dst, rect1, rect1, QuickDraw.srcCopy, dstrgn)
"""PixMapWrapper - defines the PixMapWrapper class, which wraps an opaque
def _render_one(self, entry): cmd = entry[0] if cmd == 'clear': if self._bgcolor != None: r = self._getredrawguarantee(skipclear=1) if r: r2 = Qd.NewRgn() Qd.RectRgn(r2, self._window.qdrect()) Qd.DiffRgn(r2, r, r2) Qd.EraseRgn(r2) Qd.DisposeRgn(r) Qd.DisposeRgn(r2) else: Qd.EraseRect(self._window.qdrect()) elif cmd == 'fg': self._setfgcolor(entry[1]) elif cmd == 'font': entry[1]._setfont(self._render_grafport) elif cmd == 'text': x, y, w, h = self._convert_coordinates(entry[1:5]) if not self._render_overlaprgn((x, y - h, x + w, y)): return Qd.MoveTo(x, y) # XXXX Incorrect for long strings: Qd.DrawText(entry[5], 0, len(entry[5])) elif cmd == 'icon': icon = entry[2] if icon == None: return rect = self._convert_coordinates(entry[1]) if not self._render_overlaprgn(rect): return x0, y0, x1, y1 = rect if x1 - x0 < ICONSIZE_PXL: leftextra = (ICONSIZE_PXL - (x1 - x0)) / 2 x0 = x0 + leftextra x1 = x0 + ICONSIZE_PXL if y1 - y0 < ICONSIZE_PXL: topextra = (ICONSIZE_PXL - (y1 - y0)) / 2 y0 = y0 + topextra y1 = y0 + ICONSIZE_PXL Icn.PlotCIcon((x0, y0, x1, y1), icon) elif cmd == 'image': mask, image, srcx, srcy, coordinates, w, h, units = entry[1:] dstx, dsty = self._convert_coordinates(coordinates[:2], units=units) dstrect = dstx, dsty, dstx + w, dsty + h if not self._render_overlaprgn(dstrect): return w = dstrect[2] - dstrect[0] h = dstrect[3] - dstrect[1] srcrect = srcx, srcy, srcx + w, srcy + h self._setblackwhitecolors() clip = self._window._mac_getclip() if mask: # XXXX We should also take note of the clip here. Qd.CopyMask(image[0], mask[0], self._render_grafport.GetPortBitMapForCopyBits(), srcrect, srcrect, dstrect) else: Qd.CopyBits(image[0], self._render_grafport.GetPortBitMapForCopyBits(), srcrect, dstrect, QuickDraw.srcCopy + QuickDraw.ditherCopy, clip) self._restorecolors() elif cmd == 'line': color = entry[1] points = entry[2] self._setfgcolor(color) x, y = self._convert_coordinates(points[0]) Qd.MoveTo(x, y) for np in points[1:]: x, y = self._convert_coordinates(np) Qd.LineTo(x, y) self._restorecolors() elif cmd == '3dhline': color1, color2, x0, x1, y = entry[1:] fgcolor = self._render_grafport.rgbFgColor self._setfgcolor(color1) x0, y0 = self._convert_coordinates((x0, y)) x1, y1 = self._convert_coordinates((x1, y)) if not self._render_overlaprgn((x0, y0, x1, y1 + 1)): return Qd.MoveTo(x0, y0) Qd.LineTo(x1, y1) self._setfgcolor(color2) Qd.MoveTo(x0, y0 + 1) Qd.LineTo(x1, y1 + 1) self._setfgcolor(fgcolor) self._restorecolors() elif cmd == 'box': rect = self._convert_coordinates(entry[1]) if not self._render_overlaprgn(rect): return Qd.FrameRect(rect) elif cmd == 'fbox': color = entry[1] units = entry[3] rect = self._convert_coordinates(entry[2], units) if not self._render_overlaprgn(rect): return self._setfgcolor(color) Qd.PaintRect(rect) self._restorecolors() elif cmd == 'linewidth': Qd.PenSize(entry[1], entry[1]) elif cmd == 'fpolygon': polyhandle = self._polyhandle(entry[2], cliprgn=self._render_cliprgn) if not polyhandle: return self._setfgcolor(entry[1]) Qd.PaintPoly(polyhandle) self._restorecolors() elif cmd == '3dbox': rect = self._convert_coordinates(entry[2]) if not self._render_overlaprgn(rect): return l, t, r, b = rect cl, ct, cr, cb = entry[1] clt = _colormix(cl, ct) ctr = _colormix(ct, cr) crb = _colormix(cr, cb) cbl = _colormix(cb, cl) ## print '3Dbox', (l, t, r, b) # DBG ## print 'window', self._window.qdrect() # DBG # l, r, t, b are the corners l3 = l + SIZE_3DBORDER t3 = t + SIZE_3DBORDER r3 = r - SIZE_3DBORDER b3 = b - SIZE_3DBORDER # draw left side self._setfgcolor(cl) polyhandle = self._polyhandle([(l, t), (l3, t3), (l3, b3), (l, b)], conv=0) if polyhandle: Qd.PaintPoly(polyhandle) # draw top side self._setfgcolor(ct) polyhandle = self._polyhandle([(l, t), (r, t), (r3, t3), (l3, t3)], conv=0) if polyhandle: Qd.PaintPoly(polyhandle) # draw right side self._setfgcolor(cr) polyhandle = self._polyhandle([(r3, t3), (r, t), (r, b), (r3, b3)], conv=0) if polyhandle: Qd.PaintPoly(polyhandle) # draw bottom side self._setfgcolor(cb) polyhandle = self._polyhandle([(l3, b3), (r3, b3), (r, b), (l, b)], conv=0) if polyhandle: Qd.PaintPoly(polyhandle) # draw topleft self._setfgcolor(clt) Qd.PaintRect((l, t, l3, t3)) # draw topright self._setfgcolor(ctr) Qd.PaintRect((r3, t, r, t3)) # draw botright self._setfgcolor(crb) Qd.PaintRect((r3, b3, r, b)) # draw leftbot self._setfgcolor(cbl) Qd.PaintRect((l, b3, l3, b)) self._restorecolors() elif cmd == 'diamond': rect = self._convert_coordinates(entry[1]) if not self._render_overlaprgn(rect): return x, y, x1, y1 = rect w = x1 - x h = y1 - y Qd.MoveTo(x, y + h / 2) Qd.LineTo(x + w / 2, y) Qd.LineTo(x + w, y + h / 2) Qd.LineTo(x + w / 2, y + h) Qd.LineTo(x, y + h / 2) elif cmd == 'fdiamond': rect = self._convert_coordinates(entry[2]) if not self._render_overlaprgn(rect): return x, y, x1, y1 = rect w = x1 - x h = y1 - y self._setfgcolor(entry[1]) polyhandle = self._polyhandle([(x, y + h / 2), (x + w / 2, y), (x + w, y + h / 2), (x + w / 2, y + h), (x, y + h / 2)]) if polyhandle: Qd.PaintPoly(polyhandle) self._restorecolors() elif cmd == '3ddiamond': rect = self._convert_coordinates(entry[2]) if not self._render_overlaprgn(rect): return l, t, r, b = rect cl, ct, cr, cb = entry[1] w = r - l h = b - t r = l + w b = t + h x = l + w / 2 y = t + h / 2 n = int(3.0 * w / h + 0.5) ll = l + n tt = t + 3 rr = r - n bb = b - 3 self._setfgcolor(cl) polyhandle = self._polyhandle([(l, y), (x, t), (x, tt), (ll, y)], conv=0) if polyhandle: Qd.PaintPoly(polyhandle) self._setfgcolor(ct) polyhandle = self._polyhandle([(x, t), (r, y), (rr, y), (x, tt)], conv=0) if polyhandle: Qd.PaintPoly(polyhandle) self._setfgcolor(cr) polyhandle = self._polyhandle([(r, y), (x, b), (x, bb), (rr, y)], conv=0) if polyhandle: Qd.PaintPoly(polyhandle) self._setfgcolor(cb) polyhandle = self._polyhandle([(l, y), (ll, y), (x, bb), (x, b)], conv=0) if polyhandle: Qd.PaintPoly(polyhandle) self._restorecolors() elif cmd == 'arrow': color = entry[1] src = entry[2] dst = entry[3] x0, y0, x1, y1, points = self._arrowdata(src, dst) if not self._render_overlaprgn((x0, y0, x1, y1)): return self._setfgcolor(color) Qd.MoveTo(x0, y0) Qd.LineTo(x1, y1) polyhandle = self._polyhandle(points) if polyhandle: Qd.PaintPoly(polyhandle) self._restorecolors() else: raise 'Unknown displaylist command', cmd self._dbg_did = self._dbg_did + 1
"""imgbrowse - Display pictures using img"""
from Carbon import Qt
return width + 2 * IMAGEBORDER, height + 2 * IMAGEBORDER def drawGIF((l, t, r, b), obj): handle = obj.WEGetObjectDataHandle() width, height, pixmap = _gifkeeper.get(handle.data) srcrect = 0, 0, width, height dstrect = l + IMAGEBORDER, t + IMAGEBORDER, r - IMAGEBORDER, b - IMAGEBORDER port = Qd.GetPort() bg = port.rgbBkColor fg = port.rgbFgColor Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) Qd.RGBForeColor((0, 0, 0)) ## Qd.CopyBits(pixmap, port.GetPortBitMapForCopyBits(), srcrect, dstrect, ## QuickDraw.srcCopy+QuickDraw.ditherCopy, None) Qd.CopyBits(pixmap, port.GetPortBitMapForCopyBits(), srcrect, dstrect, QuickDraw.srcCopy, None) Qd.RGBBackColor(bg) Qd.RGBForeColor(fg) # XXXX paste pixmap on screen return 0 def freeGIF(obj): handle = obj.WEGetObjectDataHandle() _gifkeeper.delete(handle.data) return 0 class _Gifkeeper: def __init__(self): self.dict = {}