From Tomas Hogarth, "Attached are the complete changed files GraphicsWindowIOS and GraphicsWindowIOS.mm. The change is in regard to the ability to adapt to device orientation. We did just have a bool indicating the window would adapt to all orientations. I have changed this to a bit mask allowing the user to specify individual orientations or combinations.
enum DeviceOrientation{ PORTRAIT_ORIENTATION = 1<<0, PORTRAIT_UPSIDEDOWN_ORIENTATION = 1<<1, LANDSCAPE_LEFT_ORIENTATION = 1<<2, LANDSCAPE_RIGHT_ORIENTATION = 1<<3, ALL_ORIENTATIONS = PORTRAIT_ORIENTATION | PORTRAIT_UPSIDEDOWN_ORIENTATION | LANDSCAPE_LEFT_ORIENTATION | LANDSCAPE_RIGHT_ORIENTATION }; typedef unsigned int DeviceOrientationFlags; The main motivation for this is to easily allow the user to specifiy that the device is in a horizontal orientation rather then having to rotate the view matrix. All flags have been tested individually as well as in combinations. The default is ALL_ORIENTATIONS to keep the exiting functionality for anyone who hasn't specified WindowData for their context traits. "
This commit is contained in:
parent
4d0b96c074
commit
9bfb043a16
@ -60,7 +60,7 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
|
||||
_viewController(NULL),
|
||||
_context(NULL),
|
||||
_ownsWindow(true),
|
||||
_adaptToDeviceOrientation(true),
|
||||
_deviceOrientationFlags(WindowData::ALL_ORIENTATIONS),
|
||||
_viewContentScaleFactor(-1.0f)
|
||||
{
|
||||
_traits = traits;
|
||||
@ -135,22 +135,31 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
|
||||
class WindowData : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
WindowData(UIWindow* window = NULL, bool adaptToDeviceOrientation = true, float scaleFactor = -1.0f)
|
||||
enum DeviceOrientation{
|
||||
PORTRAIT_ORIENTATION = 1<<0,
|
||||
PORTRAIT_UPSIDEDOWN_ORIENTATION = 1<<1,
|
||||
LANDSCAPE_LEFT_ORIENTATION = 1<<2,
|
||||
LANDSCAPE_RIGHT_ORIENTATION = 1<<3,
|
||||
ALL_ORIENTATIONS = PORTRAIT_ORIENTATION | PORTRAIT_UPSIDEDOWN_ORIENTATION | LANDSCAPE_LEFT_ORIENTATION | LANDSCAPE_RIGHT_ORIENTATION
|
||||
};
|
||||
typedef unsigned int DeviceOrientationFlags;
|
||||
|
||||
WindowData(UIWindow* window = NULL, DeviceOrientationFlags orientationFlags = ALL_ORIENTATIONS, float scaleFactor = -1.0f)
|
||||
: _window(window),
|
||||
_adaptToDeviceOrientation(adaptToDeviceOrientation),
|
||||
_deviceOrientationFlags(orientationFlags),
|
||||
_viewContentScaleFactor(scaleFactor)
|
||||
{
|
||||
}
|
||||
|
||||
void setAdaptToDeviceOrientation(bool flag) { _adaptToDeviceOrientation = flag; }
|
||||
void setAdaptToDeviceOrientation(DeviceOrientationFlags flags) { _deviceOrientationFlags = flags; }
|
||||
|
||||
void setViewContentScaleFactor(float scaleFactor) { _viewContentScaleFactor = scaleFactor; }
|
||||
|
||||
private:
|
||||
|
||||
UIWindow* _window;
|
||||
bool _adaptToDeviceOrientation;
|
||||
float _viewContentScaleFactor;
|
||||
UIWindow* _window;
|
||||
DeviceOrientationFlags _deviceOrientationFlags;
|
||||
float _viewContentScaleFactor;
|
||||
|
||||
friend class GraphicsWindowIOS;
|
||||
|
||||
@ -165,9 +174,9 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
|
||||
void adaptResize(int x, int y, int w, int h);
|
||||
|
||||
|
||||
bool adaptToDeviceOrientation() const { return _adaptToDeviceOrientation; }
|
||||
WindowData::DeviceOrientationFlags getDeviceOrientationFlags() const { return _deviceOrientationFlags; }
|
||||
|
||||
void setAdaptToDeviceOrientation(bool flag) { _adaptToDeviceOrientation = flag; }
|
||||
void getDeviceOrientationFlags(WindowData::DeviceOrientationFlags flags) { _deviceOrientationFlags = flags; }
|
||||
|
||||
|
||||
//
|
||||
@ -192,15 +201,17 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
|
||||
|
||||
private:
|
||||
|
||||
GraphicsWindowIOSWindow* _window;
|
||||
GraphicsWindowIOSGLView* _view;
|
||||
GraphicsWindowIOSWindow* _window;
|
||||
GraphicsWindowIOSGLView* _view;
|
||||
GraphicsWindowIOSGLViewController* _viewController;
|
||||
EAGLContext* _context;
|
||||
bool _updateContext;
|
||||
EAGLContext* _context;
|
||||
bool _updateContext;
|
||||
|
||||
bool _ownsWindow, _adaptToDeviceOrientation;
|
||||
bool _ownsWindow;
|
||||
|
||||
WindowData::DeviceOrientationFlags _deviceOrientationFlags;
|
||||
|
||||
float _viewContentScaleFactor;
|
||||
float _viewContentScaleFactor;
|
||||
|
||||
};
|
||||
|
||||
|
@ -510,21 +510,35 @@
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
{
|
||||
osgViewer::GraphicsWindowIOS* win = [(GraphicsWindowIOSGLView*)(self.view) getGraphicsWindow];
|
||||
|
||||
if ((win) && (win->adaptToDeviceOrientation() == false))
|
||||
return NO;
|
||||
if(!win){return NO;}
|
||||
|
||||
osgViewer::GraphicsWindowIOS::WindowData::DeviceOrientationFlags flags = win->getDeviceOrientationFlags();
|
||||
|
||||
|
||||
BOOL result(NO);
|
||||
|
||||
switch (interfaceOrientation) {
|
||||
case UIDeviceOrientationPortrait:
|
||||
if(flags & osgViewer::GraphicsWindowIOS::WindowData::PORTRAIT_ORIENTATION){
|
||||
result = YES;
|
||||
}
|
||||
break;
|
||||
case UIDeviceOrientationPortraitUpsideDown:
|
||||
result = YES;
|
||||
if(flags & osgViewer::GraphicsWindowIOS::WindowData::PORTRAIT_UPSIDEDOWN_ORIENTATION){
|
||||
result = YES;
|
||||
}
|
||||
break;
|
||||
case UIInterfaceOrientationLandscapeLeft:
|
||||
if(win->getTraits()->supportsResize && flags & osgViewer::GraphicsWindowIOS::WindowData::LANDSCAPE_LEFT_ORIENTATION){
|
||||
result = YES;
|
||||
}
|
||||
break;
|
||||
case UIInterfaceOrientationLandscapeRight:
|
||||
if(win->getTraits()->supportsResize && flags & osgViewer::GraphicsWindowIOS::WindowData::LANDSCAPE_RIGHT_ORIENTATION){
|
||||
result = YES;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
result = (win) ? (win->getTraits()->supportsResize) ? YES : NO : NO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
OSG_INFO << "shouldAutorotateToInterfaceOrientation for " << interfaceOrientation << ": " << ((result==YES) ? "YES" : "NO") << std::endl;
|
||||
@ -630,7 +644,7 @@ bool GraphicsWindowIOS::realizeImplementation()
|
||||
_window = windowData->_window;
|
||||
}
|
||||
|
||||
_adaptToDeviceOrientation = windowData->_adaptToDeviceOrientation;
|
||||
_deviceOrientationFlags = windowData->_deviceOrientationFlags;
|
||||
_viewContentScaleFactor = windowData->_viewContentScaleFactor;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user