Permalink
Browse files

Eraser button

  • Loading branch information...
1 parent b827f54 commit b4f2768a7e0deaa7f8fe3f7c770b8089a48fe149 @paulaj paulaj committed Jun 8, 2010
Showing with 21 additions and 35 deletions.
  1. +3 −2 Classes/WhiteboardView.h
  2. +18 −33 Classes/WhiteboardView.m
View
@@ -7,18 +7,19 @@
//
#import <UIKit/UIKit.h>
+#import "Button.h"
@interface WhiteboardView : UIView {
CGPoint lastLocation;
CGPoint location;
NSMutableArray *strokes;
- Boolean isErasing;
+
UIColor *myColor;
CGFloat myDistance;
NSInteger mySize;
CFMutableDictionaryRef activeStrokes;
- UIView *button;
+ Button *button;
}
//@property (nonatomic, assign) CGPoint lastLocation;
View
@@ -18,7 +18,7 @@ - (id)initWithFrame:(CGRect)frame {
lastLocation =CGPointMake(0.0, 0.0);
location =CGPointMake(0.0, 0.0);
strokes = [[NSMutableArray array] retain];
- isErasing=false;
+
myColor= [UIColor blueColor];
myDistance=0.0;
mySize=0;
@@ -86,19 +86,9 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//NSLog(@"touches began");
if ([[event allTouches] count] > 0) {
- //UITouch *touch = [[event allTouches] anyObject];
- if ([[event allTouches] count]==2){
- CGPoint point1=[[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
- CGPoint point2=[[[[event allTouches] allObjects] objectAtIndex:1] locationInView:self];
- myDistance = sqrt(pow(((point2.x) - (point1.x)), 2) + pow(((point2.y) - (point1.y)), 2));
- }
- if (myDistance<=200 & [[event allTouches] count]==2){
- isErasing=true;
- CGPoint point1=[[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
- CGPoint point2=[[[[event allTouches] allObjects] objectAtIndex:1] locationInView:self];
- lastLocation= CGPointMake((((point2.x) + (point1.x))/2.0), (((point2.y) + (point1.y))/2.0));
- //myColor=[UIColor blackColor];
- mySize= myDistance;
+ if (button.isErasing==true ){
+ lastLocation=[[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
+ mySize=10;
NSMutableArray *newStroke = [self makeNewStrokeWithColor:[UIColor blackColor] withWidth:mySize];
[[newStroke lastObject] addObject:[NSNumber numberWithFloat: lastLocation.x]];
@@ -107,7 +97,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
else{
for (UITouch *touch in [event allTouches]) {
- isErasing=false;
+
mySize=3;
lastLocation = [touch locationInView:self];
//Make a new Stroke
@@ -129,19 +119,13 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
//UITouch *touch = [[event allTouches] anyObject];
//NSLog(@"Drag");
- if (isErasing){
- if (myDistance<=200 & [[event allTouches] count]==2){
- CGPoint point1=[[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
- CGPoint point2=[[[[event allTouches] allObjects] objectAtIndex:1] locationInView:self];
- location= CGPointMake((((point2.x) + (point1.x))/2.0), (((point2.y) + (point1.y))/2.0));
+ if (button.isErasing){
+ location=[[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
+ //CGPoint point2=[[[[event allTouches] allObjects] objectAtIndex:1] locationInView:self];
[[[strokes lastObject] lastObject] addObject:[NSNumber numberWithFloat: location.x]];
[[[strokes lastObject] lastObject] addObject:[NSNumber numberWithFloat: location.y]];
- }
- else{
- isErasing=false;
- }
}
- if (isErasing==false){
+ else{
for (int i =0; i < [[event allTouches] count]; i++) {
@@ -172,15 +156,17 @@ -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CFDictionaryReplaceValue (activeStrokes, currentTouch, stroke);
}
}
- }
+
+ }
//NSLog(@"active strokes:%@",activeStrokes);
[self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
//UITouch *touch = [[event allTouches] anyObject];
- if (isErasing==false){
+
+ if (button.isErasing==false){
for (int i =0; i < [[event allTouches] count]; i++) {
//NSLog(@"End");
UITouch *currentTouch = [[[event allTouches] allObjects] objectAtIndex:i];
@@ -193,12 +179,11 @@ -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
CFDictionaryRemoveValue (activeStrokes, currentTouch);
}
}
- if(isErasing){
- //CGPoint point1=[[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
- //CGPoint point2=[[[[event allTouches] allObjects] objectAtIndex:1] locationInView:self];
- //location= CGPointMake((((point2.x) + (point1.x))/2.0), (((point2.y) + (point1.y))/2.0));
- //[[[strokes lastObject] lastObject] addObject:[NSNumber numberWithFloat: location.x]];
- //[[[strokes lastObject] lastObject] addObject:[NSNumber numberWithFloat: location.y]];
+ if(button.isErasing){
+ location=[[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
+
+ [[[strokes lastObject] lastObject] addObject:[NSNumber numberWithFloat: location.x]];
+ [[[strokes lastObject] lastObject] addObject:[NSNumber numberWithFloat: location.y]];
}
[self setNeedsDisplay];

0 comments on commit b4f2768

Please sign in to comment.