Continuo avanzando con el tema del contenedor ... he conseguido que el ejemplo testimg encuentre la imagen dentro de la carpetas Resources del contenedor ...
los cambios son los siguientes :
en el archivo fivemac.ch
esto es algo provisional y rapido :
Code: Select all | Expand
#xcommand @ <nRow>, <nCol> RESIMAGE [ <oImg> ] ;
[ OF <oWnd> ] ;
[ SIZE <nWidth>, <nHeight> ] ;
[ FILENAME <cFileName> ] ;
=> ;
[ <oImg> := ] TImage():New( <nRow>, <nCol>, <nWidth>, <nHeight>, [<oWnd>],;
[<cFileName>] , .t. )
en la clase image :
Añade el metodo :
Code: Select all | Expand
METHOD SetResfile(cFileName) INLINE ImgSetresFile( ::hWnd , cFileName )
modificado metodo :
Code: Select all | Expand
METHOD New( nTop, nLeft, nWidth, nHeight, oWnd, cFileName, lres ) CLASS TImage
DEFAULT nWidth := 100, nHeight := 100
DEFAULT lres:= .f.
::hWnd = ImgCreate( nTop, nLeft, nWidth, nHeight, oWnd:hWnd )
::oWnd = oWnd
if lres
if ! Empty( cFileName )
::SetresFile( cFileName )
endif
else
if ! Empty( cFileName ) .and. File( cFileName )
::SetFile( cFileName )
endif
endif
oWnd:AddControl( Self )
return Self
Añadida function al archivo images.m de la api .
Code: Select all | Expand
HB_FUNC( IMGSETRESFILE )
{
NSImageView * image = ( NSImageView * ) hb_parnl( 1 );
NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 2 ) ? hb_parc( 2 ) : "" ] autorelease ];
NSString *myImagePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:string];
[ image setImage : [ [ NSImage alloc ] initWithContentsOfFile : myImagePath ] ];
}
cambiando en el programa la linea :
@ 100, 139 RESIMAGE oImg OF oWnd SIZE 107, 91 FILENAME "/error.tif"
Funciona perfectamente y sabe en todo momento donde debe buscar los archivos de imagen . Supongo que sacar la ruta del contenedor no será demasiado complicado .
Saludos.
---------------- editado para añadir ---------------------
Con esta otra funcion conseguimos el path de la carpeta resource correcto :
Code: Select all | Expand
HB_FUNC( RESPATH )
{
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
hb_retc( [ bundlePath cStringUsingEncoding : NSASCIIStringEncoding ] );
}
Y con esta otra el path de la aplicacion :
Code: Select all | Expand
HB_FUNC( APPPATH )
{
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
hb_retc( [ secondParentPath cStringUsingEncoding : NSASCIIStringEncoding ] );
}
![Smile :-)](./images/smilies/icon_smile.gif)
)