Application icon

Application icon

Post by bernard.me » Tue, 04 Nov 2003 20:35:19


I want to draw the ICNS application icon that sits in the application
package in the about box an in my custom alert. The code I have does
work but the drawn icon looks ugly and is not the proper 32bit
downscaled 128x128 pixels one.
In the overridden DrawSelf I do the following:
void M_IcnsIcon::DrawSelf()
{
IconFamilyHandle iconFamHandle;
Rect frame;
OSErr err = noErr;

CalcLocalFrameRect( frame );

// Read the Icon from the file in the package
if ( err == ::ReadIconFromFSRef( &mIcnsIconFSRef, &iconFamHandle ) )
{
IconSuiteRef iconSuiteRef;

if ( err == ::IconFamilyToIconSuite( iconFamHandle,
kSelectorAllAvailableData, &iconSuiteRef ) )
{
err = ::PlotIconSuite( &frame, kAlignNone, kTransformNone,
iconSuiteRef );

// BM thinks that the IconSuiteRef can be destroyed as following
err = ::DisposeIconSuite( iconSuiteRef, true );
}
}
}

Is there some example code for drawing the application icon in the
about box starting from the .icns file?

All help welcome,
Bernard Meers
 
 
 

Application icon

Post by Isaac Wank » Wed, 05 Nov 2003 15:39:10

In article < XXXX@XXXXX.COM >,



Can you not just use an LIconControl and set the kControlIconContentTag
data tag to use the kControlContentIconRef content type?

Here's some PPx code that does what you want:

HIRect frameAppIcon = { 110, 8, 64, 64 }; // origin, size
ControlButtonContentInfo contentInfo;
FSRef iconFile;

contentInfo.contentType = kControlContentIconRef;
contentInfo.u.iconRef = NULL;

PPx::IconControl* appIcon = new PPx::IconControl;
PPx::CFString textIconFile((CFStringRef)
CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
CFSTR("CFBundleIconFile")), true);
if (textIconFile.IsValid())
{
PPx::CFURL iconURL((CFURLRef)
CFBundleCopyResourceURL(CFBundleGetMainBundle(), textIconFile,
CFSTR("icns"), CFSTR("")), false);
bool gotIt = iconURL.GetFSRef(iconFile);
status = RegisterIconRefFromFSRef(PPx::Signature::Get(), 'APPL',
&iconFile, &contentInfo.u.iconRef);
}
else
status = GetIconRef(kOnSystemDisk, kSystemIconsCreator,
kGenericApplicationIcon, &contentInfo.u.iconRef);
appIcon->Initialize(GetContentView(), frameAppIcon, PPx::visible_Yes,
PPx::enabled_Yes, contentInfo, true);
appIcon->FinishInitPersistent();
if (IsValidIconRef(contentInfo.u.iconRef))
status = ReleaseIconRef(contentInfo.u.iconRef);

--
Isaac *** erl
Metrowerks
Mac Software Developer