Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Regular Contributor
Posts: 64
Registered: ‎03-04-2010
My Device: 9930
My Carrier: VZN
Accepted Solution

img_load_file() Help!

[ Edited ]

I am having a heck of a time trying to figure out this funtion. Here is what I think it should be but!

 

	img_t			mindLogo;
	img_lib_t		ilib = NULL;
	const char 		*LP	 = "assets/logo.png";
	int	logo;
	mindLogo.flags = 0;
	mindLogo.w 	= 600;
	mindLogo.flags	|= IMG_W;
	mindLogo.h 	= 400;
	mindLogo.flags	|= IMG_H;
	logo = img_load_file(ilib, LP, NULL, &mindLogo);

It is part of a dummy's how-to-understand windows and object interactions file for myself.  I am almost sure my problem is with the const char* path of the img_load_file(). If your asking why I set the size I figured it would be safe incase future screen size or orientation changes cause any problems.

 

Here is the actual working code so far below that is just for a black parent window where I am trying to create a child img to display in the center.  Soon after text.  But the point is to make it one file one funtion for beginers practice.  Excuse the heavy commeting, I normaly wouldnt do this.

 

#include <screen/screen.h>						
#include <stdlib.h>							
#include <stdio.h>

//Start create window variables and define needed values........................
screen_context_t	hscreen_c = 0;				//Define context data type.
screen_window_t		hscreen_w = 0;			//Define window data type.
static const char 	*hmgroups = "Home Windows";	//Pointer to home group.
screen_buffer_t		hbuffer;
int hformat_w 	= SCREEN_FORMAT_RGBA8888;		//
int husage_w	= SCREEN_USAGE_NATIVE;			//
int hvis		= 0;							//
int hcolor		= 0xff000000;					//
int hshap[4]	= {0, 0, 1, 1};					//
int hdims[2]	= {0, 0};						//
int hcount = 0;							//
//End create window variables and define needed values..........................

//Start create child window variables and define needed values..................
screen_window_t		hcscreen_w = 0;				//Define child window data type.
//End create child window variables and define needed values....................

int main()
{
	//Start creating a parent window............................................
	if(screen_create_context(&hscreen_c, SCREEN_APPLICATION_CONTEXT) != 0)//Create context first.
	{
		return EXIT_FAILURE;
	}//end if

	if(screen_create_window(&hscreen_w, hscreen_c) != 0)//Create window.
	{
		screen_destroy_context(hscreen_c);
		return EXIT_FAILURE;
	}//end if

	if(screen_create_window_group(hscreen_w, hmgroups) != 0)//Create group for window.
	{
		return EXIT_FAILURE;
	}//end if

	if(screen_set_window_property_iv(hscreen_w, SCREEN_PROPERTY_FORMAT, &hformat_w) != 0)//Set window color display property.
	{
		return EXIT_FAILURE;
	}//end if

	if(screen_set_window_property_iv(hscreen_w, SCREEN_PROPERTY_USAGE, &husage_w) != 0)//Set window usage property.
	{
		return EXIT_FAILURE;
	}//end if

	if(screen_set_window_property_iv(hscreen_w, SCREEN_PROPERTY_VISIBLE, &hvis) != 0)//Set window visibility.
	{
		return EXIT_FAILURE;
	}

	if(screen_set_window_property_iv(hscreen_w, SCREEN_PROPERTY_COLOR, &hcolor) != 0)//Set window color.(Black)
	{
		return EXIT_FAILURE;
	}

	if(screen_set_window_property_iv(hscreen_w, SCREEN_PROPERTY_BUFFER_SIZE, hshap+2) != 0)//Set window shape.
	{
		return EXIT_FAILURE;
	}

	screen_get_context_property_iv(hscreen_c, SCREEN_PROPERTY_DISPLAY_COUNT, &hcount);

	screen_display_t *hdisps = calloc(hcount, sizeof(screen_display_t));
	screen_get_context_property_pv(hscreen_c, SCREEN_PROPERTY_DISPLAYS, (void **)hdisps);

	screen_display_t hdisp = hdisps[0];
	free(hdisps);

	screen_get_display_property_iv(hdisp, SCREEN_PROPERTY_SIZE, hdims);

	if(screen_set_window_property_iv(hscreen_w, SCREEN_PROPERTY_SOURCE_SIZE, hdims) != 0)//Set window
	{
		return EXIT_FAILURE;
	}
	int hpos[2] = { -hdims[0], -hdims[1] };
	screen_set_window_property_iv(hscreen_w, SCREEN_PROPERTY_SOURCE_POSITION, hpos);

	if(screen_create_window_buffers(hscreen_w, 1) != 0)//Set number of screen buffers.
	{
		return EXIT_FAILURE;
	}//end if

	screen_get_window_property_pv(hscreen_w, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&hbuffer);
	screen_post_window(hscreen_w, hbuffer, 1, hshap, 0);

	//End creating a parent window..............................................
	//Note: There is now a black screen that is 1024 x 600.  Objects go here.

	//Start destroying window. (To be done on exit.)............................
	if(screen_destroy_window(hscreen_w) != 0)//Destroy the window first.
	{
		return EXIT_FAILURE;
	}

	if(screen_destroy_context(hscreen_c) != 0)//Destroy the context last.
	{
		return EXIT_FAILURE;
	}
	//End destroying window.....................................................

return 0;
}//end main

 To make sure I don't confuse associations I just lump the image load info just after the parent window is posted.  I also #include <img/img.h>.  Can someone maybe lead me on the right path.

 

Brandon Clark
The Mind Company | www.themindspot.com

Regular Contributor
Posts: 64
Registered: ‎03-04-2010
My Device: 9930
My Carrier: VZN

An update.

I noticed I did leave out the img_attach_lib() and applied it as I think it was ment but not that has its own problems.

 

	img_t		mindLogo;
	img_lib_t	ilib = NULL;
	const char 	*LP	 = "assets/logo.png";
	int		largeLogo;
	int		logolib;
	logolib 	= img_lib_attach(&ilib);
	mindLogo.flags 	= 0;
	mindLogo.w 	= 600;
	mindLogo.flags	|= IMG_W;
	mindLogo.h 	= 400;
	mindLogo.flags	|= IMG_H;
	largeLogo	= img_load_file(logolib, LP, NULL, &mindLogo);

 

Brandon Clark
The Mind Company | www.themindspot.com

Regular Contributor
Posts: 64
Registered: ‎03-04-2010
My Device: 9930
My Carrier: VZN

Re: An update.

Soultion is to link img library.  Also my above is correct with the modification of :

largeLogo	= img_load_file(logolib, LP, NULL, &mindLogo);

 to

largeLogo	= img_load_file(ilib, LP, NULL, &mindLogo);

 

See other post for more info:

http://supportforums.blackberry.com/t5/Native-SDK-for-BlackBerry-Tablet/img-lib-attach-How-to-questi...

Brandon Clark
The Mind Company | www.themindspot.com