?? tkmacdraw.c
字號:
/* * tkMacDraw.c -- * * This file contains functions that preform drawing to * Xlib windows. Most of the functions simple emulate * Xlib functions. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * * SCCS: @(#) tkMacDraw.c 1.55 97/11/20 18:28:56 */#include "tkInt.h"#include "X.h"#include "Xlib.h"#include <stdio.h>#include <tcl.h>#include <Windows.h>#include <Fonts.h>#include <QDOffscreen.h>#include "tkMacInt.h"#ifndef PI# define PI 3.14159265358979323846#endif/* * Temporary regions that can be reused. */static RgnHandle tmpRgn = NULL;static RgnHandle tmpRgn2 = NULL;static PixPatHandle gPenPat = NULL;/* * Prototypes for functions used only in this file. */static unsigned char InvertByte _ANSI_ARGS_((unsigned char data));/* *---------------------------------------------------------------------- * * XCopyArea -- * * Copies data from one drawable to another using block transfer * routines. * * Results: * None. * * Side effects: * Data is moved from a window or bitmap to a second window or * bitmap. * *---------------------------------------------------------------------- */void XCopyArea( Display* display, /* Display. */ Drawable src, /* Source drawable. */ Drawable dest, /* Destination drawable. */ GC gc, /* GC to use. */ int src_x, /* X & Y, width & height */ int src_y, /* define the source rectangle */ unsigned int width, /* the will be copied. */ unsigned int height, int dest_x, /* Dest X & Y on dest rect. */ int dest_y){ Rect srcRect, destRect; BitMapPtr srcBit, destBit; MacDrawable *srcDraw = (MacDrawable *) src; MacDrawable *destDraw = (MacDrawable *) dest; GWorldPtr srcPort, destPort; CGrafPtr saveWorld; GDHandle saveDevice; short tmode; RGBColor origForeColor, origBackColor, whiteColor, blackColor; destPort = TkMacGetDrawablePort(dest); srcPort = TkMacGetDrawablePort(src); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); GetForeColor(&origForeColor); GetBackColor(&origBackColor); whiteColor.red = 0; whiteColor.blue = 0; whiteColor.green = 0; RGBForeColor(&whiteColor); blackColor.red = 0xFFFF; blackColor.blue = 0xFFFF; blackColor.green = 0xFFFF; RGBBackColor(&blackColor); TkMacSetUpClippingRgn(dest); /* * We will change the clip rgn in this routine, so we need to * be able to restore it when we exit. */ if (tmpRgn2 == NULL) { tmpRgn2 = NewRgn(); } GetClip(tmpRgn2); if (((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) { RgnHandle clipRgn = (RgnHandle) ((TkpClipMask*)gc->clip_mask)->value.region; int xOffset, yOffset; if (tmpRgn == NULL) { tmpRgn = NewRgn(); } xOffset = destDraw->xOff + gc->clip_x_origin; yOffset = destDraw->yOff + gc->clip_y_origin; OffsetRgn(clipRgn, xOffset, yOffset); GetClip(tmpRgn); SectRgn(tmpRgn, clipRgn, tmpRgn); SetClip(tmpRgn); OffsetRgn(clipRgn, -xOffset, -yOffset); } srcBit = &((GrafPtr) srcPort)->portBits; destBit = &((GrafPtr) destPort)->portBits; SetRect(&srcRect, (short) (srcDraw->xOff + src_x), (short) (srcDraw->yOff + src_y), (short) (srcDraw->xOff + src_x + width), (short) (srcDraw->yOff + src_y + height)); SetRect(&destRect, (short) (destDraw->xOff + dest_x), (short) (destDraw->yOff + dest_y), (short) (destDraw->xOff + dest_x + width), (short) (destDraw->yOff + dest_y + height)); tmode = srcCopy; CopyBits(srcBit, destBit, &srcRect, &destRect, tmode, NULL); RGBForeColor(&origForeColor); RGBBackColor(&origBackColor); SetClip(tmpRgn2); SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * XCopyPlane -- * * Copies a bitmap from a source drawable to a destination * drawable. The plane argument specifies which bit plane of * the source contains the bitmap. Note that this implementation * ignores the gc->function. * * Results: * None. * * Side effects: * Changes the destination drawable. * *---------------------------------------------------------------------- */voidXCopyPlane( Display* display, /* Display. */ Drawable src, /* Source drawable. */ Drawable dest, /* Destination drawable. */ GC gc, /* The GC to use. */ int src_x, /* X, Y, width & height */ int src_y, /* define the source rect. */ unsigned int width, unsigned int height, int dest_x, /* X & Y on dest where we will copy. */ int dest_y, unsigned long plane) /* Which plane to copy. */{ Rect srcRect, destRect; BitMapPtr srcBit, destBit, maskBit; MacDrawable *srcDraw = (MacDrawable *) src; MacDrawable *destDraw = (MacDrawable *) dest; GWorldPtr srcPort, destPort, maskPort; CGrafPtr saveWorld; GDHandle saveDevice; RGBColor macColor; TkpClipMask *clipPtr = (TkpClipMask*)gc->clip_mask; short tmode; destPort = TkMacGetDrawablePort(dest); srcPort = TkMacGetDrawablePort(src); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(dest); srcBit = &((GrafPtr) srcPort)->portBits; destBit = &((GrafPtr) destPort)->portBits; SetRect(&srcRect, (short) (srcDraw->xOff + src_x), (short) (srcDraw->yOff + src_y), (short) (srcDraw->xOff + src_x + width), (short) (srcDraw->yOff + src_y + height)); SetRect(&destRect, (short) (destDraw->xOff + dest_x), (short) (destDraw->yOff + dest_y), (short) (destDraw->xOff + dest_x + width), (short) (destDraw->yOff + dest_y + height)); tmode = srcOr; tmode = srcCopy + transparent; if (TkSetMacColor(gc->foreground, &macColor) == true) { RGBForeColor(&macColor); } if (clipPtr == NULL || clipPtr->type == TKP_CLIP_REGION) { /* * Case 1: opaque bitmaps. */ TkSetMacColor(gc->background, &macColor); RGBBackColor(&macColor); tmode = srcCopy; CopyBits(srcBit, destBit, &srcRect, &destRect, tmode, NULL); } else if (clipPtr->type == TKP_CLIP_PIXMAP) { if (clipPtr->value.pixmap == src) { /* * Case 2: transparent bitmaps. If it's color we ignore * the forecolor. */ if ((**(srcPort->portPixMap)).pixelSize == 1) { tmode = srcOr; } else { tmode = transparent; } CopyBits(srcBit, destBit, &srcRect, &destRect, tmode, NULL); } else { /* * Case 3: two arbitrary bitmaps. */ tmode = srcCopy; maskPort = TkMacGetDrawablePort(clipPtr->value.pixmap); maskBit = &((GrafPtr) maskPort)->portBits; CopyDeepMask(srcBit, maskBit, destBit, &srcRect, &srcRect, &destRect, tmode, NULL); } } SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * TkPutImage -- * * Copies a subimage from an in-memory image to a rectangle of * of the specified drawable. * * Results: * None. * * Side effects: * Draws the image on the specified drawable. * *---------------------------------------------------------------------- */void TkPutImage( unsigned long *colors, /* Unused on Macintosh. */ int ncolors, /* Unused on Macintosh. */ Display* display, /* Display. */ Drawable d, /* Drawable to place image on. */ GC gc, /* GC to use. */ XImage* image, /* Image to place. */ int src_x, /* Source X & Y. */ int src_y, int dest_x, /* Destination X & Y. */ int dest_y, unsigned int width, /* Same width & height for both */ unsigned int height) /* distination and source. */{ MacDrawable *destDraw = (MacDrawable *) d; CGrafPtr saveWorld; GDHandle saveDevice; GWorldPtr destPort; int i, j; BitMap bitmap; char *newData = NULL; Rect destRect, srcRect; destPort = TkMacGetDrawablePort(d); SetRect(&destRect, dest_x, dest_y, dest_x + width, dest_y + height); SetRect(&srcRect, src_x, src_y, src_x + width, src_y + height); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); if (image->depth == 1) { /* * This code assumes a pixel depth of 1 */ bitmap.bounds.top = bitmap.bounds.left = 0; bitmap.bounds.right = (short) image->width; bitmap.bounds.bottom = (short) image->height; if ((image->bytes_per_line % 2) == 1) { char *newPtr, *oldPtr; newData = (char *) ckalloc(image->height * (image->bytes_per_line + 1)); newPtr = newData; oldPtr = image->data; for (i = 0; i < image->height; i++) { for (j = 0; j < image->bytes_per_line; j++) { *newPtr = InvertByte((unsigned char) *oldPtr); newPtr++, oldPtr++; } *newPtr = 0; newPtr++; } bitmap.baseAddr = newData; bitmap.rowBytes = image->bytes_per_line + 1; } else { newData = (char *) ckalloc(image->height * image->bytes_per_line); for (i = 0; i < image->height * image->bytes_per_line; i++) { newData[i] = InvertByte((unsigned char) image->data[i]); } bitmap.baseAddr = newData; bitmap.rowBytes = image->bytes_per_line; } CopyBits(&bitmap, &((GrafPtr) destPort)->portBits, &srcRect, &destRect, srcCopy, NULL); } else { /* Color image */ PixMap pixmap; pixmap.bounds.left = 0; pixmap.bounds.top = 0; pixmap.bounds.right = (short) image->width; pixmap.bounds.bottom = (short) image->height; pixmap.pixelType = RGBDirect; pixmap.pmVersion = 4; /* 32bit clean */ pixmap.packType = 0; pixmap.packSize = 0; pixmap.hRes = 0x00480000; pixmap.vRes = 0x00480000; pixmap.pixelSize = 32; pixmap.cmpCount = 3; pixmap.cmpSize = 8; pixmap.planeBytes = 0; pixmap.pmTable = NULL; pixmap.pmReserved = 0; pixmap.baseAddr = image->data; pixmap.rowBytes = image->bytes_per_line | 0x8000; CopyBits((BitMap *) &pixmap, &((GrafPtr) destPort)->portBits, &srcRect, &destRect, srcCopy, NULL); } if (newData != NULL) { ckfree(newData); } SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * XFillRectangles -- * * Fill multiple rectangular areas in the given drawable. * * Results: * None. * * Side effects: * Draws onto the specified drawable. * *---------------------------------------------------------------------- */void XFillRectangles( Display* display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ XRectangle *rectangles, /* Rectangle array. */ int n_rectangels) /* Number of rectangles. */{ MacDrawable *macWin = (MacDrawable *) d; CGrafPtr saveWorld; GDHandle saveDevice; GWorldPtr destPort; Rect theRect; int i; destPort = TkMacGetDrawablePort(d); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); TkMacSetUpGraphicsPort(gc); for (i=0; i<n_rectangels; i++) { theRect.left = (short) (macWin->xOff + rectangles[i].x); theRect.top = (short) (macWin->yOff + rectangles[i].y); theRect.right = (short) (theRect.left + rectangles[i].width); theRect.bottom = (short) (theRect.top + rectangles[i].height); FillCRect(&theRect, gPenPat); } SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * XDrawLines -- * * Draw connected lines. * * Results: * None. * * Side effects: * Renders a series of connected lines. * *---------------------------------------------------------------------- */void XDrawLines( Display* display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ XPoint* points, /* Array of points. */ int npoints, /* Number of points. */ int mode) /* Line drawing mode. */{ MacDrawable *macWin = (MacDrawable *) d; CGrafPtr saveWorld; GWorldPtr destPort; GDHandle saveDevice; int i; destPort = TkMacGetDrawablePort(d); display->request++; if (npoints < 2) { return; /* TODO: generate BadValue error. */ } GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); TkMacSetUpGraphicsPort(gc); ShowPen(); PenPixPat(gPenPat); MoveTo((short) (macWin->xOff + points[0].x), (short) (macWin->yOff + points[0].y)); for (i = 1; i < npoints; i++) { if (mode == CoordModeOrigin) { LineTo((short) (macWin->xOff + points[i].x), (short) (macWin->yOff + points[i].y)); } else { Line((short) (macWin->xOff + points[i].x), (short) (macWin->yOff + points[i].y)); } } SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * XDrawSegments -- * * Draw unconnected lines. * * Results: * None. * * Side effects: * Renders a series of connected lines. * *---------------------------------------------------------------------- */void XDrawSegments( Display *display, Drawable d, GC gc, XSegment *segments, int nsegments){ MacDrawable *macWin = (MacDrawable *) d; CGrafPtr saveWorld; GWorldPtr destPort; GDHandle saveDevice; int i; destPort = TkMacGetDrawablePort(d); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); TkMacSetUpGraphicsPort(gc); ShowPen(); PenPixPat(gPenPat); for (i = 0; i < nsegments; i++) { MoveTo((short) (macWin->xOff + segments[i].x1), (short) (macWin->yOff + segments[i].y1)); LineTo((short) (macWin->xOff + segments[i].x2), (short) (macWin->yOff + segments[i].y2)); } SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * XFillPolygon -- * * Draws a filled polygon. * * Results: * None. * * Side effects: * Draws a filled polygon on the specified drawable. * *---------------------------------------------------------------------- */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -