PRIVATE PicHandle pict_from_gworld (GWorldPtr gp, int *lenp) { PicHandle retval; if (!gp) retval = NULL; else { Rect pict_frame; PixMapHandle pm; pm = GetGWorldPixMap (gp); pict_frame = PIXMAP_BOUNDS (pm); retval = OpenPicture (&pict_frame); if (retval) { ClipRect (&pict_frame); HLock ((Handle) pm); CopyBits ((BitMap *) STARH (pm), PORT_BITS_FOR_COPY (thePort), &pict_frame, &pict_frame, srcCopy, NULL); HUnlock ((Handle) pm); ClosePicture (); } } return retval; }
PicHandle PixMapToPict(PixMapHandle inMap,Rect *sourceRect,Rect *destRect) { PicHandle recordPic=0L; recordPic=OpenPicture(destRect); if (!recordPic) return 0L; CopyBits((BitMap *)*inMap,(BitMap *)*inMap,sourceRect,destRect,srcCopy,0L); ClosePicture(); return recordPic; }
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); }
wxMetaFileDC::wxMetaFileDC(const wxString& filename , int width , int height , const wxString& WXUNUSED(description) ) { wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ; wxASSERT_MSG( filename.empty() , _T("no file based metafile support yet")) ; m_metaFile = new wxMetaFile(filename) ; #if wxMAC_USE_CORE_GRAPHICS #else Rect r={0,0,height,width} ; RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; m_metaFile->SetHMETAFILE( (WXHMETAFILE) OpenPicture( &r ) ) ; ::GetPort( (GrafPtr*) &m_macPort ) ; m_ok = true ; #endif SetMapMode(wxMM_TEXT); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setWindowIcon(QIcon("://icon/mainIcon.png")); this->setWindowTitle("Numerical Analysis Project"); this->srcImg = new QImage(); this->destImg = srcImg; this->originPicture = new QGraphicsView(this); //初始化主窗口界面 QString srcRoute = "://icon/welcomeText.jpg"; srcImg->load(srcRoute); this->ImageShow(srcImg); //初始化菜单栏 QAction *openAction = new QAction(tr("打开"), this); QObject::connect(openAction, SIGNAL(triggered()), this, SLOT(OpenPicture())); QAction *saveOption = new QAction(tr("保存"), this); QObject::connect(saveOption, SIGNAL(triggered()), this, SLOT(SavePicture())); QMenu *openMenu = menuBar()->addMenu(tr("文件")); openMenu->addAction(openAction); openMenu->addAction(saveOption); QAction *manipOption = new QAction(tr("操作图片"), this); QObject::connect(manipOption, SIGNAL(triggered()), this, SLOT(ManipShow())); QMenu *manipMenu = menuBar()->addMenu(tr("操作")); manipMenu->addAction(manipOption); QAction *guideOption = new QAction(tr("使用方法"), this); QObject::connect(guideOption, SIGNAL(triggered()), this, SLOT(GuideShow())); QAction *aboutOption = new QAction(tr("关于"), this); QObject::connect(aboutOption, SIGNAL(triggered()), this, SLOT(AboutShow())); QMenu *helpMenu = menuBar()->addMenu(tr("帮助")); helpMenu->addAction(guideOption); helpMenu->addAction(aboutOption); }
/* ------------ Local code */ static void add_overhead_thumbnail( FileSpecifier &File) { PicHandle picture; PicHandle preview; RgnHandle clip_region; FontInfo info; short text_x, text_y; short text_length; Str255 temporary; GWorldPtr old_gworld; GDHandle old_device; struct overhead_map_data overhead_data; Rect bounds; AEDesc aeFileSpec; FSSpec *SpecPtr; // Skip all this if there's no nav services to install the preview if(!machine_has_nav_services() || NavLibraryVersion() < kNavServicesVersion_2_0) return; GetGWorld(&old_gworld, &old_device); SetGWorld(world_pixels, (GDHandle) NULL); // Note well. We're using world_pixels to create our thumbnail pict within. // If world_pixels is runing as a postage stamp (low-res + small display space) // Then it is actually smaller than the size we're looking to build a thumbnail // within. But seeing as we're generating pict images and using drawing commands // instead of bit-wise operations. It all works out. /* Create the bounding rectangle */ SetRect(&bounds, 0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT); /* Start recording.. */ picture= OpenPicture(&bounds); PaintRect(&bounds); overhead_data.scale= OVERHEAD_MAP_MINIMUM_SCALE; overhead_data.origin.x= local_player->location.x; overhead_data.origin.y= local_player->location.y; overhead_data.half_width= RECTANGLE_WIDTH(&bounds)/2; overhead_data.half_height= RECTANGLE_HEIGHT(&bounds)/2; overhead_data.width= RECTANGLE_WIDTH(&bounds); overhead_data.height= RECTANGLE_HEIGHT(&bounds); overhead_data.mode= _rendering_saved_game_preview; _render_overhead_map(&overhead_data); RGBForeColor(&rgb_black); PenSize(1, 1); TextFont(0); TextFace(normal); TextSize(0); ClosePicture(); // JTP: Add Nav Services style preview SetRect(&bounds, 0, 0, PREVIEW_WIDTH, PREVIEW_HEIGHT); preview= OpenPicture(&bounds); SetRect(&bounds, PREVIEW_IMAGE_X, PREVIEW_IMAGE_Y, THUMBNAIL_WIDTH + PREVIEW_IMAGE_X, THUMBNAIL_HEIGHT + PREVIEW_IMAGE_Y); clip_region= NewRgn(); GetClip(clip_region); ClipRect(&bounds); DrawPicture(picture, &bounds); SetClip(clip_region); /* Center the text in the rectangle */ // LP: Classic doesn't have this function #ifdef TARGET_API_MAC_CARBON CopyCStringToPascal(static_world->level_name, temporary); #else strncpy((char *)temporary,static_world->level_name,LEVEL_NAME_LENGTH); c2pstr((char *)temporary); #endif // LP: fix to allow lengths more than 127 bytes (not really necessary, but...) text_length = *ptemporary; TruncText(PREVIEW_WIDTH, (char *)temporary+1, &text_length, smTruncEnd); *ptemporary = text_length; GetFontInfo(&info); text_y= PREVIEW_HEIGHT - info.descent; text_x= PREVIEW_LABEL_X + (PREVIEW_WIDTH-StringWidth(temporary))/2; MoveTo(text_x, text_y); DrawString(temporary); ClosePicture(); // This requires NavServices 2.0, what's the inline check? // From FSS get a AEDesc OSStatus err; SpecPtr = &File.GetSpec(); err = AECreateDesc(typeFSS, SpecPtr, sizeof(FSSpec), &aeFileSpec); HLock((Handle)preview); err = NavCreatePreview(&aeFileSpec, 'PICT', *preview, GetHandleSize((Handle)preview)); HUnlock((Handle)preview); AEDisposeDesc(&aeFileSpec); KillPicture(preview); KillPicture(picture); DisposeRgn(clip_region); SetGWorld(old_gworld, old_device); }
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 } }
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); }