Skip to content

Commit

Permalink
Update image preview: better download icon
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 115 deletions.
Binary file added HUDSave.tiff
Binary file not shown.
Binary file added HUDSaveActive.tiff
Binary file not shown.
14 changes: 14 additions & 0 deletions MacBlueTelnet.xcodeproj/project.pbxproj
Expand Up @@ -8,6 +8,9 @@

/* Begin PBXBuildFile section */
070D50430D9BF40400EC2660 /* YLImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 070D50420D9BF40400EC2660 /* YLImageView.m */; };
079E9BB00F08B9480089C9E2 /* HUDSave.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 079E9BAE0F08B9480089C9E2 /* HUDSave.tiff */; };
079E9BB10F08B9480089C9E2 /* HUDSaveActive.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 079E9BAF0F08B9480089C9E2 /* HUDSaveActive.tiff */; };
079E9BCA0F08C4820089C9E2 /* YLFloatingView.m in Sources */ = {isa = PBXBuildFile; fileRef = 079E9BC90F08C4820089C9E2 /* YLFloatingView.m */; };
07B370690D6840600035E87D /* YLImagePreviewer.m in Sources */ = {isa = PBXBuildFile; fileRef = 07B370680D6840600035E87D /* YLImagePreviewer.m */; };
07B3707A0D6840B20035E87D /* HMBlkAppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 07B370790D6840B20035E87D /* HMBlkAppKit.framework */; };
07B3708E0D6840BB0035E87D /* HMBlkAppKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 07B370790D6840B20035E87D /* HMBlkAppKit.framework */; };
Expand Down Expand Up @@ -69,6 +72,10 @@
/* Begin PBXFileReference section */
070D50410D9BF40400EC2660 /* YLImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLImageView.h; sourceTree = "<group>"; };
070D50420D9BF40400EC2660 /* YLImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YLImageView.m; sourceTree = "<group>"; };
079E9BAE0F08B9480089C9E2 /* HUDSave.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = HUDSave.tiff; sourceTree = "<group>"; };
079E9BAF0F08B9480089C9E2 /* HUDSaveActive.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = HUDSaveActive.tiff; sourceTree = "<group>"; };
079E9BC80F08C4820089C9E2 /* YLFloatingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLFloatingView.h; sourceTree = "<group>"; };
079E9BC90F08C4820089C9E2 /* YLFloatingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YLFloatingView.m; sourceTree = "<group>"; };
07B370670D6840600035E87D /* YLImagePreviewer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLImagePreviewer.h; sourceTree = "<group>"; };
07B370680D6840600035E87D /* YLImagePreviewer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YLImagePreviewer.m; sourceTree = "<group>"; };
07B370790D6840B20035E87D /* HMBlkAppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = HMBlkAppKit.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -240,6 +247,8 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
079E9BAE0F08B9480089C9E2 /* HUDSave.tiff */,
079E9BAF0F08B9480089C9E2 /* HUDSaveActive.tiff */,
85EA93210D0791180098C94B /* Preferences.nib */,
85137B320D02192800833909 /* Credits.rtf */,
85834C0F0CFEC3F30015E348 /* Whit.aiff */,
Expand Down Expand Up @@ -277,6 +286,8 @@
858A54E50CAE78C8000E1AA7 /* YLMarkedTextView.m */,
8570AD5D0A3923A900838442 /* YLView.h */,
8570AD5E0A3923A900838442 /* YLView.mm */,
079E9BC80F08C4820089C9E2 /* YLFloatingView.h */,
079E9BC90F08C4820089C9E2 /* YLFloatingView.m */,
);
name = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -384,6 +395,8 @@
85A0E73D0D06B72900ACA26F /* Localizable.strings in Resources */,
85EA93230D0791180098C94B /* Preferences.nib in Resources */,
85AD6FE70D227F1D00992A1C /* DragonBall.icns in Resources */,
079E9BB00F08B9480089C9E2 /* HUDSave.tiff in Resources */,
079E9BB10F08B9480089C9E2 /* HUDSaveActive.tiff in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -429,6 +442,7 @@
07B370690D6840600035E87D /* YLImagePreviewer.m in Sources */,
070D50430D9BF40400EC2660 /* YLImageView.m in Sources */,
07B73D900E5816FF00CC97D3 /* YLPluginLoader.m in Sources */,
079E9BCA0F08C4820089C9E2 /* YLFloatingView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
16 changes: 16 additions & 0 deletions YLFloatingView.h
@@ -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
108 changes: 108 additions & 0 deletions YLFloatingView.m
@@ -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
2 changes: 2 additions & 0 deletions YLImageView.h
Expand Up @@ -8,6 +8,7 @@

#import <Cocoa/Cocoa.h>
#import "YLImagePreviewer.h"
#import "YLFloatingView.h"

enum showTips { kShowTipsNone, kShowTipsWhite, kShowTipsGray };

Expand All @@ -16,6 +17,7 @@ enum showTips { kShowTipsNone, kShowTipsWhite, kShowTipsGray };
enum showTips tipsState;

YLImagePreviewer *previewer;
YLFloatingView *indicator;
}

- (id) initWithFrame: (NSRect)frame previewer: (YLImagePreviewer *)thePreviewer;
Expand Down
132 changes: 17 additions & 115 deletions YLImageView.m
Expand Up @@ -8,51 +8,10 @@

#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
enum {
kFloatRectWidth = 100,
kFloatRectHeight = 60,
};

@implementation YLImageView

Expand All @@ -61,95 +20,38 @@ - (id) initWithFrame: (NSRect)frame previewer: (YLImagePreviewer *)thePreviewer
if ([super initWithFrame: frame])
{
tipsState = kShowTipsGray;
tipsRect = NSMakeRect(10, 10, 65, 30);
tipsRect = NSMakeRect((frame.size.width - kFloatRectWidth) / 2, 10, kFloatRectWidth, kFloatRectHeight);

previewer = thePreviewer;
[[self window] setAcceptsMouseMovedEvents: YES];
[self addTrackingRect: [self bounds]
[self addTrackingRect: tipsRect
owner: self
userData: nil
assumeInside: NO];
}

return self;
}

- (void) drawRect: (NSRect)rect
{
[super drawRect: rect];

if (tipsState != kShowTipsNone &&
[self bounds].size.width > tipsRect.origin.x + tipsRect.size.width &&
[self bounds].size.height > tipsRect.origin.y + tipsRect.size.height)
{
NSColor *color = [NSColor colorWithCalibratedRed: 0
green: 0
blue: 0
alpha: 0.5];
[color set];
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: tipsRect
cornerRadius: 8.0];
[path fill];

NSColor *tipsColor = (tipsState == kShowTipsWhite ? [NSColor whiteColor] : [NSColor colorWithCalibratedRed: 0.8
green: 0.8
blue: 0.8
alpha: 1.0]);

NSFont *font = [NSFont systemFontOfSize: 16.0];
NSString *tips = @"Save...";
NSDictionary *attrib = [NSDictionary dictionaryWithObjectsAndKeys:
tipsColor, NSForegroundColorAttributeName,
font, NSFontAttributeName, nil];

[tips drawAtPoint: NSMakePoint(20, 15)
withAttributes: attrib];
indicator = [[YLFloatingView alloc] initWithFrame: tipsRect];
[indicator setWantsLayer: YES];
[indicator setAlphaValue: 0.0];
[self addSubview: indicator];
}
}

- (void) mouseDown: (NSEvent *)event
{
NSPoint location = [event locationInWindow];
NSPoint point = [self convertPoint: location fromView: nil];

if ([self mouse: point inRect: tipsRect])
{
tipsState = kShowTipsWhite;
[self setNeedsDisplay: YES];
}
return self;
}

- (void) mouseUp: (NSEvent *)event
- (void) dealloc
{
NSPoint location = [event locationInWindow];
NSPoint point = [self convertPoint: location fromView: nil];

if ([self mouse: point inRect: tipsRect])
{
NSSavePanel *panel = [NSSavePanel savePanel];

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");
}
}

tipsState = kShowTipsGray;
[self setNeedsDisplay: YES];
[indicator release];
[super dealloc];
}

- (void) mouseEntered: (NSEvent *)event
{
tipsState = kShowTipsGray;
[self setNeedsDisplay: YES];
[[indicator animator] setAlphaValue: 0.8];
}

- (void)mouseExited: (NSEvent *)event
{
tipsState = kShowTipsNone;
[self setNeedsDisplay: YES];
[[indicator animator] setAlphaValue: 0.0];
}

- (void) setPreviewer: (YLImagePreviewer *)thePreviewer
Expand Down

0 comments on commit a52e030

Please sign in to comment.