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
Trusted Contributor
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Rotating and resizing screen

Hi all, 

 

I am back with another screen problem, this time I am successfully listening for orientation change, I can get the screen to rotate appropriatly, I just can't seem to get the screen to go to 0,0 and fill the entire pb screen if it is rotated to portrait. I can get it to go back to how I want it when rotated back to landscape but portrait isn't doing as wanted.

 

Instead rotating to portrait is making the screen start at something like x = -200 and the screen is still wider than the 600 width I set when in portrait mode.

 

Can anyone see a problem in my code / approach?

 

The screen is shown over the top of QMainWindow and contains just an img_t and the screens width and height are set initially to the width/height of the img.

 

int MyWindow::bbutil_rotate_screen_surface(int angle) {
	int rc, rotation, skip = 1, temp;;

	int size[2];

	if ((angle != 0) && (angle != 90) && (angle != 180) && (angle != 270)) {
		fprintf(stderr, "Invalid angle\n");
		return EXIT_FAILURE;
	}

	rc = screen_get_window_property_iv(screen, SCREEN_PROPERTY_ROTATION, &rotation);
	if (rc) {
		perror("screen_set_window_property_iv");
		return EXIT_FAILURE;
	}

	rc = screen_get_window_property_iv(screen, SCREEN_PROPERTY_BUFFER_SIZE, size);
	if (rc) {
		perror("screen_set_window_property_iv");
		return EXIT_FAILURE;
	}
	cout << "\n size[0] is: " << size[0];
	cout << "\n size[1] is: " << size[1];
	cout << "\n rotation is: " << rotation;
	cout << "\n angle is: " << angle;
	cout.flush();
	boolean landscape;
	if(angle == 0 || angle == 180)
	{
		cout << "landscape mode";
		landscape = true;
	}
	else
	{
		cout << "portrait mode";
		landscape = false;
	}


	rc = screen_set_window_property_iv(screen, SCREEN_PROPERTY_ROTATION, &angle);
	navigator_set_window_angle(angle) ;
	if (rc) {
		perror("screen_set_window_property_iv");
		return EXIT_FAILURE;
	}

	if (landscape) {


		int xpos = (1024 - img.w)/2+150;
		int ypos = 0;//(600 - img.h)/2 ;
		viewport_size[0] = img.w;
		viewport_size[1] = img.h;
		viewport_pos[0] = xpos;
		viewport_pos[1] = ypos;
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_POSITION , viewport_pos);
		//screen_set_window_property_iv(screen, SCREEN_PROPERTY_SOURCE_SIZE , viewport_size);
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_SIZE , viewport_size);
		screen_flush_context(screencontext,0);


	}
	else
	{
		//img.w = 600;
		//img.h = 1024;
		viewport_size[0] = 600;
		viewport_size[1] = 1024;
		viewport_pos[0] = 0;
		viewport_pos[1] = 0;
		//screen_set_window_property_iv(screen, SCREEN_PROPERTY_SOURCE_POSITION , viewport_pos);
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_POSITION , viewport_pos);
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_SIZE , viewport_size);
		screen_flush_context(screencontext,0);
	}

	return EXIT_SUCCESS;
}

 

Trusted Contributor
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: Rotating and resizing screen

nearly solved this problem now, i have also added set buffer_size of screen and swapped around my array values as [0] is for height and [1] is for width when in portrait mode it seems.

 

My only issue now is even though the code is run for both if i rotate to right portrait or left potrait  the screen ends up starting at something like y = 100 when rotating right compared to starting (correctly) at 0 when rotated left.

 

if(landscape)
{
  //do stuff
}
	else
	{
		
		viewport_size[0] = 900;
		viewport_size[1] = 600;
		viewport_pos[0] = 1;
		viewport_pos[1] = 1;
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_SOURCE_POSITION , viewport_pos);
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_POSITION , viewport_pos);
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_SIZE , viewport_size);
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_BUFFER_SIZE , viewport_size);

	}

 

Trusted Contributor
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: Rotating and resizing screen

Could anybody advise what they would do when handling rotation in a qt app when a native screen is shown over the top of a QMainWindow?

 

I can get the native screen to rotate using code provided but that seems to break the qt window when i then remove the native window - it then no longer rotates.

 

Is there a way of doing this properly?