Skip to content

Commit

Permalink
Refactored Counter display to be an embedded subview that knows how t…
Browse files Browse the repository at this point in the history
…o draw itself, rather than drawing directly in drawPostPage:.

Signed-off-by: Jonathan 'Wolf' Rentzsch <[email protected]>
  • Loading branch information
Philippe Casgrain authored and rentzsch committed Jul 13, 2009
1 parent 2bc84f5 commit 71d81c7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
3 changes: 3 additions & 0 deletions BlitzPDFView.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

@class CounterView;

@interface BlitzPDFView : PDFView
{
uint16_t secondsElapsed;
CounterView *counterView;
}

@property uint16_t secondsElapsed;
Expand Down
55 changes: 49 additions & 6 deletions BlitzPDFView.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#import "BlitzPDFView.h"

@implementation BlitzPDFView
@interface CounterView : NSView
{
uint16_t secondsElapsed;
}

@property uint16_t secondsElapsed;

@end


@implementation CounterView
@synthesize secondsElapsed;

// Following function stolen from http://cocoa.karelia.com/Foundation_Categories/NSColor__Instantiat.m
Expand Down Expand Up @@ -29,14 +39,12 @@ @implementation BlitzPDFView
#define nineOclock 180.0f
#define sixOclock 270.0f

- (void)drawPagePost:(PDFPage*)page {
const CGFloat kSize = 80.0f;
- (void)drawRect:(NSRect)rect {
const CGFloat kOuterRingWidth = 8.0f;
const CGFloat kPadding = 20.0f;

NSColor *outerSlideElapsedWedgeColor = colorFromHexRGB(@"2c8fff");

NSRect bounds = NSMakeRect([self bounds].size.width - kPadding - kSize, kPadding, kSize, kSize);
NSRect bounds = [self bounds];
NSPoint center = NSMakePoint(NSMidX(bounds), NSMidY(bounds));

{
Expand Down Expand Up @@ -107,7 +115,7 @@ - (void)drawPagePost:(PDFPage*)page {

{
const CGFloat dotSize = 10.0f;
NSRect dotBounds = NSMakeRect(-dotSize/2, (kSize/2)-dotSize+1, dotSize, dotSize);
NSRect dotBounds = NSMakeRect(-dotSize/2, (bounds.size.width/2)-dotSize+1, dotSize, dotSize);
NSRect glowBounds = NSInsetRect(dotBounds, -5.0f, -5.0f);

NSBezierPath *outerSlideElapsedDotGlow = [NSBezierPath bezierPathWithOvalInRect:glowBounds];
Expand Down Expand Up @@ -135,6 +143,41 @@ - (void)drawPagePost:(PDFPage*)page {
}
}

@end

@implementation BlitzPDFView
@dynamic secondsElapsed;

- (void)drawPagePost:(PDFPage*)page {
const CGFloat kSize = 80.0f;
const CGFloat kPadding = 20.0f;

if (counterView == nil)
{
counterView = [[CounterView alloc] initWithFrame:NSMakeRect(0, 0, kSize, kSize)];
[self addSubview: counterView];
}

NSRect frame = NSMakeRect([self bounds].size.width - kPadding - kSize, kPadding, kSize, kSize);
counterView.frame = frame;
[counterView setNeedsDisplay: YES];
}

- (void)dealloc
{
[counterView release];
[super dealloc];
}

- (uint16_t) secondsElapsed {
return secondsElapsed;
}

- (void)setSecondsElapsed:(uint16_t)secs {
secondsElapsed = secs;
counterView.secondsElapsed = secs;
}

- (IBAction)updateSecondsElapsed:(id)sender {
self.secondsElapsed = [sender intValue];
[self setNeedsDisplay:YES];
Expand Down

0 comments on commit 71d81c7

Please sign in to comment.