From 71d81c7c23229e5c710708a5e0a169bc0dbcb61e Mon Sep 17 00:00:00 2001 From: Philippe Casgrain Date: Mon, 13 Jul 2009 12:13:27 +0800 Subject: [PATCH] Refactored Counter display to be an embedded subview that knows how to draw itself, rather than drawing directly in drawPostPage:. Signed-off-by: Jonathan 'Wolf' Rentzsch --- BlitzPDFView.h | 3 +++ BlitzPDFView.m | 55 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/BlitzPDFView.h b/BlitzPDFView.h index a620a1e..882a7db 100644 --- a/BlitzPDFView.h +++ b/BlitzPDFView.h @@ -1,9 +1,12 @@ #import #import +@class CounterView; + @interface BlitzPDFView : PDFView { uint16_t secondsElapsed; + CounterView *counterView; } @property uint16_t secondsElapsed; diff --git a/BlitzPDFView.m b/BlitzPDFView.m index 092f746..bd9349c 100644 --- a/BlitzPDFView.m +++ b/BlitzPDFView.m @@ -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 @@ -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)); { @@ -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]; @@ -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];