mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-29 02:40:05 +00:00
Fixed some iOS screen position problems.
This commit is contained in:
parent
d5dc5b2ba9
commit
e5172b88e9
2 changed files with 94 additions and 60 deletions
|
|
@ -25,6 +25,49 @@
|
|||
|
||||
class UIViewComponentPeer;
|
||||
|
||||
namespace Orientations
|
||||
{
|
||||
static Desktop::DisplayOrientation convertToJuce (UIInterfaceOrientation orientation)
|
||||
{
|
||||
switch (orientation)
|
||||
{
|
||||
case UIInterfaceOrientationPortrait: return Desktop::upright;
|
||||
case UIInterfaceOrientationPortraitUpsideDown: return Desktop::upsideDown;
|
||||
case UIInterfaceOrientationLandscapeLeft: return Desktop::rotatedClockwise;
|
||||
case UIInterfaceOrientationLandscapeRight: return Desktop::rotatedAntiClockwise;
|
||||
default: jassertfalse; // unknown orientation!
|
||||
}
|
||||
|
||||
return Desktop::upright;
|
||||
}
|
||||
|
||||
static CGAffineTransform getCGTransformFor (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;
|
||||
}
|
||||
|
||||
static NSUInteger getSupportedOrientations()
|
||||
{
|
||||
NSUInteger allowed = 0;
|
||||
Desktop& d = Desktop::getInstance();
|
||||
|
||||
if (d.isOrientationEnabled (Desktop::upright)) allowed |= UIInterfaceOrientationMaskPortrait;
|
||||
if (d.isOrientationEnabled (Desktop::upsideDown)) allowed |= UIInterfaceOrientationMaskPortraitUpsideDown;
|
||||
if (d.isOrientationEnabled (Desktop::rotatedClockwise)) allowed |= UIInterfaceOrientationMaskLandscapeLeft;
|
||||
if (d.isOrientationEnabled (Desktop::rotatedAntiClockwise)) allowed |= UIInterfaceOrientationMaskLandscapeRight;
|
||||
|
||||
return allowed;
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
} // (juce namespace)
|
||||
|
||||
|
|
@ -57,7 +100,9 @@ class UIViewComponentPeer;
|
|||
{
|
||||
}
|
||||
|
||||
- (NSUInteger) supportedInterfaceOrientations;
|
||||
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation;
|
||||
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration: (NSTimeInterval) duration;
|
||||
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation;
|
||||
@end
|
||||
|
||||
|
|
@ -128,8 +173,7 @@ public:
|
|||
void updateHiddenTextContent (TextInputTarget* target);
|
||||
void globalFocusChanged (Component*);
|
||||
|
||||
virtual BOOL shouldRotate (UIInterfaceOrientation interfaceOrientation);
|
||||
virtual void displayRotated();
|
||||
void updateTransformAndScreenBounds();
|
||||
|
||||
void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
|
||||
|
||||
|
|
@ -215,20 +259,14 @@ private:
|
|||
|
||||
@implementation JuceUIViewController
|
||||
|
||||
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
|
||||
- (NSUInteger) supportedInterfaceOrientations
|
||||
{
|
||||
JuceUIView* juceView = (JuceUIView*) [self view];
|
||||
jassert (juceView != nil && juceView->owner != nullptr);
|
||||
return juceView->owner->shouldRotate (interfaceOrientation);
|
||||
return Orientations::getSupportedOrientations();
|
||||
}
|
||||
|
||||
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation
|
||||
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
|
||||
{
|
||||
JuceUIView* juceView = (JuceUIView*) [self view];
|
||||
jassert (juceView != nil && juceView->owner != nullptr);
|
||||
juceView->owner->displayRotated();
|
||||
|
||||
[UIView setAnimationsEnabled: YES];
|
||||
return Desktop::getInstance().isOrientationEnabled (Orientations::convertToJuce (interfaceOrientation));
|
||||
}
|
||||
|
||||
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation
|
||||
|
|
@ -237,15 +275,41 @@ private:
|
|||
[UIView setAnimationsEnabled: NO]; // disable this because it goes the wrong way and looks like crap.
|
||||
}
|
||||
|
||||
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation
|
||||
{
|
||||
JuceUIView* juceView = (JuceUIView*) [self view];
|
||||
jassert (juceView != nil && juceView->owner != nullptr);
|
||||
juceView->owner->updateTransformAndScreenBounds();
|
||||
|
||||
[UIView setAnimationsEnabled: YES];
|
||||
}
|
||||
|
||||
- (void) viewDidLoad
|
||||
{
|
||||
JuceUIView* juceView = (JuceUIView*) [self view];
|
||||
jassert (juceView != nil && juceView->owner != nullptr);
|
||||
juceView->owner->updateTransformAndScreenBounds();
|
||||
}
|
||||
|
||||
- (void) viewWillAppear: (BOOL) animated
|
||||
{
|
||||
[self viewDidLoad];
|
||||
}
|
||||
|
||||
- (void) viewDidAppear: (BOOL) animated
|
||||
{
|
||||
[self viewDidLoad];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation JuceUIView
|
||||
|
||||
- (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
|
||||
- (JuceUIView*) initWithOwner: (UIViewComponentPeer*) peer
|
||||
withFrame: (CGRect) frame
|
||||
{
|
||||
[super initWithFrame: frame];
|
||||
owner = owner_;
|
||||
owner = peer;
|
||||
|
||||
hiddenTextView = [[UITextView alloc] initWithFrame: CGRectZero];
|
||||
[self addSubview: hiddenTextView];
|
||||
|
|
@ -352,9 +416,9 @@ juce::Point<int> juce_lastMousePos;
|
|||
//==============================================================================
|
||||
@implementation JuceUIWindow
|
||||
|
||||
- (void) setOwner: (UIViewComponentPeer*) owner_
|
||||
- (void) setOwner: (UIViewComponentPeer*) peer
|
||||
{
|
||||
owner = owner_;
|
||||
owner = peer;
|
||||
isZooming = false;
|
||||
}
|
||||
|
||||
|
|
@ -383,7 +447,7 @@ UIViewComponentPeer::UIViewComponentPeer (Component& comp, const int windowStyle
|
|||
fullScreen (false),
|
||||
insideDrawRect (false)
|
||||
{
|
||||
CGRect r = convertToCGRect (component.getLocalBounds());
|
||||
CGRect r = convertToCGRect (component.getBounds());
|
||||
|
||||
view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
|
||||
|
||||
|
|
@ -391,6 +455,7 @@ UIViewComponentPeer::UIViewComponentPeer (Component& comp, const int windowStyle
|
|||
view.hidden = ! component.isVisible();
|
||||
view.opaque = component.isOpaque();
|
||||
view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
|
||||
view.transform = CGAffineTransformIdentity;
|
||||
|
||||
if (isSharedWindow)
|
||||
{
|
||||
|
|
@ -406,6 +471,8 @@ UIViewComponentPeer::UIViewComponentPeer (Component& comp, const int windowStyle
|
|||
r.origin.y = [UIScreen mainScreen].bounds.size.height - (r.origin.y + r.size.height);
|
||||
|
||||
window = [[JuceUIWindow alloc] init];
|
||||
window.autoresizesSubviews = NO;
|
||||
window.transform = CGAffineTransformIdentity;
|
||||
window.frame = r;
|
||||
window.opaque = component.isOpaque();
|
||||
window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
|
||||
|
|
@ -417,7 +484,7 @@ UIViewComponentPeer::UIViewComponentPeer (Component& comp, const int windowStyle
|
|||
|
||||
view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
|
||||
|
||||
[window setRootViewController: controller];
|
||||
window.rootViewController = controller;
|
||||
[window addSubview: view];
|
||||
|
||||
window.hidden = view.hidden;
|
||||
|
|
@ -601,42 +668,7 @@ bool UIViewComponentPeer::isFullScreen() const
|
|||
return fullScreen;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
static Desktop::DisplayOrientation convertToJuceOrientation (UIInterfaceOrientation interfaceOrientation)
|
||||
{
|
||||
switch (interfaceOrientation)
|
||||
{
|
||||
case UIInterfaceOrientationPortrait: return Desktop::upright;
|
||||
case UIInterfaceOrientationPortraitUpsideDown: return Desktop::upsideDown;
|
||||
case UIInterfaceOrientationLandscapeLeft: return Desktop::rotatedClockwise;
|
||||
case UIInterfaceOrientationLandscapeRight: return Desktop::rotatedAntiClockwise;
|
||||
default: jassertfalse; // unknown orientation!
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return Desktop::getInstance().isOrientationEnabled (convertToJuceOrientation (interfaceOrientation));
|
||||
}
|
||||
|
||||
void UIViewComponentPeer::displayRotated()
|
||||
void UIViewComponentPeer::updateTransformAndScreenBounds()
|
||||
{
|
||||
Desktop& desktop = Desktop::getInstance();
|
||||
const Rectangle<int> oldArea (component.getBounds());
|
||||
|
|
@ -644,7 +676,7 @@ void UIViewComponentPeer::displayRotated()
|
|||
|
||||
const_cast <Desktop::Displays&> (desktop.getDisplays()).refresh();
|
||||
|
||||
window.transform = getCGTransformForDisplayOrientation (desktop.getCurrentOrientation());
|
||||
window.transform = Orientations::getCGTransformFor (desktop.getCurrentOrientation());
|
||||
view.transform = CGAffineTransformIdentity;
|
||||
|
||||
if (fullScreen)
|
||||
|
|
@ -665,6 +697,8 @@ void UIViewComponentPeer::displayRotated()
|
|||
|
||||
setBounds (x, y, oldArea.getWidth(), oldArea.getHeight(), false);
|
||||
}
|
||||
|
||||
[view setNeedsDisplay];
|
||||
}
|
||||
|
||||
bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
|
||||
|
|
@ -896,8 +930,8 @@ void UIViewComponentPeer::drawRect (CGRect r)
|
|||
if (! component.isOpaque())
|
||||
CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
|
||||
|
||||
CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
|
||||
CoreGraphicsContext g (cg, view.bounds.size.height, [UIScreen mainScreen].scale);
|
||||
CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, getComponent().getHeight()));
|
||||
CoreGraphicsContext g (cg, getComponent().getHeight(), [UIScreen mainScreen].scale);
|
||||
|
||||
insideDrawRect = true;
|
||||
handlePaint (g);
|
||||
|
|
@ -944,8 +978,8 @@ public:
|
|||
UIViewComponentPeer* const peer;
|
||||
const Rectangle<int> rect;
|
||||
|
||||
AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
|
||||
: peer (peer_), rect (rect_)
|
||||
AsyncRepaintMessage (UIViewComponentPeer* const p, const Rectangle<int>& r)
|
||||
: peer (p), rect (r)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ void Desktop::setMousePosition (const Point<int>&)
|
|||
|
||||
Desktop::DisplayOrientation Desktop::getCurrentOrientation() const
|
||||
{
|
||||
return convertToJuceOrientation ([[UIApplication sharedApplication] statusBarOrientation]);
|
||||
return Orientations::convertToJuce ([[UIApplication sharedApplication] statusBarOrientation]);
|
||||
}
|
||||
|
||||
void Desktop::Displays::findDisplays()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue