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
New Developer
lmuller
Posts: 20
Registered: ‎03-27-2012
My Device: Z10 LE, PlayBook & Dev Alpha C
My Carrier: Vodafone

How to set an orientation depending on the screensize in native code?

Hi!

 

I'm currently working on a game and am trying to set the orientation depending on the screensize of the device.

 

With one package I'd like to support the Dev Alpha A/B but also the new keyboard device (Dev Alpha C?) with the squared display (720x720px).

 

On devices like the Dev Alpha A/B it should launch in landscape mode (touch controls), on the Dev Alpha C it should launch in portait mode (key controls). I don't want to allow automatic orientation of the app.

 

I've tried to set the orientation on launch using:

bbutil_rotate_screen_surface(angle)

Unfortunately this only seens to rotate the surface but not the navigator? When I query the screensize with eglQuerySurface it does seem to return the proper width/height values.

 

Do I need an aditional call to make it rotate to the requested orientation?

 

 

 

Just FYI, if I use auto orientation with the following code, it does resize/rotate properly. The problem however is that at least on my Dev Alpha B device it will always launch the app in portait mode first even if my device is rotated in landscape.

 

bar-descriptor.xml

<initialWindow>
	<autoOrients>true</autoOrients>
	<systemChrome>none</systemChrome>
	<transparent>false</transparent>
</initialWindow>

Navigator event handler:

case NAVIGATOR_ORIENTATION_CHECK: {
	//Signal navigator that we intend to resize
	navigator_orientation_check_response(event_bps, true);
}
break;

case NAVIGATOR_ORIENTATION: {
	if (EXIT_FAILURE == qnxResize(event_bps)) {
		ofLogError("ofAppQNXWindow") << "Could not resize...";
		qnxIsRunning = false;
		return;
	}
}
break;

 Handle the resize:

int ofAppQNXWindow::qnxResize(bps_event_t *event) {

	if (event) {
		int angle = navigator_event_get_orientation_angle(event);

		//Let bbutil rotate current screen surface to this angle
		if (EXIT_FAILURE == bbutil_rotate_screen_surface(angle)) {
			return EXIT_FAILURE;
		}
	}

	EGLint surface_width, surface_height;
	eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width);
	eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height);

	EGLint err = eglGetError();
	if (err != 0x3000) {
		return EXIT_FAILURE;
	}

	qnxWindowWidth = surface_width;
	qnxWindowHeight = surface_height;

	ofNotifyWindowResized(qnxWindowWidth, qnxWindowHeight);

	qnxUpdate();
	if (event) {
		qnxRender();
		navigator_done_orientation(event);
	}

	return EXIT_SUCCESS;
}

 

 

 

 

 

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: How to set an orientation depending on the screensize in native code?

[ Edited ]

We'll have to wait and see what the Dev Alpha C provides, but I have a feeling that specifying "landscape" in the bar-descriptor will do the right thing on both devices.  (eg. that landscape and portrait on the -C may be the same thing).

 

That's just speculation though.  Solving the problem the right way would be a good thing.

I know in cascades, you can do something like:

    OrientationSupport::instance()->setSupportedDisplayOrientation(
                SupportedDisplayOrientation::DisplayLandscape);

 So there should be a native equivalent...

 

have you looked in bps/navigator.h?

there are lots of functions in there.. for example:

navigator_rotation_lock()

navigator_set_orientation()

navigator_set_orientation_mode()

navigator_set_window_angle()

....

Please use plain text.
New Developer
lmuller
Posts: 20
Registered: ‎03-27-2012
My Device: Z10 LE, PlayBook & Dev Alpha C
My Carrier: Vodafone

Re: How to set an orientation depending on the screensize in native code?

Hi Sean,

 

I've did some more work today trying to figure it out but I guess it is just broken for some reason...

 

I tried to do the opposite as well, launch it in landscape mode then try to set it to portait.

 

Code snippet:

// Get screen dimensions
EGLint surface_width, surface_height;
eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width);
eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height);

// Show in log
ofLogNotice("ofAppQNXWindow") << "surface_width: " << surface_width;
ofLogNotice("ofAppQNXWindow") << "surface_height: " << surface_height;

// Rotate the surface
bbutil_rotate_screen_surface(0);

// Rotate the navigator
navigator_set_orientation(NAVIGATOR_TOP_UP, 0);
navigator_set_orientation_mode(NAVIGATOR_PORTRAIT, 0);

// Get screen dimensions again
eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width);
eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height);

ofLogNotice("ofAppQNXWindow") << "surface_width: " << surface_width;
ofLogNotice("ofAppQNXWindow") << "surface_height: " << surface_height;

 

Result:

[ofAppQNXWindow:notice] surface_width: 1280
[ofAppQNXWindow:notice] surface_height: 768
[ofAppQNXWindow:notice] surface_width: 768
[ofAppQNXWindow:notice] surface_height: 1280

 So bbutil_rotate_screen_surface seems to rotate the surface just fine (the values of width and height are swapped properly) but the navigator won't change. I still have to swipe from the wrong end to put the app to the background.

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: How to set an orientation depending on the screensize in native code?

Have you looked at the source for bbutil_rotate_screen_surface()?  does it even talk to navigator?  To reorient the device correctly, you need to interact with navigator (the window manager).

 

Keep in mind that bbutil.c is just some helper code written by a sample author.

It looks like the function you are talking about is purely meant to be used in reaction to a navigator reorient event.  It's just updating window properties.

 

As mentioned earlier, you should be looking for a navigator function, not a screen function.

 

Cheers,

Sean

Please use plain text.
New Developer
lmuller
Posts: 20
Registered: ‎03-27-2012
My Device: Z10 LE, PlayBook & Dev Alpha C
My Carrier: Vodafone

Re: How to set an orientation depending on the screensize in native code?

[ Edited ]

In the bbutil_rotate_screen_surface function it only takes care of the opengl screen surface. It doesn't talks to the navigator.

 

Besides destroying and recreating a surface it only does this at the end:

( http://origin-developer.blackberry.com/native/reference/bb10/screen_libref/topic/screen_set_window_p... )

 

https://github.com/falcon4ever/ofxQNX/blob/develop/src/bbutil.c#L966

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

 

SCREEN_PROPERTY_ROTATION

A single integer that defines the current rotation of the API object.

When retrieving or setting this property type, ensure that you provide sufficient storage for one integer. The following API objects have this property, each with its own variant of this definition:

  • display: The current rotation of the display. The rotation value is one of: 090180270 degrees clockwise. Its used for the positioning and sizing of the display. Changing the display rotation, does not implicitly change any window properties.
  • window: The current rotation of the window. Window rotation is absolute. In the configuration file, graphics.conf, the value of this property can be set so that windows of a specified class will have its property initialized to this value. The following is the usage for setting this property in graphics.conf:
    • rotation = [rotation 0, 90, 180, 270]

 

According to the documentation the following two functions should be able to set the navigator:

 

navigator_set_orientation()

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_re...

 

navigator_set_orientation_mode()

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_re...

 

When you run the code sample above, both methods return BPS_SUCCESS without even rotating the navigator...

 

*update*

I just checked the result of navigator_get_device_lock_state() and it returns NAVIGATOR_DEVICE_LOCK_STATE_UNLOCKED

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: How to set an orientation depending on the screensize in native code?

yup, it's going to be one of the navigator functions.

I'll clarify the usage with the nav folks in the coming days.

 

regarding navigator_get_device_lock_state(), that's just going to tell you whether your screen is awake, asleep, locked, etc.  I don't think it relates to orientation-lock.

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: How to set an orientation depending on the screensize in native code?

Hi Laurence,

It sounds like things are still in flux a bit here regarding the 1:1 devices.

I am pretty sure that if you explicitly force your app to "landscape" mode in your bar-descriptor file, that it will be handled properly on the keyboard device.  (eg. that portrait and landscape mode are actually going to behave the same -- keyboard at bottom).

We'll have to revisit this when devices become available, but this is my preliminary understanding, and you can probably plan accordingly.

 

Cheers,

Sean

Please use plain text.
New Developer
lmuller
Posts: 20
Registered: ‎03-27-2012
My Device: Z10 LE, PlayBook & Dev Alpha C
My Carrier: Vodafone

Re: How to set an orientation depending on the screensize in native code?

Hi Sean,

thanks for the update. For now we will indeed just force our app to run in landscape mode. We'll see how things go after BB10 is launched and the new devices are released.
Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: How to set an orientation depending on the screensize in native code?

yup. at worst, you may just need a small update when keyboard-devices are available.

 

 

Please use plain text.