Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update image preview: better download icon
git-svn-id: https://nally.googlecode.com/svn/trunk@215 db928f3c-c32d-11dd-ba5c-d3b7c2b3b534
- Loading branch information
gzjjgod
committed
Jan 3, 2009
1 parent
04e8c2f
commit a52e030
Showing
7 changed files
with
157 additions
and
115 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// YLFloatingView.h | ||
// MacBlueTelnet | ||
// | ||
// Created by Jjgod Jiang on 12/29/08. | ||
// Copyright 2008 Jjgod Jiang. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface YLFloatingView : NSView { | ||
BOOL mouseDown; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// | ||
// YLFloatingView.m | ||
// MacBlueTelnet | ||
// | ||
// Created by Jjgod Jiang on 12/29/08. | ||
// Copyright 2008 Jjgod Jiang. All rights reserved. | ||
// | ||
|
||
#import "YLFloatingView.h" | ||
#import "YLImageView.h" | ||
|
||
@interface NSBezierPath (RoundRect) | ||
|
||
- (void) appendBezierPathWithRoundedRect:(NSRect)rect cornerRadius: (float)radius; | ||
+ (NSBezierPath *) bezierPathWithRoundedRect:(NSRect)rect cornerRadius: (float)radius; | ||
|
||
@end | ||
|
||
|
||
@implementation NSBezierPath (RoundRect) | ||
|
||
- (void) appendBezierPathWithRoundedRect:(NSRect)rect cornerRadius: (float)radius { | ||
if (! NSIsEmptyRect(rect)) | ||
{ | ||
if (radius > 0.0) { | ||
// Clamp radius to be no larger than half the rect's width or height. | ||
float clampedRadius = MIN(radius, 0.5 * MIN(rect.size.width, | ||
rect.size.height)); | ||
|
||
NSPoint topLeft = NSMakePoint(NSMinX(rect), NSMaxY(rect)); | ||
NSPoint topRight = NSMakePoint(NSMaxX(rect), NSMaxY(rect)); | ||
NSPoint bottomRight = NSMakePoint(NSMaxX(rect), NSMinY(rect)); | ||
|
||
[self moveToPoint:NSMakePoint(NSMidX(rect), NSMaxY(rect))]; | ||
[self appendBezierPathWithArcFromPoint:topLeft | ||
toPoint:rect.origin radius:clampedRadius]; | ||
[self appendBezierPathWithArcFromPoint:rect.origin | ||
toPoint:bottomRight radius:clampedRadius]; | ||
[self appendBezierPathWithArcFromPoint:bottomRight | ||
toPoint:topRight radius:clampedRadius]; | ||
[self appendBezierPathWithArcFromPoint:topRight | ||
toPoint:topLeft radius:clampedRadius]; | ||
[self closePath]; | ||
} else { | ||
// When radius == 0.0, this degenerates to the simple case of a plain rectangle. | ||
[self appendBezierPathWithRect:rect]; | ||
} | ||
} | ||
} | ||
|
||
+ (NSBezierPath *) bezierPathWithRoundedRect:(NSRect)rect cornerRadius: (float)radius | ||
{ | ||
NSBezierPath *result = [NSBezierPath bezierPath]; | ||
[result appendBezierPathWithRoundedRect:rect cornerRadius:radius]; | ||
return result; | ||
} | ||
|
||
@end | ||
|
||
@implementation YLFloatingView | ||
|
||
- (void) drawRect: (NSRect) rect | ||
{ | ||
NSColor *color = [NSColor colorWithCalibratedRed: 0 | ||
green: 0 | ||
blue: 0 | ||
alpha: 1]; | ||
[color set]; | ||
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: rect | ||
cornerRadius: 10.0]; | ||
[path fill]; | ||
|
||
NSString *imageFile = @"HUDSave"; | ||
if (mouseDown) | ||
imageFile = @"HUDSaveActive"; | ||
NSImage *img = [[NSImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource: imageFile | ||
ofType: @"tiff"]]; | ||
[img compositeToPoint: NSMakePoint((rect.size.width - [img size].width) / 2, | ||
(rect.size.height - [img size].height) / 2) | ||
operation: NSCompositeCopy]; | ||
[img release]; | ||
} | ||
|
||
- (void) mouseDown: (NSEvent *) event | ||
{ | ||
mouseDown = YES; | ||
[self setNeedsDisplay: YES]; | ||
} | ||
|
||
- (void) mouseUp: (NSEvent *) event | ||
{ | ||
NSSavePanel *panel = [NSSavePanel savePanel]; | ||
YLImagePreviewer *previewer = [(YLImageView *)[self superview] previewer]; | ||
|
||
if ([panel runModalForDirectory: nil | ||
file: [previewer filename]] == NSFileHandlingPanelOKButton) | ||
{ | ||
/* BOOL ret = */ [[previewer receivedData] writeToFile: [panel filename] | ||
atomically: YES]; | ||
// NSLog(@"save as %@: %s", [panel filename], ret == YES ? "done" : "failed"); | ||
} | ||
|
||
mouseDown = NO; | ||
[self setNeedsDisplay: YES]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters