| 1 | /* |
|---|
| 2 | * SapphireFrontRowCompat.m |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by Graham Booker on Oct. 29, 2007. |
|---|
| 6 | * Copyright 2007 Sapphire Development Team and/or www.nanopi.net |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
|---|
| 10 | * General Public License as published by the Free Software Foundation; either version 3 of the License, |
|---|
| 11 | * or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
|---|
| 14 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|---|
| 15 | * Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License along with this program; if not, |
|---|
| 18 | * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #import "SapphireFrontRowCompat.h" |
|---|
| 22 | #import <ExceptionHandling/NSExceptionHandler.h> |
|---|
| 23 | #import "SapphireButtonControl.h" |
|---|
| 24 | |
|---|
| 25 | /*Yes, this is the wrong class, but otherwise gcc gripes about BRImage class not existing; this removes warnings so no harm*/ |
|---|
| 26 | @interface SapphireFrontRowCompat (compat) |
|---|
| 27 | + (id)imageWithPath:(NSString *)path; |
|---|
| 28 | - (id)downsampledImageForMaxSize:(NSSize)size; |
|---|
| 29 | + (id)imageWithCGImageRef:(CGImageRef)ref; |
|---|
| 30 | - (CGImageRef)image; |
|---|
| 31 | @end |
|---|
| 32 | |
|---|
| 33 | NSData *CreateBitmapDataFromImage(CGImageRef image, unsigned int width, unsigned int height); |
|---|
| 34 | |
|---|
| 35 | /*Yes, wrong class and other wrong things, just to shut up warnings*/ |
|---|
| 36 | @interface BRAdornedMenuItemLayer (compat) |
|---|
| 37 | + (id)folderMenuItem; |
|---|
| 38 | + (id)menuItem; |
|---|
| 39 | - (void)setTitle:(NSString *)title; |
|---|
| 40 | - (void)setTitle:(NSString *)title withAttributes:(NSDictionary *)attributes; |
|---|
| 41 | - (void)setRightJustifiedText:(NSString *)text; |
|---|
| 42 | - (void)setLeftIconInfo:(BRTexture *)icon; |
|---|
| 43 | - (void)setRightIconInfo:(BRTexture *)icon; |
|---|
| 44 | @end |
|---|
| 45 | |
|---|
| 46 | @interface BRThemeInfo (compat) |
|---|
| 47 | - (id)selectedSettingImage; |
|---|
| 48 | - (id)unplayedPodcastImage; |
|---|
| 49 | - (id)unplayedVideoImage; |
|---|
| 50 | - (id)returnToImage; |
|---|
| 51 | @end |
|---|
| 52 | |
|---|
| 53 | @interface BRButtonControl (compat) |
|---|
| 54 | - (id)initWithMasterLayerSize:(NSSize)fp8; |
|---|
| 55 | @end |
|---|
| 56 | |
|---|
| 57 | @interface BRTextControl (compat) |
|---|
| 58 | - (void)setText:(NSString *)text withAttributes:(NSDictionary *)attr; |
|---|
| 59 | - (NSRect)controllerFrame; /*technically wrong; it is really a CGRect*/ |
|---|
| 60 | - (NSSize)renderedSizeWithMaxSize:(NSSize)maxSize; /*technically wrong; it is really a CGSize*/ |
|---|
| 61 | @end |
|---|
| 62 | |
|---|
| 63 | @interface NSException (compat) |
|---|
| 64 | - (NSArray *)callStackReturnAddresses; |
|---|
| 65 | @end |
|---|
| 66 | |
|---|
| 67 | @interface BRAlertController (compat) |
|---|
| 68 | + (BRAlertController *)alertOfType:(int)type titled:(NSString *)title primaryText:(NSString *)primaryText secondaryText:(NSString *)secondaryText; |
|---|
| 69 | @end |
|---|
| 70 | |
|---|
| 71 | @interface BROptionDialog (compat) |
|---|
| 72 | - (void)setPrimaryInfoText:(NSString *)text withAttributes:(NSDictionary *)attributes; |
|---|
| 73 | @end |
|---|
| 74 | |
|---|
| 75 | @interface BRTextWithSpinnerController (compat) |
|---|
| 76 | - (BRTextWithSpinnerController *)initWithTitle:(NSString *)title text:(NSString *)text isNetworkDependent:(BOOL)networkDependent; |
|---|
| 77 | @end |
|---|
| 78 | |
|---|
| 79 | @interface BRControl (compat) |
|---|
| 80 | - (void)insertControl:(id)control atIndex:(long)index; |
|---|
| 81 | @end |
|---|
| 82 | |
|---|
| 83 | @interface BRWaitSpinnerControl (compat) |
|---|
| 84 | - (void)setSpins:(BOOL)spin; |
|---|
| 85 | @end |
|---|
| 86 | |
|---|
| 87 | @interface BRTextEntryControl (compat) |
|---|
| 88 | - (id)initWithTextEntryStyle:(int)style; |
|---|
| 89 | @end |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | @implementation SapphireFrontRowCompat |
|---|
| 93 | |
|---|
| 94 | static SapphireFrontRowCompatATVVersion atvVersion = SapphireFrontRowCompatATVVersionUnknown; |
|---|
| 95 | static BOOL usingLeopard = NO; |
|---|
| 96 | static BOOL usingATypeOfTakeTwo = NO; |
|---|
| 97 | static BOOL usingLeopardOrATypeOfTakeTwo = NO; |
|---|
| 98 | |
|---|
| 99 | + (void)initialize |
|---|
| 100 | { |
|---|
| 101 | if(NSClassFromString(@"BRAdornedMenuItemLayer") == nil) |
|---|
| 102 | { |
|---|
| 103 | atvVersion = SapphireFrontRowCompatATVVersionLeopardFrontrow; |
|---|
| 104 | usingLeopard = YES; |
|---|
| 105 | usingLeopardOrATypeOfTakeTwo = YES; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | if(NSClassFromString(@"BRBaseAppliance") != nil) |
|---|
| 109 | { |
|---|
| 110 | atvVersion = SapphireFrontRowCompatATVVersion2; |
|---|
| 111 | usingLeopard = NO; |
|---|
| 112 | usingATypeOfTakeTwo = YES; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | if(NSClassFromString(@"BRVideoPlayerController") == nil) |
|---|
| 116 | atvVersion = SapphireFrontRowCompatATVVersion2Dot2; |
|---|
| 117 | |
|---|
| 118 | if([(Class)NSClassFromString(@"BRController") instancesRespondToSelector:@selector(wasExhumed)]) |
|---|
| 119 | atvVersion = SapphireFrontRowCompatATVVersion2Dot3; |
|---|
| 120 | |
|---|
| 121 | if(NSClassFromString(@"BRPhotoImageProxy") != nil) |
|---|
| 122 | atvVersion = SapphireFrontRowCompatATVVersion2Dot4; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | + (SapphireFrontRowCompatATVVersion)atvVersion |
|---|
| 126 | { |
|---|
| 127 | return atvVersion; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | + (BOOL)usingLeopard |
|---|
| 131 | { |
|---|
| 132 | return usingLeopard; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | + (BOOL)usingATypeOfTakeTwo |
|---|
| 136 | { |
|---|
| 137 | return usingATypeOfTakeTwo; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | + (BOOL)usingLeopardOrATypeOfTakeTwo |
|---|
| 141 | { |
|---|
| 142 | return usingLeopardOrATypeOfTakeTwo; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | + (BOOL)usingFrontRow |
|---|
| 146 | { |
|---|
| 147 | return atvVersion >= SapphireFrontRowCompatATVVersionLeopardFrontrow; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | + (BOOL)usingTakeTwo |
|---|
| 151 | { |
|---|
| 152 | return atvVersion >= SapphireFrontRowCompatATVVersion2; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | + (BOOL)usingTakeTwoDotTwo |
|---|
| 156 | { |
|---|
| 157 | return atvVersion >= SapphireFrontRowCompatATVVersion2Dot2; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | + (BOOL)usingTakeTwoDotThree |
|---|
| 161 | { |
|---|
| 162 | return atvVersion >= SapphireFrontRowCompatATVVersion2Dot3; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | + (BOOL)usingTakeTwoDotFour |
|---|
| 166 | { |
|---|
| 167 | return atvVersion >= SapphireFrontRowCompatATVVersion2Dot4; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | + (id)imageAtPath:(NSString *)path |
|---|
| 171 | { |
|---|
| 172 | if(usingLeopardOrATypeOfTakeTwo) { |
|---|
| 173 | Class cls = NSClassFromString(@"BRImage"); |
|---|
| 174 | return [cls imageWithPath:path]; |
|---|
| 175 | } else { |
|---|
| 176 | // this returns a CGImageRef |
|---|
| 177 | NSURL *url = [NSURL fileURLWithPath:path]; |
|---|
| 178 | CGImageRef imageRef = NULL; |
|---|
| 179 | CGImageSourceRef sourceRef; |
|---|
| 180 | |
|---|
| 181 | sourceRef = CGImageSourceCreateWithURL((CFURLRef)url, NULL); |
|---|
| 182 | if(sourceRef) { |
|---|
| 183 | imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL); |
|---|
| 184 | CFRelease(sourceRef); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | return [(id)imageRef autorelease]; |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | + (id)imageAtPath:(NSString *)path scene:(BRRenderScene *)scene |
|---|
| 192 | { |
|---|
| 193 | if(usingLeopardOrATypeOfTakeTwo) { |
|---|
| 194 | return [self imageAtPath:path]; |
|---|
| 195 | } else { |
|---|
| 196 | CGImageRef imageRef = (CGImageRef)[self imageAtPath:path]; |
|---|
| 197 | BRTexture *ret = nil; |
|---|
| 198 | |
|---|
| 199 | if(imageRef != NULL) { |
|---|
| 200 | /*Create a texture*/ |
|---|
| 201 | ret = [BRBitmapTexture textureWithImage:imageRef context:[scene resourceContext] mipmap:YES]; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | return ret; |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | + (id)imageFromData:(NSData *)imageData |
|---|
| 209 | { |
|---|
| 210 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 211 | { |
|---|
| 212 | Class cls = NSClassFromString(@"BRImage"); |
|---|
| 213 | return [cls imageWithData:imageData]; |
|---|
| 214 | } |
|---|
| 215 | else |
|---|
| 216 | { |
|---|
| 217 | CGImageRef coverArt = nil; |
|---|
| 218 | CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)imageData, nil); |
|---|
| 219 | if(source != NULL) |
|---|
| 220 | coverArt = CGImageSourceCreateImageAtIndex(source, 1, nil); |
|---|
| 221 | CFRelease(source); |
|---|
| 222 | return [(id)coverArt autorelease]; |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | + (id)coverartAsImage: (CGImageRef)imageRef |
|---|
| 227 | { |
|---|
| 228 | // Non-FR - return CGImageRef |
|---|
| 229 | if (!usingLeopardOrATypeOfTakeTwo) |
|---|
| 230 | return (id)imageRef; |
|---|
| 231 | |
|---|
| 232 | // FR - return BRImage |
|---|
| 233 | Class cls = NSClassFromString(@"BRImage"); |
|---|
| 234 | return (id)[cls imageWithCGImageRef:imageRef]; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | + (BRAdornedMenuItemLayer *)textMenuItemForScene:(BRRenderScene *)scene folder:(BOOL)folder |
|---|
| 238 | { |
|---|
| 239 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 240 | { |
|---|
| 241 | if(folder) |
|---|
| 242 | return [NSClassFromString(@"BRTextMenuItemLayer") folderMenuItem]; |
|---|
| 243 | else |
|---|
| 244 | return [NSClassFromString(@"BRTextMenuItemLayer") menuItem]; |
|---|
| 245 | } |
|---|
| 246 | else |
|---|
| 247 | { |
|---|
| 248 | if(folder) |
|---|
| 249 | return [NSClassFromString(@"BRAdornedMenuItemLayer") adornedFolderMenuItemWithScene:scene]; |
|---|
| 250 | else |
|---|
| 251 | return [NSClassFromString(@"BRAdornedMenuItemLayer") adornedMenuItemWithScene:scene]; |
|---|
| 252 | } |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | + (void)setTitle:(NSString *)title forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 256 | { |
|---|
| 257 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 258 | [menu setTitle:title]; |
|---|
| 259 | else |
|---|
| 260 | [[menu textItem] setTitle:title]; |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | + (void)setTitle:(NSString *)title withAttributes:(NSDictionary *)attributes forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 264 | { |
|---|
| 265 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 266 | [menu setTitle:title withAttributes:attributes]; |
|---|
| 267 | else |
|---|
| 268 | [[menu textItem] setTitle:title withAttributes:attributes]; |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | + (NSString *)titleForMenu:(BRAdornedMenuItemLayer *)menu { |
|---|
| 272 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 273 | return [menu title]; |
|---|
| 274 | else |
|---|
| 275 | return [[menu textItem] title]; |
|---|
| 276 | } |
|---|
| 277 | + (void)setRightJustifiedText:(NSString *)text forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 278 | { |
|---|
| 279 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 280 | [menu setRightJustifiedText:text]; |
|---|
| 281 | else |
|---|
| 282 | [[menu textItem] setRightJustifiedText:text]; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | + (void)setLeftIcon:(BRTexture *)icon forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 286 | { |
|---|
| 287 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 288 | [menu setLeftIconInfo:[NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 289 | icon, @"BRMenuIconImageKey", |
|---|
| 290 | nil]]; |
|---|
| 291 | else |
|---|
| 292 | [menu setLeftIcon:icon]; |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | + (void)setRightIcon:(BRTexture *)icon forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 296 | { |
|---|
| 297 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 298 | [menu setRightIconInfo:[NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 299 | icon, @"BRMenuIconImageKey", |
|---|
| 300 | nil]]; |
|---|
| 301 | else |
|---|
| 302 | [menu setRightIcon:icon]; |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | + (id)selectedSettingImageForScene:(BRRenderScene *)scene |
|---|
| 306 | { |
|---|
| 307 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 308 | return [[BRThemeInfo sharedTheme] selectedSettingImage]; |
|---|
| 309 | else |
|---|
| 310 | return [[BRThemeInfo sharedTheme] selectedSettingImageForScene:scene]; |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | + (id)unplayedPodcastImageForScene:(BRRenderScene *)scene |
|---|
| 314 | { |
|---|
| 315 | if(atvVersion >= SapphireFrontRowCompatATVVersion2Dot4) |
|---|
| 316 | return [[BRThemeInfo sharedTheme] unplayedVideoImage]; |
|---|
| 317 | else if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 318 | return [[BRThemeInfo sharedTheme] unplayedPodcastImage]; |
|---|
| 319 | else |
|---|
| 320 | return [[BRThemeInfo sharedTheme] unplayedPodcastImageForScene:scene]; |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | + (id)returnToImageForScene:(BRRenderScene *)scene { |
|---|
| 324 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 325 | return [[BRThemeInfo sharedTheme] returnToImage]; |
|---|
| 326 | else |
|---|
| 327 | return [[BRThemeInfo sharedTheme] returnToImageForScene:scene]; |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | + (NSRect)frameOfController:(id)controller |
|---|
| 331 | { |
|---|
| 332 | if(usingATypeOfTakeTwo) |
|---|
| 333 | // ATV2 |
|---|
| 334 | return [controller frame]; |
|---|
| 335 | else if(usingLeopard) |
|---|
| 336 | // 10.5 |
|---|
| 337 | return [controller controllerFrame]; |
|---|
| 338 | else |
|---|
| 339 | return [[controller masterLayer] frame]; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | + (void)setText:(NSString *)text withAtrributes:(NSDictionary *)attributes forControl:(BRTextControl *)control |
|---|
| 343 | { |
|---|
| 344 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 345 | [control setText:text withAttributes:attributes]; |
|---|
| 346 | else |
|---|
| 347 | { |
|---|
| 348 | if(attributes != nil) |
|---|
| 349 | [control setTextAttributes:attributes]; |
|---|
| 350 | [control setText:text]; |
|---|
| 351 | } |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | + (NSSize)textControl:(BRTextControl *)text renderedSizeWithMaxSize:(NSSize)maxSize |
|---|
| 355 | { |
|---|
| 356 | if(usingATypeOfTakeTwo) |
|---|
| 357 | return [text renderedSizeWithMaxSize:maxSize]; |
|---|
| 358 | |
|---|
| 359 | [text setMaximumSize:maxSize]; |
|---|
| 360 | return [text renderedSize]; |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | + (void)addDividerAtIndex:(int)index toList:(BRListControl *)list |
|---|
| 364 | { |
|---|
| 365 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 366 | [list addDividerAtIndex:index withLabel:@""]; |
|---|
| 367 | else |
|---|
| 368 | [list addDividerAtIndex:index]; |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | + (void)addSublayer:(id)sub toControl:(id)controller |
|---|
| 372 | { |
|---|
| 373 | if(usingLeopardOrATypeOfTakeTwo) { |
|---|
| 374 | // ATV2 |
|---|
| 375 | if(NSClassFromString(@"BRPanel") == nil) |
|---|
| 376 | [controller addControl:sub]; |
|---|
| 377 | // 10.5 |
|---|
| 378 | else |
|---|
| 379 | [[controller layer] addSublayer:sub]; |
|---|
| 380 | } |
|---|
| 381 | else |
|---|
| 382 | [[controller masterLayer] addSublayer:sub]; |
|---|
| 383 | } |
|---|
| 384 | |
|---|
| 385 | + (void)insertSublayer:(id)sub toControl:(id)controller atIndex:(long)index { |
|---|
| 386 | if(usingLeopardOrATypeOfTakeTwo) { |
|---|
| 387 | // ATV2 |
|---|
| 388 | if(NSClassFromString(@"BRPanel") == nil) |
|---|
| 389 | [controller insertControl:sub atIndex:index]; |
|---|
| 390 | // 10.5 |
|---|
| 391 | else |
|---|
| 392 | [[controller layer] insertSublayer:sub atIndex:index]; |
|---|
| 393 | } else |
|---|
| 394 | [[controller masterLayer] insertSublayer:sub atIndex:index]; |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | + (BRHeaderControl *)newHeaderControlWithScene:(BRRenderScene *)scene |
|---|
| 398 | { |
|---|
| 399 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 400 | return [[BRHeaderControl alloc] init]; |
|---|
| 401 | else |
|---|
| 402 | return [[BRHeaderControl alloc] initWithScene:scene]; |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | + (BRButtonControl *)newButtonControlWithScene:(BRRenderScene *)scene masterLayerSize:(NSSize)size; |
|---|
| 406 | { |
|---|
| 407 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 408 | return [[SapphireButtonControl alloc] initWithMasterLayerSize:size]; |
|---|
| 409 | else |
|---|
| 410 | return [[BRButtonControl alloc] initWithScene:scene masterLayerSize:size]; |
|---|
| 411 | } |
|---|
| 412 | |
|---|
| 413 | + (BRTextControl *)newTextControlWithScene:(BRRenderScene *)scene |
|---|
| 414 | { |
|---|
| 415 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 416 | return [[BRTextControl alloc] init]; |
|---|
| 417 | else |
|---|
| 418 | return [[BRTextControl alloc] initWithScene:scene]; |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | + (BRTextEntryControl *)newTextEntryControlWithScene:(BRRenderScene *)scene |
|---|
| 422 | { |
|---|
| 423 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 424 | { |
|---|
| 425 | if(atvVersion >= SapphireFrontRowCompatATVVersion2Dot2) |
|---|
| 426 | return [[BRTextEntryControl alloc] initWithTextEntryStyle:1]; |
|---|
| 427 | return [[BRTextEntryControl alloc] initWithTextEntryStyle:0]; |
|---|
| 428 | } |
|---|
| 429 | else |
|---|
| 430 | return [[BRTextEntryControl alloc] initWithScene:scene]; |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | + (BRProgressBarWidget *)newProgressBarWidgetWithScene:(BRRenderScene *)scene |
|---|
| 434 | { |
|---|
| 435 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 436 | return [[BRProgressBarWidget alloc] init]; |
|---|
| 437 | else |
|---|
| 438 | return [[BRProgressBarWidget alloc] initWithScene:scene]; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | + (BRMarchingIconLayer *)newMarchingIconLayerWithScene:(BRRenderScene *)scene |
|---|
| 442 | { |
|---|
| 443 | if(usingATypeOfTakeTwo) |
|---|
| 444 | return nil; |
|---|
| 445 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 446 | return [[BRMarchingIconLayer alloc] init]; |
|---|
| 447 | else |
|---|
| 448 | return [[BRMarchingIconLayer alloc] initWithScene:scene]; |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | + (BRImageLayer *)newImageLayerWithScene:(BRRenderScene *)scene { |
|---|
| 452 | // 10.5 |
|---|
| 453 | if(usingLeopardOrATypeOfTakeTwo && NSClassFromString(@"BRImageLayer") != nil) |
|---|
| 454 | return [[BRImageLayer alloc] init]; |
|---|
| 455 | // ATV2 |
|---|
| 456 | else if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 457 | return [[NSClassFromString(@"BRImageControl") alloc] init]; |
|---|
| 458 | else |
|---|
| 459 | return [[BRImageLayer layerWithScene:scene] retain]; |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | + (void)setImage:(id)image forLayer:(BRImageLayer *)layer { |
|---|
| 463 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 464 | // this cast is not proper, it just makes a warning disappear. |
|---|
| 465 | [layer setImage:(CGImageRef)image]; |
|---|
| 466 | else |
|---|
| 467 | [layer setTexture:image]; |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | + (BRImageLayer *)newImageLayerWithImage:(id)image scene:(BRRenderScene *)scene { |
|---|
| 471 | BRImageLayer *result = [self newImageLayerWithScene:scene]; |
|---|
| 472 | [self setImage:image forLayer:result]; |
|---|
| 473 | return result; |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | + (void)renderScene:(BRRenderScene *)scene |
|---|
| 477 | { |
|---|
| 478 | if(!usingLeopardOrATypeOfTakeTwo) |
|---|
| 479 | [scene renderScene]; |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | + (BRAlertController *)alertOfType:(int)type titled:(NSString *)title primaryText:(NSString *)primaryText secondaryText:(NSString *)secondaryText withScene:(BRRenderScene *)scene { |
|---|
| 483 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 484 | return [BRAlertController alertOfType:type |
|---|
| 485 | titled:title |
|---|
| 486 | primaryText:primaryText |
|---|
| 487 | secondaryText:secondaryText]; |
|---|
| 488 | else |
|---|
| 489 | return [BRAlertController alertOfType:type |
|---|
| 490 | titled:title |
|---|
| 491 | primaryText:primaryText |
|---|
| 492 | secondaryText:secondaryText |
|---|
| 493 | withScene:scene]; |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | + (BROptionDialog *)newOptionDialogWithScene:(BRRenderScene *)scene { |
|---|
| 497 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 498 | return [[BROptionDialog alloc] init]; |
|---|
| 499 | else |
|---|
| 500 | return [[BROptionDialog alloc] initWithScene:scene]; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | + (void)setOptionDialogPrimaryInfoText:(NSString *)primaryInfoText withAttributes:(NSDictionary *)attributes optionDialog:(BROptionDialog *)dialog { |
|---|
| 504 | if(usingLeopardOrATypeOfTakeTwo) { |
|---|
| 505 | [dialog setPrimaryInfoText:primaryInfoText withAttributes:attributes]; |
|---|
| 506 | } else { |
|---|
| 507 | [dialog setPrimaryInfoText:primaryInfoText]; |
|---|
| 508 | [dialog setPrimaryInfoTextAttributes:attributes]; |
|---|
| 509 | } |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | + (BRTextWithSpinnerController *)newTextWithSpinnerControllerTitled:(NSString *)title text:(NSString *)text isNetworkDependent:(BOOL)networkDependent scene:(BRRenderScene *)scene { |
|---|
| 513 | if(usingLeopardOrATypeOfTakeTwo) |
|---|
| 514 | return [[BRTextWithSpinnerController alloc] initWithTitle:title text:text isNetworkDependent:networkDependent]; |
|---|
| 515 | else |
|---|
| 516 | return [[BRTextWithSpinnerController alloc] initWithScene:scene title:title text:text showBack:NO isNetworkDependent:NO]; |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | + (void)setSpinner:(BRWaitSpinnerControl *)spinner toSpin:(BOOL)spin |
|---|
| 520 | { |
|---|
| 521 | if([spinner respondsToSelector:@selector(setSpins:)]) |
|---|
| 522 | [spinner setSpins:spin]; |
|---|
| 523 | else if([spinner respondsToSelector:@selector(startSpinning)]) |
|---|
| 524 | { |
|---|
| 525 | if(spin) |
|---|
| 526 | [spinner startSpinning]; |
|---|
| 527 | else |
|---|
| 528 | [spinner stopSpinning]; |
|---|
| 529 | } |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | + (BREventRemoteAction)remoteActionForEvent:(BREvent *)event |
|---|
| 533 | { |
|---|
| 534 | if(atvVersion >= SapphireFrontRowCompatATVVersion2Dot4) |
|---|
| 535 | return [event remoteAction]; |
|---|
| 536 | |
|---|
| 537 | BREventPageUsageHash hashVal = (uint32_t)([event page] << 16 | [event usage]); |
|---|
| 538 | switch (hashVal) { |
|---|
| 539 | case kBREventTapMenu: |
|---|
| 540 | return kBREventRemoteActionMenu; |
|---|
| 541 | case kBREventTapPlayPause: |
|---|
| 542 | return kBREventRemoteActionPlay; |
|---|
| 543 | case kBREventTapRight: |
|---|
| 544 | return kBREventRemoteActionRight; |
|---|
| 545 | case kBREventTapLeft: |
|---|
| 546 | return kBREventRemoteActionLeft; |
|---|
| 547 | case kBREventTapUp: |
|---|
| 548 | return kBREventRemoteActionUp; |
|---|
| 549 | case kBREventTapDown: |
|---|
| 550 | return kBREventRemoteActionDown; |
|---|
| 551 | case kBREventHoldMenu: |
|---|
| 552 | return kBREventRemoteActionMenuHold; |
|---|
| 553 | case kBREventHoldPlayPause: |
|---|
| 554 | return kBREventRemoteActionPlayHold; |
|---|
| 555 | case kBREventHoldUp: |
|---|
| 556 | return kBREventRemoteActionHoldUp; |
|---|
| 557 | case kBREventHoldDown: |
|---|
| 558 | return kBREventRemoteActionHoldDown; |
|---|
| 559 | case kBREventHoldLeft: |
|---|
| 560 | return kBREventRemoteActionHoldLeft; |
|---|
| 561 | case kBREventHoldRight: |
|---|
| 562 | return kBREventRemoteActionHoldRight; |
|---|
| 563 | |
|---|
| 564 | //Unknowns: |
|---|
| 565 | case kBREventTapExit: |
|---|
| 566 | case kBREventPlay: |
|---|
| 567 | case kBREventPause: |
|---|
| 568 | case kBREventFastForward: |
|---|
| 569 | case kBREventRewind: |
|---|
| 570 | case kBREventNextTrack: |
|---|
| 571 | case kBREventPreviousTrack: |
|---|
| 572 | case kBREventStop: |
|---|
| 573 | case kBREventEject: |
|---|
| 574 | case kBREventRandomPlay: |
|---|
| 575 | case kBREventVolumeUp: |
|---|
| 576 | case kBREventVolumeDown: |
|---|
| 577 | /* Commented out due to it throwing warnings |
|---|
| 578 | case kBREventPairRemote: |
|---|
| 579 | case kBREventUnpairRemote: |
|---|
| 580 | case kBREventLowBattery: |
|---|
| 581 | case kBREventSleepNow: |
|---|
| 582 | case kBREventSystemReset: |
|---|
| 583 | case kBREventBlackScreenRecovery:*/ |
|---|
| 584 | default: |
|---|
| 585 | return 0; |
|---|
| 586 | } |
|---|
| 587 | } |
|---|
| 588 | |
|---|
| 589 | + (NSArray *)callStackReturnAddressesForException:(NSException *)exception |
|---|
| 590 | { |
|---|
| 591 | if([exception respondsToSelector:@selector(callStackReturnAddresses)]) |
|---|
| 592 | { |
|---|
| 593 | NSArray *ret = [exception callStackReturnAddresses]; |
|---|
| 594 | if([ret count]) |
|---|
| 595 | return ret; |
|---|
| 596 | } |
|---|
| 597 | return [[exception userInfo] objectForKey:NSStackTraceKey]; |
|---|
| 598 | } |
|---|
| 599 | |
|---|
| 600 | + (RUIPreferences *)sharedFrontRowPreferences { |
|---|
| 601 | Class preferencesClass = NSClassFromString(@"RUIPreferences"); |
|---|
| 602 | if(!preferencesClass) preferencesClass = NSClassFromString(@"BRPreferences"); |
|---|
| 603 | |
|---|
| 604 | if(preferencesClass) |
|---|
| 605 | return [preferencesClass sharedFrontRowPreferences]; |
|---|
| 606 | else |
|---|
| 607 | return nil; |
|---|
| 608 | } |
|---|
| 609 | |
|---|
| 610 | @end |
|---|