Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/zoomCocoa/ZoomPixmapWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

// Initialisation
- (id) initWithZoomView: (ZoomView*) view;
- (void) setZoomView: (ZoomView*) view;
@property (assign) ZoomView* zoomView;

// Getting the pixmap
- (NSSize) size;
- (NSImage*) pixmap;
@property (readonly) NSSize size;
@property (readonly, retain) NSImage *pixmap;

// Input information
- (NSPoint) inputPos;
@property (readonly) NSPoint inputPos;
- (ZStyle*) inputStyle;

@end
72 changes: 33 additions & 39 deletions src/zoomCocoa/ZoomPixmapWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright (c) 2004 Andrew Hunter. All rights reserved.
//

#include <tgmath.h>
#import "ZoomPixmapWindow.h"


Expand All @@ -16,9 +17,9 @@ - (id) initWithZoomView: (ZoomView*) view {
self = [super init];

if (self) {
pixmap = [[NSImage alloc] initWithSize: NSMakeSize(640, 480)];
[pixmap setFlipped: YES];
pixmap = [[NSImage alloc] initWithSize: NSMakeSize(640, 400)];
zView = view;
[zView.window setContentSize: NSMakeSize(640, 400)];

inputStyle = nil;
}
Expand All @@ -39,9 +40,7 @@ - (NSSize) size {
return [pixmap size];
}

- (NSImage*) pixmap {
return pixmap;
}
@synthesize pixmap;

// = Standard window commands =

Expand All @@ -63,10 +62,10 @@ - (NSSize) sizeOfFont: (NSFont*) font {
NSLayoutManager* layoutManager = [[NSLayoutManager alloc] init];

// Width is one 'em'
float width = [@"M" sizeWithAttributes: [NSDictionary dictionaryWithObjectsAndKeys: NSFontAttributeName, font, nil]].width;
CGFloat width = [@"M" sizeWithAttributes: [NSDictionary dictionaryWithObjectsAndKeys: NSFontAttributeName, font, nil]].width;

// Height is decided by the layout manager
float height = [layoutManager defaultLineHeightForFont: font];
CGFloat height = [layoutManager defaultLineHeightForFont: font];

return NSMakeSize(width, height);
}
Expand Down Expand Up @@ -94,7 +93,7 @@ - (void) setSize: (NSSize) windowSize {

- (void) plotRect: (NSRect) rect
withStyle: (ZStyle*) style {
[pixmap lockFocus];
[pixmap lockFocusFlipped:YES];

NSColor* foregroundColour = [zView foregroundColourForStyle: style];
[foregroundColour set];
Expand All @@ -107,29 +106,29 @@ - (void) plotRect: (NSRect) rect
- (void) plotText: (NSString*) text
atPoint: (NSPoint) point
withStyle: (ZStyle*) style {
[pixmap lockFocus];
[pixmap lockFocusFlipped:YES];

NSMutableDictionary* attr = [[zView attributesForStyle: style] mutableCopy];

// Draw the background
float height = [self sizeOfFont: [attr objectForKey: NSFontAttributeName]].height;
float descender = [[attr objectForKey: NSFontAttributeName] descender];
CGFloat height = [self sizeOfFont: [attr objectForKey: NSFontAttributeName]].height;
CGFloat descender = [[attr objectForKey: NSFontAttributeName] descender];
NSSize size = [text sizeWithAttributes: attr];

point.y -= ceilf(height)+1.0;
point.y -= ceil(height)+1.0;

size.height = height;
NSRect backgroundRect;
backgroundRect.origin = point;
backgroundRect.size = size;
backgroundRect.origin.y -= descender;

backgroundRect.origin.x = floorf(backgroundRect.origin.x);
backgroundRect.origin.y = floorf(backgroundRect.origin.y);
backgroundRect.size.width = ceilf(backgroundRect.size.width);
backgroundRect.size.height = ceilf(backgroundRect.size.height) + 1.0;
backgroundRect.origin.x = floor(backgroundRect.origin.x);
backgroundRect.origin.y = floor(backgroundRect.origin.y);
backgroundRect.size.width = ceil(backgroundRect.size.width);
backgroundRect.size.height = ceil(backgroundRect.size.height) + 1.0;

[[attr objectForKey: NSBackgroundColorAttributeName] set];
[(NSColor*)[attr objectForKey: NSBackgroundColorAttributeName] set];
NSRectFill(backgroundRect);

// Draw the text
Expand All @@ -145,20 +144,22 @@ - (void) plotText: (NSString*) text

- (void) scrollRegion: (NSRect) region
toPoint: (NSPoint) where {
[pixmap lockFocus];
[pixmap lockFocusFlipped:YES];

// Used to use NSCopyBits but Apple randomly broke it sometime in Snow Leopard. The docs lied anyway.
// This is much slower :-(
NSBitmapImageRep* copiedBits = [[NSBitmapImageRep alloc] initWithFocusedViewRect: region];
NSImage* copiedImage = [[NSImage alloc] init];
[copiedImage addRepresentation: copiedBits];
[copiedImage setFlipped: YES];
[copiedBits release];
[copiedImage drawInRect: NSMakeRect(where.x, where.y, region.size.width, region.size.height)
fromRect: NSMakeRect(0,0, region.size.width, region.size.height)
operation: NSCompositeSourceOver
fraction: 1.0];
operation: NSCompositingOperationSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];

[copiedBits release];
[copiedImage release];

// Uh, docs say we should use NSNullObject here, but it's not defined. Making a guess at its value (sigh)
// This would be less of a problem in a view, because we can get the view's own graphics state. But you
Expand Down Expand Up @@ -203,7 +204,7 @@ - (NSSize) measureString: (in NSString*) string
}

- (NSColor*) colourAtPixel: (NSPoint) point {
[pixmap lockFocus];
[pixmap lockFocusFlipped:YES];

if (point.x <= 0) point.x = 1;
if (point.y <= 0) point.y = 1;
Expand All @@ -222,13 +223,11 @@ - (void) setInputPosition: (NSPoint) point
inputPos = point;
if (inputStyle) {
[inputStyle release];
inputStyle = style;
}
inputStyle = [style copy];
}

- (NSPoint) inputPos {
return inputPos;
}
@synthesize inputPos;

- (ZStyle*) inputStyle {
return inputStyle;
Expand All @@ -238,21 +237,18 @@ - (void) plotImageWithNumber: (int) number
atPoint: (NSPoint) point {
NSImage* img = [[zView resources] imageWithNumber: number];

NSRect imgRect;
imgRect.origin = NSMakePoint(0,0);
imgRect.size = [img size];

NSRect destRect;
destRect.origin = point;
destRect.size = [[zView resources] sizeForImageWithNumber: number
forPixmapSize: [pixmap size]];

[pixmap lockFocus];
[img setFlipped: [pixmap isFlipped]];
[pixmap lockFocusFlipped:YES];
[img drawInRect: destRect
fromRect: imgRect
operation: NSCompositeSourceOver
fraction: 1.0];
fromRect: NSZeroRect
operation: NSCompositingOperationSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];
[pixmap unlockFocus];

[zView setNeedsDisplay: YES];
Expand All @@ -278,9 +274,7 @@ - (id)initWithCoder:(NSCoder *)decoder {
return self;
}

- (void) setZoomView: (ZoomView*) view {
zView = view;
}
@synthesize zoomView=zView;

// = Input styles =

Expand Down