Skip to content

Commit

Permalink
Making oneShot show a colored grid, moving some code around to make i…
Browse files Browse the repository at this point in the history
…ncludes work. Ugly.
  • Loading branch information
stave committed Sep 22, 2010
1 parent 5e2bb2d commit a65ec98
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 33 deletions.
7 changes: 1 addition & 6 deletions MyController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ typedef struct swap {
BOOL isSpecial;
} Swap;

typedef struct block {
int color;
BOOL isMultiplier;
BOOL isSpecial;
} Block;

@interface MyController : NSObject
{
@public
OpenGLScreenReader *mOpenGLScreenReader;
NSWindow *mWindow;
MyView *mView;
Expand Down
36 changes: 18 additions & 18 deletions MyController.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#import "MyController.h"
#import <Carbon/Carbon.h>

#define redBlock 1
#define blueBlock 2
#define purpleBlock 3
#define greenBlock 4
#define yellowBlock 5
#define orangeBlock 6
#define whiteBlock 7

static char colors[8] = {'X','R','B','P','G','Y','O','W'};

int getBlock(float r, float g, float b) {
Expand All @@ -23,7 +15,7 @@ int getBlock(float r, float g, float b) {
//Multiplier blocks
if (r > .7 && r < .8 && g > .7 && r < .8 && b < .55) return yellowBlock + 10;
if (r < .5 && b > .7) return blueBlock + 10;
if (r < .6 && g > .67 && b < .65) return greenBlock + 10;
if (r < .6 && g > .65 && b < .65) return greenBlock + 10;
if (r > .65 && g < .5 && b > .65) return purpleBlock + 10;
if (r > .7 && g > .4 && b < .44) return orangeBlock + 10;
if (r > .67 && g > .67 && b > .67 && r < .86 && b < .86 && g < .86) return whiteBlock + 10;
Expand All @@ -50,8 +42,8 @@ @implementation MyController
- (id)init
{
if(self = [super init]) {
captureX = 0;
captureY = 0;
captureX = 480;
captureY = 260;
mWindow = NULL;
mOpenGLScreenReader = [[OpenGLScreenReader alloc] init];
shift = NO;
Expand Down Expand Up @@ -211,11 +203,13 @@ - (IBAction)makeMove:(id)sender {

- (IBAction)oneShot:(id)sender {
if(mWindow == NULL) [self initWindow];
[self hideWindow:self];
//[self hideWindow:self];
// Read the screen bits
[mOpenGLScreenReader readFullScreenToBuffer];

[self captureBoard];
[mView setBoard:board];
[mView setNeedsDisplay:YES];

int i,j;
for (i = 7; i >= 0; i--) {
Expand Down Expand Up @@ -801,11 +795,12 @@ - (void) captureBoard {
CGFloat gacc = 0.0;
CGFloat bacc = 0.0;
int count = 0;
for(k = i - 4; k < i + 4; k ++)
for(l = j - 4; l < j + 4; l++) {
racc += (rawData[k*bytesPerRow + (l * bytesPerPixel)] * 1.0) / 255.0;
gacc += (rawData[k*bytesPerRow + (l * bytesPerPixel) + 1] * 1.0) / 255.0;
bacc += (rawData[k*bytesPerRow + (l * bytesPerPixel) + 2] * 1.0) / 255.0;
int dim=4;
for(k = i - dim; k < i+dim; k ++)
for(l = j - dim; l < j+dim; l++) {
racc += (rawData[k*bytesPerRow + (l * bytesPerPixel)] * 1.0/255.0);
gacc += (rawData[k*bytesPerRow + (l * bytesPerPixel) + 1] * 1.0/255.0);
bacc += (rawData[k*bytesPerRow + (l * bytesPerPixel) + 2] * 1.0/255.0);
count ++;
}

Expand All @@ -826,6 +821,9 @@ - (void) captureBoard {
board[y][x].color = getBlock(r, g, b);
board[y][x].isMultiplier = NO;
board[y][x].isSpecial = NO;
board[y][x].r = r;
board[y][x].g = g;
board[y][x].b = b;

if(board[y][x].color >= 20) {
board[y][x].color -= 20;
Expand All @@ -836,8 +834,10 @@ - (void) captureBoard {
board[y][x].isMultiplier = YES;
}

if(board[y][x].color == -1)
if(board[y][x].color == -1) {
printf("***");
board[y][x].color = 0;
}

printf("\n");

Expand Down
17 changes: 17 additions & 0 deletions myView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,29 @@

#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>
#define redBlock 1
#define blueBlock 2
#define purpleBlock 3
#define greenBlock 4
#define yellowBlock 5
#define orangeBlock 6
#define whiteBlock 7

typedef struct block {
int color;
float r,g,b;
BOOL isMultiplier;
BOOL isSpecial;
} Block;

@interface MyView : NSView {
id myReader;
int captureX, captureY;

Block blocks[81];
}

- (void)setBoard:(Block[][9])board;
- (void)setReader:(NSObject *)reader;
- (void)setCaptureX:(int)x y:(int)y;
@end
63 changes: 54 additions & 9 deletions myView.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ -(id) init
{
self = [super init];
myReader = NULL;
captureX = 0;
captureY = 0;
captureX = 480;
captureY = 260;
return self;
}

Expand Down Expand Up @@ -52,31 +52,76 @@ - (void)drawRect:(NSRect)needsDisplayInRect {
NSFrameRectWithWidth ( rect1, 1 );

[green set];

//static char colors[8] = {'X','R','B','P','G','Y','O','W'};
NSArray* colorArray = [NSArray arrayWithObjects:
[NSColor grayColor], [NSColor redColor],
[NSColor blueColor], [NSColor purpleColor],
[NSColor greenColor], [NSColor yellowColor], [NSColor orangeColor],
[NSColor grayColor], nil];


int idx=0;
//printf("*******************************************\n");
for(i = captureY + 20; i < captureY + 320; i += 40)
for(j = captureX + 20; j < captureX + 320; j += 40) {
for(i = captureY + 20; i < captureY + 320; i += 40) {
for(j = captureX + 20; j < captureX + 320; j += 40, idx++) {

rect1 = NSMakeRect(j-17,i-17,34,34);
[[colorArray objectAtIndex:blocks[idx].color] set];
NSFrameRectWithWidth ( rect1, 3 );

rect1 = NSMakeRect(j-15,i-15,30,30);
[[NSColor colorWithDeviceRed:blocks[idx].r
green:blocks[idx].g
blue:blocks[idx].b
alpha:1.0] set];

NSFrameRectWithWidth ( rect1, 3 );

if (blocks[idx].isMultiplier) {
[[NSColor whiteColor] set];
NSFrameRectWithWidth ( rect1, 1 );
}

if (blocks[idx].isSpecial) {
[[NSColor blackColor] set];
NSFrameRectWithWidth ( rect1, 1 );
}

rect1 = NSMakeRect(j-2,i-2,4,4);
NSRectFill(rect1);
}
}


CFRelease(imageRef);
free(rawData);
}

[self setNeedsDisplay:YES];



}

- (void)setReader:(NSObject *)reader {
myReader = reader;
}

- (void)setCaptureX:(int)x y:(int)y {
//NSLog(@"Capturing at x=%d, y=%d",x,y);
captureX = x;
captureY = y;
}

- (void)setBoard:(Block[][9])board {

int i,j;


int idx=0;
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++,idx++) {
blocks[idx] = board[i][j];
}
}
return;

}

@end

0 comments on commit a65ec98

Please sign in to comment.