[futurebasic] [FB] Image not showing in HIImageView

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2012 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Sun, 29 Jan 2012 03:19:27 -0500
Brian,

See if this helps. In fn HIWindowGetBounds, _kHICoordSpace72DPIGlobal
was returning global screen bounds rather than the bounds for the window
structure. Pass _kHICoordSpaceWindow to get the window structure bounds.

I found it easier to put a HIImageView in the nib and load the image into it.

Ken


include "Tlbx HIView.incl"
include "Util_NibCFStrings.incl"
include resources "About.nib"
include resources "VMTImage.png"

// MacWindows.h
toolbox fn HIWindowGetBounds( WindowRef inWindow, WindowRegionCode inRegion, HICoordinateSpace inSpace, HIRect *outBounds ) = OSStatus

local fn CreateCGImageFromBundleResource( fileName as CFStringRef ) as CGImageRef
'~'1
dim as CFURLRef           url
dim as CGImageRef         image : image = NULL
dim as CGImageSourceRef   source

url = fn CFBundleCopyResourceURL( fn CFBundleGetMainBundle(), fileName, NULL, NULL )
if ( url )
source = fn CGImageSourceCreateWithURL( url, NULL )
if ( source )
image = fn CGImageSourceCreateImageAtIndex( source, 0, NULL )
CFRelease( source )
end if
CFRelease( url )
end if
end fn = image

local fn BuildAboutWnd
'~'1
dim as IBNibRef   nibRef
dim as WindowRef  wndRef
dim as HIRect     viewRect, bounds
dim as HIViewRef  imageView, contentView
dim as CGImageRef image
dim as OSStatus   stat

stat = fn CreateNibReference( @"About", @nibRef )
stat = fn CreateWindowFromNib( nibRef, @"Window", @wndRef )
DisposeNibReference( nibRef )


stat = fn HIImageViewCreate ( 0, imageView )
stat = fn HIViewSetVisible( imageView, _true )
stat = fn HIViewFindByID( fn HIViewGetRoot( wndRef ), kHIViewWindowContentID, @contentView )
stat = fn HIViewAddSubview ( contentView, imageView )

stat = fn HIWindowGetBounds( wndRef, _kWindowContentRgn, _kHICoordSpaceWindow, @bounds )
viewRect = fn CGRectMake( bounds.origin.x + 100.0, bounds.origin.y - 20.0, 200.0, 200.0 )

stat = fn HIViewSetFrame ( imageView, @viewRect )
image = fn CreateCGImageFromBundleResource( @"VMTImage.png" )
stat = fn HIImageViewSetImage( imageView, image )
CFRelease( image )

stat = fn HIImageViewSetScaleToFit( imageView, _true )
stat = fn HIViewSetVisible( imageView, _true )
ShowWindow( wndRef )
end fn

fn BuildAboutWnd
RunApplicationEventLoop()