Re: PlotIconRefInContext doesn't work
Re: PlotIconRefInContext doesn't work
- Subject: Re: PlotIconRefInContext doesn't work
- From: Mike <email@hidden>
- Date: Sat, 17 May 2008 13:16:56 -0700
Michael Babin wrote:
On May 17, 2008, at 10:06 AM, Michael Vannorsdel wrote:
I'm thinking the window might be redrawing itself right after your own
drawing and erasing it. You could try disabling the window's auto
displaying and flush the window buffer after your draw to determine if
this is the case.
I don't know where you're doing the drawing to know if it's safe from
being erased or not.
On May 17, 2008, at 12:37 AM, Mike wrote:
It's a local NSRect which I assume is interchangeable with CGRect as
they are the same.
I fill in the rect at the top of the method with the Rect of the item
in the window from IB and then I hide the item before drawing to
prevent my stuff from being drawn over.
CGContextFillRect doesn't do anything either. Just a blank space as
with PlotIconRefInContext.
If that were indeed the problem (some other drawing taking place after
his own and erasing it), an easier way to check for it would be to use
Quartz Debug, turn on "Autoflush drawing", set a breakpoint at the
CGContextFillRect call, and step over it to see if the rect is indeed
filled as expected.
I tried adding a -display message at the end of the method which forces
a flush, but nothing changed. This is for an about box window. One
question I have is: do I need to subclass NSWindow and then override the
drawing and updating methods in order to get this to work? I will give
Quartz Debug a try. Here is the entire method:
/////////////////////////////////////////////////////////////////////
// Display the About box and fill it with version and system info.
/////////////////////////////////////////////////////////////////////
- (IBAction)about:(id)sender
{
unsigned len = 0;
NSRect iconRectNS = { 0, 0, 0, 0 };
CGContextRef windowContext = NULL;
RGBColor inLabelColor = { 1, 1, 1 };
IconRef icon = NULL;
NSGraphicsContext *a = nil;
NSString *aboutNameString = nil;
NSString *bundleGetInfoString = nil;
NSString *aboutFinalString = nil;
NSString *tempHardwareInfoString = nil;
NSFont *newFont = nil;
NSRange theActualTextUpperStorageRange;
NSTextStorage *theActualTextUpperStorage = nil;
NSMutableAttributedString *theActualTextUpperStorageAsString = nil;
NSRange theActualTextLowerStorageRange;
NSTextStorage *theActualTextLowerStorage = nil;
NSMutableAttributedString *theActualTextLowerStorageAsString = nil;
OSStatus err = noErr;
if( aboutWindow && mainWindow && model && helpMenu &&
aboutWindowLowerTextView && aboutWindowUpperTextView )
{
// Center the about window...
[ aboutWindow center ];
[ aboutWindow useOptimizedDrawing:YES ];
// Make font
newFont = [ NSFont fontWithName:kHelveticaFontName
size:kAboutBoxFontSize ];
////////////////////////////////////////////////////
// Make usable text for the about box upper pane...
////////////////////////////////////////////////////
// Get about name string...
aboutNameString = [ [ NSBundle mainBundle ]
localizedStringForKey:kWSAppAboutNameStringKey value:nil table:nil ];
// Append CFBundleGetInfoString string...
bundleGetInfoString = [ [ NSBundle mainBundle ]
objectForInfoDictionaryKey:(NSString*)kCFBundleGetInfoCFStringKey ];
// Make final string for upper pane...
aboutFinalString = [ aboutNameString
stringByAppendingString:bundleGetInfoString ];
if( aboutFinalString )
{
////////////////////////////////////////////////
// Set the text in the about box upper pane...
////////////////////////////////////////////////
// Get refs to text view's NSTextStorage's...
theActualTextUpperStorage = [ aboutWindowUpperTextView textStorage ];
if( theActualTextUpperStorage )
{
// Get text storage's text...
theActualTextUpperStorageAsString = (NSMutableAttributedString*)[
theActualTextUpperStorage mutableString ];
if( theActualTextUpperStorageAsString )
{
// Make range for old text...
memset( &theActualTextUpperStorageRange, kMemsetBufferFillValue, sizeof(
theActualTextUpperStorageRange ) );
len = [ theActualTextUpperStorageAsString length ];
theActualTextUpperStorageRange = NSMakeRange( 0, len );
// Replace upper text!
[ theActualTextUpperStorage
replaceCharactersInRange:theActualTextUpperStorageRange
withString:aboutFinalString ];
}
// Set font...
[ theActualTextUpperStorage setFont:newFont ];
}
// Force data model to reload hardware info...
[ model loadHardwareInfo ];
/////////////////////////////////////////////
// Make usable text for the bottom pane...
/////////////////////////////////////////////
theActualTextLowerStorage = [ aboutWindowLowerTextView textStorage ];
if( theActualTextLowerStorage )
{
// Get text storage's text...
theActualTextLowerStorageAsString = (NSMutableAttributedString*)[
theActualTextLowerStorage mutableString ];
if( theActualTextLowerStorageAsString )
{
// Make range for old text...
memset( &theActualTextLowerStorageRange, kMemsetBufferFillValue, sizeof(
theActualTextLowerStorageRange ) );
len = [ theActualTextLowerStorageAsString length ];
theActualTextLowerStorageRange = NSMakeRange( 0, len );
// Replace lower text!
tempHardwareInfoString = [ model hardwareInfoString ];
[ theActualTextLowerStorage
replaceCharactersInRange:theActualTextLowerStorageRange
withString:tempHardwareInfoString ];
}
// Set font...
[ theActualTextLowerStorage setFont:newFont ];
}
// Order main window to back...
[ mainWindow orderBack:self ];
// Make sure the about window's level is in front of the shielding
window level...
[ aboutWindow setLevel:( CGShieldingWindowLevel() + 1 ) ];
// Make about window frontmost...
[ aboutWindow makeKeyAndOrderFront:self ];
// Plot the machine icon, if available...
if( model && aboutWindowMachineIcon )
{
// Copy the rect to a new NSRect to modify...
iconRectNS = [ aboutWindowMachineIcon frame ];
[ aboutWindowMachineIcon setHidden:YES ];
[ aboutWindowMachineIcon setNeedsDisplay:NO ];
// Set context...
a = [ NSGraphicsContext graphicsContextWithWindow:aboutWindow ];
if( a )
{
[ NSGraphicsContext setCurrentContext:a ];
// Get window's context...
windowContext = [ [ NSGraphicsContext currentContext ] graphicsPort ];
if( windowContext )
{
// Plot!
GetIconRef( kOnSystemDisk, kSystemIconsCreator, kFinderIcon, &icon );
err = PlotIconRefInContext( windowContext,
(CGRect*)&iconRectNS,
kAlignAbsoluteCenter,
kTransformNone,
&inLabelColor,
kPlotIconRefNormalFlags,
icon );
}
}
}
// Last, force the selected menu item on the About menu to be "Help"...
[ helpMenu selectItemAtIndex:0 ];
[ helpMenu setNeedsDisplay:YES ];
// Force update in about window...
[ aboutWindow display ];
}
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden