Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // WordSearch.m
- // AntsAndGrasshoppy
- //
- // Created by moeadmin on 6/30/10.
- // Copyright 2010 __MyCompanyName__. All rights reserved.
- //
- #import "WordSearch.h"
- @implementation WordSearch
- @synthesize doSomethingButton, points, pointsEnd;
- -(NSString *) filePath {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- NSString *path = [documentsDirectory stringByAppendingPathComponent:@"AG.sqlite"];
- return path;
- }
- -(IBAction)doSomething:(id)sender
- {
- UIActionSheet *actionSheet = [[UIActionSheet alloc]
- initWithTitle:@"Find ten -ng words. (Letters in red denote the begining of the words. Accept any 10 words.)"
- delegate:self
- cancelButtonTitle:@"Ok!"
- destructiveButtonTitle:@"Examples"
- otherButtonTitles:nil];
- [actionSheet showInView:self];
- [actionSheet release];
- }
- -(void)actionSheet:(UIActionSheet *)actionSheet
- didDismissWithButtonIndex:(NSInteger)buttonIndex
- {
- if(!buttonIndex == [actionSheet cancelButtonIndex])
- {
- NSString *msg = @"Examples: LONG, GANG (Highlighted in blue)";
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
- @"Examples"
- message:msg
- delegate:self
- cancelButtonTitle:@"Ok!"
- otherButtonTitles:nil];
- [alert show];
- [alert release];
- [msg release];
- }
- }
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- mouseSwiped = NO;
- UITouch *touch = [touches anyObject];
- if ([touch tapCount] == 2) {
- drawImage.image = nil;
- return;
- }
- startLocation = [touch locationInView:self];
- startLocation.y += 55;
- }
- -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- /* mouseSwiped = YES;
- UITouch *touch = [touches anyObject];
- endLocation = [touch locationInView:self];
- endLocation.y += 55;
- UIGraphicsBeginImageContext(self.frame.size);
- [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
- CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
- CGContextBeginPath(UIGraphicsGetCurrentContext());
- CGContextMoveToPoint(UIGraphicsGetCurrentContext(), endLocation.x, endLocation.y);
- CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), startLocation.x, startLocation.y);
- CGContextStrokePath(UIGraphicsGetCurrentContext());
- drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- /* if((242 < startLocation.x < 257) && (242 < endLocation.x < 257) && (75 < startLocation.y < 90) && (147 < endLocation.y < 163))
- {
- UIGraphicsBeginImageContext(self.frame.size);
- [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
- CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
- CGContextBeginPath(UIGraphicsGetCurrentContext());
- CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 242.0, 147.0);
- CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 242.0, 75.0);
- CGContextStrokePath(UIGraphicsGetCurrentContext());
- drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- }*/
- // endLocation = startLocation;
- /* mouseMoved++;
- if (mouseMoved == 10) {
- mouseMoved = 0;
- }*/
- }
- -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- points = [[NSMutableArray alloc] init];
- pointsEnd = [[NSMutableArray alloc] init];
- // endLocation = startLocation;
- UITouch *touch = [touches anyObject];
- endLocation = [touch locationInView:self];
- endLocation.y += 55;
- if([touch tapCount] == 2) {
- drawImage.image = nil;
- return;
- }
- /* if(!mouseSwiped) {
- UIGraphicsBeginImageContext(self.frame.size);
- [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
- CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
- CGContextMoveToPoint(UIGraphicsGetCurrentContext(), endLocation.x, endLocation.y);
- CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endLocation.x, endLocation.y);
- CGContextStrokePath(UIGraphicsGetCurrentContext());
- CGContextFlush(UIGraphicsGetCurrentContext());
- drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();*/
- if((( startLocation.x >= 242.0 && startLocation.x <= 257.0) && (startLocation.y >= 130.0 && startLocation.y <= 145.0))
- && ((endLocation.x >= 242.0 && endLocation.x <= 257.0) && (endLocation.y>=203.0 && endLocation.y <= 218.0)))
- {
- UIGraphicsBeginImageContext(self.frame.size);
- [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
- CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
- CGContextBeginPath(UIGraphicsGetCurrentContext());
- CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startLocation.x, startLocation.y);
- CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endLocation.x, endLocation.y);
- CGContextStrokePath(UIGraphicsGetCurrentContext());
- drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- //store the points in array
- [points addObject:[NSValue valueWithCGPoint:CGPointMake(startLocation.x, startLocation.y)]];
- [pointsEnd addObject:[NSValue valueWithCGPoint:CGPointMake(endLocation.x, endLocation.y)]];
- mouseSwiped = YES;
- }
- else
- {
- drawImage.image = nil;
- startLocation.x = 0.0;
- startLocation.y = 0.0;
- endLocation.x = 0.0;
- endLocation.y = 0.0;
- //use for loop to go thru no of cgpoint to draw
- if(!mouseSwiped) {
- for (cnt = 0; cnt < 1; cnt++) {
- CGPoint startPoint = [(NSValue *)[points objectAtIndex:cnt] CGPointValue];
- CGPoint endPoint = [(NSValue *)[pointsEnd objectAtIndex:cnt] CGPointValue];
- UIGraphicsBeginImageContext(self.frame.size);
- [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
- CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
- CGContextBeginPath(UIGraphicsGetCurrentContext());
- CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startPoint.x, startPoint.y);
- CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endPoint.x, endPoint.y);
- CGContextStrokePath(UIGraphicsGetCurrentContext());
- drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- }
- }
- }
- }
- /*-(void)drawRect: (CGRect) rect {
- //draw the line from start to end
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextSetLineWidth(context,10.0);
- CGContextSetRGBStrokeColor(context, 0.0, 1.0, 1.0, 0.75);
- CGContextMoveToPoint(context, 242.0, 78.0);
- CGContextAddLineToPoint(context, 242.0, 150.0);
- CGContextStrokePath(context);
- CGContextSetLineWidth(context,10.0);
- CGContextSetRGBStrokeColor(context, 0.0, 1.0, 1.0, 0.75);
- CGContextMoveToPoint(context, 170.0, 78.0);
- CGContextAddLineToPoint(context, 242.0, 78.0);
- CGContextStrokePath(context);
- }
- /* if (((170.0 < startLocation.x < 185.0) && (75.0 < startLocation.y < 90.0) && (242.0 < endLocation.x < 257.0) && (75.0 < endLocation.y == 90.0)) ||
- ((242.0 < startLocation.x < 257.0) && (75.0 < startLocation.y < 90.0) && (170.0 < endLocation.x < 185.0) && (75.0 < endLocation.y < 90.0))) {
- [points addObject:[NSValue valueWithCGPoint:CGPointMake(startLocation, endLocation)]];
- }
- /* for (int cnt = 0; cnt < 1; cnt++) {
- CGPoint startPoint = [(NSValue *)[points objectAtIndex:cnt] CGPointValue];
- CGPoint endPoint = [(NSValue *)[pointsEnd objectAtIndex:cnt] CGPointValue];
- CGContextRef con = UIGraphicsGetCurrentContext();
- CGContextSetLineWidth(con, 10.0);
- CGContextSetRGBStrokeColor(con, 0.0, 0.5, 1.0, 0.75);
- CGContextMoveToPoint(con, startPoint.x, startPoint.y);
- CGContextAddLineToPoint(con, endPoint.x, endPoint.y);
- CGContextStrokePath(con);
- }*/
- //}
- /*
- // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
- // Custom initialization
- }
- return self;
- }
- */
- /*
- // Implement loadView to create a view hierarchy programmatically, without using a nib.
- - (void)loadView {
- }
- */
- /*
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- [super viewDidLoad];
- }*/
- /*
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- */
- - (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (void)dealloc {
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement