Sha256: 9e5d31698974d970f6bf17616336011a3d173833e55f20f4d8d82baf7c660948

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

#include <GosuImpl/Orientation.hpp>
#include <Gosu/Timing.hpp>
#import <UIKit/UIKit.h>

namespace
{
    static const unsigned CHANGE_AFTER_MS = 500;
    
    Gosu::Orientation orientationToGosu(UIDeviceOrientation orientation)
    {
        return orientation == UIDeviceOrientationLandscapeLeft ? Gosu::orLandscapeLeft : Gosu::orLandscapeRight;
    }
}

Gosu::Orientation Gosu::currentOrientation()
{
    UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation];
    unsigned now = Gosu::milliseconds();
    
    static Orientation orientation = Gosu::Orientation(-1);
    static unsigned waitingForChangeSince = now;
    
    if (not UIDeviceOrientationIsLandscape(newOrientation) or orientationToGosu(newOrientation) == orientation)
        waitingForChangeSince = now;
    
    if (now - waitingForChangeSince >= CHANGE_AFTER_MS or orientation == Gosu::Orientation(-1))
    {
        orientation = orientationToGosu(newOrientation);
        [UIApplication sharedApplication].statusBarOrientation =
            (newOrientation == UIDeviceOrientationLandscapeLeft ? UIInterfaceOrientationLandscapeRight : UIInterfaceOrientationLandscapeLeft);
    }
    
    return orientation;
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gosu-0.7.47.1 GosuImpl/Orientation.mm
gosu-0.7.46 GosuImpl/Orientation.mm
gosu-0.7.45 GosuImpl/Orientation.mm
gosu-0.7.44 GosuImpl/Orientation.mm
gosu-0.7.43 GosuImpl/Orientation.mm
gosu-0.7.41 GosuImpl/Orientation.mm