1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added checks to make sure that the current interface orientation is actually allowed when changing allowed interface orientations

This commit is contained in:
hogliux 2016-10-03 14:39:54 +01:00
parent 848073d207
commit 40994fcdab

View file

@ -48,6 +48,20 @@ namespace Orientations
return Desktop::upright;
}
static UIInterfaceOrientation convertFromJuce (Desktop::DisplayOrientation orientation)
{
switch (orientation)
{
case Desktop::upright: return UIInterfaceOrientationPortrait;
case Desktop::upsideDown: return UIInterfaceOrientationPortraitUpsideDown;
case Desktop::rotatedClockwise: return UIInterfaceOrientationLandscapeLeft;
case Desktop::rotatedAntiClockwise: return UIInterfaceOrientationLandscapeRight;
default: jassertfalse; // unknown orientation!
}
return UIInterfaceOrientationPortrait;
}
static CGAffineTransform getCGTransformFor (const Desktop::DisplayOrientation orientation) noexcept
{
if (isUsingOldRotationMethod())
@ -1029,7 +1043,30 @@ void Desktop::setKioskComponent (Component* kioskModeComp, bool enableOrDisable,
}
}
void Desktop::allowedOrientationsChanged() {}
void Desktop::allowedOrientationsChanged()
{
// if the current orientation isn't allowed anymore then switch orientations
if (! isOrientationEnabled (getCurrentOrientation()))
{
DisplayOrientation orientations[] = { upright, upsideDown, rotatedClockwise, rotatedAntiClockwise };
const int n = sizeof (orientations) / sizeof (DisplayOrientation);
int i;
for (i = 0; i < n; ++i)
if (isOrientationEnabled (orientations[i]))
break;
// you need to support at least one orientation
jassert (i < n);
i = jmin (n - 1, i);
NSNumber *value = [NSNumber numberWithInt:Orientations::convertFromJuce (orientations[i])];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[value release];
}
}
//==============================================================================
void UIViewComponentPeer::repaint (const Rectangle<int>& area)