?? tkmacdraw.c
字號:
void XFillPolygon( Display* display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ XPoint* points, /* Array of points. */ int npoints, /* Number of points. */ int shape, /* Shape to draw. */ int mode) /* Drawing mode. */{ MacDrawable *macWin = (MacDrawable *) d; PolyHandle polygon; CGrafPtr saveWorld; GDHandle saveDevice; GWorldPtr destPort; int i; destPort = TkMacGetDrawablePort(d); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); TkMacSetUpGraphicsPort(gc); PenNormal(); polygon = OpenPoly(); MoveTo((short) (macWin->xOff + points[0].x), (short) (macWin->yOff + points[0].y)); for (i = 1; i < npoints; i++) { if (mode == CoordModePrevious) { Line((short) (macWin->xOff + points[i].x), (short) (macWin->yOff + points[i].y)); } else { LineTo((short) (macWin->xOff + points[i].x), (short) (macWin->yOff + points[i].y)); } } ClosePoly(); FillCPoly(polygon, gPenPat); KillPoly(polygon); SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * XDrawRectangle -- * * Draws a rectangle. * * Results: * None. * * Side effects: * Draws a rectangle on the specified drawable. * *---------------------------------------------------------------------- */void XDrawRectangle( Display* display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ int x, /* Upper left corner. */ int y, unsigned int width, /* Width & height of rect. */ unsigned int height){ MacDrawable *macWin = (MacDrawable *) d; Rect theRect; CGrafPtr saveWorld; GDHandle saveDevice; GWorldPtr destPort; destPort = TkMacGetDrawablePort(d); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); TkMacSetUpGraphicsPort(gc); theRect.left = (short) (macWin->xOff + x); theRect.top = (short) (macWin->yOff + y); theRect.right = (short) (theRect.left + width); theRect.bottom = (short) (theRect.top + height); ShowPen(); PenPixPat(gPenPat); FrameRect(&theRect); SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * XDrawArc -- * * Draw an arc. * * Results: * None. * * Side effects: * Draws an arc on the specified drawable. * *---------------------------------------------------------------------- */void XDrawArc( Display* display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ int x, /* Upper left of */ int y, /* bounding rect. */ unsigned int width, /* Width & height. */ unsigned int height, int angle1, /* Staring angle of arc. */ int angle2) /* Ending angle of arc. */{ MacDrawable *macWin = (MacDrawable *) d; Rect theRect; short start, extent; CGrafPtr saveWorld; GDHandle saveDevice; GWorldPtr destPort; destPort = TkMacGetDrawablePort(d); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); TkMacSetUpGraphicsPort(gc); theRect.left = (short) (macWin->xOff + x); theRect.top = (short) (macWin->yOff + y); theRect.right = (short) (theRect.left + width); theRect.bottom = (short) (theRect.top + height); start = (short) (90 - (angle1 / 64)); extent = (short) (-(angle2 / 64)); ShowPen(); PenPixPat(gPenPat); FrameArc(&theRect, start, extent); SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * XFillArc -- * * Draw a filled arc. * * Results: * None. * * Side effects: * Draws a filled arc on the specified drawable. * *---------------------------------------------------------------------- */voidXFillArc( Display* display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ int x, /* Upper left of */ int y, /* bounding rect. */ unsigned int width, /* Width & height. */ unsigned int height, int angle1, /* Staring angle of arc. */ int angle2) /* Ending angle of arc. */{ MacDrawable *macWin = (MacDrawable *) d; Rect theRect; short start, extent; PolyHandle polygon; double sin1, cos1, sin2, cos2, angle; double boxWidth, boxHeight; double vertex[2], center1[2], center2[2]; CGrafPtr saveWorld; GDHandle saveDevice; GWorldPtr destPort; destPort = TkMacGetDrawablePort(d); display->request++; GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(d); TkMacSetUpGraphicsPort(gc); theRect.left = (short) (macWin->xOff + x); theRect.top = (short) (macWin->yOff + y); theRect.right = (short) (theRect.left + width); theRect.bottom = (short) (theRect.top + height); start = (short) (90 - (angle1 / 64)); extent = (short) (- (angle2 / 64)); if (gc->arc_mode == ArcChord) { boxWidth = theRect.right - theRect.left; boxHeight = theRect.bottom - theRect.top; angle = -(angle1/64.0)*PI/180.0; sin1 = sin(angle); cos1 = cos(angle); angle -= (angle2/64.0)*PI/180.0; sin2 = sin(angle); cos2 = cos(angle); vertex[0] = (theRect.left + theRect.right)/2.0; vertex[1] = (theRect.top + theRect.bottom)/2.0; center1[0] = vertex[0] + cos1*boxWidth/2.0; center1[1] = vertex[1] + sin1*boxHeight/2.0; center2[0] = vertex[0] + cos2*boxWidth/2.0; center2[1] = vertex[1] + sin2*boxHeight/2.0; polygon = OpenPoly(); MoveTo((short) ((theRect.left + theRect.right)/2), (short) ((theRect.top + theRect.bottom)/2)); LineTo((short) (center1[0] + 0.5), (short) (center1[1] + 0.5)); LineTo((short) (center2[0] + 0.5), (short) (center2[1] + 0.5)); ClosePoly(); ShowPen(); FillCArc(&theRect, start, extent, gPenPat); FillCPoly(polygon, gPenPat); KillPoly(polygon); } else { ShowPen(); FillCArc(&theRect, start, extent, gPenPat); } SetGWorld(saveWorld, saveDevice);}/* *---------------------------------------------------------------------- * * TkScrollWindow -- * * Scroll a rectangle of the specified window and accumulate * a damage region. * * Results: * Returns 0 if the scroll genereated no additional damage. * Otherwise, sets the region that needs to be repainted after * scrolling and returns 1. * * Side effects: * Scrolls the bits in the window. * *---------------------------------------------------------------------- */intTkScrollWindow( Tk_Window tkwin, /* The window to be scrolled. */ GC gc, /* GC for window to be scrolled. */ int x, /* Position rectangle to be scrolled. */ int y, int width, int height, int dx, /* Distance rectangle should be moved. */ int dy, TkRegion damageRgn) /* Region to accumulate damage in. */{ MacDrawable *destDraw = (MacDrawable *) Tk_WindowId(tkwin); RgnHandle rgn = (RgnHandle) damageRgn; CGrafPtr saveWorld; GDHandle saveDevice; GWorldPtr destPort; Rect srcRect, scrollRect; destPort = TkMacGetDrawablePort(Tk_WindowId(tkwin)); GetGWorld(&saveWorld, &saveDevice); SetGWorld(destPort, NULL); TkMacSetUpClippingRgn(Tk_WindowId(tkwin)); /* * Due to the implementation below the behavior may be differnt * than X in certain cases that should never occur in Tk. The * scrollRect is the source rect extended by the offset (the union * of the source rect and the offset rect). Everything * in the extended scrollRect is scrolled. On X, it's possible * to "skip" over an area if the offset makes the source and * destination rects disjoint and non-aligned. */ SetRect(&srcRect, (short) (destDraw->xOff + x), (short) (destDraw->yOff + y), (short) (destDraw->xOff + x + width), (short) (destDraw->yOff + y + height)); scrollRect = srcRect; if (dx < 0) { scrollRect.left += dx; } else { scrollRect.right += dx; } if (dy < 0) { scrollRect.top += dy; } else { scrollRect.bottom += dy; } /* * Adjust clip region so that we don't copy any windows * that may overlap us. */ RectRgn(rgn, &srcRect); DiffRgn(rgn, destPort->visRgn, rgn); OffsetRgn(rgn, dx, dy); DiffRgn(destPort->clipRgn, rgn, destPort->clipRgn); SetEmptyRgn(rgn); /* * When a menu is up, the Mac does not expect drawing to occur and * does not clip out the menu. We have to do it ourselves. This * is pretty gross. */ if (tkUseMenuCascadeRgn == 1) { Point scratch = {0, 0}; MacDrawable *macDraw = (MacDrawable *) Tk_WindowId(tkwin); LocalToGlobal(&scratch); CopyRgn(tkMenuCascadeRgn, rgn); OffsetRgn(rgn, -scratch.h, -scratch.v); DiffRgn(destPort->clipRgn, rgn, destPort->clipRgn); SetEmptyRgn(rgn); macDraw->toplevel->flags |= TK_DRAWN_UNDER_MENU; } ScrollRect(&scrollRect, dx, dy, rgn); SetGWorld(saveWorld, saveDevice); /* * Fortunantly, the region returned by ScrollRect is symanticlly * the same as what we need to return in this function. If the * region is empty we return zero to denote that no damage was * created. */ if (EmptyRgn(rgn)) { return 0; } else { return 1; }}/* *---------------------------------------------------------------------- * * TkMacSetUpGraphicsPort -- * * Set up the graphics port from the given GC. * * Results: * None. * * Side effects: * The current port is adjusted. * *---------------------------------------------------------------------- */voidTkMacSetUpGraphicsPort( GC gc) /* GC to apply to current port. */{ RGBColor macColor; if (gPenPat == NULL) { gPenPat = NewPixPat(); } if (TkSetMacColor(gc->foreground, &macColor) == true) { /* TODO: cache RGBPats for preformace - measure gains... */ MakeRGBPat(gPenPat, &macColor); } PenNormal(); if(gc->function == GXxor) { PenMode(patXor); } if (gc->line_width > 1) { PenSize(gc->line_width, gc->line_width); }}/* *---------------------------------------------------------------------- * * TkMacSetUpClippingRgn -- * * Set up the clipping region so that drawing only occurs on the * specified X subwindow. * * Results: * None. * * Side effects: * The clipping region in the current port is changed. * *---------------------------------------------------------------------- */voidTkMacSetUpClippingRgn( Drawable drawable) /* Drawable to update. */{ MacDrawable *macDraw = (MacDrawable *) drawable; if (macDraw->winPtr != NULL) { if (macDraw->flags & TK_CLIP_INVALID) { TkMacUpdateClipRgn(macDraw->winPtr); } /* * When a menu is up, the Mac does not expect drawing to occur and * does not clip out the menu. We have to do it ourselves. This * is pretty gross. */ if (macDraw->clipRgn != NULL) { if (tkUseMenuCascadeRgn == 1) { Point scratch = {0, 0}; GDHandle saveDevice; GWorldPtr saveWorld; GetGWorld(&saveWorld, &saveDevice); SetGWorld(TkMacGetDrawablePort(drawable), NULL); LocalToGlobal(&scratch); SetGWorld(saveWorld, saveDevice); if (tmpRgn == NULL) { tmpRgn = NewRgn(); } CopyRgn(tkMenuCascadeRgn, tmpRgn); OffsetRgn(tmpRgn, -scratch.h, -scratch.v); DiffRgn(macDraw->clipRgn, tmpRgn, tmpRgn); SetClip(tmpRgn); macDraw->toplevel->flags |= TK_DRAWN_UNDER_MENU; } else { SetClip(macDraw->clipRgn); } } }}/* *---------------------------------------------------------------------- * * TkMacMakeStippleMap -- * * Given a drawable and a stipple pattern this function draws the * pattern repeatedly over the drawable. The drawable can then * be used as a mask for bit-bliting a stipple pattern over an * object. * * Results: * A BitMap data structure. * * Side effects: * None. * *---------------------------------------------------------------------- */BitMapPtrTkMacMakeStippleMap( Drawable drawable, /* Window to apply stipple. */ Drawable stipple) /* The stipple pattern. */{ MacDrawable *destDraw = (MacDrawable *) drawable; GWorldPtr destPort; BitMapPtr bitmapPtr; int width, height, stippleHeight, stippleWidth; int i, j; char * data; Rect bounds; destPort = TkMacGetDrawablePort(drawable); width = destPort->portRect.right - destPort->portRect.left; height = destPort->portRect.bottom - destPort->portRect.top; bitmapPtr = (BitMap *) ckalloc(sizeof(BitMap)); data = (char *) ckalloc(height * ((width / 8) + 1)); bitmapPtr->bounds.top = bitmapPtr->bounds.left = 0; bitmapPtr->bounds.right = (short) width; bitmapPtr->bounds.bottom = (short) height; bitmapPtr->baseAddr = data; bitmapPtr->rowBytes = (width / 8) + 1; destPort = TkMacGetDrawablePort(stipple); stippleWidth = destPort->portRect.right - destPort->portRect.left; stippleHeight = destPort->portRect.bottom - destPort->portRect.top; for (i = 0; i < height; i += stippleHeight) { for (j = 0; j < width; j += stippleWidth) { bounds.left = j; bounds.top = i; bounds.right = j + stippleWidth; bounds.bottom = i + stippleHeight; CopyBits(&((GrafPtr) destPort)->portBits, bitmapPtr, &((GrafPtr) destPort)->portRect, &bounds, srcCopy, NULL); } } return bitmapPtr;}/* *---------------------------------------------------------------------- * * InvertByte -- * * This function reverses the bits in the passed in Byte of data. * * Results: * The incoming byte in reverse bit order. * * Side effects: * None. * *---------------------------------------------------------------------- */static unsigned charInvertByte( unsigned char data) /* Byte of data. */{ unsigned char i; unsigned char mask = 1, result = 0; for (i = (1 << 7); i != 0; i /= 2) { if (data & mask) { result |= i; } mask = mask << 1; } return result;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -