Revision: 2544
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2544&view=rev
Author:   hofman
Date:     2007-07-23 04:34:12 -0700 (Mon, 23 Jul 2007)

Log Message:
-----------
Move transition settings to the transition controller. Change some method names 
and split code for better readability.

Modified Paths:
--------------
    trunk/SKPDFView.h
    trunk/SKPDFView.m
    trunk/SKTransitionController.h
    trunk/SKTransitionController.m

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2007-07-23 00:23:53 UTC (rev 2543)
+++ trunk/SKPDFView.h   2007-07-23 11:34:12 UTC (rev 2544)
@@ -91,10 +91,6 @@
     
     SKTransitionController *transitionController;
     
-    SKAnimationTransitionStyle transitionStyle;
-    float transitionDuration;
-    BOOL transitionShouldRestrict;
-    
        PDFAnnotation *activeAnnotation;
        PDFAnnotation *highlightAnnotation;
        PDFAnnotationTextWidget *editAnnotation;

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2007-07-23 00:23:53 UTC (rev 2543)
+++ trunk/SKPDFView.m   2007-07-23 11:34:12 UTC (rev 2544)
@@ -151,9 +151,6 @@
     annotationMode = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKLastAnnotationModeKey];
     
     transitionController = nil;
-    transitionStyle = SKNoTransition;
-    transitionDuration = 1.0;
-    transitionShouldRestrict = YES;
     
     spellingTag = [NSSpellChecker uniqueSpellDocumentTag];
     
@@ -533,28 +530,34 @@
     }
 }
 
+- (SKTransitionController * )transitionController {
+    if (transitionController == nil)
+        transitionController = [[SKTransitionController alloc] 
initWithView:self];
+    return transitionController;
+}
+
 - (SKAnimationTransitionStyle)transitionStyle {
-    return transitionStyle;
+    return [[self transitionController] transitionStyle];
 }
 
 - (void)setTransitionStyle:(SKAnimationTransitionStyle)style {
-    transitionStyle = style;
+    [[self transitionController] setTransitionStyle:style];
 }
 
 - (float)transitionDuration {
-    return transitionDuration;
+    return [[self transitionController] duration];
 }
 
 - (void)setTransitionDuration:(float)duration {
-    transitionDuration = duration;
+    [[self transitionController] setDuration:duration];
 }
 
 - (BOOL)transitionShouldRestrict {
-    return transitionShouldRestrict;
+    return [[self transitionController] shouldRestrict];
 }
 
 - (void)setTransitionShouldRestrict:(BOOL)flag {
-    transitionShouldRestrict = flag;
+    [[self transitionController] setShouldRestrict:flag];
 }
 
 #pragma mark Reading bar
@@ -587,27 +590,25 @@
 #pragma mark Actions
 
 - (void)animateTransitionForNextPage:(BOOL)next {
-    if (transitionController == nil)
-        transitionController = [[SKTransitionController alloc] 
initWithView:self];
     NSRect rect = [self convertRect:[[self currentPage] boundsForBox:[self 
displayBox]] fromPage:[self currentPage]];
-    [transitionController prepareForAnimationWithTransitionStyle:[self 
transitionStyle] fromRect:rect shouldRestrict:transitionShouldRestrict];
+    [[self transitionController] prepareAnimationForRect:rect];
     if (next)
         [super goToNextPage:self];
     else
         [super goToPreviousPage:self];
     rect = [self convertRect:[[self currentPage] boundsForBox:[self 
displayBox]] fromPage:[self currentPage]];
-    [transitionController animateWithTransitionStyle:[self transitionStyle] 
direction:next ? CGSLeft : CGSRight duration:[self transitionDuration] 
fromRect:rect shouldRestrict:transitionShouldRestrict];
+    [[self transitionController] animateForRect:rect forward:next];
 }
 
 - (void)goToNextPage:(id)sender {
-    if (hasNavigation && autohidesCursor && [self transitionStyle] != 
SKNoTransition && [self canGoToNextPage])
+    if (hasNavigation && autohidesCursor && transitionController && [self 
transitionStyle] != SKNoTransition && [self canGoToNextPage])
         [self animateTransitionForNextPage:YES];
     else
         [super goToNextPage:sender];
 }
 
 - (void)goToPreviousPage:(id)sender {
-    if (hasNavigation && autohidesCursor && [self transitionStyle] != 
SKNoTransition && [self canGoToPreviousPage])
+    if (hasNavigation && autohidesCursor && transitionController && [self 
transitionStyle] != SKNoTransition && [self canGoToPreviousPage])
         [self animateTransitionForNextPage:NO];
     else
         [super goToPreviousPage:sender];

Modified: trunk/SKTransitionController.h
===================================================================
--- trunk/SKTransitionController.h      2007-07-23 00:23:53 UTC (rev 2543)
+++ trunk/SKTransitionController.h      2007-07-23 11:34:12 UTC (rev 2544)
@@ -120,6 +120,10 @@
     NSView *view;
     CIImage *initialImage;
     NSRect imageRect;
+    
+    SKAnimationTransitionStyle transitionStyle;
+    float duration;
+    BOOL shouldRestrict;
 }
 
 + (NSArray *)transitionFilterNames;
