Sha256: f64d338dcd0262d1ac2d6a84e9062ff27666d80f69f55fc9fd5a9d1ab1db5aa3

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

#include "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

1 entries across 1 versions & 1 rubygems

Version Path
gosu-0.7.48 GosuImpl/Orientation.mm