[futurebasic] Re: [FB] Make Picture Button by bundle image

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2011 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Sun, 22 May 2011 12:58:24 +1200
Yoshiyuki Hasegawa wrote:

> As for the bevel button definition, the outside frame of the bevel button is displayed.
> What is the definition that makes the button from the image that the bundle is done?
> I am not found it with the header.

Returning to _kControlPictureProc / _kControlPictureNoTrackProc, I found how to set a picture button's image from a PicHandle:
  fn SetControlData( c, _kControlPicturePart, _kControlPictureHandleTag, 4, @picH )

Robert P.


'------------------------------------------
include "Tlbx CFBundle.incl"
include "Tlbx ControlDefinitions.incl"
include "Util_FileDirectory.incl"

include resources "Image.png"

local mode
local fn PicHandleFromBundleResource( fileName as CFStringRef, subDirectory as CFStringRef ) as PicHandle
'~'1
dim as CFURLRef                  url
dim as FSSpec                    spec
dim as PicHandle                 picH : picH = 0
dim as GraphicsImportComponent   comp

url = fn CFBundleCopyResourceURL( fn CFBundleGetMainBundle(), fileName, 0, subDirectory )
long if ( url )
fn FD_CFURLGetFSSpec( url, @spec )
long if ( fn GetGraphicsImporterForFile( spec, @comp ) == _noErr )
fn GraphicsImportGetAsPicture( comp, @picH )
fn CloseComponent( comp )
end if
CFRelease( url )
end if
end fn = picH


local mode
local fn ControlSetPicHandle( c as ControlRef, picH as PicHandle )
'~'1
end fn = fn SetControlData( c, _kControlPicturePart, _kControlPictureHandleTag, 4, @picH )


local fn PictureButtonDemo
'~'1
dim as Rect       r
dim as PicHandle  picH

window -1
SetRect( r, 20, 20, 200, 60 )
appearance button -1,,,,,, @r, _kControlPictureProc
picH = fn PicHandleFromBundleResource( @"Image.png", 0 )
if ( picH ) then fn ControlSetPicHandle( button&( 1 ), picH )
button 1
window 1
end fn


fn PictureButtonDemo
HandleEvents
'----------------------------------------