@@ -129,7 +133,16 @@
 - (NSView *)view;
 - (void)setView:(NSView *)newView;
 
-- 
(void)prepareForAnimationWithTransitionStyle:(SKAnimationTransitionStyle)transitionStyle
 fromRect:(NSRect)rect shouldRestrict:(BOOL)shouldRestrict;
-- (void)animateWithTransitionStyle:(SKAnimationTransitionStyle)transitionStyle 
direction:(CGSTransitionOption)direction duration:(float)duration 
fromRect:(NSRect)rect shouldRestrict:(BOOL)shouldRestrict;
+- (SKAnimationTransitionStyle)transitionStyle;
+- (void)setTransitionStyle:(SKAnimationTransitionStyle)style;
 
+- (float)duration;
+- (void)setDuration:(float)newDuration;
+
+- (BOOL)shouldRestrict;
+- (void)setShouldRestrict:(BOOL)flag;
+
+- (void)prepareAnimationForRect:(NSRect)rect;
+- (void)animateForRect:(NSRect)rect forward:(BOOL)forward;
+
 @end

Modified: trunk/SKTransitionController.m
===================================================================
--- trunk/SKTransitionController.m      2007-07-23 00:23:53 UTC (rev 2543)
+++ trunk/SKTransitionController.m      2007-07-23 11:34:12 UTC (rev 2544)
@@ -82,6 +82,11 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] SKTransitionWindow : NSWindow
[EMAIL PROTECTED]
+
+#pragma mark -
+
 @implementation SKTransitionController
 
 + (NSArray *)transitionFilterNames {
@@ -99,6 +104,9 @@
 - (id)initWithView:(NSView *)aView {
     if (self = [super init]) {
         view = aView;
+        transitionStyle = SKNoTransition;
+        duration = 1.0;
+        shouldRestrict = YES;
     }
     return self;
 }
@@ -117,6 +125,30 @@
     view = newView;
 }
 
+- (SKAnimationTransitionStyle)transitionStyle {
+    return transitionStyle;
+}
+
+- (void)setTransitionStyle:(SKAnimationTransitionStyle)style {
+    transitionStyle = style;
+}
+
+- (float)duration {
+    return duration;
+}
+
+- (void)setDuration:(float)newDuration {
+    duration = newDuration;
+}
+
+- (BOOL)shouldRestrict {
+    return shouldRestrict;
+}
+
+- (void)setShouldRestrict:(BOOL)flag {
+    shouldRestrict = flag;
+}
+
 - (CIFilter *)filterWithName:(NSString *)name {
     static NSMutableDictionary *filters = nil;
     if (filters == nil)
@@ -164,10 +196,12 @@
     return [translationFilter valueForKey:@"outputImage"];
 }
 
