rendered paste body#include <stdlib.h>
#import <GraphicsServices/GraphicsServices.h>
#import "FriskyApplication.h"
@implementation FriskyApplication
- (void)reloadROMArray
{
NSArray *files, *strs;
NSEnumerator *e;
NSString *filename, *prettyFilename;
UIImageAndTextTableCell *tableCell;
if (ROMArray)
[ROMArray release];
ROMArray = [[NSMutableArray alloc] init];
files = [[NSFileManager defaultManager] directoryContentsAtPath:
@"/var/root/Media/ROMs/SNES"];
if (!files)
return;
e = [files objectEnumerator];
while ((filename = (NSString *)[e nextObject])) {
strs = [filename componentsSeparatedByString: @"."];
if ([strs count] < 2)
continue;
prettyFilename = [strs objectAtIndex: [strs count] - 2];
tableCell = [[UIImageAndTextTableCell alloc] init];
[tableCell setTitle: prettyFilename];
[tableCell setShowDisclosure: YES];
[ROMArray addObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat: @"/var/root/Media/ROMs/SNES/%@",
filename], @"Path", prettyFilename, @"PrettyFilename",
tableCell, @"Cell", nil]];
}
}
- (int)numberOfRowsInTable: (UITable *)table
{
return [ROMArray count];
}
- (UITableCell *)table: (UITable *)table cellForRow: (int)row column: (int)col
{
return [[ROMArray objectAtIndex: row] objectForKey: @"Cell"];
}
- (BOOL)shouldShowDisclosureForItemAtRow: (int)row inDataSource:(id) dataSource
{
return YES;
}
- (void)userDidChooseROMWithPath: (NSString *)path
{
[navigationBar pushNavigationItem: [[UINavigationItem alloc] initWithTitle:
@"Controls Test"]];
[navigationBar setBarStyle: 1];
[navigationBar showButtonsWithLeftTitle: nil rightTitle: @"Tools"
leftBack: YES];
[self setStatusBarMode: 1 orientation: 0 duration: [UITransitionView
defaultDurationForTransition: 1]];
[transitionView transition: 1 toView: gameplayView];
appMode = 1;
}
- (void)tableSelectionDidChange: (NSNotification *)notif
{
[self userDidChooseROMWithPath: [[ROMArray objectAtIndex: [loadROMTable
selectedRow]] objectForKey: @"Path"]];
}
- (BOOL)handleEvent:(GSEventRef)event
{
BOOL result;
struct CGPoint pt;
struct CGPoint pt2;
result = [super handleEvent: event];
if (!result)
return result;
pt = GSEventGetLocationInWindow(event, window);
if (!GSEventIsChordingHandEvent(event))
[[navigationBar topItem] setTitle: [NSString stringWithFormat:
@"(%g, %g)", pt.x, pt.y]];
else {
pt = GSEventGetInnerMostPathPosition(event);
pt2 = GSEventGetOuterMostPathPosition(event);
/* pt2 = pt;
pt.x -= GSEventGetDeltaX(event);
pt.y -= GSEventGetDeltaY(event);
pt2.x += GSEventGetDeltaX(event);
pt2.y += GSEventGetDeltaY(event); */
[[navigationBar topItem] setTitle: [NSString stringWithFormat:
@"(%g,%g)(%g,%g)", pt.x, pt.y, pt2.x, pt2.y]];
}
return result;
}
- (void)applicationDidFinishLaunching: (id)sender
{
float controlAreaTop, controlAreaHeight;
int i;
struct CGRect rect;
CGColorSpaceRef colorSpace;
UINavigationItem *loadROMNavigationItem;
UITableColumn *loadROMTableColumn;
UIView *contentView;
appMode = 0;
window = [[UIWindow alloc] initWithContentRect: [UIHardware
fullScreenApplicationContentRect]];
rect.origin.x = rect.origin.y = 0.0f;
rect.size = [UIHardware fullScreenApplicationContentRect].size;
contentView = [[UIView alloc] initWithFrame: rect];
loadROMNavigationItem = [[UINavigationItem alloc] initWithTitle:
@"Load ROM"];
[loadROMNavigationItem setBackButtonTitle: @"Load"];
rect.origin.x = rect.origin.y = 0.0f;
rect.size = [UINavigationBar defaultSize];
navigationBar = [[UINavigationBar alloc] initWithFrame: rect];
[navigationBar pushNavigationItem: loadROMNavigationItem];
[navigationBar enableAnimation];
rect.origin.x = 0.0f;
rect.origin.y = [UINavigationBar defaultSize].height;
rect.size.width = [UIHardware mainScreenSize].width;
rect.size.height = [UIHardware
fullScreenApplicationContentRect].size.height - [UINavigationBar
defaultSize].height;
transitionView = [[UITransitionView alloc] initWithFrame: rect];
rect.origin.y = 0.0f;
loadROMTable = [[UITable alloc] initWithFrame: rect];
[loadROMTable setSeparatorStyle: 1];
gameplayView = [[UIView alloc] initWithFrame: rect];
[gameplayView setOpaque: YES];
colorSpace = CGColorSpaceCreateDeviceRGB();
[gameplayView setBackgroundColor: CGColorCreate(colorSpace, (const float[])
{ 0.0f, 0.0f, 0.0f, 1.0f })];
loadROMTableColumn = [[UITableColumn alloc] initWithTitle: @"ROM"
identifier: @"romName" width: [UIHardware mainScreenSize].width];
ROMArray = nil;
[self reloadROMArray];
[loadROMTable addTableColumn: loadROMTableColumn];
[loadROMTable setDataSource: self];
[loadROMTable setDelegate: self];
screenView = [[UIView alloc] initWithFrame: CGRectMake(32.0f, 8.0f,
256.0f, 239.0f)];
[screenView setOpaque: YES];
[screenView setBackgroundColor: CGColorCreate(colorSpace, (const float[])
{ 1.0f, 1.0f, 1.0f, 1.0f })];
buttonImages[0] = [[UIImage imageNamed: @"ButtonY.png"] retain];
buttonImages[1] = [[UIImage imageNamed: @"ButtonB.png"] retain];
buttonImages[2] = [[UIImage imageNamed: @"ButtonA.png"] retain];
buttonImages[3] = [[UIImage imageNamed: @"ButtonX.png"] retain];
buttonImages[8] = [[UIImage imageNamed: @"ButtonL.png"] retain];
buttonImages[9] = [[UIImage imageNamed: @"ButtonR.png"] retain];
buttonImages[10] = [[UIImage imageNamed: @"ButtonSelect.png"] retain];
buttonImages[11] = [[UIImage imageNamed: @"ButtonStart.png"] retain];
highlightedButtonImages[0] = [[UIImage imageNamed:
@"HighlightedButtonY.png"] retain];
highlightedButtonImages[1] = [[UIImage imageNamed:
@"HighlightedButtonB.png"] retain];
highlightedButtonImages[2] = [[UIImage imageNamed:
@"HighlightedButtonA.png"] retain];
highlightedButtonImages[3] = [[UIImage imageNamed:
@"HighlightedButtonX.png"] retain];
highlightedButtonImages[8] = [[UIImage imageNamed:
@"HighlightedButtonL.png"] retain];
highlightedButtonImages[9] = [[UIImage imageNamed:
@"HighlightedButtonR.png"] retain];
highlightedButtonImages[10] = [[UIImage imageNamed:
@"HighlightedButtonSelect.png"] retain];
highlightedButtonImages[11] = [[UIImage imageNamed:
@"HighlightedButtonStart.png"] retain];
for (i = 4; i < 8; i++) {
buttonImages[i] = [[UIImage imageNamed: @"DPadButton.png"] retain];
highlightedButtonImages[i] = [[UIImage imageNamed:
@"HighlightedDPadButton.png"] retain];
}
controlAreaTop = 239.0f + 8.0f;
controlAreaHeight = [gameplayView frame].size.height - controlAreaTop;
/* YBAX */
buttonImageViews[0] = [[UIImageView alloc] initWithFrame: CGRectMake(
160.0f + 8.0f, controlAreaTop + controlAreaHeight / 2.0f - 24.0f,
48.0f, 48.0f)];
buttonImageViews[1] = [[UIImageView alloc] initWithFrame: CGRectMake(
160.0f + 8.0f + 48.0f, controlAreaTop + controlAreaHeight / 2.0f -
24.0f + 48.0f, 48.0f, 48.0f)];
buttonImageViews[2] = [[UIImageView alloc] initWithFrame: CGRectMake(
160.0f + 8.0f + 48.0f*2, controlAreaTop + controlAreaHeight / 2.0f -
24.0f, 48.0f, 48.0f)];
buttonImageViews[3] = [[UIImageView alloc] initWithFrame: CGRectMake(
160.0f + 8.0f + 48.0f, controlAreaTop + controlAreaHeight / 2.0f -
24.0f - 48.0f, 48.0f, 48.0f)];
/* D-Pad */
buttonImageViews[4] = [[UIImageView alloc] initWithFrame: CGRectMake(
16.0f, controlAreaTop + controlAreaHeight / 2.0f - 30.0f, 60.0f,
60.0f)];
buttonImageViews[5] = [[UIImageView alloc] initWithFrame: CGRectMake(
50.0f, controlAreaTop + controlAreaHeight / 2.0f - 64.0f, 60.0f,
60.0f)];
[buttonImageViews[5] setRotationBy: 90.0f];
buttonImageViews[6] = [[UIImageView alloc] initWithFrame: CGRectMake(
50.0f, controlAreaTop + controlAreaHeight / 2.0f + 4.0f, 60.0f,
60.0f)];
[buttonImageViews[6] setRotationBy: 270.0f];
buttonImageViews[7] = [[UIImageView alloc] initWithFrame: CGRectMake(
84.0f, controlAreaTop + controlAreaHeight / 2.0f - 30.0f, 60.0f,
60.0f)];
[buttonImageViews[7] setRotationBy: 180.0f];
/* L, R, Select, Start */
buttonImageViews[8] = [[UIImageView alloc] initWithFrame: CGRectMake(
168.0f, controlAreaTop + controlAreaHeight / 2.0f - 72.0f, 32.0f,
32.0f)];
buttonImageViews[9] = [[UIImageView alloc] initWithFrame: CGRectMake(
320.0f - 8.0f - 32.0f, controlAreaTop + controlAreaHeight / 2.0f -
72.0f, 32.0f, 32.0f)];
buttonImageViews[10] = [[UIImageView alloc] initWithFrame: CGRectMake(
168.0f, controlAreaTop + controlAreaHeight / 2.0f + 40.0f, 32.0f,
32.0f)];
buttonImageViews[11] = [[UIImageView alloc] initWithFrame: CGRectMake(
320.0f - 8.0f - 32.0f, controlAreaTop + controlAreaHeight / 2.0f +
40.0f, 32.0f, 32.0f)];
for (i = 0; i < 12; i++) {
[buttonImageViews[i] setImage: buttonImages[i]];
[gameplayView addSubview: buttonImageViews[i]];
}
[gameplayView addSubview: screenView];
[transitionView addSubview: loadROMTable];
[contentView addSubview: navigationBar];
[contentView addSubview: transitionView];
[window setContentView: contentView];
[window _setHidden: NO];
[window orderFront: self];
[window makeKey: self];
#if 0
CGImageRef img = [self createApplicationDefaultPNG];
CGImageDestinationRef exportDestination =
CGImageDestinationCreateWithURL(CFURLCreateWithFileSystemPath(
kCFAllocatorDefault, CFSTR("/var/root/Media/Default.png"),
kCFURLPOSIXPathStyle, false),
CFSTR("public.png"), 1, NULL);
CGImageDestinationAddImage(exportDestination, img, NULL);
CGImageDestinationFinalize(exportDestination);
#endif
[loadROMTable reloadData];
[loadROMTable updateDisclosures];
}
@end