// Create the offscreen GWorld (using Image as target memory) void QuicktimeLiveImageStream::createGWorld() { Rect destinationBounds; OSStatus err; GDHandle origDevice; CGrafPtr origPort; destinationBounds.left = 0; destinationBounds.top = 0; destinationBounds.right = m_videoRectWidth; destinationBounds.bottom = m_videoRectHeight; err = QTNewGWorldFromPtr(&m_gw, k32ARGBPixelFormat, &destinationBounds, NULL, NULL, 0, (Ptr)data(), 4*m_videoRectWidth); if (err !=0 ) { OSG_DEBUG << "Could not create gWorld" << std::endl; } else { // Query GetGWorld (&origPort, &origDevice); SetGWorld (m_gw, NULL); // set current graphics port to offscreen m_pixmap = GetGWorldPixMap(m_gw); if (m_pixmap) { if (!LockPixels (m_pixmap)) // lock offscreen pixel map { OSG_FATAL << "Could not lock PixMap" << std::endl; } } // Set back SetGWorld(origPort, origDevice); } }
void createOffscreen(int pictItem) { PicHandle pict; Rect rect; CGrafPtr currentPort; GDHandle currentDevice; if (gGWorld != nil) DisposeGWorld( gGWorld ); pict = (PicHandle)GetResource( 'PICT', pictItem + 127 ); rect = (**pict).picFrame; GetGWorld( ¤tPort, ¤tDevice ); NewGWorld( &gGWorld, 32, &rect, nil, nil, 0 ); LockPixels( GetPortPixMap(gGWorld)); SetGWorld( gGWorld, nil ); DrawPicture( pict, &rect ); SetGWorld( currentPort, currentDevice ); ReleaseResource( (Handle)pict ); }
bool MCRegionCalculateMask(MCRegionRef self, int32_t w, int32_t h, MCBitmap*& r_mask) { // Create a pixmap Pixmap t_image; t_image = MCscreen -> createpixmap(w, h, 1, False); // Draw into the pixmap's port CGrafPtr t_old_port; GDHandle t_old_device; GetGWorld(&t_old_port, &t_old_device); SetGWorld((CGrafPtr)t_image -> handle . pixmap, NULL); BackColor(whiteColor); ForeColor(blackColor); Rect t_rect; SetRect(&t_rect, 0, 0, w, h); EraseRect(&t_rect); PaintRgn((RgnHandle)self); SetGWorld(t_old_port, t_old_device); // Fetch the pixmap as a bitmap MCBitmap *t_bitmap; t_bitmap = MCscreen -> getimage(t_image, 0, 0, w, h, False); // Discard the pixmap MCscreen -> freepixmap(t_image); r_mask = t_bitmap; return true; }
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); }
// Same as above except that it quickly uses a gworld to allow the systems excellent routines to do // the business instead. short RGB2IndexGW(CTabHandle theTable,RGBColor *theCol) { Boolean openWorld=false; short index=-1; if (gBL_TintWorld==0L) { openWorld=true; OpenTintWorld(theTable); } if (gBL_TintWorld) { CGrafPtr origPort; GDHandle origGD; GetGWorld(&origPort,&origGD); SetGWorld(gBL_TintWorld,0L); SetCPixel(0,0,theCol); index=GPixelColour(GetGWorldPixMap(gBL_TintWorld),0,0); SetGWorld(origPort,origGD); } else return -1; if (openWorld) CloseTintWorld(); return index; }
void _set_port_to_gworld( void) { assert(!old_graphics_port && !old_graphics_device && !destination_graphics_port); GetGWorld(&old_graphics_port, &old_graphics_device); SetGWorld((GWorldPtr) world_pixels, NULL); destination_graphics_port= (GrafPtr) world_pixels; }
// 2. // Create the Video Digitizer (using GWorld Pixmap as target mamory) void QuicktimeLiveImageStream::createVideoDigitizer() { // #define videoDigitizerComponentType = 'vdig' ComponentDescription video_component_description; video_component_description.componentType = 'vdig'; /* A unique 4-byte code indentifying the command set */ video_component_description.componentSubType = 0; /* Particular flavor of this instance */ video_component_description.componentManufacturer = 0; /* Vendor indentification */ video_component_description.componentFlags = 0; /* 8 each for Component,Type,SubType,Manuf/revision */ video_component_description.componentFlagsMask = 0; /* Mask for specifying which flags to consider in search, zero during registration */ long num_video_components = CountComponents (&video_component_description); OSG_DEBUG << " available Video DigitizerComponents : " << num_video_components << std::endl; if (num_video_components) { Component aComponent = 0; short aDeviceID = 0; do { ComponentDescription full_video_component_description = video_component_description; aComponent = FindNextComponent(aComponent, &full_video_component_description); if (aComponent && (aDeviceID == m_videoDeviceID)) { OSG_DEBUG << "Component" << std::endl; OSErr err; Handle compName = NewHandle(256); Handle compInfo = NewHandle(256); err = GetComponentInfo( aComponent, &full_video_component_description, compName,compInfo,0); OSG_DEBUG << " Name: " << pstr_printable((StringPtr)*compName) << std::endl; OSG_DEBUG << " Desc: " << pstr_printable((StringPtr)*compInfo) << std::endl; //Capabilities VideoDigitizerComponent component_instance = OpenComponent(aComponent); m_vdig = component_instance; //Setup // Onscreen // Check capability and setting of Sequence Grabber GDHandle origDevice; CGrafPtr origPort; GetGWorld (&origPort, &origDevice); VideoDigitizerError error; Rect destinationBounds; destinationBounds.left = 0; destinationBounds.top = 0; destinationBounds.right = m_videoRectWidth; destinationBounds.bottom = m_videoRectHeight; error = VDSetPlayThruDestination(m_vdig, m_pixmap, &destinationBounds, 0, 0); //error = VDSetPlayThruGlobalRect(m_vdig, (GrafPtr)origPort, &destinationBounds); if (error != noErr) { OSG_FATAL << "VDSetPlayThruDestination : error" << std::endl; } print_video_component_capability(component_instance); break; } ++aDeviceID; } while (0 != aComponent); } }
void SaveQDDrawingState( QDDrawingState *ioDrawingState, const Boolean inSaveTextState ) { GWorldPtr tempWorld; GDHandle tempDevice; Assert( ioDrawingState != nil ); // Get the current GWorld, so I can access it's fields. GetGWorld( &tempWorld, &tempDevice ); // Get the background state. GetBackColor( &ioDrawingState->backColor ); /*#if !( defined( TARGET_API_MAC_CARBON ) && ( TARGET_API_MAC_CARBON == 1 ) ) if ( tempWorld->bkPixPat == nil ) ioDrawingState->backPixPatH = nil; else #endif ioDrawingState->backPixPatH = NewPixPat( ); if ( ioDrawingState->backPixPatH != nil ) GetPortBackPixPat( tempWorld, ioDrawingState->backPixPatH ); */ // Get the pen/foreground state. GetForeColor( &ioDrawingState->foreColor ); /*#if !( defined( TARGET_API_MAC_CARBON ) && ( TARGET_API_MAC_CARBON == 1 ) ) if ( tempWorld->pnPixPat == nil ) ioDrawingState->penPixPatH = nil; else #endif ioDrawingState->penPixPatH = NewPixPat( ); if ( ioDrawingState->penPixPatH != nil ) GetPortPenPixPat( tempWorld, ioDrawingState->penPixPatH ); */ GetPenState( &ioDrawingState->penState ); // Optionally save the text font, face, size and mode. ioDrawingState->haveTextState = inSaveTextState; if ( inSaveTextState ) { ioDrawingState->textStyle.tsFont = GetPortTextFont( tempWorld ); ioDrawingState->textStyle.tsFace = GetPortTextFace( tempWorld ); ioDrawingState->textStyle.tsSize = GetPortTextSize( tempWorld ); ioDrawingState->textMode = GetPortTextMode( tempWorld ); } #if ALIST_USEAPPEARANCEMGR && TARGET_RT_MAC_CFM // If we're running under CFM and have Appearance Mgr 1.1 or later, use the ThemeDrawingState routines. if ( local_AppearanceMgrVersion( ) > 0x0110 ) ioDrawingState->haveThemeState = ( GetThemeDrawingState( &ioDrawingState->themeState ) == noErr ); else { ioDrawingState->haveThemeState = false; ioDrawingState->themeState = nil; } #endif }
void _set_port_to_screen_window( void) { #if SUPPORT_DRAW_SPROCKET _set_port_to_gworld(); #else assert(!old_graphics_port && !old_graphics_device && !destination_graphics_port); GetGWorld(&old_graphics_port, &old_graphics_device); SetGWorld((GWorldPtr) screen_window, NULL); destination_graphics_port= (GrafPtr) screen_window; #endif }
void MCScreenDC::querymouse(int2 &x, int2 &y) { CGrafPtr oldport; GDHandle olddevice; GetGWorld(&oldport, &olddevice); MoveWindow(invisibleWin, 0, 0, False); // OS X moves this. SetGWorld(GetWindowPort(invisibleWin), GetMainDevice()); Point mloc; GetMouse(&mloc); //get local mouse position SetGWorld(oldport, olddevice); x = mloc.h; y = mloc.v; }
ALIST_API ControlPartCode ALSetFocus(ControlPartCode focusPart, ALHandle hAL) { ControlPartCode result; Boolean oldFocus; CGrafPtr savePort; WindowPtr winRef; if (hAL == nil || *hAL == nil) return kControlFocusNoPart; // Keep track of the old state of things. oldFocus = (BTST((*hAL)->flags, alFFocused) != 0); switch (focusPart) { case kControlFocusNoPart: // Turn off all focusing. BCLR((*hAL)->flags, alFFocused); result = kControlFocusNoPart; break; case kControlFocusNextPart: // Switch the state from off/on to on/off. case kControlFocusPrevPart: if (BTST((*hAL)->flags, alFFocused)) { // Turn off the focus. BCLR((*hAL)->flags, alFFocused); result = kControlFocusNoPart; } else { // Turn on the focus. BSET((*hAL)->flags, alFFocused); result = kControlListBoxPart; } break; case kControlListBoxPart: // Turn on focusing. BSET((*hAL)->flags, alFFocused); result = kControlListBoxPart; break; default: // simply return the state of focus result = (BTST((*hAL)->flags, alFFocused)) ? kControlListBoxPart : kControlFocusNoPart; break; } // If the focus changed, redraw if the alFDrawFocus feature is turned on. if ( BTST((*hAL)->features, alFDrawFocus) && oldFocus != (BTST((*hAL)->flags, alFFocused) != 0)) { GDHandle saveDevice; GetGWorld(&savePort, &saveDevice); ALGetInfo(alWindow, &winRef, hAL); SetPortWindowPort(winRef); _ALDrawListBorder(hAL); SetGWorld(savePort, saveDevice); } return result; } // ALSetFocus
// Create the Sequence Grabber Audio Channel void QuicktimeLiveImageStream::createSequenceGrabberAudioChannel() { // Check capability and setting of Sequence Grabber GDHandle origDevice; CGrafPtr origPort; // Create GWorld GetGWorld (&origPort, &origDevice); SetGWorld (m_gw, NULL); // set current graphics port to offscreen // Setup // Get a video channel ComponentResult result = SGNewChannel (m_gSeqGrabber, SoundMediaType, &m_gSoundChannel); if ((m_gSoundChannel != nil) && (result == noErr)) { result = SGInitChannel(m_gSoundChannel, m_gSeqGrabber); // result = SGSetChannelUsage (m_gSoundChannel, seqGrabPreview ); // Usage if (g_s_use_sg_record) result = SGSetChannelUsage (m_gSoundChannel, seqGrabRecord | seqGrabLowLatencyCapture); else { result = SGSetChannelUsage (m_gSoundChannel, seqGrabPreview | seqGrabRecord | seqGrabLowLatencyCapture); } // Get Str255 deviceName; Str255 inputName; short inputNumber; result = SGGetChannelDeviceAndInputNames(m_gSoundChannel, deviceName, inputName, &inputNumber); // Set // OSG_DEBUG << "Setting up audio component from input prefs" << std::endl; result = SGSetChannelDevice (m_gSoundChannel, m_soundDeviceIDStr); result = SGSetChannelDeviceInput(m_gSoundChannel, m_soundDeviceInputID); // Set the volume low to prevent feedback when we start the preview, // in case the mic is anywhere near the speaker. short volume = 0; result = SGGetChannelVolume (m_gSoundChannel, &volume); // result = SGSetChannelVolume (m_gSoundChannel, 255); // Inform result = SGChangedSource (m_gSeqGrabber, m_gSoundChannel); } else { OSG_FATAL << "Could not create SGNewChannel for Sound Channel" << std::endl; } // Set GWorld back SetGWorld(origPort, origDevice); }
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); }
// 1. // Create the Sequence Grabber (using GWorld as target memory) void QuicktimeLiveImageStream::createSequenceGrabber() { ComponentDescription sg_component_description; sg_component_description.componentType = SeqGrabComponentType; /* A unique 4-byte code indentifying the command set */ sg_component_description.componentSubType = 0L; /* Particular flavor of this instance */ sg_component_description.componentManufacturer = 'appl'; /* Vendor indentification */ sg_component_description.componentFlags = 0L; /* 8 each for Component,Type,SubType,Manuf/revision */ sg_component_description.componentFlagsMask = 0L; /* Mask for specifying which flags to consider in search, zero during registration */ long num_sg_components = CountComponents (&sg_component_description); if (num_sg_components) { Component aComponent = 0; ComponentDescription full_sg_component_description = sg_component_description; aComponent = FindNextComponent(aComponent, &full_sg_component_description); if (aComponent) { m_gSeqGrabber = OpenComponent(aComponent); // If we got a sequence grabber, set it up if (m_gSeqGrabber != 0L) { // Check capability and setting of Sequence Grabber GDHandle origDevice; CGrafPtr origPort; // Create GWorld GetGWorld (&origPort, &origDevice); SetGWorld (m_gw, NULL); // set current graphics port to offscreen // Initialize the sequence grabber ComponentResult result = noErr; result = SGInitialize (m_gSeqGrabber); if (result == noErr) { // Set GWorld result = SGSetGWorld(m_gSeqGrabber, (CGrafPtr)m_gw, 0); if (result != noErr) { OSG_FATAL << "Could not set GWorld on SG" << std::endl; } } // Set GWorld back SetGWorld(origPort, origDevice); } } } }
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); }
OSStatus MovieMaker::addFrame() { OSStatus error = noErr; Handle compressedData; short syncFlag; long dataSize; UnsignedWide now; CGrafPtr oldPort; GDHandle oldGDeviceH; GetGWorld(&oldPort, &oldGDeviceH); SetGWorld(gworld, nil); // Compress the frame and add it to the movie error = SCCompressSequenceFrame(ci,GetPortPixMap(gworld),&rect,&compressedData,&dataSize,&syncFlag); Microseconds(&now); if (error == noErr) { double duration = (now.lo - lastFrameTime.lo); // duration in microseconds duration *= GetMovieTimeScale(movie); duration *= 1.0 / 1000000.0; error = AddMediaSample( media, compressedData, 0, dataSize, (TimeValue)duration, (SampleDescriptionHandle)idh, 1, syncFlag, nil); } lastFrameTime = now; SetGWorld(oldPort, oldGDeviceH); return error; }
void mac_setfont(GWorldPtr world, Str255 fontname) { GDHandle oldGD; GWorldPtr oldGW; GetGWorld(&oldGW, &oldGD); LockPixels(world->portPixMap); { short fontID; SetGWorld( world, 0); GetFNum(fontname, &fontID); TextFont(fontID); TextSize(14); TextFace(extend/*|bold*/); } SetGWorld(oldGW, oldGD); UnlockPixels(world->portPixMap); }
PRIVATE GWorldPtr gworld_from_pict (PicHandle ph) { GWorldPtr retval; retval = NULL; if (ph) { CGrafPtr save_port; GDHandle save_device; Rect r; OSErr err; GetGWorld (&save_port, &save_device); save_port = MR (save_port); save_device = MR (save_device); r = HxX (ph, picFrame); err = NewGWorld (&retval, 32, &r, NULL, NULL, keepLocal); if (retval) { PixMapHandle pm; retval = MR (retval); SetGWorld (retval, NULL); pm = GetGWorldPixMap (retval); LockPixels (pm); DrawPicture (ph, &r); #if 0 #warning THIS INTERFERES WITH PICT PASTING { char *p; EraseRect (&r); p = GetPixBaseAddr (pm); memset (p, 0x00, 4 * RECT_HEIGHT(&r) * RECT_WIDTH (&r)); memset (p, 0xFF, 4 * RECT_HEIGHT(&r) * RECT_WIDTH (&r) / 2); } #endif UnlockPixels (pm); } SetGWorld (save_port, save_device); } return retval; }
void dev_draw_text_gmode(PixMapHandle pixmap, int x, int y, const char* s, int len, int pmask, int mode, int fgcolor, int bgcolor, int ton_mode) { //pixmap must be already locked GDHandle oldGD; GWorldPtr oldGW; int color, trans, width; Rect rect= {0,0,16,32}, destrect; GetGWorld(&oldGW, &oldGD); LockPixels(charbufWorld->portPixMap); SetGWorld(charbufWorld,0); trans=0; if( fgcolor==trans ) trans++; if( bgcolor==trans ) trans++; if( fgcolor==trans ) trans++; color= ( (mode&2)? bgcolor:trans ); dev_box(charbufWorld->portPixMap, rect, color, 0xFF); color= ( (mode&1)? fgcolor:trans ); charbufWorld->fgColor= color; TextMode(srcOr); MoveTo(0,13); DrawText(s,0,len); if( ton_mode==2 ){ expand_horizontality(charbufWorld->portPixMap, len*8, 16); } width= len*8; if( ton_mode==2 ) width*=2; rect.right=width; destrect.left=x; destrect.top=y; destrect.right=x+width; destrect.bottom=destrect.top+16; MyCopyBits(charbufWorld->portPixMap, pixmap, rect, destrect, 0x11/*trans*/, trans, pmask, 0, 0, NULL); SetGWorld(oldGW, oldGD); UnlockPixels(charbufWorld->portPixMap); }
void _HYPlatformGraphicPane::_StartDraw (void) { _HYGraphicPane * parent = (_HYGraphicPane*)this; GetGWorld (&savedPort,&savedDevice); ::GetForeColor (&saveFG); ::GetBackColor (&saveBG); SetGWorld (thePane,nil); LockPixels (GetGWorldPixMap(thePane)); RGBColor c = {256*parent->bColor.R,256*parent->bColor.G,256*parent->bColor.B}; if (parent->bColor.R+parent->bColor.B+(long)parent->bColor.G==765) c = (RGBColor){0xffff,0xffff,0xffff}; RGBBackColor (&c); c = (RGBColor){256*parent->color.R,256*parent->color.G,256*parent->color.B}; RGBForeColor (&c); //if (parent->depth>1) TextMode (srcOr); //else //TextMode (srcCopy); }
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); }
void TkMacSetUpClippingRgn( 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); } } } }
void DrawLobsterPICTtoGWorld(CGrafPtr destGWorld, Rect *srcRect) { // put the overlay into the GWorld, move the picture to the bottom right of the movie PicHandle pict = GetPicture(129); if (pict) { CGrafPtr oldPort; GDHandle oldDevice; Rect frame = (**pict).picFrame; GetGWorld(&oldPort, &oldDevice); SetGWorld(destGWorld, nil); // normalize coordinates OffsetRect(&frame, -frame.left, -frame.left); // grow frame to be as big as source rect OffsetRect(&frame, srcRect->right - frame.right, srcRect->bottom - frame.bottom); DrawPicture(pict, &frame); SetGWorld(oldPort, oldDevice); ReleaseResource((Handle)pict); } }
void drawWindowFrame(WindowRef window) { /*------------------------------------------------------ Draw the frame of our window. This function needs to draw the title bar, the grow box, the title string and the structural aspects of the window. --------------------------------------------------------*/ static GWorldPtr framePict=NULL; static Rect pictureRect; GrafPtr thePort; Rect frame; if(!framePict){//haven't cached our picture PicHandle myPicture=GetPicture(kPictureID); GrafPtr origPort; GDHandle origDev; GetGWorld(&origPort,&origDev); pictureRect=(*myPicture)->picFrame; NewGWorld(&framePict,0,&pictureRect,NULL,NULL,0); SetGWorld(framePict,NULL); DrawPicture(myPicture,&pictureRect); SetGWorld(origPort,origDev); ReleaseResource((Handle)myPicture); } getCurrentPortBounds(&frame); GetPort(&thePort); CopyBits(GetPortBitMapForCopyBits(framePict), GetPortBitMapForCopyBits(thePort), &pictureRect,&frame,srcCopy,NULL);//draw our picture myWindowDrawGrowBox(window,0);//draw grow box as part of frame if(IsWindowHilited(window)) { //do any hilighting } }
RgnHandle getWindowStructureRegion(WindowRef window, RgnHandle structureRegion) { /*------------------------------------------------------ Define the structural region of our window. --------------------------------------------------------*/ static RgnHandle pictureRgn=NULL; static Rect pictureRect; Rect windowRect; SetEmptyRgn(structureRegion); if(!pictureRgn){//haven't Cached our region yet PicHandle myPicture=GetPicture(kMaskPictureID); GrafPtr origPort; GDHandle origDev; GWorldPtr pictMask; PixMapHandle maskBitMap; GetGWorld(&origPort,&origDev); pictureRgn=NewRgn(); pictureRect=(*myPicture)->picFrame; NewGWorld(&pictMask,1,&pictureRect,NULL,NULL,0); maskBitMap=GetPortPixMap(pictMask); LockPixels(maskBitMap); SetGWorld(pictMask,NULL); EraseRect(&pictureRect); DrawPicture(myPicture,&pictureRect); BitMapToRegion(pictureRgn,(BitMap*)*maskBitMap);//use the mask to create a region InsetRgn(pictureRgn,1,1); SetGWorld(origPort,origDev); UnlockPixels(maskBitMap); DisposeGWorld(pictMask); ReleaseResource((Handle)myPicture); } getCurrentPortBounds(&windowRect);//how big is the window CopyRgn(pictureRgn,structureRegion);//make a copy of our cached region MapRgn(structureRegion,&pictureRect,&windowRect);//scale it to our actual window size return structureRegion; }
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); }
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); }
int TkScrollWindow( 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; } }
void XFillArc( 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); }
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); }