-- (CIFilter *)transitionFilter:(SKAnimationTransitionStyle)transitionStyle 
forRect:(NSRect)rect inBounds:(NSRect)bounds 
shouldRestrict:(BOOL)shouldRestrict initialCIImage:(CIImage *)initialCIImage 
finalCIImage:(CIImage *)finalCIImage {
+- (CIFilter *)transitionFilterForRect:(NSRect)rect initialCIImage:(CIImage 
*)initialCIImage finalCIImage:(CIImage *)finalCIImage {
     NSString *filterName = [[[self class] transitionFilterNames] 
objectAtIndex:transitionStyle - SKCoreImageTransition];
     CIFilter *transitionFilter = [self filterWithName:filterName];
     
+    NSRect bounds = [view bounds];
+    
     NSEnumerator *keyEnum = [[transitionFilter inputKeys] objectEnumerator];
     NSString *key;
     
@@ -224,7 +258,7 @@
 
 - (NSWindow *)transitionWindow {
     if (transitionWindow == nil) {
-        transitionWindow = [[NSWindow alloc] initWithContentRect:NSZeroRect 
styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
+        transitionWindow = [[SKTransitionWindow alloc] 
initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask 
backing:NSBackingStoreBuffered defer:NO];
         [transitionWindow setReleasedWhenClosed:NO];
         [transitionWindow setIgnoresMouseEvents:YES];
         
@@ -241,9 +275,9 @@
     return transitionView;
 }
 
-- 
(void)prepareForAnimationWithTransitionStyle:(SKAnimationTransitionStyle)transitionStyle
 fromRect:(NSRect)rect shouldRestrict:(BOOL)shouldRestrict {
+- (void)prepareAnimationForRect:(NSRect)rect {
        if (transitionStyle == SKNoTransition) {
-
+        // Do nothing
        } else if (transitionStyle < SKCoreImageTransition) {
         if (CoreGraphicsServicesTransitionsDefined()) {
             if (shouldRestrict) {
@@ -263,9 +297,9 @@
     imageRect = rect;
 }
 
-- (void)animateWithTransitionStyle:(SKAnimationTransitionStyle)transitionStyle 
direction:(CGSTransitionOption)direction duration:(float)duration 
fromRect:(NSRect)rect shouldRestrict:(BOOL)shouldRestrict {
+- (void)animateForRect:(NSRect)rect forward:(BOOL)forward {
        if (transitionStyle == SKNoTransition) {
-
+        // Do nothing
        } else if (transitionStyle < SKCoreImageTransition) {
         if (CoreGraphicsServicesTransitionsDefined()) {
             
@@ -273,7 +307,7 @@
             
             if (shouldRestrict) {
                 if (initialImage == nil)
-                    [self 
prepareForAnimationWithTransitionStyle:transitionStyle fromRect:rect 
shouldRestrict:shouldRestrict];
+                    [self prepareAnimationForRect:rect];
                 
                 NSRect bounds = [view bounds];
                 imageRect = 
NSIntegralRect(NSIntersectionRect(NSUnionRect(imageRect, rect), bounds));
@@ -302,7 +336,7 @@
             // specify our specifications
             spec.unknown1 = 0;
             spec.type =  transitionStyle;
-            spec.option = direction;
+            spec.option = forward ? CGSLeft : CGSRight;
             spec.backColour = NULL;
             spec.wid = [(shouldRestrict ? [self transitionWindow] : [view 
window]) windowNumber];
             
@@ -339,22 +373,21 @@
        } else {
         
         if (initialImage == nil)
-            [self prepareForAnimationWithTransitionStyle:transitionStyle 
fromRect:rect shouldRestrict:shouldRestrict];
+            [self prepareAnimationForRect:rect];
         
         NSRect bounds = [view bounds];
         imageRect = NSIntegralRect(NSIntersectionRect(NSUnionRect(imageRect, 
rect), bounds));
         
         CIImage *finalImage = [self createCurrentImage];
         
-        CIFilter *transitionFilter = [self transitionFilter:transitionStyle 
forRect:imageRect inBounds:[view bounds] shouldRestrict:shouldRestrict 
initialCIImage:initialImage finalCIImage:finalImage];
+        CIFilter *transitionFilter = [self transitionFilterForRect:imageRect 
initialCIImage:initialImage finalCIImage:finalImage];
         
         [finalImage release];
         [initialImage release];
         initialImage = nil;
         
-        NSWindow *window = [view window];
         NSRect frame = [view convertRect:[view frame] toView:nil];
-        frame.origin = [window convertBaseToScreen:frame.origin];
+        frame.origin = [[view window] convertBaseToScreen:frame.origin];
         
         SKTransitionAnimation *animation = [[SKTransitionAnimation alloc] 
initWithFilter:transitionFilter duration:duration 
animationCurve:NSAnimationEaseInOut];
         [[self transitionView] setAnimation:animation];
@@ -362,17 +395,17 @@
         
         [[self transitionWindow] setFrame:frame display:NO];
         [[self transitionWindow] orderBack:nil];
-        [window addChildWindow:transitionWindow ordered:NSWindowAbove];
+        [[view window] addChildWindow:transitionWindow ordered:NSWindowAbove];
         
         [animation startAnimation];
         
         // Update the view and its window, so it shows the correct state when 
it is shown.
         [view display];
         // Remember we disabled flushing in the previous method, we need to 
balance that.
-        [window enableFlushWindow];
-        [window flushWindow];
+        [[view window] enableFlushWindow];
+        [[view window] flushWindow];
         
-        [window removeChildWindow:transitionWindow];
+        [[view window] removeChildWindow:transitionWindow];
         [[self transitionWindow] orderOut:nil];
         [[self transitionView] setAnimation:nil];
         
@@ -445,8 +478,8 @@
     long parm = 1;
     [[self openGLContext] setValues:&parm forParameter:NSOpenGLCPSwapInterval];
     
-    // Make sure that everything we don't need is disabled. Some of these
-    //are enabled by default and can slow down rendering.
+    // Make sure that everything we don't need is disabled.
+    // Some of these are enabled by default and can slow down rendering.
     
     glDisable(GL_ALPHA_TEST);
     glDisable(GL_DEPTH_TEST);
@@ -492,29 +525,44 @@
     return image ? image : [animation currentImage];
 }
 
-- (void)drawRect:(NSRect)rect {
+- (CIContext *)ciContext {
+    if (context == nil) {
+        [[self openGLContext] makeCurrentContext];
+        
+        NSOpenGLPixelFormat *pf = [self pixelFormat];
+        if (pf == nil)
+            pf = [[self class] defaultPixelFormat];
+        
+        context = [[CIContext contextWithCGLContext:CGLGetCurrentContext() 
pixelFormat:[pf CGLPixelFormatObj] options:nil] retain];
+    }
+    return context;
+}
+
+- (void)updateMatrices {
     NSRect bounds = [self bounds];
     
-    [[self openGLContext] makeCurrentContext];
+    [[self openGLContext] update];
     
-    if (needsReshape) {
-        // reset the views coordinate system when the view has been resized or 
scrolled
-        
-        glViewport (0, 0, NSWidth(bounds), NSHeight(bounds));
+    glViewport(0, 0, NSWidth(bounds), NSHeight(bounds));
 
-        glMatrixMode(GL_PROJECTION);
-        glLoadIdentity();
-        glOrtho(NSMinX(bounds), NSMaxX(bounds), NSMinY(bounds), 
NSMaxY(bounds), -1, 1);
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+    glOrtho(NSMinX(bounds), NSMaxX(bounds), NSMinY(bounds), NSMaxY(bounds), 
-1, 1);
 
-        glMatrixMode(GL_MODELVIEW);
-        glLoadIdentity();
-        
-        [[self openGLContext] update];
-        
-        needsReshape = NO;
-    }
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
     
-    glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+    needsReshape = NO;
+}
+
+- (void)drawRect:(NSRect)rect {
+    
+    [[self openGLContext] makeCurrentContext];
+    
+    if (needsReshape)
+        [self updateMatrices];
+    
+    glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
     glBegin(GL_POLYGON);
         glVertex2f(NSMinX(rect), NSMinY(rect));
         glVertex2f(NSMaxX(rect), NSMinY(rect));
@@ -523,21 +571,18 @@
     glEnd();
     
     CIImage *currentImage = [self currentImage];
-    
     if (currentImage) {
-        
-        if (context == nil) {
-            NSOpenGLPixelFormat *pf = [self pixelFormat];
-            if (pf == nil)
-                pf = [[self class] defaultPixelFormat];
-            context = [[CIContext contextWithCGLContext:CGLGetCurrentContext() 
pixelFormat:[pf CGLPixelFormatObj] options:nil] retain];
-        }
-        
-        [context drawImage:currentImage inRect:*(CGRect*)&bounds 
fromRect:*(CGRect*)&bounds];
-        
+        NSRect bounds = [self bounds];
+        [[self ciContext] drawImage:currentImage inRect:*(CGRect*)&bounds 
fromRect:*(CGRect*)&bounds];
     }
     
     glFlush();
 }
 
 @end
+
+
[EMAIL PROTECTED] SKTransitionWindow
+- (BOOL)canBecomeMainWindow { return NO; }
+- (BOOL)canBecomeKeyWindow { return NO; }
[EMAIL PROTECTED]


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to