void drawPixelImageData() { int row, col; Rect rect; unsigned char value; char *image; int index = 0; Str255 string; RGBColor color = { 32000, 32000, 32000 }; //Byte mode; Rect tempRect1; ForeColor( blackColor ); SetRect( &rect, 0, 0, 20, 20 ); /* For this example, let's just use only the upper left corner of the image. */ // Draw the offscreen image to the screen to see what it looks like. //CopyBits( (BitMap *)*gPixmap, &gWindow->portBits, &rect, // &gWindow->portRect, srcCopy, 0 ); //(**gPixmap).rowBytes ^= 0x8000; CopyBits( (BitMap *)*gPixmap, GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &rect, GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0 ); //(**gPixmap).rowBytes ^= 0x8000; RGBForeColor( &color ); // Again, set the pointer to the beginning of the pixel image. image = GetPixBaseAddr( gPixmap ); /***************************************************************/ /* Finally let's display the pixel values on top of the image. */ /***************************************************************/ /* Loop through the first 20 rows of the pixel image. */ for (row = 0; row < rect.bottom; row++) { // Loop through the first 20 columns of the pixel image. for (index = 0, col = 0; col < rect.right; col++) { // Get the value at this index into the pixel image. value = (unsigned char)*(image + index); MoveTo( col * 30, row * 20 ); LineTo( col * 30, (row + 1) * 20 ); LineTo( (col + 1) * 30, (row + 1) * 20 ); MoveTo( (col * 30) + 6, (row * 20) + 14 ); NumToString( (long)value, string ); DrawString( string ); index++; } // Increment the pointer to the next row of the pixel image. image += ((**gPixmap).rowBytes & 0x7fff); } }
void _HYPlatformGraphicPane::_CopyToClipboard (void) { _HYGraphicPane* parent = (_HYGraphicPane*)this; #ifdef TARGET_API_MAC_CARBON ClearCurrentScrap(); #else ZeroScrap(); #endif Rect bRect; bRect.left = bRect.top = 0; bRect.right = parent->w; bRect.bottom = parent->h; PicHandle pic = OpenPicture (&bRect); GrafPtr topPort; GetPort (&topPort); LockPixels (GetGWorldPixMap(thePane)); #ifdef OPAQUE_TOOLBOX_STRUCTS CopyBits (GetPortBitMapForCopyBits(thePane),GetPortBitMapForCopyBits(topPort), &bRect,&bRect,srcCopy,(RgnHandle)nil); #else CopyBits ((BitMap*)*GetGWorldPixMap(thePane), (BitMap*)&(topPort->portBits),&bRect,&bRect, srcCopy,(RgnHandle)nil); #endif UnlockPixels (GetGWorldPixMap(thePane)); ClosePicture (); HLock ((Handle)pic); #ifdef TARGET_API_MAC_CARBON ScrapRef theScrapRef; GetCurrentScrap(&theScrapRef); PutScrapFlavor(theScrapRef, 'PICT', kScrapFlavorMaskNone,GetHandleSize((Handle)pic),*pic); #else PutScrap (GetHandleSize((Handle)pic),'PICT',*pic); #endif KillPicture (pic); }
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 } }
static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects) { GWorldPtr memworld; GrafPtr saveport; CGrafPtr thePort; const BitMap *memBits; const BitMap *winBits; int i; Rect update; /* Copy from the offscreen GWorld to the window port */ GetPort(&saveport); SetPortWindowPort(SDL_Window); thePort = GetWindowPort(SDL_Window); memworld = (GWorldPtr)GetWRefCon(SDL_Window); #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld); #else memBits = &((GrafPtr)memworld)->portBits; #endif #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS winBits = GetPortBitMapForCopyBits(thePort); #else winBits = &SDL_Window->portBits; #endif for ( i=0; i<numrects; ++i ) { update.left = rects[i].x; update.right = rects[i].x+rects[i].w; update.top = rects[i].y; update.bottom = rects[i].y+rects[i].h; CopyBits(memBits, winBits, &update, &update, srcCopy, nil); } #if TARGET_API_MAC_CARBON if ( QDIsPortBuffered(thePort) ) { QDFlushPortBuffer(thePort, NULL); } #endif SetPort(saveport); }
void drawImage(WindowPtr theWindow) { Rect tempRect1; /* Copy the offscreen image back onto the window. */ //CopyBits( (BitMap *)&gPixMap, &gWindow->portBits, &gPixMap.bounds, // &gWindow->portRect, srcCopy, 0l); CopyBits( (BitMap *)&gPixMap, GetPortBitMapForCopyBits(GetWindowPort(theWindow)), &gPixMap.bounds, GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0L); ShowWindow( gWindow ); }
void drawSourceImage() { Rect rect; Rect outlineRect; Rect tempRect1; GetPortBounds(gGWorld, &tempRect1); SetRect( &rect, 20, 37, 20 + tempRect1.right, 37 + tempRect1.bottom); outlineRect = rect; InsetRect( &outlineRect, -5, -5 ); drawDeepBox( &outlineRect ); ForeColor( blackColor ); BackColor( whiteColor ); CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &((**(GetPortPixMap(gGWorld))).bounds), &rect, srcCopy, nil ); }
static boolean plotsmallicon (Rect r, short iconlist, short iconnum, boolean flinvert) { hdlsmalliconbits hbits; short mode; BitMap bmap; GrafPtr w; GetPort (&w); hbits = (hdlsmalliconbits) GetResource ('SICN', iconlist); if (hbits == nil) /*failed to load the resource*/ return (false); r.right = r.left + widthsmallicon; /*we only pay attention to the top, left fields of rectangle*/ r.bottom = r.top + heightsmallicon; bmap.baseAddr = (Ptr) &(*hbits) [iconnum]; bmap.rowBytes = 2; bmap.bounds.top = bmap.bounds.left = 0; bmap.bounds.bottom = r.bottom - r.top; bmap.bounds.right = r.right - r.left; if (flinvert) mode = notSrcCopy; else mode = srcOr; //Code change by Timothy Paustian Saturday, May 20, 2000 10:06:20 PM //Changed to Opaque call for Carbon //I have not tested this yet. #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 CopyBits(&bmap, GetPortBitMapForCopyBits(w), &bmap.bounds, &r, mode, nil); #else CopyBits (&bmap, &(*w).portBits, &bmap.bounds, &r, mode, nil); #endif return (true); } /*plotsmallicon*/
void x_async_refresh(CGContextRef myContext,CGRect myBoundingBox) { #ifdef ENABLEQD CEmulatorMac* pEmu = (CEmulatorMac*)CEmulator::theEmulator; if (!pEmu) return ; #endif #ifndef DRIVER_IOS x_vbl_count++; #endif addFrameRate(0); CHANGE_BORDER(1,0xFF); // OG if (macUsingCoreGraphics) { if(r_sim65816.is_emulator_offscreen_available() && g_kimage_offscreen.dev_handle) { /* void addConsoleWindow(Kimage* _dst); addConsoleWindow(&g_kimage_offscreen); */ CGContextSaveGState(myContext); #ifndef DRIVER_IOS // CGContextTranslateCTM(myContext,0.0, X_A2_WINDOW_HEIGHT); CGContextTranslateCTM(myContext,0.0, myBoundingBox.size.height); CGContextScaleCTM(myContext,1.0,-1.0); #endif CGImageRef myImage = CGBitmapContextCreateImage((CGContextRef)g_kimage_offscreen.dev_handle); CGContextDrawImage(myContext, myBoundingBox, myImage);// 6 #ifndef VIDEO_SINGLEVLINE if (r_sim65816.get_video_fx() == VIDEOFX_CRT) { CGContextSetRGBFillColor(myContext,0,0,0,0.5); for(int h=0;h<g_kimage_offscreen.height;h+=2) { CGRect r = CGRectMake(0,h,g_kimage_offscreen.width_act,1); CGContextFillRect(myContext,r); } } #endif CGImageRelease(myImage); CGContextRestoreGState(myContext); #ifndef DRIVER_IOS if (!messageLine.IsEmpty()) { CGContextSaveGState(myContext); CGContextSetTextMatrix(myContext,CGAffineTransformIdentity); CGContextTranslateCTM(myContext,0.0, X_A2_WINDOW_HEIGHT); CGContextScaleCTM(myContext,1.0,-1.0); CGContextSelectFont(myContext, "Courier", 14.0, kCGEncodingMacRoman); CGContextSetTextDrawingMode(myContext, kCGTextFill); CGContextSetRGBFillColor (myContext, 1,1, 1, 1); CGContextSetShouldAntialias(myContext, true); #define SHADOW 4.0 CGFloat myColorValues[] = {0.5, 0.5, 0.5, 1.0}; CGColorSpaceRef myColorSpace = CGColorSpaceCreateDeviceRGB ();// 9 CGColorRef myColor = CGColorCreate (myColorSpace, myColorValues); CGContextSetShadowWithColor(myContext, CGSizeMake(SHADOW, -SHADOW), 4, myColor //CGColorCreateGenericGray(0.5,1.0) ); CGContextShowTextAtPoint(myContext, 20.0, X_A2_WINDOW_HEIGHT-20.0, messageLine.c_str(), messageLine.GetLength()); CGContextRestoreGState(myContext); messageLineVBL--; if (messageLineVBL<0) messageLine.Empty(); else x_refresh_video(); } #endif } else { CGContextSaveGState(myContext); #if defined(DRIVER_IOS) // efface en noir si l'émulateur n'avait pas encore démarré (le cas sur 3GS) CGContextSetRGBFillColor (myContext, 0, 0, 0, 1); #else CGContextSetRGBFillColor (myContext, 0, 0, 1, 1); #endif CGContextFillRect (myContext, CGRectMake (0, 0, X_A2_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT)); CGContextRestoreGState(myContext); } } else { #ifdef ENABLEQD CGrafPtr window_port = pEmu->window_port; Rect src_rect; Rect dest_rect; SetRect(&src_rect,0,0,704,462); SetRect(&dest_rect,0,0,704,462); if (pixmap_backbuffer) CopyBits( (BitMap *)(*pixmap_backbuffer), GetPortBitMapForCopyBits(window_port), &src_rect, &dest_rect, srcCopy, NULL); #endif } CHANGE_BORDER(1,0); if (r_sim65816.is_emulator_offscreen_available() && g_driver.x_handle_state_on_paint) g_driver.x_handle_state_on_paint(myBoundingBox.size.width,myBoundingBox.size.height); }
//----------------------------------------------------------------------------- // QutTexture_CreateGWorldFromPICT : Create a GWorld from a PICT. //----------------------------------------------------------------------------- GWorldPtr QutTexture_CreateGWorldFromPICT(PicHandle thePicture, TQ3PixelType pixelType) { GWorldPtr deepGWorld, theGWorld; Boolean shouldDither; GDHandle saveDevice; CGrafPtr savePort; TQ3Uns32 theDepth; OSErr theErr; // Work out the depth of GWorld, and if it should be dithered if (pixelType == kQ3PixelTypeARGB16 || pixelType == kQ3PixelTypeRGB16) theDepth = 16; else theDepth = 32; shouldDither = (theDepth == 16); // Create a GWorld to hold the image data theErr = NewGWorld(&theGWorld, theDepth, &(*thePicture)->picFrame, NULL, NULL, useTempMem | kQ3NativeEndianPixMap ); if (theErr != noErr || theGWorld == NULL) return(NULL); // If we should dither, create a deep GWorld if (theDepth == 16 && shouldDither) theErr = NewGWorld(&deepGWorld, 32, &(*thePicture)->picFrame, NULL, NULL, useTempMem | kQ3NativeEndianPixMap ); else deepGWorld = NULL; // If we have a deep GWorld, draw the image into that and then // copy it into the output GWorld. If we don't have a deep GWorld, // just draw it directly into the output GWorld. if (deepGWorld != NULL) { // Draw the picture into the deep GWorld GetGWorld(&savePort, &saveDevice); SetGWorld(deepGWorld, NULL); LockPixels(GetGWorldPixMap(deepGWorld)); DrawPicture(thePicture, &(*thePicture)->picFrame); UnlockPixels(GetGWorldPixMap(deepGWorld)); SetGWorld(savePort, saveDevice); // Copy this into the output GWorld GetGWorld(&savePort, &saveDevice); SetGWorld(theGWorld, NULL); LockPixels(GetGWorldPixMap(theGWorld)); CopyBits(GetPortBitMapForCopyBits(deepGWorld), GetPortBitMapForCopyBits(theGWorld), &(*thePicture)->picFrame, &(*thePicture)->picFrame, ditherCopy, NULL); UnlockPixels(GetGWorldPixMap(theGWorld)); SetGWorld(savePort, saveDevice); // Clean up DisposeGWorld(deepGWorld); deepGWorld = NULL; } else { // Draw the picture into the output GWorld GetGWorld(&savePort, &saveDevice); SetGWorld(theGWorld, NULL); LockPixels(GetGWorldPixMap(theGWorld)); DrawPicture(thePicture, &(*thePicture)->picFrame); UnlockPixels(GetGWorldPixMap(theGWorld)); SetGWorld(savePort, saveDevice); } return(theGWorld); }
bool MCImageBitmapToPICT(MCImageBitmap *p_bitmap, MCMacSysPictHandle &r_pict) { #ifdef LIBGRAPHICS_BROKEN bool t_success = true; Pixmap drawdata = nil, drawmask = nil; MCBitmap *maskimagealpha = nil; t_success = MCImageSplitPixmaps(p_bitmap, drawdata, drawmask, maskimagealpha); if (!t_success) return false; Rect t_rect; SetRect(&t_rect, 0, 0, p_bitmap->width, p_bitmap->height); GWorldPtr t_old_gworld; GDHandle t_old_gdevice; GetGWorld(&t_old_gworld, &t_old_gdevice); PixMapHandle t_draw_pixmap; t_draw_pixmap = GetGWorldPixMap((CGrafPtr)drawdata -> handle . pixmap); GWorldPtr t_img_gworld; t_img_gworld = NULL; if (t_success) { QDErr t_err; t_err = NewGWorld(&t_img_gworld, 32, &t_rect, NULL, NULL, 0); if (t_err != noErr) t_success = false; } if (t_success) { SetGWorld(t_img_gworld, GetGDevice()); PenMode(srcCopy); ForeColor(blackColor); BackColor(whiteColor); if (maskimagealpha != NULL) { GWorldPtr t_alpha_gworld; if (NewGWorldFromPtr(&t_alpha_gworld, 8, &t_rect, GetCTable(40), NULL, 0, maskimagealpha -> data, maskimagealpha -> bytes_per_line) == noErr) { const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; t_src_bits = GetPortBitMapForCopyBits((CGrafPtr)drawdata -> handle . pixmap); const BitMap *t_mask_bits; t_mask_bits = GetPortBitMapForCopyBits(t_alpha_gworld); EraseRect(&t_rect); CopyDeepMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect, srcCopy, NULL); } } else if (drawmask != NULL) { PixMapHandle t_mask_pixmap; t_mask_pixmap = GetGWorldPixMap((CGrafPtr)drawmask -> handle . pixmap); EraseRect(&t_rect); const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; LockPixels(t_draw_pixmap); t_src_bits = (BitMap *)*t_draw_pixmap; const BitMap *t_mask_bits; LockPixels(t_mask_pixmap); t_mask_bits = (BitMap *)*t_mask_pixmap; CopyMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect); UnlockPixels(t_mask_pixmap); UnlockPixels(t_draw_pixmap); } else { const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; LockPixels(t_draw_pixmap); t_src_bits = (BitMap *)*t_draw_pixmap; CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL); UnlockPixels(t_draw_pixmap); } } PicHandle t_handle; t_handle = NULL; if (t_success) { OpenCPicParams t_params; t_params . srcRect = t_rect; t_params . hRes = 72 << 16; t_params . vRes = 72 << 16; t_params . version = -2; t_params . reserved1 = 0; t_params . reserved2 = 0; t_handle = OpenCPicture(&t_params); if (t_handle == NULL) t_success = false; } if (t_success) { GWorldPtr t_pict_gworld; GDHandle t_pict_gdevice; GetGWorld(&t_pict_gworld, &t_pict_gdevice); PenMode(srcCopy); ForeColor(blackColor); BackColor(whiteColor); const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_pict_gworld); const BitMap *t_src_bits; t_src_bits = GetPortBitMapForCopyBits(t_img_gworld); CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL); ClosePicture(); } if (t_img_gworld != NULL) DisposeGWorld(t_img_gworld); SetGWorld(t_old_gworld, t_old_gdevice); MCscreen->freepixmap(drawdata); MCscreen->freepixmap(drawmask); if (maskimagealpha != nil) MCscreen->destroyimage(maskimagealpha); if (t_success) r_pict = (MCMacSysPictHandle)t_handle; return t_success; #else return false; #endif }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MyEventHandler // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OSStatus AUMixer3DView::MyEventHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent) { OSStatus result = noErr; UInt32 eventClass = GetEventClass(inEvent); UInt32 eventKind = GetEventKind(inEvent); // draw event if(eventClass == kEventClassWindow) { if(eventKind == kEventWindowDrawContent ) { Rect r = {mOffsetY, mOffsetX, mOffsetY + 400, mOffsetX + 400}; RGBForeColor(&mBackgroundColor ); PaintRect(&r); for(int i = 0; i < kNTrackers; i++) { gTrackers[i]->Draw(); } gListener->Draw(); return noErr; } } CGrafPtr gp = GetWindowPort(GetCarbonWindow()); CGrafPtr save; GetPort(&save); SetPort(gp ); const float kDistanceScale = 0.1 /*0.3*/; /* k3DMixerRenderingFlags_InterAuralDelay = (1L << 0), k3DMixerRenderingFlags_DopplerShift = (1L << 1), k3DMixerRenderingFlags_DistanceAttenuation = (1L << 2), k3DMixerRenderingFlags_DistanceFilter = (1L << 3), k3DMixerRenderingFlags_DistanceDiffusion = (1L << 4) */ if(eventClass == kEventClassCommand ) { HICommand command; GetEventParameter (inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command); SInt16 value = ::GetControlValue((ControlRef)command.menu.menuRef ); //char *p = ((char*)&command.commandID ); //printf("%x command.commandID = %d : %d : %c%c%c%c\n", command.menu.menuRef, command.commandID, int(value), p[0],p[1],p[2],p[3] ); if(command.commandID == 'algo' ) { // set rendering algorithm UInt32 algo = value - 1; for(int i = 0; i < kNTrackers; i++) { AudioUnitSetProperty( GetEditAudioUnit(), kAudioUnitProperty_SpatializationAlgorithm, kAudioUnitScope_Input, i, &algo, sizeof(algo) ); } // rendering flags have changed with setting of rendering algorithm SetRenderingFlagsCheckboxes(); } else if(command.commandID == 'volm' ) { Float32 s = float(value) / 100.0; s = s*s; if(s == 0.0) { s = -96.0; } else { s = 20.0 * log10(s); } //printf("volume = %f dB\n", s); // set master gain in dB AudioUnitSetParameter(GetEditAudioUnit(), k3DMixerParam_Gain, kAudioUnitScope_Output, 0, s, 0 ); } else if(command.commandID == 'attn' ) { // volume attenuation curve Float64 s = float(value) / 100.0; //printf("volume atten curve= %f\n", s); // volume attenuation curve follows the law: 1.0 / (1.0 + s *(distance - 1.0) ) // // where distance is in meters, and s is generally between 0.1 and 1.0 (0.3 is good default) // // there is no attenuation if distance <= 1.0 meter for(int i = 0; i < kNTrackers; i++) { result = AudioUnitSetProperty( GetEditAudioUnit(), kAudioUnitProperty_3DMixerDistanceAtten, kAudioUnitScope_Input, i, &s, sizeof(s) ); } } else { UInt32 mask = 0; switch(command.commandID ) { case 'atr0': mask = k3DMixerRenderingFlags_InterAuralDelay; break; case 'atr1': mask = k3DMixerRenderingFlags_DopplerShift; break; case 'atr2': mask = k3DMixerRenderingFlags_DistanceAttenuation; break; case 'atr3': mask = k3DMixerRenderingFlags_DistanceFilter; break; case 'atr4': mask = k3DMixerRenderingFlags_DistanceDiffusion; break; case 'rvrb': { UInt32 usesReverb = value; AudioUnitSetProperty( GetEditAudioUnit(), kAudioUnitProperty_UsesInternalReverb, kAudioUnitScope_Input, 0, &usesReverb, sizeof(usesReverb) ); break; } } if(mask != 0) { for(int i = 0; i < kNTrackers; i++) { UInt32 flags; UInt32 size = sizeof(flags); AudioUnitGetProperty( GetEditAudioUnit(), kAudioUnitProperty_3DMixerRenderingFlags, kAudioUnitScope_Input, i, &flags, &size ); if(value > 0) { flags |= mask; } else { flags &= ~mask; } AudioUnitSetProperty( GetEditAudioUnit(), kAudioUnitProperty_3DMixerRenderingFlags, kAudioUnitScope_Input, i, &flags, size ); } return noErr; } } return eventNotHandledErr; } else if(eventClass == kEventClassMouse ) { HIPoint mousePos; result = GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint, NULL, /* can be NULL */ sizeof(HIPoint), NULL, /* can be NULL */ &mousePos); UInt32 modifiers; result = GetEventParameter( inEvent, kEventParamKeyModifiers, typeUInt32, NULL, /* can be NULL */ sizeof(UInt32), NULL, /* can be NULL */ &modifiers); Point pt; pt.h = short(mousePos.x); pt.v = short(mousePos.y); Rect r2 = GetPortBitMapForCopyBits(gp)->bounds; GlobalToLocal(&pt); pt.h -= mOffsetX; pt.v -= mOffsetY; if(!mIsTrackingMouse && (pt.h < 0 || pt.v < 0) ) return eventNotHandledErr; // check for title bar if(pt.v < 0 && pt.v > -30 ) { return eventNotHandledErr; } Rect r1; GetPortBounds(gp, &r1 ); //int width = r1.right-r1.left; //int height = r1.bottom-r1.top; //!!@ hardcoded int width = 400; int height = 400; int centerx = int(0.5*width); int centery = int(0.5*height); static int currentLine = 0; float x = pt.h - centerx; float y = -(pt.v - centery); float rangle = atan2(x,y); float angle = 180.0 * rangle / 3.14159; static int hitx = 0; static int hity = 0; static float hitAngle = 0.0; switch(eventKind) { case kEventMouseDown: { mIsTrackingMouse = true; // determine the closest source float bestDistance = 100000.0; int bestIndex = 0; for(int i = 0; i < kNTrackers; i++) { if(gTrackers[i]->Distance(pt.h, pt.v) < bestDistance ) { bestIndex = i; bestDistance = gTrackers[i]->Distance(pt.h, pt.v); } } if(modifiers & (1L << shiftKeyBit)) { Float32 gain; AudioUnitGetParameter(GetEditAudioUnit(), k3DMixerParam_Gain, kAudioUnitScope_Input, bestIndex, &gain); if (gain > -120) gain = -120; else gain = 0; AudioUnitSetParameter(GetEditAudioUnit(), k3DMixerParam_Gain, kAudioUnitScope_Input, bestIndex, gain, 0); } currentLine = bestIndex; SetInput(currentLine); for(int i = 0; i < kNTrackers; i++) { if(i != currentLine) gTrackers[i]->Draw(); gTrackers[i]->Anchor(); } hitx = (int)x; hity = (int)y; hitAngle = angle; } case kEventMouseDragged: { if(modifiers & (1L << optionKeyBit) ) { for(int i = 0; i < kNTrackers; i++) { float newAngle = gTrackers[i]->Rotate(angle - hitAngle ); AudioUnitSetParameter(GetEditAudioUnit(), 0 /* azimuth */, kAudioUnitScope_Input, i, newAngle, 0 ); } gListener->Draw(); } else if(modifiers & (1L << cmdKeyBit) ) { for(int i = 0; i < kNTrackers; i++) { float angle; float pixelDistance; gTrackers[i]->Offset(x-hitx, -(y-hity), angle, pixelDistance ); float distance = kDistanceScale * pixelDistance; AudioUnitSetParameter(GetEditAudioUnit(), 0 /* azimuth */, kAudioUnitScope_Input, i, angle, 0 ); AudioUnitSetParameter(GetEditAudioUnit(), 2 /* distance */, kAudioUnitScope_Input, i, distance, 0 ); } gListener->Draw(); } else { TrackingLine *trackingLine = gTrackers[currentLine]; if(trackingLine) { trackingLine->Track(pt.h, pt.v); for(int i = 0; i < kNTrackers; i++) { if(i != currentLine) gTrackers[i]->Draw(); gTrackers[i]->Anchor(); } gListener->Draw(); } AudioUnitSetParameter(GetEditAudioUnit(), 0 /* azimuth */, kAudioUnitScope_Input, currentLine, angle, 0 ); float distance = kDistanceScale * sqrt( x*x + y*y); AudioUnitSetParameter(GetEditAudioUnit(), 2 /* distance */, kAudioUnitScope_Input, currentLine, distance, 0 ); } break; } case kEventMouseUp: mIsTrackingMouse = false; break; } SetPort(save); return noErr; } else { UInt8 keyCode; result = GetEventParameter( inEvent, kEventParamKeyMacCharCodes, typeChar, NULL, /* can be NULL */ sizeof(UInt8), NULL, /* can be NULL */ &keyCode); #if 1 switch(keyCode) { case 'q': SetFileInput(0); break; case 'w': SetFileInput(1); break; case 'e': SetFileInput(2); break; case 'r': SetFileInput(3); break; case 't': SetFileInput(4); break; case 'y': SetFileInput(5); break; case 'u': SetFileInput(6); break; case 'i': SetFileInput(7); break; case 'o': SetFileInput(8); break; case 'p': SetFileInput(9); break; case 'a': SetFileInput(10); break; case 's': SetFileInput(11); break; case 'd': SetFileInput(12); break; default: break; } #endif SetPort(save); return noErr; } return eventNotHandledErr; }
PicHandle GetScreenAsPicHandle(int width, int height, int destWidth, int destHeight) { PicHandle myPicture; Rect drawSize, scaleSize; GWorldPtr drawWorld, scaleWorld; Byte *graphicsIn, *graphicsOut; int row, graphicsRowBytes; SetRect(&drawSize, 0, 0, width, height); SetRect(&scaleSize, 0, 0, destWidth, destHeight); InitGWorld(&drawWorld, &drawSize, 16); InitGWorld(&scaleWorld, &scaleSize, 16); graphicsIn = (Byte *) GFX.Screen; graphicsOut = (Byte *) GetPixBaseAddr(GetGWorldPixMap(drawWorld)); graphicsRowBytes = GetPixRowBytes(GetGWorldPixMap(drawWorld)); for (row = 0; row < height; row++) { memcpy(graphicsOut, graphicsIn, width * 2); if (directDisplay) { if (drawingMethod != kDrawingOpenGL) graphicsIn += 512 * 2; else graphicsIn += width * 2; } else { if (lastDrawingMethod != kDrawingOpenGL) graphicsIn += 512 * 2; else graphicsIn += width * 2; } graphicsOut += graphicsRowBytes; } if ((scaleSize.right * scaleSize.bottom) < (drawSize.right * drawSize.bottom)) { PrepareForGDrawing(drawWorld); CopyBits(GetPortBitMapForCopyBits(drawWorld), GetPortBitMapForCopyBits(scaleWorld), &drawSize, &scaleSize, srcCopy | ditherCopy, nil); FinishGDrawing(drawWorld); PrepareForGDrawing(scaleWorld); myPicture = OpenPicture(&scaleSize); CopyBits(GetPortBitMapForCopyBits(scaleWorld), GetPortBitMapForCopyBits(scaleWorld), &scaleSize, &scaleSize, srcCopy, nil); ClosePicture(); FinishGDrawing(scaleWorld); } else { PrepareForGDrawing(scaleWorld); myPicture = OpenPicture(&scaleSize); CopyBits(GetPortBitMapForCopyBits(drawWorld), GetPortBitMapForCopyBits(scaleWorld), &drawSize, &scaleSize, srcCopy, nil); ClosePicture(); FinishGDrawing(scaleWorld); } DisposeGWorld(drawWorld); DisposeGWorld(scaleWorld); return myPicture; }
void wxMacToolTip::Draw() { if ( m_label.Length() == 0 ) return ; if ( m_window == s_ToolTipWindowRef ) { m_shown = true ; #if TARGET_CARBON HMHelpContentRec tag ; tag.version = kMacHelpVersion; SetRect( &tag.absHotRect , m_position.x - 2 , m_position.y - 2 , m_position.x + 2 , m_position.y + 2 ) ; QDLocalToGlobalRect( GetWindowPort( m_window ) , &tag.absHotRect ) ; m_helpTextRef.Assign( m_label , wxFONTENCODING_DEFAULT ) ; tag.content[kHMMinimumContentIndex].contentType = kHMCFStringContent ; tag.content[kHMMinimumContentIndex].u.tagCFString = m_helpTextRef ; tag.content[kHMMaximumContentIndex].contentType = kHMCFStringContent ; tag.content[kHMMaximumContentIndex].u.tagCFString = m_helpTextRef ; tag.tagSide = kHMDefaultSide; HMDisplayTag( &tag ); #else wxMacPortStateHelper help( (GrafPtr) GetWindowPort( m_window ) ); FontFamilyID fontId ; Str255 fontName ; SInt16 fontSize ; Style fontStyle ; GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; GetFNum( fontName, &fontId ); TextFont( fontId ) ; TextSize( fontSize ) ; TextFace( fontStyle ) ; FontInfo fontInfo; ::GetFontInfo(&fontInfo); short lineh = fontInfo.ascent + fontInfo.descent + fontInfo.leading; short height = 0 ; int i = 0 ; int length = m_label.Length() ; int width = 0 ; int thiswidth = 0 ; int laststop = 0 ; wxCharBuffer text = m_label.mb_str( wxConvLocal) ; while( i < length ) { if( text[i] == 13 || text[i] == 10) { thiswidth = ::TextWidth( text , laststop , i - laststop ) ; if ( thiswidth > width ) width = thiswidth ; height += lineh ; laststop = i+1 ; } i++ ; } if ( i - laststop > 0 ) { thiswidth = ::TextWidth( text , laststop , i - laststop ) ; if ( thiswidth > width ) width = thiswidth ; height += lineh ; } m_rect.left = m_position.x + kTipOffset; m_rect.top = m_position.y + kTipOffset; m_rect.right = m_rect.left + width + 2 * kTipBorder; m_rect.bottom = m_rect.top + height + 2 * kTipBorder; Rect r ; GetPortBounds( GetWindowPort( m_window ) , &r ) ; if ( m_rect.top < 0 ) { m_rect.bottom += -m_rect.top ; m_rect.top = 0 ; } if ( m_rect.left < 0 ) { m_rect.right += -m_rect.left ; m_rect.left = 0 ; } if ( m_rect.right > r.right ) { m_rect.left -= (m_rect.right - r.right ) ; m_rect.right = r.right ; } if ( m_rect.bottom > r.bottom ) { m_rect.top -= (m_rect.bottom - r.bottom) ; m_rect.bottom = r.bottom ; } ClipRect( &m_rect ) ; BackColor( whiteColor ) ; ForeColor(blackColor ) ; GWorldPtr port ; NewGWorld( &port , wxDisplayDepth() , &m_rect , NULL , NULL , 0 ) ; CGrafPtr origPort ; GDHandle origDevice ; GetGWorld( &origPort , &origDevice ) ; SetGWorld( port , NULL ) ; m_backpict = OpenPicture(&m_rect); CopyBits(GetPortBitMapForCopyBits(GetWindowPort(m_window)), GetPortBitMapForCopyBits(port), &m_rect, &m_rect, srcCopy, NULL); ClosePicture(); SetGWorld( origPort , origDevice ) ; DisposeGWorld( port ) ; PenNormal() ; RGBColor tooltipbackground = { 0xFFFF , 0xFFFF , 0xC000 } ; BackColor( whiteColor ) ; RGBForeColor( &tooltipbackground ) ; PaintRect( &m_rect ) ; ForeColor(blackColor ) ; FrameRect( &m_rect ) ; SetThemeTextColor(kThemeTextColorNotification,wxDisplayDepth(),true) ; ::MoveTo( m_rect.left + kTipBorder , m_rect.top + fontInfo.ascent + kTipBorder); i = 0 ; laststop = 0 ; height = 0 ; while( i < length ) { if( text[i] == 13 || text[i] == 10) { ::DrawText( text , laststop , i - laststop ) ; height += lineh ; ::MoveTo( m_rect.left + kTipBorder , m_rect.top + fontInfo.ascent + kTipBorder + height ); laststop = i+1 ; } i++ ; } ::DrawText( text , laststop , i - laststop ) ; ::TextMode( srcOr ) ; #endif } }
int main2() { mpeg3_t *file; int i, result = 0; unsigned char *output, **output_rows; float *audio_output_f; short *audio_output_i; long total_samples = 0; Rect sourceRect; OSErr error; PixMapHandle hPixmap; Ptr gBaseLocation; long targetRowBytes; file = mpeg3_open("randomAlien.mpg"); if(file) { mpeg3_set_cpus(file, 1); //audio_output_f = (float *) memoryAllocate(1,BUFSIZE * sizeof(float)); //audio_output_i = (short *) memoryAllocate(1,BUFSIZE * sizeof(short)); //mpeg3_set_sample(file, 11229518, 0); //result = mpeg3_read_audio(file, audio_output_f, 0, 0, BUFSIZE, 0); // result = mpeg3_read_audio(file, 0, audio_output_i, 1, BUFSIZE, 0); // fwrite(audio_output_i, BUFSIZE, 1, stdout); //mpeg3_set_frame(file, 1000, 0); sourceRect.top = 0; sourceRect.left = 0; sourceRect.bottom = mpeg3_video_height(file, 0); sourceRect.right = mpeg3_video_width(file, 0); error = NewGWorld (&gpGWOffScreen, 32, &sourceRect, NULL, NULL, keepLocal); if (error != noErr) { DebugStr ("\pUnable to allocate off screen image"); } hPixmap = GetGWorldPixMap (gpGWOffScreen); error = LockPixels (hPixmap); gBaseLocation = GetPixBaseAddr(hPixmap); targetRowBytes = ((**hPixmap).rowBytes & 0x3FFF)/4; output_rows = (unsigned char **) memoryAllocate(1,sizeof(unsigned char*) * mpeg3_video_height(file, 0)); for(i = 0; i < mpeg3_video_height(file, 0); i++) output_rows[i] = (unsigned char*) gBaseLocation + i * targetRowBytes*4; for (i=0;i < mpeg3_video_frames(file, 0);i++) { result = mpeg3_read_frame(file, output_rows, 0, 0, mpeg3_video_width(file, 0), mpeg3_video_height(file, 0), mpeg3_video_width(file, 0), mpeg3_video_height(file, 0), MPEG3_RGBAF8888, 0); CopyBits (GetPortBitMapForCopyBits(gpGWOffScreen), GetPortBitMapForCopyBits(GetWindowPort(pWindow)), &sourceRect, &sourceRect, srcCopy, NULL); } UnlockPixels (hPixmap); DisposeGWorld(gpGWOffScreen); memoryFree(output_rows); fprintf(stderr, "Audio streams: %d\n", mpeg3_total_astreams(file)); for(i = 0; i < mpeg3_total_astreams(file); i++) { fprintf(stderr, " Stream %d: channels %d sample rate %d total samples %ld\n", i, mpeg3_audio_channels(file, i), mpeg3_sample_rate(file, i), mpeg3_audio_samples(file, i)); } fprintf(stderr, "Video streams: %d\n", mpeg3_total_vstreams(file)); for(i = 0; i < mpeg3_total_vstreams(file); i++) { fprintf(stderr, " Stream %d: width %d height %d frame rate %0.3f total frames %ld\n", i, mpeg3_video_width(file, i), mpeg3_video_height(file, i), mpeg3_frame_rate(file, i), mpeg3_video_frames(file, i)); } mpeg3_close(file); }
void saveToPICTFile() { /* Saving a PixMap as a PICT file isn't too hard. 1. Open a Picture with the port set to the destination of #2. 2. CopyBits the PixMap onto itself or another port. (Because CopyBits is recorded in Pictures. 3. Close the picture. 4. Open the data fork for the file. 5. Write out 512 bytes of zeros followed by the contents of the Picture handle. 6. Close the file. */ PicHandle picHandle; OSErr anErr = noErr; OSType fileTypeToSave = 'PICT'; OSType creatorType = 'ogle'; NavReplyRecord reply; NavDialogOptions dialogOptions; FSSpec documentFSSpec; long inOutCount; short refNum, count; AEKeyword theKeyword; DescType actualType; unsigned char header[512]; Size actualSize; Rect tempRect1; CopyBits(GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), (BitMap*) &gPixMap, GetPortBounds(GetWindowPort(gWindow), &tempRect1), &gPixMap.bounds, srcCopy, 0L); SetPortWindowPort(gWindow); picHandle = OpenPicture(&gPixMap.bounds); CopyBits((BitMap*) &gPixMap, GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), &gPixMap.bounds, GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0L); ClosePicture(); for (count = 0; count < 512; count++) header[count] = 0x00; anErr = NavGetDefaultDialogOptions(&dialogOptions); dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation; anErr = NavPutFile( nil, &reply, &dialogOptions, nil, fileTypeToSave, creatorType, nil ); if (anErr == noErr && reply.validRecord) { anErr = AEGetNthPtr(&(reply.selection), 1, typeFSS, &theKeyword, &actualType, &documentFSSpec, sizeof(documentFSSpec), &actualSize ); if (anErr == noErr) { anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript); if (anErr == dupFNErr) { anErr = FSpDelete(&documentFSSpec); anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript); } // this is quick 'n' dirty or there'd be more robust handling here // write the file FSpOpenDF(&documentFSSpec, fsRdWrPerm, &refNum ); inOutCount = 512; anErr = FSWrite(refNum, &inOutCount, header); // write the header if (anErr == noErr) { inOutCount = GetHandleSize((Handle)picHandle); anErr = FSWrite(refNum,&inOutCount,*picHandle); } FSClose( refNum ); } reply.translationNeeded = false; anErr = NavCompleteSave(&reply, kNavTranslateInPlace); NavDisposeReply(&reply); } KillPicture(picHandle); }
/* convert IPIcon to Picture */ PicHandle IPIconToPicture(const IPIconRec *ipIcon,short iconKind) { ResType iconType; short iconSize,iconDepth; long offset=0; OSErr err; GWorldPtr iconGWorld; PixMapHandle iconPix; Handle dataHandle; Ptr src,dst; PicHandle picture; OpenCPicParams picParam; Rect iconRect; Rect temp; long rowBytes,iconRowBytes; short i; CTabHandle ctab=nil; GWorldPtr cPort; GDHandle cDevice; /* invalid icon kind */ if (iconKind < 0) return nil; iconType=gIconType[iconKind]; iconSize=gIconSize[iconKind]; iconDepth=gIconDepth[iconKind]; SetRect(&iconRect,0,0,iconSize,iconSize); temp=iconRect; temp.right++; err=GetDataFromIPIcon(&dataHandle,ipIcon,iconKind); if (err != noErr || dataHandle == nil) return nil; /* return nil when there are no icons */ if (GetHandleSize(dataHandle) != iconSize*(long)iconSize*(iconDepth>1 ? iconDepth : 2)/8) return nil; switch (iconKind) { case kL1Mask: offset=32*32/8; break; case kS1Mask: offset=16*16/8; break; case kL8Mask: case kS8Mask: case kT8Mask: ctab=GetGrayscaleCTable(iconDepth,true); break; } GetGWorld(&cPort,&cDevice); err=NewGWorld(&iconGWorld,iconDepth,&temp,ctab,0,useTempMem); if (ctab != NULL) DisposeHandle((Handle)ctab); if (err != noErr) return nil; HLock(dataHandle); SetGWorld(iconGWorld,0); iconPix=GetGWorldPixMap(iconGWorld); LockPixels(iconPix); rowBytes=MyGetPixRowBytes(iconPix) & 0x3fff; EraseRect(&iconRect); src=*dataHandle+offset; dst=MyGetPixBaseAddr(iconPix); iconRowBytes=iconSize*iconDepth/8; for (i=0; i<iconSize; i++) { BlockMoveData(src,dst,iconRowBytes); src+=iconRowBytes; dst+=rowBytes; } HUnlock(dataHandle); UnlockPixels(iconPix); picParam.srcRect=iconRect; picParam.hRes=72L<<16; picParam.vRes=72L<<16; picParam.version=-2; picParam.reserved1=0; picParam.reserved2=0; picture=OpenCPicture(&picParam); ForeColor(blackColor); BackColor(whiteColor); ClipRect(&iconRect); EraseRect(&iconRect); #if 1 CopyBits(GetPortBitMapForCopyBits(iconGWorld),GetPortBitMapForCopyBits(iconGWorld), &iconRect,&iconRect,srcCopy,nil); #else { IconFamilyHandle iconFamily; IconRef iconRef; err=IPIconToIconFamily(ipIcon,&iconFamily); err=RegisterIconRefFromIconFamily(kIconPartyCreator,'TEMP',iconFamily,&iconRef); DisposeHandle((Handle)iconFamily); err=PlotIconRef(&iconRect,kAlignNone,kTransformNone,kIconServicesNormalUsageFlag, iconRef); err=ReleaseIconRef(iconRef); } #endif #if __BIG_ENDIAN__ (**picture).picFrame=iconRect; #endif ClosePicture(); SetGWorld(cPort,cDevice); #if 0 CopyBits(GetPortBitMapForCopyBits(iconGWorld),GetPortBitMapForCopyBits(GetWindowPort(MyFrontNonFloatingWindow())), &iconRect,&familyIconRect[iconKind],srcCopy,nil); DrawPicture(picture,&familyIconRect[iconKind]); #endif DisposeGWorld(iconGWorld); return picture; }