Skip to content

Instantly share code, notes, and snippets.

@motoishmz
Created May 27, 2013 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motoishmz/5658376 to your computer and use it in GitHub Desktop.
Save motoishmz/5658376 to your computer and use it in GitHub Desktop.
@implementation SomeUtils
static NSString * const kPlistName = @"MySettings";
static NSString * const kExtention = @"plist";
+ (NSDictionary*) launchSetting
{
NSString* path = [[NSBundle mainBundle] pathForResource:kPlistName ofType:kExtention];
NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile:path];
return plist[@"LaunchView"];
}
+ (double)map:(double)value
inputMin:(double)inputMin
inputMax:(double)inputMax
outputMin:(double)outputMin
outputMax:(double)outputMax
{
/*!
[code from ofMath.cpp]
see also http://ofxfenster.undef.ch/doc/ofMath_8cpp_source.html
*/
return (value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin;
}
+ (double)convertOrientationToDegrees:(UIDeviceOrientation)orientation
{
return
orientation == UIDeviceOrientationPortrait ? 0 :
orientation == UIDeviceOrientationLandscapeRight ? 90 :
orientation == UIDeviceOrientationLandscapeLeft ? -90 :
0;
}
+ (CGPoint)convertTouchToRatioInScreen:(CGPoint)point orientation:(UIDeviceOrientation)orientation;
{
static const float minRatio = -1.0;
static const float maxRatio = 1.0;
CGFloat deviceWidth = CGRectGetWidth([[UIScreen mainScreen] bounds]);
CGFloat deviceHeight = CGRectGetHeight([[UIScreen mainScreen] bounds]);
CGPoint swapedPos;
if (orientation == UIDeviceOrientationPortrait)
{
swapedPos = point;
}
else if (orientation == UIDeviceOrientationLandscapeLeft)
{
swapedPos.x = deviceHeight - point.y;
swapedPos.y = point.x;
}
else if (orientation == UIDeviceOrientationLandscapeRight)
{
swapedPos.x = point.y;
swapedPos.y = deviceWidth - point.x;
}
else
{
assert(NO);
}
CGPoint ratio;
if (UIDeviceOrientationIsPortrait(orientation))
{
ratio.x = swapedPos.x / deviceWidth * (maxRatio - minRatio) + minRatio;
ratio.y = swapedPos.y / deviceHeight * (maxRatio - minRatio) + minRatio;
}
else
{
ratio.x = swapedPos.x / deviceHeight * (maxRatio - minRatio) + minRatio;
ratio.y = swapedPos.y / deviceWidth * (maxRatio - minRatio) + minRatio;
}
return ratio;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment