Permalink
Browse files

Updated the drawing and ABL code to handle a variable number of touch…

…es (touch tracking is still hardcoded to report just 2)
  • Loading branch information...
1 parent 0021a01 commit d2723df67050125d7706ae1a21adfc20272dbc7e @mattrubin mattrubin committed May 16, 2012
Showing with 65 additions and 24 deletions.
  1. +1 −1 ABL
  2. +20 −8 Ablaze/ABLWrapper.mm
  3. +6 −4 Ablaze/FlatView.m
  4. +2 −2 Ablaze/TouchState.h
  5. +36 −9 Ablaze/TouchState.m
View
@@ -17,14 +17,26 @@ @implementation ABLWrapper
-bool updateX(float* buffer){
- bool a = [ts getXs:buffer];
- printf("X: %f, %f\n", buffer[0], buffer[1]);
+bool updateX(float* buffer, unsigned int *count){
+ bool a = [ts getXs:buffer withCount:count];
+
+ printf("X: ");
+ for (int i=0; i<*count; i++) {
+ printf("%.0f,", buffer[i]);
+ }
+ printf("\n");
+
return a;
}
-bool updateY(float* buffer){
- bool a = [ts getYs:buffer];
- printf("Y: %f, %f\n", buffer[0], buffer[1]);
+bool updateY(float* buffer, unsigned int *count){
+ bool a = [ts getYs:buffer withCount:count];
+
+ printf("Y: ");
+ for (int i=0; i<*count; i++) {
+ printf("%.0f,", buffer[i]);
+ }
+ printf("\n");
+
return a;
}
@@ -38,8 +50,8 @@ -(id)init {
transform = ABTransform(true);
ABSymbol *pos[2] = {
- new ABSymPull("touchXs", 2, updateX),
- new ABSymPull("touchYs", 2, updateY),
+ new ABSymVarPull("touchXs", 11, updateX),
+ new ABSymVarPull("touchYs", 11, updateY),
};
ABSymbol *mean[2] = {
View
@@ -30,10 +30,12 @@ - (id)initWithFrame:(CGRect)frame
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
- UIColor *redColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
- CGContextSetFillColorWithColor(context, redColor.CGColor);
-
- CGContextFillEllipseInRect(context, CGRectMake(middlePoint.x-TOUCH_RADIUS, middlePoint.y-TOUCH_RADIUS, 2*TOUCH_RADIUS, 2*TOUCH_RADIUS));
+ if([points count]>0) {
+ UIColor *redColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
+ CGContextSetFillColorWithColor(context, redColor.CGColor);
+
+ CGContextFillEllipseInRect(context, CGRectMake(middlePoint.x-TOUCH_RADIUS, middlePoint.y-TOUCH_RADIUS, 2*TOUCH_RADIUS, 2*TOUCH_RADIUS));
+ }
UIColor *blueColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];
CGContextSetFillColorWithColor(context, blueColor.CGColor);
View
@@ -18,7 +18,7 @@
-(void)handleTouches:(NSSet*)changedTouches;
-(void)print;
--(BOOL)getXs:(float*)buffer;
--(BOOL)getYs:(float*)buffer;
+-(BOOL)getXs:(float*)buffer withCount:(unsigned int *)count;
+-(BOOL)getYs:(float*)buffer withCount:(unsigned int *)count;
@end
View
@@ -94,49 +94,65 @@ -(void)print {
}
--(BOOL)getXs:(float*)buffer {
+-(BOOL)getXs:(float*)buffer withCount:(unsigned int *)count {
NSString* touchKey;
BOOL success = YES;
@synchronized(touchOrder){
success = ([touchOrder count]>0);
if(success)
touchKey = [touchOrder objectAtIndex:0];
}
- if(!success) return NO;
+ if(!success) {
+ *count = 0;
+ return NO;
+ }
@synchronized(touches){
TouchStateTouch* tst = [touches valueForKey:touchKey];
success = (tst!=nil);
if(success){
buffer[0] = tst.location.x;
- buffer[1] = tst.location.x;
}
}
- if(!success) return NO;
+ if(!success) {
+ *count = 0;
+ return NO;
+ }
@synchronized(touchOrder){
success = ([touchOrder count]>1);
if(success)
touchKey = [touchOrder objectAtIndex:1];
}
- if(!success) return YES;
+ if(!success) {
+ *count = 1;
+ return YES;
+ }
@synchronized(touches){
TouchStateTouch* tst = [touches valueForKey:touchKey];
success = (tst!=nil);
if(success){
buffer[1] = tst.location.x;
}
}
+ if(!success) {
+ *count = 1;
+ } else {
+ *count = 2;
+ }
return YES;
}
--(BOOL)getYs:(float*)buffer {
+-(BOOL)getYs:(float*)buffer withCount:(unsigned int *)count {
NSString* touchKey;
BOOL success = YES;
@synchronized(touchOrder){
success = ([touchOrder count]>0);
if(success)
touchKey = [touchOrder objectAtIndex:0];
}
- if(!success) return NO;
+ if(!success) {
+ *count = 0;
+ return NO;
+ }
@synchronized(touches){
TouchStateTouch* tst = [touches valueForKey:touchKey];
success = (tst!=nil);
@@ -145,20 +161,31 @@ -(BOOL)getYs:(float*)buffer {
buffer[1] = tst.location.y;
}
}
- if(!success) return NO;
+ if(!success) {
+ *count = 0;
+ return NO;
+ }
@synchronized(touchOrder){
success = ([touchOrder count]>1);
if(success)
touchKey = [touchOrder objectAtIndex:1];
}
- if(!success) return YES;
+ if(!success) {
+ *count = 1;
+ return YES;
+ }
@synchronized(touches){
TouchStateTouch* tst = [touches valueForKey:touchKey];
success = (tst!=nil);
if(success){
buffer[1] = tst.location.y;
}
}
+ if(!success) {
+ *count = 1;
+ } else {
+ *count = 2;
+ }
return YES;
}

0 comments on commit d2723df

Please sign in to comment.