Skip to content

Commit

Permalink
record when action is triggered, and draw a chevron in thetrack view
Browse files Browse the repository at this point in the history
  • Loading branch information
markd2 committed Oct 15, 2012
1 parent 108c16e commit d279224
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Classes/BWGestureTrackView.h
Expand Up @@ -10,6 +10,9 @@
- (void) removeAllRecognizers;
- (void) trackGestureRecognizer: (UIGestureRecognizer *) gestureRecognizer;

// The recognizer's action was triggered. Make a note of it.
- (void) recordActionForGestureRecognizer: (UIGestureRecognizer *) gestureRecognizer;

- (void) startRecording;
- (void) stopRecording;

Expand Down
45 changes: 42 additions & 3 deletions Classes/BWGestureTrackView.m
Expand Up @@ -9,6 +9,12 @@
static const CGFloat kRecognizerHeight = 30.0;
static const CGFloat kLabelWidth = 200;
static const CGFloat kLabelTextSize = 15.0;
static const CGFloat kActionChevronSize = 6.0;

// Synthetic states for the recognizer tracking
enum {
kActionTriggered = UIGestureRecognizerStateFailed + 2000
};


static const char *g_stateNames[] = {
Expand Down Expand Up @@ -50,7 +56,7 @@ @interface BWGestureThing : NSObject
@property (nonatomic, assign) NSTimeInterval timestamp; // absolute time

+ (id) thingFromGesture: (UIGestureRecognizer *) gesture
state: (UIGestureRecognizerState) state;
state: (int) state;

@end // BWGestureThing

Expand Down Expand Up @@ -237,7 +243,10 @@ - (void) drawRecognizer: (UIGestureRecognizer *) recognizer

CGFloat pointsPerSecond = rect.size.width / self.totalDuration;

// Render all the various states
for (BWGestureThing *thing in track) {
if (thing.state == kActionTriggered) continue;

NSTimeInterval adjustedTimestamp = thing.timestamp - _startTimestamp;
CGFloat xPosition = rect.origin.x + adjustedTimestamp * pointsPerSecond;

Expand All @@ -250,6 +259,29 @@ - (void) drawRecognizer: (UIGestureRecognizer *) recognizer
[[UIColor redColor] set];
UIRectFrame (labelRect);
}

// Draw the action triggers
UIBezierPath *bezierPath = [UIBezierPath bezierPath];

[[UIColor grayColor] set];
for (BWGestureThing *thing in track) {
if (thing.state != kActionTriggered) continue;

[bezierPath removeAllPoints];

NSTimeInterval adjustedTimestamp = thing.timestamp - _startTimestamp;
CGFloat xPosition = rect.origin.x + adjustedTimestamp * pointsPerSecond;
CGFloat yBottom = rect.origin.y + rect.size.height;

// Make a little chevron thing
[bezierPath moveToPoint: CGPointMake (xPosition - kActionChevronSize / 2.0,
yBottom)];
[bezierPath addLineToPoint: CGPointMake (xPosition,
yBottom - kActionChevronSize)];
[bezierPath addLineToPoint: CGPointMake (xPosition + kActionChevronSize / 2.0,
yBottom)];
[bezierPath stroke];
}

} // drawRecognizer

Expand Down Expand Up @@ -296,13 +328,19 @@ - (void) drawRect: (CGRect) rect {
} // drawRect


- (void) recordActionForGestureRecognizer: (UIGestureRecognizer *) gestureRecognizer {
[self recordState: kActionTriggered
forRecognizer: gestureRecognizer];
} // recordActionForGestureRecognizer


@end // BWGestureTrackView


@implementation BWGestureThing

- (id) initWithGesture: (UIGestureRecognizer *) recognizer
state: (UIGestureRecognizerState) state {
state: (int) state {

if ((self = [super init])) {
_recognizer = recognizer;
Expand All @@ -316,7 +354,7 @@ - (id) initWithGesture: (UIGestureRecognizer *) recognizer


+ (id) thingFromGesture: (UIGestureRecognizer *) recognizer
state: (UIGestureRecognizerState) state {
state: (int) state {
return [[self alloc] initWithGesture: recognizer
state: state];
} // thingFromGesture
Expand All @@ -330,4 +368,5 @@ - (NSString *) description {

} // description


@end // BWGestureThing
2 changes: 1 addition & 1 deletion Classes/BWTimeScrubberView.m
Expand Up @@ -91,7 +91,7 @@ - (void) drawTimelineInRect: (CGRect) rect {
currentTime = 1.0;
[[UIColor grayColor] set];
[path removeAllPoints];
while (currentTime < self.totalDuration) {
while (currentTime <= self.totalDuration) {
[path moveToPoint: CGPointMake (currentTime * pointsPerSecond, 0.0)];
[path addLineToPoint: CGPointMake (currentTime * pointsPerSecond,
rect.size.height)];
Expand Down
5 changes: 5 additions & 0 deletions Classes/BWViewController.m
Expand Up @@ -129,26 +129,31 @@ - (void) addSomeGestures {

- (void) iPinchYou: (UIPinchGestureRecognizer *) pinchy {
QuietLog (@"PEENCH");
[self.gestureTrackView recordActionForGestureRecognizer: pinchy];
} // iPinchYou


- (void) twoTap: (UITapGestureRecognizer *) tappy {
QuietLog (@"TAPPY");
[self.gestureTrackView recordActionForGestureRecognizer: tappy];
} // twoTap


- (void) longPress: (UILongPressGestureRecognizer *) pressy {
QuietLog (@"PRESSY");
[self.gestureTrackView recordActionForGestureRecognizer: pressy];
} // longPress


- (void) panny: (UIPanGestureRecognizer *) panny {
QuietLog (@"PANNY");
[self.gestureTrackView recordActionForGestureRecognizer: panny];
} // panny


- (void) checky: (BIDCheckMarkGestureRecognizer *) checky {
QuietLog (@"CHECKY");
[self.gestureTrackView recordActionForGestureRecognizer: checky];
} // panny


Expand Down

0 comments on commit d279224

Please sign in to comment.