Revision: 7518 http://skim-app.svn.sourceforge.net/skim-app/?rev=7518&view=rev Author: hofman Date: 2011-10-20 09:19:21 +0000 (Thu, 20 Oct 2011) Log Message: ----------- Have the annotation classes draw the selection highlight, as it depends on the class. Draw rectangles for quad points (lines) rather than full bounds of markup notes.
Modified Paths: -------------- trunk/NSGeometry_SKExtensions.h trunk/NSGeometry_SKExtensions.m trunk/PDFAnnotationLine_SKExtensions.m trunk/PDFAnnotationLink_SKExtensions.m trunk/PDFAnnotationMarkup_SKExtensions.m trunk/PDFAnnotation_SKExtensions.h trunk/PDFAnnotation_SKExtensions.m trunk/SKPDFView.m Modified: trunk/NSGeometry_SKExtensions.h =================================================================== --- trunk/NSGeometry_SKExtensions.h 2011-10-14 22:21:37 UTC (rev 7517) +++ trunk/NSGeometry_SKExtensions.h 2011-10-20 09:19:21 UTC (rev 7518) @@ -183,6 +183,11 @@ #pragma mark - +extern void SKDrawGrabHandle(NSPoint point, CGFloat radius, BOOL active); +extern void SKDrawGrabHandles(NSRect rect, CGFloat radius, NSInteger mask); + +#pragma mark - + extern void SKShiftAndResizeViews(NSArray *views, CGFloat dx, CGFloat dw); extern void SKAutoSizeButtons(NSArray *buttons, BOOL rightAlign); extern CGFloat SKAutoSizeLabelFields(NSArray *labelFields, NSArray *controls, BOOL resizeControls); Modified: trunk/NSGeometry_SKExtensions.m =================================================================== --- trunk/NSGeometry_SKExtensions.m 2011-10-14 22:21:37 UTC (rev 7517) +++ trunk/NSGeometry_SKExtensions.m 2011-10-20 09:19:21 UTC (rev 7518) @@ -112,6 +112,30 @@ #pragma mark - +void SKDrawGrabHandle(NSPoint point, CGFloat radius, BOOL active) +{ + NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(point.x - 0.875 * radius, point.y - 0.875 * radius, 1.75 * radius, 1.75 * radius)]; + [path setLineWidth:0.25 * radius]; + [[NSColor colorWithCalibratedRed:0.737118 green:0.837339 blue:0.983108 alpha:active ? 1.0 : 0.8] setFill]; + [[NSColor colorWithCalibratedRed:0.278477 green:0.467857 blue:0.810941 alpha:active ? 1.0 : 0.8] setStroke]; + [path fill]; + [path stroke]; +} + +void SKDrawGrabHandles(NSRect rect, CGFloat radius, NSInteger mask) +{ + SKDrawGrabHandle(NSMakePoint(NSMinX(rect), NSMidY(rect)), radius, mask == SKMinXEdgeMask); + SKDrawGrabHandle(NSMakePoint(NSMaxX(rect), NSMidY(rect)), radius, mask == SKMaxXEdgeMask); + SKDrawGrabHandle(NSMakePoint(NSMidX(rect), NSMaxY(rect)), radius, mask == SKMaxYEdgeMask); + SKDrawGrabHandle(NSMakePoint(NSMidX(rect), NSMinY(rect)), radius, mask == SKMinYEdgeMask); + SKDrawGrabHandle(NSMakePoint(NSMinX(rect), NSMaxY(rect)), radius, mask == (SKMinXEdgeMask | SKMaxYEdgeMask)); + SKDrawGrabHandle(NSMakePoint(NSMinX(rect), NSMinY(rect)), radius, mask == (SKMinXEdgeMask | SKMinYEdgeMask)); + SKDrawGrabHandle(NSMakePoint(NSMaxX(rect), NSMaxY(rect)), radius, mask == (SKMaxXEdgeMask | SKMaxYEdgeMask)); + SKDrawGrabHandle(NSMakePoint(NSMaxX(rect), NSMinY(rect)), radius, mask == (SKMaxXEdgeMask | SKMinYEdgeMask)); +} + +#pragma mark - + #define MIN_BUTTON_WIDTH 82.0 #define MAX_BUTTON_WIDTH 100.0 #define EXTRA_BUTTON_WIDTH 12.0 Modified: trunk/PDFAnnotationLine_SKExtensions.m =================================================================== --- trunk/PDFAnnotationLine_SKExtensions.m 2011-10-14 22:21:37 UTC (rev 7517) +++ trunk/PDFAnnotationLine_SKExtensions.m 2011-10-20 09:19:21 UTC (rev 7518) @@ -113,6 +113,14 @@ return NSInsetRect(bounds, -16.0, -16.0); } +- (void)drawSelectionHighlight:(NSUInteger)mask { + NSPoint origin = [self bounds].origin; + NSPoint point = SKAddPoints(origin, [self startPoint]); + SKDrawGrabHandle(point, 4.0, mask == SKMinXEdgeMask); + point = SKAddPoints(origin, [self endPoint]); + SKDrawGrabHandle(point, 4.0, mask == SKMaxXEdgeMask); +} + - (NSSet *)keysForValuesToObserveForUndo { static NSSet *lineKeys = nil; if (lineKeys == nil) { Modified: trunk/PDFAnnotationLink_SKExtensions.m =================================================================== --- trunk/PDFAnnotationLink_SKExtensions.m 2011-10-14 22:21:37 UTC (rev 7517) +++ trunk/PDFAnnotationLink_SKExtensions.m 2011-10-20 09:19:21 UTC (rev 7518) @@ -38,6 +38,7 @@ #import "PDFAnnotationLink_SKExtensions.h" #import "SKRuntime.h" +#import "NSGeometry_SKExtensions.h" @implementation PDFAnnotationLink (SKExtensions) @@ -54,6 +55,20 @@ original_toolTip = (id (*)(id, SEL))SKReplaceInstanceMethodImplementationFromSelector(self, @selector(toolTip), @selector(replacement_toolTip)); } +- (void)drawSelectionHighlight:(NSUInteger)mask { + NSRect rect = NSInsetRect(NSIntegralRect([self bounds]), 1.0, 1.0); + CGFloat radius = floor(0.3 * NSHeight(rect)); + NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius]; + [NSGraphicsContext saveGraphicsState]; + [NSBezierPath setDefaultLineWidth:2.0]; + [[NSColor colorWithCalibratedWhite:0.0 alpha:0.1] setFill]; + [[NSColor colorWithCalibratedWhite:0.0 alpha:0.5] setStroke]; + [path fill]; + [path stroke]; + [NSBezierPath setDefaultLineWidth:1.0]; + [NSGraphicsContext restoreGraphicsState]; +} + - (BOOL)isLink { return YES; } - (NSArray *)accessibilityAttributeNames { Modified: trunk/PDFAnnotationMarkup_SKExtensions.m =================================================================== --- trunk/PDFAnnotationMarkup_SKExtensions.m 2011-10-14 22:21:37 UTC (rev 7517) +++ trunk/PDFAnnotationMarkup_SKExtensions.m 2011-10-20 09:19:21 UTC (rev 7518) @@ -296,6 +296,22 @@ return bounds; } +- (void)drawSelectionHighlight:(NSUInteger)mask { + // archived annotations (or annotations we didn't create) won't have these + if ([self hasLineRects] == NO) + [self regenerateLineRects]; + + NSPointerArray *lines = [self lineRects]; + NSUInteger i, iMax = [lines count]; + + [NSGraphicsContext saveGraphicsState]; + [NSBezierPath setDefaultLineWidth:1.0]; + [[NSColor colorWithCalibratedRed:0.278477 green:0.467857 blue:0.810941 alpha:1.0] setStroke]; + for (i = 0; i < iMax; i++) + [NSBezierPath strokeRect:NSInsetRect(NSIntegralRect(*(NSRectPointer)[lines pointerAtIndex:i]), 0.5, 0.5)]; + [NSGraphicsContext restoreGraphicsState]; +} + - (BOOL)isMarkup { return YES; } - (BOOL)hasBorder { return NO; } Modified: trunk/PDFAnnotation_SKExtensions.h =================================================================== --- trunk/PDFAnnotation_SKExtensions.h 2011-10-14 22:21:37 UTC (rev 7517) +++ trunk/PDFAnnotation_SKExtensions.h 2011-10-20 09:19:21 UTC (rev 7518) @@ -79,6 +79,8 @@ - (NSRect)displayRectForBounds:(NSRect)bounds; +- (void)drawSelectionHighlight:(NSUInteger)mask; + - (void)registerUserName; - (NSSet *)keysForValuesToObserveForUndo; Modified: trunk/PDFAnnotation_SKExtensions.m =================================================================== --- trunk/PDFAnnotation_SKExtensions.m 2011-10-14 22:21:37 UTC (rev 7517) +++ trunk/PDFAnnotation_SKExtensions.m 2011-10-20 09:19:21 UTC (rev 7518) @@ -231,6 +231,16 @@ return bounds; } +- (void)drawSelectionHighlight:(NSUInteger)mask { + [NSGraphicsContext saveGraphicsState]; + [NSBezierPath setDefaultLineWidth:1.0]; + [[NSColor colorWithCalibratedRed:0.278477 green:0.467857 blue:0.810941 alpha:1.0] setStroke]; + [NSBezierPath strokeRect:NSInsetRect(NSIntegralRect([self bounds]), 0.5, 0.5)]; + if ([self isResizable]) + SKDrawGrabHandles([self bounds], 4.0, mask); + [NSGraphicsContext restoreGraphicsState]; +} + - (void)registerUserName { if ([[NSUserDefaults standardUserDefaults] boolForKey:SKUseUserNameKey]) { NSString *userName = [[NSUserDefaults standardUserDefaults] stringForKey:SKUserNameKey]; Modified: trunk/SKPDFView.m =================================================================== --- trunk/SKPDFView.m 2011-10-14 22:21:37 UTC (rev 7517) +++ trunk/SKPDFView.m 2011-10-20 09:19:21 UTC (rev 7518) @@ -69,6 +69,7 @@ #import "SKLineInspector.h" #import "PDFView_SKExtensions.h" #import "NSMenu_SKExtensions.h" +#import "NSGeometry_SKExtensions.h" #define ANNOTATION_MODE_COUNT 9 #define TOOL_MODE_COUNT 5 @@ -117,9 +118,6 @@ static inline NSInteger SKIndexOfRectAtYInOrderedRects(CGFloat y, NSPointerArray *rectArray, BOOL lower); -static void SKDrawGrabHandle(NSPoint point, CGFloat radius, BOOL active); -static void SKDrawGrabHandles(NSRect rect, CGFloat radius, NSInteger mask); - enum { SKNavigationNone, SKNavigationBottom, @@ -358,32 +356,8 @@ [NSGraphicsContext restoreGraphicsState]; } - if ([[activeAnnotation page] isEqual:pdfPage]) { - BOOL isLink = [activeAnnotation isLink]; - CGFloat lineWidth = isLink ? 2.0 : 1.0; - NSRect bounds = [activeAnnotation bounds]; - NSRect rect = NSInsetRect(NSIntegralRect(bounds), 0.5 * lineWidth, 0.5 * lineWidth); - [NSBezierPath setDefaultLineWidth:lineWidth]; - if (isLink) { - CGFloat radius = floor(0.3 * NSHeight(rect)); - NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius]; - [[NSColor colorWithCalibratedWhite:0.0 alpha:0.1] setFill]; - [[NSColor colorWithCalibratedWhite:0.0 alpha:0.5] setStroke]; - [path fill]; - [path stroke]; - } else if ([[activeAnnotation type] isEqualToString:SKNLineString]) { - NSPoint point = SKAddPoints(bounds.origin, [(PDFAnnotationLine *)activeAnnotation startPoint]); - SKDrawGrabHandle(point, 4.0, dragMask == SKMinXEdgeMask); - point = SKAddPoints(bounds.origin, [(PDFAnnotationLine *)activeAnnotation endPoint]); - SKDrawGrabHandle(point, 4.0, dragMask == SKMaxXEdgeMask); - } else if (editField == nil) { - [[NSColor colorWithCalibratedRed:0.278477 green:0.467857 blue:0.810941 alpha:1.0] setStroke]; - [NSBezierPath strokeRect:rect]; - if ([activeAnnotation isResizable]) - SKDrawGrabHandles(bounds, 4.0, dragMask); - } - [NSBezierPath setDefaultLineWidth:1.0]; - } + if ([[activeAnnotation page] isEqual:pdfPage] && editField == nil) + [activeAnnotation drawSelectionHighlight:dragMask]; if ([[highlightAnnotation page] isEqual:pdfPage]) { NSRect bounds = [highlightAnnotation bounds]; @@ -4344,27 +4318,3 @@ } return MIN(i, iMax - 1); } - -#pragma mark Grab handles - -static void SKDrawGrabHandle(NSPoint point, CGFloat radius, BOOL active) -{ - NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(point.x - 0.875 * radius, point.y - 0.875 * radius, 1.75 * radius, 1.75 * radius)]; - [path setLineWidth:0.25 * radius]; - [[NSColor colorWithCalibratedRed:0.737118 green:0.837339 blue:0.983108 alpha:active ? 1.0 : 0.8] setFill]; - [[NSColor colorWithCalibratedRed:0.278477 green:0.467857 blue:0.810941 alpha:active ? 1.0 : 0.8] setStroke]; - [path fill]; - [path stroke]; -} - -static void SKDrawGrabHandles(NSRect rect, CGFloat radius, NSInteger mask) -{ - SKDrawGrabHandle(NSMakePoint(NSMinX(rect), NSMidY(rect)), radius, mask == SKMinXEdgeMask); - SKDrawGrabHandle(NSMakePoint(NSMaxX(rect), NSMidY(rect)), radius, mask == SKMaxXEdgeMask); - SKDrawGrabHandle(NSMakePoint(NSMidX(rect), NSMaxY(rect)), radius, mask == SKMaxYEdgeMask); - SKDrawGrabHandle(NSMakePoint(NSMidX(rect), NSMinY(rect)), radius, mask == SKMinYEdgeMask); - SKDrawGrabHandle(NSMakePoint(NSMinX(rect), NSMaxY(rect)), radius, mask == (SKMinXEdgeMask | SKMaxYEdgeMask)); - SKDrawGrabHandle(NSMakePoint(NSMinX(rect), NSMinY(rect)), radius, mask == (SKMinXEdgeMask | SKMinYEdgeMask)); - SKDrawGrabHandle(NSMakePoint(NSMaxX(rect), NSMaxY(rect)), radius, mask == (SKMaxXEdgeMask | SKMaxYEdgeMask)); - SKDrawGrabHandle(NSMakePoint(NSMaxX(rect), NSMinY(rect)), radius, mask == (SKMaxXEdgeMask | SKMinYEdgeMask)); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Ciosco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit