Skip to content

Commit

Permalink
Eraser button
Browse files Browse the repository at this point in the history
  • Loading branch information
paulaj committed Jun 8, 2010
1 parent b827f54 commit b4f2768
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
5 changes: 3 additions & 2 deletions Classes/WhiteboardView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 18 additions & 33 deletions Classes/WhiteboardView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]];
Expand All @@ -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
Expand All @@ -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++) {

Expand Down Expand Up @@ -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];
Expand All @@ -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];

Expand Down

0 comments on commit b4f2768

Please sign in to comment.