Skip to content

Instantly share code, notes, and snippets.

@shauninman
Created January 13, 2012 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shauninman/1604270 to your computer and use it in GitHub Desktop.
Save shauninman/1604270 to your computer and use it in GitHub Desktop.
Some categories for http://sparrow-framework.org
//
// Sparrow+SI.h
//
#import <UIKit/UIKit.h>
@interface SPUtils (DeviceAdditions)
+ (BOOL)isDevicePad;
+ (BOOL)isDeviceRetina;
@end
@implementation SPUtils (DeviceAdditions)
+ (BOOL)isDevicePad
{
static int result = -1;
if (result == -1)
{
result = ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
}
return (BOOL)result;
}
+ (BOOL)isDeviceRetina
{
static int result = -1;
if (result == -1)
{
result = ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0);
}
return (BOOL)result;
}
@end
@interface SPDisplayObject (Centering)
@property (nonatomic, assign) SPPoint *center;
@end
@implementation SPDisplayObject (Centering)
- (SPPoint *)center
{
return [SPPoint pointWithX:self.x+self.width/2 y:self.y+self.height/2];
}
- (void)setCenter:(SPPoint *)center
{
self.x = center.x-self.width/2;
self.y = center.y-self.height/2;
}
@end
@implementation SPGLTexture (NearestNeighbor)
- (void)setFilter:(SPTextureFilter)filterType
{
mFilter = SPTextureFilterNearestNeighbor;
glBindTexture(GL_TEXTURE_2D, mTextureID);
int magFilter = GL_NEAREST;
int minFilter = mMipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment