01-26-2013 05:05 PM
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;
}
01-27-2013 04:57 AM - edited 01-27-2013 05:01 AM
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()
....
01-27-2013 02:21 PM
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.
01-27-2013 05:55 PM
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
01-27-2013 06:10 PM - edited 01-27-2013 06:16 PM
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:
https://github.com/falcon4ever/ofxQNX/blob/develop
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:
According to the documentation the following two functions should be able to set the navigator:
navigator_set_orientation_mode()
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
01-27-2013 06:33 PM
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.
01-28-2013 05:22 PM
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
01-28-2013 05:30 PM
01-28-2013 05:33 PM
yup. at worst, you may just need a small update when keyboard-devices are available.