Commits

Jay Yu committed ab4b698

work in progress: NSUserDefaults

Comments (0)

Files changed (3)

Calculator/GraphingView.h

 @class GraphingView;
 @protocol GraphingViewDataSource
 - (double)yAxisValue:(GraphingView *)sender atXAxis:(double)xAxis;
+
+@optional
+- (void)setDefault:(GraphingView *)sender origin:(CGPoint)origin scale:(CGFloat)scale;
 @end
 
 @interface GraphingView : UIView
 
 @property (nonatomic, weak) id <GraphingViewDataSource> dataSource;
 
-
 - (void)pinch:(UIPinchGestureRecognizer *)gesture;
 
 @end

Calculator/GraphingView.m

 #import "GraphingView.h"
 #import "AxesDrawer.h"
 
-
 @implementation GraphingView
 @synthesize dataSource = _dataSource;
 @synthesize scale = _scale;
     }
 }
 
+- (void)tripleTap:(UITapGestureRecognizer *)gesture
+{
+    if (gesture.state == UIGestureRecognizerStateEnded) {
+        CGPoint new_origin = [gesture locationInView:self];
+        self.origin = new_origin;
+    }
+}
 
 - (void)drawRect:(CGRect)rect
 {
     CGContextRef context = UIGraphicsGetCurrentContext();
-    
+
     CGPoint midPoint = self.origin; // center of our bounds in our coordinate system
 
     CGFloat scale = self.scale;
 
     [AxesDrawer drawAxesInRect:rect originAtPoint:midPoint scale:scale];
-    
+
     CGFloat x = 0.0;  // Always begin drawing from the left edge of the UIView
     CGFloat y;
     double x_t;  // X Axis UIView coordinate - converted from CGFloat to the graph coordination system
     double y_t;  // Raw Y Axis value returned from runProgram
     BOOL drawing = NO;
-    
+
     while (x < self.bounds.size.width) {
         x_t = [self translateCoordinateToAxisValue:x originAtPoint:midPoint scale:scale];
         y_t = [self.dataSource yAxisValue:self atXAxis:x_t];

Calculator/GraphingViewController.m

 @property (nonatomic, strong) id program;
 @property (nonatomic, strong) NSDictionary *variables;
 @property (readonly) NSString *title;
-
 @end
 
 @implementation GraphingViewController
     [self.graphingView addGestureRecognizer:[[UIPinchGestureRecognizer alloc] initWithTarget:self.graphingView action:@selector(pinch:)]];
 
     [self.graphingView addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self.graphingView action:@selector(pan:)]];
+
+    UITapGestureRecognizer *tripleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.graphingView action:@selector(tripleTap:)];
+    tripleTapGestureRecognizer.numberOfTapsRequired = 3;
+
+    [self.graphingView addGestureRecognizer:tripleTapGestureRecognizer];
 }
 
 - (void)setup
 {
-    
+
 }
 
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 
 - (void)initProgram:(id)program
 {
-    self.program = program; 
+    self.program = program;
 }
 
 - (double)yAxisValue:(GraphingView *)sender atXAxis:(double)xAxis
 {
     NSDictionary *vars = [NSDictionary dictionaryWithObjectsAndKeys:
                           [NSNumber numberWithDouble:xAxis], @"x", nil];
-    
+
     double yAxis = [CalculatorBrain runProgram:self.program usingVariableValues:vars];
 //    NSLog(@"yAxis: x axis: %f, y axis: %f", xAxis, yAxis);
-    
+
     return yAxis;
-    
+
+}
+
+#define SCALE_KEY @"GraphingViewController.Scale"
+#define ORIGIN_X_KEY @"GraphingViewController.OriginX"
+#define ORIGIN_Y_KEY @"GraphingViewController.OriginY"
+
+- (void)setDefault:(GraphingView *)sender origin:(CGPoint)origin scale:(CGFloat)scale
+{
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+    [defaults setFloat:origin.x forKey:ORIGIN_X_KEY];
+    [defaults setFloat:origin.y forKey:ORIGIN_Y_KEY];
+    [defaults setFloat:scale forKey:SCALE_KEY];
+    [defaults synchronize];
+
 }
 
 
 {
     [super viewDidLoad];
 	// Do any additional setup after loading the view.
+
+//    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+//    CGPoint origin = [defaults objectForKey:ORIGIN_KEY];
+//    CGFloat scale = [defaults objectForKey:SCALE_KEY];
+
 }
 
 - (void)viewDidUnload
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.