From eede1abbca57f3b7800391206d1c447aa4db747e Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 23 Dec 2011 20:35:00 +0000 Subject: [PATCH] update titlebar git-svn-id: svn://qnap.local/TwoTerm/branches/frameless@2341 5590a31f-7b70-45f8-8c82-aa3a8e5f4507 --- 2Term.xcodeproj/project.pbxproj | 32 +++--- English.lproj/TermWindow.xib | 181 ++++++++++++++++++-------------- TermWindowController.mm | 1 + Views/ColorView.h | 18 ++++ Views/ColorView.m | 35 ++++++ Views/EmulatorWindow.h | 7 ++ Views/EmulatorWindow.m | 73 +++++++++++-- Views/TermContentView.m | 8 +- Views/TitleBarView.h | 6 +- Views/TitleBarView.m | 90 +++++++++++----- 10 files changed, 328 insertions(+), 123 deletions(-) create mode 100644 Views/ColorView.h create mode 100644 Views/ColorView.m diff --git a/2Term.xcodeproj/project.pbxproj b/2Term.xcodeproj/project.pbxproj index ec0e81c..8d3b92a 100644 --- a/2Term.xcodeproj/project.pbxproj +++ b/2Term.xcodeproj/project.pbxproj @@ -38,10 +38,11 @@ B61EF7C914815AF8008C1891 /* NewTerminal.xib in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7C714815AF8008C1891 /* NewTerminal.xib */; }; B61EF7CC14815E07008C1891 /* TitleBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = B61EF7CB14815E07008C1891 /* TitleBarView.m */; }; B61EF7CF148163E7008C1891 /* TitleBarView.xib in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7CD148163E7008C1891 /* TitleBarView.xib */; }; - B61EF7D71482FB6D008C1891 /* titlebar-center.png.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D41482FB6D008C1891 /* titlebar-center.png.png */; }; - B61EF7D81482FB6D008C1891 /* titlebar-left.png.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D51482FB6D008C1891 /* titlebar-left.png.png */; }; - B61EF7D91482FB6D008C1891 /* titlebar-right.png.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D61482FB6D008C1891 /* titlebar-right.png.png */; }; + B61EF7D71482FB6D008C1891 /* titlebar-center.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D41482FB6D008C1891 /* titlebar-center.png */; }; + B61EF7D81482FB6D008C1891 /* titlebar-left.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D51482FB6D008C1891 /* titlebar-left.png */; }; + B61EF7D91482FB6D008C1891 /* titlebar-right.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D61482FB6D008C1891 /* titlebar-right.png */; }; B627333B12E3FF5B00A14C94 /* ChildMonitor.m in Sources */ = {isa = PBXBuildFile; fileRef = B627333A12E3FF5B00A14C94 /* ChildMonitor.m */; }; + B638188214A179D60027D007 /* ColorView.m in Sources */ = {isa = PBXBuildFile; fileRef = B638188114A179D60027D007 /* ColorView.m */; }; B66412391480A070003BC8D3 /* EmulatorWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = B66412381480A070003BC8D3 /* EmulatorWindow.m */; }; B676063B11DEAD3500D6B66C /* TermWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = B676063A11DEAD3500D6B66C /* TermWindowController.mm */; }; B676065111DEBAE900D6B66C /* TermWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = B676065011DEBAE900D6B66C /* TermWindow.xib */; }; @@ -132,11 +133,13 @@ B61EF7CA14815E07008C1891 /* TitleBarView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TitleBarView.h; sourceTree = ""; }; B61EF7CB14815E07008C1891 /* TitleBarView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TitleBarView.m; sourceTree = ""; }; B61EF7CE148163E7008C1891 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/TitleBarView.xib; sourceTree = ""; }; - B61EF7D41482FB6D008C1891 /* titlebar-center.png.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-center.png.png"; sourceTree = ""; }; - B61EF7D51482FB6D008C1891 /* titlebar-left.png.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-left.png.png"; sourceTree = ""; }; - B61EF7D61482FB6D008C1891 /* titlebar-right.png.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-right.png.png"; sourceTree = ""; }; + B61EF7D41482FB6D008C1891 /* titlebar-center.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-center.png"; sourceTree = ""; }; + B61EF7D51482FB6D008C1891 /* titlebar-left.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-left.png"; sourceTree = ""; }; + B61EF7D61482FB6D008C1891 /* titlebar-right.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-right.png"; sourceTree = ""; }; B627333912E3FF5B00A14C94 /* ChildMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChildMonitor.h; sourceTree = ""; }; B627333A12E3FF5B00A14C94 /* ChildMonitor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChildMonitor.m; sourceTree = ""; }; + B638188014A179D60027D007 /* ColorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorView.h; sourceTree = ""; }; + B638188114A179D60027D007 /* ColorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ColorView.m; sourceTree = ""; }; B66412371480A070003BC8D3 /* EmulatorWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EmulatorWindow.h; sourceTree = ""; }; B66412381480A070003BC8D3 /* EmulatorWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EmulatorWindow.m; sourceTree = ""; }; B676063911DEAD3500D6B66C /* TermWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TermWindowController.h; sourceTree = ""; }; @@ -301,9 +304,9 @@ B612F46B12DD5E02005D1B77 /* Views */ = { isa = PBXGroup; children = ( - B68E632812FF909C00EAFF5F /* ExampleView.h */, B66412371480A070003BC8D3 /* EmulatorWindow.h */, B66412381480A070003BC8D3 /* EmulatorWindow.m */, + B68E632812FF909C00EAFF5F /* ExampleView.h */, B68E632912FF909C00EAFF5F /* ExampleView.m */, B612F46C12DD5E02005D1B77 /* CurveView.h */, B612F46D12DD5E02005D1B77 /* CurveView.m */, @@ -313,6 +316,8 @@ B612870D1480B4F6002E04DF /* TermContentView.m */, B61EF7CA14815E07008C1891 /* TitleBarView.h */, B61EF7CB14815E07008C1891 /* TitleBarView.m */, + B638188014A179D60027D007 /* ColorView.h */, + B638188114A179D60027D007 /* ColorView.m */, ); path = Views; sourceTree = ""; @@ -320,9 +325,9 @@ B66979CE11E6BCAE002ED475 /* images */ = { isa = PBXGroup; children = ( - B61EF7D41482FB6D008C1891 /* titlebar-center.png.png */, - B61EF7D51482FB6D008C1891 /* titlebar-left.png.png */, - B61EF7D61482FB6D008C1891 /* titlebar-right.png.png */, + B61EF7D41482FB6D008C1891 /* titlebar-center.png */, + B61EF7D51482FB6D008C1891 /* titlebar-left.png */, + B61EF7D61482FB6D008C1891 /* titlebar-right.png */, B61EF7C31481561E008C1891 /* titlebar-corner.png */, B61EF7C41481561E008C1891 /* titlebar-middle.png */, B6801BD812EB549300B22E9E /* vt100-charset.png */, @@ -396,9 +401,9 @@ B61EF7C61481561E008C1891 /* titlebar-middle.png in Resources */, B61EF7C914815AF8008C1891 /* NewTerminal.xib in Resources */, B61EF7CF148163E7008C1891 /* TitleBarView.xib in Resources */, - B61EF7D71482FB6D008C1891 /* titlebar-center.png.png in Resources */, - B61EF7D81482FB6D008C1891 /* titlebar-left.png.png in Resources */, - B61EF7D91482FB6D008C1891 /* titlebar-right.png.png in Resources */, + B61EF7D71482FB6D008C1891 /* titlebar-center.png in Resources */, + B61EF7D81482FB6D008C1891 /* titlebar-left.png in Resources */, + B61EF7D91482FB6D008C1891 /* titlebar-right.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -436,6 +441,7 @@ B66412391480A070003BC8D3 /* EmulatorWindow.m in Sources */, B612870E1480B4F6002E04DF /* TermContentView.m in Sources */, B61EF7CC14815E07008C1891 /* TitleBarView.m in Sources */, + B638188214A179D60027D007 /* ColorView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/English.lproj/TermWindow.xib b/English.lproj/TermWindow.xib index 5d40712..36bd209 100644 --- a/English.lproj/TermWindow.xib +++ b/English.lproj/TermWindow.xib @@ -39,7 +39,7 @@ NSApplication - 15 + 271 2 {{158, 575}, {600, 424}} 539492352 @@ -58,56 +58,6 @@ 274 YES - - - 4362 - - YES - - - 298 - {{150, 4}, {300, 17}} - - - - 2 - _NS:3944 - YES - - 67239488 - 138418176 - Label - - LucidaGrande - 13 - 1044 - - _NS:3944 - - - 3 - MCAwAA - - - 6 - System - textColor - - 3 - MAA - - - - - - {{0, 400}, {600, 24}} - - - - 2 - _NS:1192 - TitleBarView - 274 @@ -122,9 +72,9 @@ {600, 424} - + 2 - CurveView + ColorView {600, 424} @@ -139,6 +89,56 @@ 128 YES + + + 274 + + YES + + + 290 + {{75, 2}, {250, 17}} + + + + 2 + _NS:3944 + YES + + 67239488 + 138450944 + Label + + LucidaGrande-Bold + 13 + 2072 + + _NS:3944 + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 1 + MSAwIDAAA + + + + + {400, 24} + + + + 2 + _NS:1192 + TitleBarView + @@ -197,19 +197,19 @@ - titleBar - - + titleBarView + + - 25 + 29 label - - + + - 24 + 33 @@ -265,7 +265,6 @@ YES - @@ -276,27 +275,27 @@ Emulator View - 21 - + 28 + YES - + - + - 22 - + 30 + YES - + - + - 23 - - + 31 + + @@ -312,9 +311,13 @@ 1.NSWindowTemplate.visibleAtLaunch 2.CustomClassName 2.IBPluginDependency - 21.IBPluginDependency - 22.IBPluginDependency - 23.IBPluginDependency + 28.IBPluginDependency + 30.IBPluginDependency + 30.IBViewIntegration.shadowBlurRadius + 30.IBViewIntegration.shadowColor + 30.IBViewIntegration.shadowOffsetHeight + 30.IBViewIntegration.shadowOffsetWidth + 31.IBPluginDependency 5.IBPluginDependency 9.IBPluginDependency @@ -330,6 +333,13 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + + 3 + MAA + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -347,7 +357,7 @@ - 27 + 35 @@ -360,6 +370,14 @@ ./Classes/ChildMonitor.h + + ColorView + NSView + + IBProjectSource + ./Classes/ColorView.h + + CurveView NSView @@ -411,6 +429,17 @@ EmulatorWindow NSWindow + + titleBarView + TitleBarView + + + titleBarView + + titleBarView + TitleBarView + + IBProjectSource ./Classes/EmulatorWindow.h diff --git a/TermWindowController.mm b/TermWindowController.mm index e0f8601..afe6c22 100644 --- a/TermWindowController.mm +++ b/TermWindowController.mm @@ -237,6 +237,7 @@ _emulator = [klass new]; [self didChangeValueForKey: @"emulator"]; + [window setBackgroundColor: backgroundColor]; [_emulatorView setEmulator: _emulator]; [_emulatorView setForegroundColor: foregroundColor]; diff --git a/Views/ColorView.h b/Views/ColorView.h new file mode 100644 index 0000000..c519a24 --- /dev/null +++ b/Views/ColorView.h @@ -0,0 +1,18 @@ +// +// ColorView.h +// 2Term +// +// Created by Kelvin Sherlock on 12/20/2011. +// Copyright (c) 2011 __MyCompanyName__. All rights reserved. +// + +#import + +@interface ColorView : NSView +{ + NSColor *_color; +} + +@property (nonatomic, retain) NSColor *color; + +@end diff --git a/Views/ColorView.m b/Views/ColorView.m new file mode 100644 index 0000000..690779a --- /dev/null +++ b/Views/ColorView.m @@ -0,0 +1,35 @@ +// +// ColorView.m +// 2Term +// +// Created by Kelvin Sherlock on 12/20/2011. +// Copyright (c) 2011 __MyCompanyName__. All rights reserved. +// + +#import "ColorView.h" + +@implementation ColorView + +@synthesize color = _color; + +- (void)drawRect:(NSRect)dirtyRect +{ + [_color setFill]; + NSRectFill(dirtyRect); +} + +-(void)setColor:(NSColor *)color +{ + if (_color == color) return; + [_color release]; + _color = [color retain]; + [self setNeedsDisplay: YES]; +} + +-(void)dealloc +{ + [_color release]; + [super dealloc]; +} + +@end diff --git a/Views/EmulatorWindow.h b/Views/EmulatorWindow.h index ba361e3..4c2d9ca 100644 --- a/Views/EmulatorWindow.h +++ b/Views/EmulatorWindow.h @@ -7,9 +7,16 @@ // #import +@class TitleBarView; @interface EmulatorWindow : NSWindow { + TitleBarView *_titleBarView; } +@property (nonatomic, retain) IBOutlet TitleBarView *titleBarView; + +-(void)adjustTitleBar; + + @end diff --git a/Views/EmulatorWindow.m b/Views/EmulatorWindow.m index 962540a..3e09680 100644 --- a/Views/EmulatorWindow.m +++ b/Views/EmulatorWindow.m @@ -7,17 +7,20 @@ // #import "EmulatorWindow.h" +#import "TitleBarView.h" @implementation EmulatorWindow +@synthesize titleBarView = _titleBarView; + -(id)initWithContentRect:(NSRect)contentRect - styleMask:(NSUInteger)aStyle + styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { if ((self = [super initWithContentRect: contentRect - styleMask: NSBorderlessWindowMask + styleMask: styleMask backing: bufferingType defer: flag])) { @@ -29,6 +32,7 @@ [self setResizeIncrements: NSMakeSize(1.0, 2.0)]; [self setMovableByWindowBackground: YES]; + //[self setBackgroundColor: [NSColor clearColor]]; //[self setHasShadow: NO]; //[self setHasShadow: YES]; @@ -38,15 +42,16 @@ return self; } + -(id)initWithContentRect:(NSRect)contentRect - styleMask:(NSUInteger)aStyle + styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag screen:(NSScreen *)screen { if ((self = [super initWithContentRect: contentRect - styleMask: NSBorderlessWindowMask | NSResizableWindowMask + styleMask: styleMask backing: bufferingType defer: flag screen: screen])) @@ -67,12 +72,33 @@ } --(void)awakeFromNib +-(void)dealloc { - [NSApp addWindowsItem: self title: @"Window Title" filename: NO]; - //[self setHasShadow: YES]; + [_titleBarView release]; + [super dealloc]; } +-(void)setTitle:(NSString *)aString +{ + [super setTitle: aString]; + [_titleBarView setTitle: aString]; +} + +-(void)setBackgroundColor:(NSColor *)color +{ + NSLog(@"%@", color); + [super setBackgroundColor: color]; + [_titleBarView setColor: color]; +} + +-(void)awakeFromNib +{ + [self adjustTitleBar]; + + //[NSApp addWindowsItem: self title: @"Window Title" filename: NO]; + //[self setHasShadow: YES]; +} +/* -(BOOL)canBecomeKeyWindow { return YES; } @@ -84,7 +110,40 @@ -(BOOL)isExcludedFromWindowsMenu { return NO; } +*/ +-(void)adjustTitleBar +{ + + NSView *themeView; + NSArray *array; + + themeView = [[self contentView] superview]; + + NSLog(@"%@", themeView); + + NSLog(@"%u", (int)[_titleBarView retainCount]); + + [_titleBarView setColor: [NSColor blackColor]]; + [_titleBarView setFrame: [themeView bounds]]; + [_titleBarView setTitle: [self title]]; + + NSLog(@"%@", [self title]); + + array = [themeView subviews]; + + NSLog(@"%@", array); + + [themeView addSubview: _titleBarView + positioned: NSWindowBelow + relativeTo: [array objectAtIndex: 0]]; + + + array = [themeView subviews]; + + NSLog(@"%@", array); + +} @end diff --git a/Views/TermContentView.m b/Views/TermContentView.m index 4f33f1f..04a0449 100644 --- a/Views/TermContentView.m +++ b/Views/TermContentView.m @@ -14,6 +14,9 @@ -(void)createTrackingArea { + + return; + NSRect rect; NSRect bounds; @@ -46,11 +49,13 @@ } + -(void)updateTrackingAreas { [self createTrackingArea]; } + -(void)dealloc { [_trackingArea release]; @@ -58,7 +63,7 @@ [super dealloc]; } - +/* -(void)mouseEntered:(NSEvent *)theEvent { //NSLog(@"%s", sel_getName(_cmd)); @@ -74,5 +79,6 @@ [_titleBar fadeOut]; // animate title bar out. } +*/ @end diff --git a/Views/TitleBarView.h b/Views/TitleBarView.h index ff97e64..8bc2bfe 100644 --- a/Views/TitleBarView.h +++ b/Views/TitleBarView.h @@ -10,14 +10,16 @@ @interface TitleBarView : NSView { + NSColor *_color; NSTextField *_label; NSImage *_rightImage; NSImage *_leftImage; NSImage *_centerImage; } -@property (nonatomic, assign) IBOutlet NSTextField *label; -@property (nonatomic, assign) NSString *title; +@property (nonatomic, retain) NSColor *color; +@property (nonatomic, retain) IBOutlet NSTextField *label; +@property (nonatomic, retain) NSString *title; -(void)fadeIn; -(void)fadeOut; diff --git a/Views/TitleBarView.m b/Views/TitleBarView.m index 71b4bf7..38204b5 100644 --- a/Views/TitleBarView.m +++ b/Views/TitleBarView.m @@ -12,19 +12,30 @@ @implementation TitleBarView @synthesize label = _label; +@synthesize color = _color; + +-(id)initWithFrame:(NSRect)frameRect +{ + if ((self = [super initWithFrame: frameRect])) + { + [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [self awakeFromNib]; + } + + return self; +} -(void)awakeFromNib -{ - [_label setTextColor: [NSColor whiteColor]]; - [self setContentFilters: [NSArray array]]; - +{ _leftImage = [[NSImage imageNamed: @"titlebar-left.png"] retain]; _rightImage = [[NSImage imageNamed: @"titlebar-right.png"] retain]; _centerImage = [[NSImage imageNamed: @"titlebar-center.png"] retain]; - [self setWantsLayer: YES]; - [[self layer] setOpacity: 0.0]; + + [_label setStringValue: @""]; + [_label setBackgroundColor: [NSColor clearColor]]; + [_label setTextColor: [NSColor whiteColor]]; } -(void)dealloc @@ -37,7 +48,37 @@ -(void)setTitle:(NSString *)title { - [_label setStringValue: title]; + NSAttributedString *as; + NSDictionary *attr; + NSShadow *shadow; + NSMutableParagraphStyle *ps; + + if (!title) + { + [_label setStringValue: @""]; + return; + } + + shadow = [NSShadow new]; + [shadow setShadowBlurRadius: 1.0]; + [shadow setShadowColor: [NSColor blackColor]]; + [shadow setShadowOffset: NSMakeSize(0.0, 1.0)]; + + ps = [NSMutableParagraphStyle new]; + [ps setAlignment: NSCenterTextAlignment]; + [ps setLineBreakMode: NSLineBreakByTruncatingMiddle]; + + attr = [NSDictionary dictionaryWithObjectsAndKeys: + shadow, NSShadowAttributeName, + ps, NSParagraphStyleAttributeName, + nil]; + + as = [[NSAttributedString alloc] initWithString: title attributes: attr]; + [_label setAttributedStringValue: as]; + + + [as release]; + [shadow release]; } -(NSString *)title @@ -45,31 +86,32 @@ return [_label stringValue]; } + +-(BOOL)isFlipped +{ + return YES; +} + + -(void)drawRect:(NSRect)dirtyRect { NSRect bounds; - NSRect rect; - + + bounds = [self bounds]; - /* - NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: NSMakeRect(0, 0, bounds.size.width, bounds.size.height * 2) - xRadius: 5.0 yRadius: 5.0]; + + NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: NSMakeRect(0, 0, bounds.size.width, bounds.size.height) + xRadius: 4.0 + yRadius: 4.0]; [path addClip]; - */ - rect = NSMakeRect(0, 0, 10, 24); - if (NSIntersectsRect(rect, dirtyRect)) - [_leftImage drawInRect: rect fromRect: NSMakeRect(0, 0, 10, 24) operation: NSCompositeSourceOver fraction: 1.0]; + + [_color setFill]; + NSRectFill(dirtyRect); + + NSDrawThreePartImage(NSMakeRect(0, 0, bounds.size.width, 24.0),_leftImage, _centerImage, _rightImage, NO, NSCompositeSourceOver, 1.0, YES); - - rect = NSMakeRect(bounds.size.width - 10, 0, 10, 24); - if (NSIntersectsRect(rect, dirtyRect)) - [_rightImage drawInRect: rect fromRect: NSMakeRect(0, 0, 10, 24) operation: NSCompositeSourceOver fraction: 1.0]; - - - bounds = NSInsetRect(bounds, 10, 0); - [_centerImage drawInRect: bounds fromRect:NSMakeRect(0, 0, 1, 24) operation: NSCompositeSourceOver fraction: 1.0]; } -(void)fadeIn