Browse Source

iOS rotation and desktop positioning fixes.

tags/2021-05-28
jules 13 years ago
parent
commit
0e898a5d7c
1 changed files with 36 additions and 17 deletions
  1. +36
    -17
      modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm

+ 36
- 17
modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm View File

@@ -230,6 +230,14 @@ private:
JuceUIView* juceView = (JuceUIView*) [self view]; JuceUIView* juceView = (JuceUIView*) [self view];
jassert (juceView != nil && juceView->owner != nullptr); jassert (juceView != nil && juceView->owner != nullptr);
juceView->owner->displayRotated(); juceView->owner->displayRotated();
[UIView setAnimationsEnabled: YES];
}
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation
duration: (NSTimeInterval) duration
{
[UIView setAnimationsEnabled: NO]; // disable this because it goes the wrong way and looks like crap.
} }
@end @end
@@ -488,7 +496,7 @@ void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNo
{ {
const Rectangle<int> bounds (rotatedScreenPosToReal (Rectangle<int> (x, y, w, h))); const Rectangle<int> bounds (rotatedScreenPosToReal (Rectangle<int> (x, y, w, h)));
window.frame = convertToCGRect (bounds); window.frame = convertToCGRect (bounds);
view.frame = CGRectMake (0, 0, (CGFloat) bounds.getWidth(), (CGFloat) bounds.getHeight());
view.frame = CGRectMake (0, 0, (CGFloat) w, (CGFloat) h);
handleMovedOrResized(); handleMovedOrResized();
} }
@@ -500,13 +508,10 @@ Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
if (global && view.window != nil) if (global && view.window != nil)
{ {
r = [view convertRect: r toView: nil];
CGRect wr = view.window.frame;
r = [view convertRect: r toView: view.window];
r = [view.window convertRect: r toWindow: nil];
const Rectangle<int> windowBounds (realScreenPosToRotated (convertToRectInt (wr)));
r.origin.x += windowBounds.getX();
r.origin.y += windowBounds.getY();
return realScreenPosToRotated (convertToRectInt (r));
} }
return convertToRectInt (r); return convertToRectInt (r);
@@ -601,7 +606,7 @@ bool UIViewComponentPeer::isFullScreen() const
namespace namespace
{ {
Desktop::DisplayOrientation convertToJuceOrientation (UIInterfaceOrientation interfaceOrientation)
static Desktop::DisplayOrientation convertToJuceOrientation (UIInterfaceOrientation interfaceOrientation)
{ {
switch (interfaceOrientation) switch (interfaceOrientation)
{ {
@@ -614,6 +619,19 @@ namespace
return Desktop::upright; return Desktop::upright;
} }
static CGAffineTransform getCGTransformForDisplayOrientation (const Desktop::DisplayOrientation orientation) noexcept
{
switch (orientation)
{
case Desktop::upsideDown: return CGAffineTransformMake (-1, 0, 0, -1, 0, 0);
case Desktop::rotatedClockwise: return CGAffineTransformMake (0, -1, 1, 0, 0, 0);
case Desktop::rotatedAntiClockwise: return CGAffineTransformMake (0, 1, -1, 0, 0, 0);
default: break;
}
return CGAffineTransformIdentity;
}
} }
BOOL UIViewComponentPeer::shouldRotate (UIInterfaceOrientation interfaceOrientation) BOOL UIViewComponentPeer::shouldRotate (UIInterfaceOrientation interfaceOrientation)
@@ -629,6 +647,9 @@ void UIViewComponentPeer::displayRotated()
const_cast <Desktop::Displays&> (desktop.getDisplays()).refresh(); const_cast <Desktop::Displays&> (desktop.getDisplays()).refresh();
window.transform = getCGTransformForDisplayOrientation (desktop.getCurrentOrientation());
view.transform = CGAffineTransformIdentity;
if (fullScreen) if (fullScreen)
{ {
fullScreen = false; fullScreen = false;
@@ -636,18 +657,16 @@ void UIViewComponentPeer::displayRotated()
} }
else if (! isSharedWindow) else if (! isSharedWindow)
{ {
const float l = oldArea.getX() / (float) oldDesktop.getWidth();
const float r = oldArea.getRight() / (float) oldDesktop.getWidth();
const float t = oldArea.getY() / (float) oldDesktop.getHeight();
const float b = oldArea.getBottom() / (float) oldDesktop.getHeight();
// this will re-centre the window, but leave its size unchanged
const float centreRelX = oldArea.getCentreX() / (float) oldDesktop.getWidth();
const float centreRelY = oldArea.getCentreY() / (float) oldDesktop.getHeight();
const Rectangle<int> newDesktop (desktop.getDisplays().getMainDisplay().userArea); const Rectangle<int> newDesktop (desktop.getDisplays().getMainDisplay().userArea);
setBounds ((int) (l * newDesktop.getWidth()),
(int) (t * newDesktop.getHeight()),
(int) ((r - l) * newDesktop.getWidth()),
(int) ((b - t) * newDesktop.getHeight()),
false);
const int x = ((int) (newDesktop.getWidth() * centreRelX)) - (oldArea.getWidth() / 2);
const int y = ((int) (newDesktop.getHeight() * centreRelY)) - (oldArea.getHeight() / 2);
setBounds (x, y, oldArea.getWidth(), oldArea.getHeight(), false);
} }
} }


Loading…
Cancel
Save