wxPaintDC::wxPaintDC(wxWindow *window) { m_window = window ; wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; wxPoint origin = window->GetClientAreaOrigin() ; wxSize size = window->GetClientSize() ; int x , y ; x = origin.x ; y = origin.y ; window->MacWindowToRootWindow( &x , &y ) ; m_macLocalOrigin.x = x ; m_macLocalOrigin.y = y ; SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; m_macPort = UMAGetWindowPort( windowref ) ; m_ok = TRUE ; SetBackground(window->MacGetBackgroundBrush()); SetFont( window->GetFont() ) ; }
/*Assumes that all regions are in the guest coordinates system*/ static void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *window) { ContextInfo *c = renderspuGetWindowContext(window); RgnHandle rgn; GLboolean result = true; DEBUG_MSG_POETZSCH (("ApplyVisibleRegion %x\n", window)); if (!c || !c->context) return; rgn = NewRgn(); SetEmptyRgn(rgn); if (render_spu.hRootVisibleRegion) { /* The render_spu.hRootVisibleRegion has coordinates from the root * window. We intersect it with the rect of the OpenGL window we * currently process. */ SetRectRgn(rgn, window->x, window->y, window->x + window->BltInfo.width, window->y + window->BltInfo.height); SectRgn(render_spu.hRootVisibleRegion, rgn, rgn); /* Because the clipping is done in the coordinate space of the OpenGL * window we have to remove the x/y position from the newly created * region. */ OffsetRgn (rgn, -window->x, -window->y); } else { /* If there is not root clipping region is available, create a base * region with the size of the target window. This covers all * needed/possible space. */ SetRectRgn(rgn, 0, 0, window->BltInfo.width, window->BltInfo.height); } /* Now intersect the window clipping region with a additional region e.g. * for the seamless mode. */ if (window->hVisibleRegion) SectRgn(rgn, window->hVisibleRegion, rgn); if (rgn && !EmptyRgn(rgn)) { /* Set the clip region to the context */ result = render_spu.ws.aglSetInteger(c->context, AGL_CLIP_REGION, (const GLint*)rgn); CHECK_AGL_RC (result, "Render SPU (renderspu_SystemWindowVisibleRegion): SetInteger Failed"); result = render_spu.ws.aglEnable(c->context, AGL_CLIP_REGION); CHECK_AGL_RC (result, "Render SPU (renderspu_SystemWindowVisibleRegion): Enable Failed"); } /* Clear the region structure */ DisposeRgn (rgn); }
int TkRectInRegion( TkRegion region, int x, int y, unsigned int width, unsigned int height) { RgnHandle rgn = (RgnHandle) region; RgnHandle rectRgn, destRgn; int result; rectRgn = NewRgn(); destRgn = NewRgn(); SetRectRgn(rectRgn, x, y, x + width, y + height); SectRgn(rgn, rectRgn, destRgn); if (EmptyRgn(destRgn)) { result = RectangleOut; } else if (EqualRgn(rgn, destRgn)) { result = RectangleIn; } else { result = RectanglePart; } DisposeRgn(rectRgn); DisposeRgn(destRgn); return result; }
void TkIntersectRegion( TkRegion sra, TkRegion srb, TkRegion dr_return) { RgnHandle srcRgnA = (RgnHandle) sra; RgnHandle srcRgnB = (RgnHandle) srb; RgnHandle destRgn = (RgnHandle) dr_return; SectRgn(srcRgnA, srcRgnB, destRgn); }
void wxTopLevelWindowMac::MacUpdate( long timestamp) { wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; RgnHandle visRgn = NewRgn() ; GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), visRgn ); BeginUpdate( (WindowRef)m_macWindow ) ; RgnHandle updateRgn = NewRgn(); RgnHandle diffRgn = NewRgn() ; if ( updateRgn && diffRgn ) { #if 1 // macos internal control redraws clean up areas we'd like to redraw ourselves // therefore we pick the boundary rect and make sure we can redraw it // this has to be intersected by the visRgn in order to avoid drawing over its own // boundaries RgnHandle trueUpdateRgn = NewRgn() ; Rect trueUpdateRgnBoundary ; GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn ); GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ; RectRgn( updateRgn , &trueUpdateRgnBoundary ) ; SectRgn( updateRgn , visRgn , updateRgn ) ; if ( trueUpdateRgn ) DisposeRgn( trueUpdateRgn ) ; SetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ; #else GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); #endif DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; if ( !EmptyRgn( updateRgn ) ) { MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; } } if ( updateRgn ) DisposeRgn( updateRgn ); if ( diffRgn ) DisposeRgn( diffRgn ); if ( visRgn ) DisposeRgn( visRgn ) ; EndUpdate( (WindowRef)m_macWindow ) ; SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; m_macNeedsErasing = false ; }
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); }
void TkMacUpdateClipRgn( TkWindow *winPtr) { RgnHandle rgn; int x, y; TkWindow *win2Ptr; if (winPtr == NULL) { return; } if (winPtr->privatePtr->flags & TK_CLIP_INVALID) { rgn = winPtr->privatePtr->aboveClipRgn; if (tmpRgn == NULL) { tmpRgn = NewRgn(); } /* * Start with a region defined by the window bounds. */ x = winPtr->privatePtr->xOff; y = winPtr->privatePtr->yOff; SetRectRgn(rgn, (short) x, (short) y, (short) (winPtr->changes.width + x), (short) (winPtr->changes.height + y)); /* * Clip away the area of any windows that may obscure this * window. * For a non-toplevel window, first, clip to the parents visable * clip region. * Second, clip away any siblings that are higher in the * stacking order. * For an embedded toplevel, just clip to the container's visible * clip region. Remember, we only allow one contained window * in a frame, and don't support any other widgets in the frame either. * This is not currently enforced, however. */ if (!Tk_IsTopLevel(winPtr)) { TkMacUpdateClipRgn(winPtr->parentPtr); SectRgn(rgn, winPtr->parentPtr->privatePtr->aboveClipRgn, rgn); win2Ptr = winPtr->nextPtr; while (win2Ptr != NULL) { if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) { win2Ptr = win2Ptr->nextPtr; continue; } x = win2Ptr->privatePtr->xOff; y = win2Ptr->privatePtr->yOff; SetRectRgn(tmpRgn, (short) x, (short) y, (short) (win2Ptr->changes.width + x), (short) (win2Ptr->changes.height + y)); DiffRgn(rgn, tmpRgn, rgn); win2Ptr = win2Ptr->nextPtr; } } else if (Tk_IsEmbedded(winPtr)) { TkWindow *contWinPtr; contWinPtr = TkpGetOtherWindow(winPtr); if (contWinPtr != NULL) { TkMacUpdateClipRgn(contWinPtr); SectRgn(rgn, contWinPtr->privatePtr->aboveClipRgn, rgn); } else if (gMacEmbedHandler != NULL) { gMacEmbedHandler->getClipProc((Tk_Window) winPtr, tmpRgn); SectRgn(rgn, tmpRgn, rgn); } /* * NOTE: Here we should handle out of process embedding. */ } /* * The final clip region is the aboveClip region (or visable * region) minus all the children of this window. * Alternatively, if the window is a container, we must also * subtract the region of the embedded window. */ rgn = winPtr->privatePtr->clipRgn; CopyRgn(winPtr->privatePtr->aboveClipRgn, rgn); win2Ptr = winPtr->childList; while (win2Ptr != NULL) { if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) { win2Ptr = win2Ptr->nextPtr; continue; } x = win2Ptr->privatePtr->xOff; y = win2Ptr->privatePtr->yOff; SetRectRgn(tmpRgn, (short) x, (short) y, (short) (win2Ptr->changes.width + x), (short) (win2Ptr->changes.height + y)); DiffRgn(rgn, tmpRgn, rgn); win2Ptr = win2Ptr->nextPtr; } if (Tk_IsContainer(winPtr)) { win2Ptr = TkpGetOtherWindow(winPtr); if (win2Ptr != NULL) { if (Tk_IsMapped(win2Ptr)) { x = win2Ptr->privatePtr->xOff; y = win2Ptr->privatePtr->yOff; SetRectRgn(tmpRgn, (short) x, (short) y, (short) (win2Ptr->changes.width + x), (short) (win2Ptr->changes.height + y)); DiffRgn(rgn, tmpRgn, rgn); } } /* * NOTE: Here we should handle out of process embedding. */ } winPtr->privatePtr->flags &= ~TK_CLIP_INVALID; } }
void DrawNoSectPolyRecursive (CMap *theMap, PolyObjectHdl MapPolyHdl, DrawSpecRecPtr drawSettings,Rect subRect) { long PointCount, PlotCount = 0, PointIndex; LongPoint MatrixPt; Point LastScrPt, ThisScrPt, FirstScrPt; LongPoint **RgnPtsHdl; PolyHandle PolyHdl = nil; //////////// Boolean alwaysIn123 = true; Boolean alwaysIn174 = true; Boolean alwaysIn456 = true; Boolean alwaysIn386 = true; Boolean canSkipDrawingPolygon = false; // 1 7 4 // 2 0 5 // 3 8 6 //////////////// PointCount = GetPolyPointCount (MapPolyHdl); RgnPtsHdl = GetPolyPointsHdl (MapPolyHdl); Boolean bDrawBlackAndWhite = (sharedPrinting && settings.printMode != COLORMODE); #define MAXNUMSEGMENTS 8000 // JLM, It seems the limit is 32K not 64K at the documentation says short thisSectionOfPlane,prevSectionOfPlane; Boolean canSkipThisPt,skippedAPt,offQuickDrawPlane=false; Point lastSkippedPt; Rect fuzzyRect = subRect; long lineWidth = 1, esiCode; long outsetPixels = 2*lineWidth+2; // needs to be wider that the line width //long penWidth = 3; long penWidth = 2; long halfPenWidth = 0; InsetRect(&fuzzyRect,-outsetPixels,-outsetPixels); if (RgnPtsHdl != nil) { // must clip to this rect in addtion to the original clip Rect clippingRect = subRect; RgnHandle saveClip = NewRgn(), addition = NewRgn() , newClip = NewRgn(); GetClip(saveClip); GetClip(newClip); RectRgn(addition, &clippingRect); SectRgn(newClip, addition, newClip); SetClip(newClip); if(newClip) DisposeRgn(newClip); if(addition) DisposeRgn(addition); if (drawSettings -> fillCode != kNoFillCode) PolyHdl = OpenPoly (); else { PolyHdl = OpenPoly (); //Our_PmForeColor (gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd); Our_PmForeColor (drawSettings -> foreColorInd); } GetObjectESICode ((ObjectRecHdl) MapPolyHdl,&esiCode); if (esiCode>0) // -500 is the default { //halfPenWidth = penWidth/2; #ifdef MAC PenSize(penWidth,penWidth); #else PenStyle(BLACK,penWidth); #endif } for (PointIndex = 0,skippedAPt = false,prevSectionOfPlane = -1; PointIndex < PointCount; ++PointIndex) { MatrixPt = (*RgnPtsHdl) [PointIndex]; // theMap -> GetScrPoint (&MatrixPt, &ThisScrPt); //ThisScrPt.h = SameDifferenceX(MatrixPt.h); //ThisScrPt.v = (gRect.bottom + gRect.top) - SameDifferenceY(MatrixPt.v); ThisScrPt = GetQuickDrawPt(MatrixPt.h, MatrixPt.v, &gRect, &offQuickDrawPlane); // code goes here, what to do when point is off quickdraw plane? //if (offQuickDrawPlane) break; ThisScrPt.h += drawSettings -> offsetDx; ThisScrPt.v += drawSettings -> offsetDy; if(PolyHdl) { //// JLM 2/18/99 // for points outside the drawing area, it is not necessary to move to the correct point, // as long as we preserve the winding. This allows us to ignore many of the points outside // the drawing rectangle gRect thisSectionOfPlane = SectionOfPlane(&fuzzyRect,ThisScrPt); if( thisSectionOfPlane > 0 // outside of the rectangle && thisSectionOfPlane == prevSectionOfPlane // we have not changed sections of the plane && PointIndex < PointCount -1) // not the last point canSkipThisPt = true; else canSkipThisPt = false; prevSectionOfPlane = thisSectionOfPlane; if(canSkipThisPt) { skippedAPt = true; lastSkippedPt =ThisScrPt; continue; } /// JLM 3/6/01 switch(thisSectionOfPlane) { case 1: alwaysIn456 = false; alwaysIn386 = false; break; case 2: alwaysIn174 = false; alwaysIn456 = false; alwaysIn386 = false; break; case 3: alwaysIn174 = false; alwaysIn456 = false; break; case 4: alwaysIn123 = false; alwaysIn386 = false; break; case 5: alwaysIn123 = false; alwaysIn174 = false; alwaysIn386 = false; break; case 6: alwaysIn123 = false; alwaysIn174 = false; break; case 7: alwaysIn123 = false; alwaysIn456 = false; alwaysIn386 = false; break; case 8: alwaysIn123 = false; alwaysIn174 = false; alwaysIn456 = false; break; default: alwaysIn123 = false; alwaysIn174 = false; alwaysIn456 = false; alwaysIn386 = false; break; } ////// if(skippedAPt) { // then we have to draw to the previous point // before we draw to the current point PointIndex--; //so we do the previous point below ThisScrPt = lastSkippedPt; // restore the coordinates of the previous point prevSectionOfPlane = -1; // force the next point to not be skipped } skippedAPt = false; if(PlotCount > MAXNUMSEGMENTS) { // there is a bug on the max when the number of points gets too large // try recusion ClosePoly(); KillPoly(PolyHdl); SetClip(saveClip);// JLM 8/4/99 goto recursion; } ////////////// } if (PointIndex == 0) { MyMoveTo (ThisScrPt.h-halfPenWidth, ThisScrPt.v-halfPenWidth); FirstScrPt = ThisScrPt; LastScrPt = ThisScrPt; PlotCount = 0; } else { if (LastScrPt.h != ThisScrPt.h || LastScrPt.v != ThisScrPt.v) { MyLineTo (ThisScrPt.h-halfPenWidth, ThisScrPt.v-halfPenWidth); LastScrPt = ThisScrPt; ++PlotCount; } } } if (drawSettings -> bClosed) /* draw a line from last point to first point if requested */ { MyLineTo (FirstScrPt.h-halfPenWidth, FirstScrPt.v-halfPenWidth); ++PlotCount; } if (PolyHdl != nil) { ClosePoly (); ////////////// JLM 3/6/01 if(alwaysIn123 || alwaysIn174 || alwaysIn456 || alwaysIn386) canSkipDrawingPolygon = true; if(canSkipDrawingPolygon) PlotCount = 0; // so that we skip the code below //////////// if (PlotCount > 0) { if (PlotCount > 2) /* polygon must contain more than 2 line-to points */ { if (drawSettings -> bErase || (drawSettings -> fillCode == kNoFillCode && drawSettings -> backColorInd == kWaterColorInd)) ErasePoly (PolyHdl); if (drawSettings -> fillCode == kPaintFillCode) { // this is the usual drawing code Our_PmForeColor (bDrawBlackAndWhite || gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd);//JLM if(bDrawBlackAndWhite) SetPenPat(UPSTRIPES); PaintPoly(PolyHdl);//JLM if(bDrawBlackAndWhite) SetPenPat(BLACK); } else if (drawSettings -> fillCode == kPatFillCode) FillPoly (PolyHdl, &(drawSettings -> backPattern)); } if (drawSettings -> frameCode == kPaintFrameCode) { Our_PmForeColor (bDrawBlackAndWhite || gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd); FramePoly (PolyHdl); } else if (drawSettings -> frameCode == kPatFrameCode) { PenPat (&(drawSettings -> forePattern)); FramePoly (PolyHdl); } } KillPoly (PolyHdl); } SetClip(saveClip); if(saveClip) DisposeRgn(saveClip); } #ifdef MAC PenSize(1,1); #else PenStyle(BLACK,1); #endif return; //////////////////////////////// recursion: //////////////////////////////// { #define MAXRECURSION 20 static short sRecursionValue = 0; if(sRecursionValue >= MAXRECURSION) { printError("max recusion exceeded"); } else { // use recursion Rect subBoundingRect; long middleH = (subRect.left+subRect.right)/2; long middleV = (subRect.top+subRect.bottom)/2; long index; sRecursionValue++; // divide the points up and Draw again for(index = 0; index < 4; index++) { subBoundingRect = subRect; switch(index) { case 0: subBoundingRect.top = middleV; subBoundingRect.left = middleH; break; case 1: subBoundingRect.top = middleV; subBoundingRect.right = middleH; break; case 2: subBoundingRect.bottom = middleV; subBoundingRect.left = middleH; break; default: subBoundingRect.bottom = middleV; subBoundingRect.right = middleH; break; } // the recursive call DrawNoSectPolyRecursive (theMap,MapPolyHdl,drawSettings,subBoundingRect); } // all done sRecursionValue--; return; } } }
void shellupdatecontent (Rect contentrect) { /* update the portion of contectrect in shellwindow that needs updating, and validate the area updated 2/11/91 dmb: it turns out that we usually want to update the scroll bars at this time too, before redrawing contectrect 12/9/91 dmb: quick bail-out if update rgn is empty 9/22/92 dmb: don't draw scrollbars when update rgn is empty */ register hdlwindowinfo hw = shellwindowinfo; register hdlregion contentrgn, updatergn; hdlregion actualupdatergn; actualupdatergn = getupdateregion (shellwindow); if (EmptyRgn (actualupdatergn)) { #ifdef WIN95VERSION DeleteObject (actualupdatergn); #endif return; } shellupdatescrollbars (hw); updatergn = NewRgn (); CopyRgn (actualupdatergn, updatergn); /*window's update rgn is global*/ globaltolocalrgn (updatergn); #ifdef MACVERSION RectRgn (contentrgn = NewRgn (), &contentrect); #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 //in carbon a copy of the update region is returned. DisposeRgn(actualupdatergn); actualupdatergn = nil; #endif #endif #ifdef WIN95VERSION DeleteObject (actualupdatergn); insetrect (&contentrect, -1, -1); contentrgn = CreateRectRgn (contentrect.left, contentrect.top, contentrect.right, contentrect.bottom); #endif SectRgn (contentrgn, updatergn, contentrgn); /*re-use contentrgn*/ #if defined(WIN95VERSION) && fldebug /****** DEBUG CODE *********/ if (false) { RECT rrr; GetClientRect (shellwindow, &rrr); DeleteObject(contentrgn); contentrgn = CreateRectRgn (rrr.left, rrr.top, rrr.right, rrr.bottom); FillRect (getport(), &rrr, GetStockObject (WHITE_BRUSH)); } #endif if (!EmptyRgn (contentrgn)) { (**hw).drawrgn = contentrgn; /*for display routines to refer to*/ //Code change by Timothy Paustian Monday, June 19, 2000 3:09:46 PM //Changed to Opaque call for Carbon #ifdef MACVERSION #if TARGET_API_MAC_CARBON == 1 ValidWindowRgn((WindowRef) hw, contentrgn); #else ValidRgn (contentrgn); /*no need to draw it again. do now to simulate beginupdate*/ #endif #endif #ifdef WIN95VERSION ValidateRgn (shellwindow, contentrgn); #endif pushcliprgn (contentrgn, false); (*shellglobals.updateroutine) (); popclip (); (**hw).drawrgn = nil; /*keep it neat, this guy is a temp*/ } DisposeRgn (updatergn); DisposeRgn (contentrgn); } /*shellupdatecontent*/