Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  WordSearch.m
  3. //  AntsAndGrasshoppy
  4. //
  5. //  Created by moeadmin on 6/30/10.
  6. //  Copyright 2010 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "WordSearch.h"
  10.  
  11. @implementation WordSearch
  12. @synthesize doSomethingButton, points, pointsEnd;
  13.  
  14. -(NSString *) filePath {
  15.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  16.     NSString *documentsDirectory = [paths objectAtIndex:0];
  17.     NSString *path = [documentsDirectory stringByAppendingPathComponent:@"AG.sqlite"];
  18.     return path;
  19. }
  20.  
  21. -(IBAction)doSomething:(id)sender
  22. {
  23.     UIActionSheet *actionSheet = [[UIActionSheet alloc]
  24.                                   initWithTitle:@"Find ten -ng words. (Letters in red denote the begining of the words. Accept any 10 words.)"
  25.                                   delegate:self
  26.                                   cancelButtonTitle:@"Ok!"
  27.                                   destructiveButtonTitle:@"Examples"
  28.                                   otherButtonTitles:nil];
  29.     [actionSheet showInView:self];
  30.     [actionSheet release];
  31. }
  32.  
  33. -(void)actionSheet:(UIActionSheet *)actionSheet
  34. didDismissWithButtonIndex:(NSInteger)buttonIndex
  35. {
  36.     if(!buttonIndex == [actionSheet cancelButtonIndex])
  37.     {
  38.         NSString *msg = @"Examples: LONG, GANG (Highlighted in blue)";
  39.        
  40.         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
  41.                               @"Examples"
  42.                                                         message:msg
  43.                                                        delegate:self
  44.                                               cancelButtonTitle:@"Ok!"
  45.                                               otherButtonTitles:nil];
  46.         [alert show];
  47.         [alert release];
  48.         [msg release];
  49.     }
  50. }
  51.  
  52. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  53.     mouseSwiped = NO;
  54.     UITouch *touch = [touches anyObject];
  55.    
  56.     if ([touch tapCount] == 2) {
  57.         drawImage.image = nil;
  58.         return;
  59.     }
  60.    
  61.     startLocation = [touch locationInView:self];
  62.     startLocation.y += 55;
  63. }
  64.  
  65. -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  66. /*  mouseSwiped = YES;
  67.     UITouch *touch = [touches anyObject];
  68.     endLocation = [touch locationInView:self];
  69.     endLocation.y += 55;
  70.    
  71.     UIGraphicsBeginImageContext(self.frame.size);
  72.     [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  73.     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
  74.     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
  75.     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
  76.     CGContextBeginPath(UIGraphicsGetCurrentContext());
  77.     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), endLocation.x, endLocation.y);
  78.     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), startLocation.x, startLocation.y);
  79.     CGContextStrokePath(UIGraphicsGetCurrentContext());
  80.     drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
  81.     UIGraphicsEndImageContext();
  82.    
  83. /*  if((242 < startLocation.x < 257) && (242 < endLocation.x < 257) && (75 < startLocation.y < 90) && (147 < endLocation.y < 163))
  84.     {
  85.         UIGraphicsBeginImageContext(self.frame.size);
  86.         [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  87.         CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
  88.         CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
  89.         CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
  90.         CGContextBeginPath(UIGraphicsGetCurrentContext());
  91.         CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 242.0, 147.0);
  92.         CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 242.0, 75.0);
  93.         CGContextStrokePath(UIGraphicsGetCurrentContext());
  94.         drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
  95.         UIGraphicsEndImageContext();
  96.     }*/
  97.    
  98. //  endLocation = startLocation;
  99.    
  100. /*  mouseMoved++;
  101.    
  102.     if (mouseMoved == 10) {
  103.         mouseMoved = 0;
  104.     }*/
  105. }
  106.  
  107. -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  108.  
  109.     points = [[NSMutableArray alloc] init];
  110.     pointsEnd = [[NSMutableArray alloc] init];
  111. //  endLocation = startLocation;
  112.    
  113.     UITouch *touch = [touches anyObject];
  114.     endLocation = [touch locationInView:self];
  115.     endLocation.y += 55;
  116.  
  117.     if([touch tapCount] == 2) {
  118.         drawImage.image = nil;
  119.         return;
  120.     }
  121. /*  if(!mouseSwiped) {
  122.         UIGraphicsBeginImageContext(self.frame.size);
  123.         [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  124.         CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
  125.         CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
  126.         CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
  127.         CGContextMoveToPoint(UIGraphicsGetCurrentContext(), endLocation.x, endLocation.y);
  128.         CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endLocation.x, endLocation.y);
  129.         CGContextStrokePath(UIGraphicsGetCurrentContext());
  130.         CGContextFlush(UIGraphicsGetCurrentContext());
  131.         drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
  132.         UIGraphicsEndImageContext();*/
  133.        
  134.     if((( startLocation.x >= 242.0 && startLocation.x <= 257.0) && (startLocation.y >= 130.0 && startLocation.y <= 145.0))
  135.         && ((endLocation.x >= 242.0  && endLocation.x <= 257.0) &&  (endLocation.y>=203.0 && endLocation.y <= 218.0)))
  136.     {
  137.         UIGraphicsBeginImageContext(self.frame.size);
  138.         [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  139.         CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
  140.         CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
  141.         CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
  142.         CGContextBeginPath(UIGraphicsGetCurrentContext());
  143.         CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startLocation.x, startLocation.y);
  144.         CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endLocation.x, endLocation.y);
  145.         CGContextStrokePath(UIGraphicsGetCurrentContext());
  146.         drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
  147.         UIGraphicsEndImageContext();
  148.        
  149.         //store the points in  array
  150.         [points addObject:[NSValue valueWithCGPoint:CGPointMake(startLocation.x, startLocation.y)]];
  151.         [pointsEnd addObject:[NSValue valueWithCGPoint:CGPointMake(endLocation.x, endLocation.y)]];
  152.         mouseSwiped = YES;
  153.     }
  154.     else
  155.     {
  156.         drawImage.image = nil;
  157.         startLocation.x = 0.0;
  158.         startLocation.y = 0.0;
  159.         endLocation.x = 0.0;
  160.         endLocation.y = 0.0;
  161.        
  162.         //use for loop to go thru no of cgpoint to draw
  163.         if(!mouseSwiped) {
  164.             for (cnt = 0; cnt < 1; cnt++) {
  165.                 CGPoint startPoint = [(NSValue *)[points objectAtIndex:cnt] CGPointValue];
  166.                 CGPoint endPoint = [(NSValue *)[pointsEnd objectAtIndex:cnt] CGPointValue];
  167.                 UIGraphicsBeginImageContext(self.frame.size);
  168.                 [drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  169.                 CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
  170.                 CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
  171.                 CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.25, 0.75, 0.70);
  172.                 CGContextBeginPath(UIGraphicsGetCurrentContext());
  173.                 CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startPoint.x, startPoint.y);
  174.                 CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endPoint.x, endPoint.y);
  175.                 CGContextStrokePath(UIGraphicsGetCurrentContext());
  176.                 drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
  177.                 UIGraphicsEndImageContext();
  178.             }
  179.         }
  180.     }
  181. }
  182.  
  183. /*-(void)drawRect: (CGRect) rect {
  184.     //draw the line from start to end
  185.     CGContextRef context = UIGraphicsGetCurrentContext();
  186.     CGContextSetLineWidth(context,10.0);
  187.     CGContextSetRGBStrokeColor(context, 0.0, 1.0, 1.0, 0.75);
  188.     CGContextMoveToPoint(context, 242.0, 78.0);
  189.     CGContextAddLineToPoint(context, 242.0, 150.0);
  190.     CGContextStrokePath(context);
  191.    
  192.     CGContextSetLineWidth(context,10.0);
  193.     CGContextSetRGBStrokeColor(context, 0.0, 1.0, 1.0, 0.75);
  194.     CGContextMoveToPoint(context, 170.0, 78.0);
  195.     CGContextAddLineToPoint(context, 242.0, 78.0);
  196.     CGContextStrokePath(context);
  197. }
  198. /*  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)) ||
  199.        ((242.0 < startLocation.x < 257.0) && (75.0 < startLocation.y < 90.0) && (170.0 < endLocation.x < 185.0) && (75.0 < endLocation.y < 90.0))) {
  200.            
  201.             [points addObject:[NSValue valueWithCGPoint:CGPointMake(startLocation, endLocation)]];
  202.         }  
  203. /*  for (int cnt = 0; cnt < 1; cnt++) {
  204.         CGPoint startPoint = [(NSValue *)[points objectAtIndex:cnt] CGPointValue];
  205.         CGPoint endPoint = [(NSValue *)[pointsEnd objectAtIndex:cnt] CGPointValue];
  206.         CGContextRef con = UIGraphicsGetCurrentContext();
  207.         CGContextSetLineWidth(con, 10.0);
  208.         CGContextSetRGBStrokeColor(con, 0.0, 0.5, 1.0, 0.75);
  209.         CGContextMoveToPoint(con, startPoint.x, startPoint.y);
  210.         CGContextAddLineToPoint(con, endPoint.x, endPoint.y);
  211.         CGContextStrokePath(con);
  212.     }*/
  213. //}
  214.  
  215. /*
  216.  // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  217. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  218.     if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  219.         // Custom initialization
  220.     }
  221.     return self;
  222. }
  223. */
  224.  
  225. /*
  226. // Implement loadView to create a view hierarchy programmatically, without using a nib.
  227. - (void)loadView {
  228. }
  229. */
  230.  
  231. /*
  232. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  233. - (void)viewDidLoad {
  234.     [super viewDidLoad];
  235. }*/
  236.  
  237.  
  238. /*
  239. // Override to allow orientations other than the default portrait orientation.
  240. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  241.     // Return YES for supported orientations
  242.     return (interfaceOrientation == UIInterfaceOrientationPortrait);
  243. }
  244. */
  245.  
  246. - (void)viewDidUnload {
  247.     // Release any retained subviews of the main view.
  248.     // e.g. self.myOutlet = nil;
  249. }
  250.  
  251.  
  252. - (void)dealloc {
  253.     [super dealloc];
  254. }
  255.  
  256.  
  257. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement