From: Kent Sutherland Date: Thu, 22 Jan 2004 23:06:10 +0000 (+0000) Subject: Added sizing to the main status window class, and added a basic icon and X-Git-Tag: v0.2~5 X-Git-Url: http://git.ithinksw.org/ITKit.git/commitdiff_plain/5e2815af6cd3f5dffaca2e8d1876c0a355209859 Added sizing to the main status window class, and added a basic icon and text status window. --- diff --git a/ITIconAndTextStatusWindow.h b/ITIconAndTextStatusWindow.h new file mode 100755 index 0000000..9955f04 --- /dev/null +++ b/ITIconAndTextStatusWindow.h @@ -0,0 +1,25 @@ +/* + * ITKit + * ITIconAndTextStatusWindow + * ITTransientStatusWindow subclass to show an icon and text. + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * Responsibility : Joseph Spiros + * + * Copyright (c) 2002 - 2004 iThink Software. + * All Rights Reserved + * + */ + +#import +#import "ITTransientStatusWindow.h" + +@interface ITIconAndTextStatusWindow : ITTransientStatusWindow { + NSImage *_image; +} + +- (void)setImage:(NSImage *)newImage; +- (void)buildTextWindowWithString:(NSString *)text; + +@end diff --git a/ITIconAndTextStatusWindow.m b/ITIconAndTextStatusWindow.m new file mode 100755 index 0000000..afe0066 --- /dev/null +++ b/ITIconAndTextStatusWindow.m @@ -0,0 +1,223 @@ +/* + * ITKit + * ITIconAndTextStatusWindow + * ITTransientStatusWindow subclass to show an icon and text. + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * Responsibility : Joseph Spiros + * + * Copyright (c) 2002 - 2004 iThink Software. + * All Rights Reserved + * + */ + +#import "ITIconAndTextStatusWindow.h" +#import "ITWindowPositioning.h" +#import "ITWindowEffect.h" +#import "ITImageView.h" +#import "ITTextField.h" + +#define SW_PAD 24.00 +#define SW_SPACE 24.00 +#define SW_MINW 211.00 +#define SW_BORDER 32.00 +#define SW_METER_PAD 4.00 +#define SW_BUTTON_PAD_R 30.00 +#define SW_BUTTON_PAD_B 24.00 +#define SW_BUTTON_DIV 12.00 +#define SW_BUTTON_EXTRA_W 8.00 +#define SW_SHADOW_SAT 1.25 +#define SMALL_DIVISOR 1.33333 +#define MINI_DIVISOR 1.66667 + +@implementation ITIconAndTextStatusWindow + +/*************************************************************************/ +#pragma mark - +#pragma mark INITIALIZATION / DEALLOCATION METHODS +/*************************************************************************/ + +- (id)initWithContentView:(NSView *)contentView + exitMode:(ITTransientStatusWindowExitMode)exitMode + backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType +{ + if ( ( self = [super initWithContentView:contentView exitMode:exitMode backgroundType:backgroundType] ) ) { + //Defaults + _image = [[NSImage imageNamed:@"NSApplicationIcon"] retain]; + [self setSizing:ITTransientStatusWindowRegular]; + } + return self; +} + +- (void)dealloc +{ + [_image release]; + [super dealloc]; +} + +- (void)setImage:(NSImage *)newImage +{ + [_image autorelease]; + _image = [newImage copy]; +} + +/*************************************************************************/ +#pragma mark - +#pragma mark INSTANCE METHODS +/*************************************************************************/ + +- (NSRect)setupWindowWithDataSize:(NSSize)dataSize +{ + float divisor = 1.0; + NSRect imageRect; + float imageWidth = 0.0; + float imageHeight = 0.0; + float dataWidth = dataSize.width; + float dataHeight = dataSize.height; + float contentHeight = 0.0; + float windowWidth = 0.0; + float windowHeight = 0.0; + NSRect visibleFrame = [[self screen] visibleFrame]; + NSPoint screenOrigin = visibleFrame.origin; + float screenWidth = visibleFrame.size.width; + float screenHeight = visibleFrame.size.height; + float maxWidth = ( screenWidth - (SW_BORDER * 2) ); + float maxHeight = ( screenHeight - (SW_BORDER * 2) ); + float excessWidth = 0.0; + float excessHeight = 0.0; + NSPoint windowOrigin; + ITImageView *imageView; + BOOL shouldAnimate = ( ! (([self visibilityState] == ITWindowAppearingState) || + ([self visibilityState] == ITWindowVanishingState)) ); + + if ( [self sizing] == ITTransientStatusWindowSmall ) { + divisor = SMALL_DIVISOR; + } else if ( [self sizing] == ITTransientStatusWindowMini ) { + divisor = MINI_DIVISOR; + } + +// Get image width and height. + imageWidth = ( [_image size].width / divisor ); + imageHeight = ( [_image size].height / divisor ); + +// Set the content height to the greater of the text and image heights. + contentHeight = ( ( imageHeight > dataHeight ) ? imageHeight : dataHeight ); + +// Setup the Window, and remove all its contentview's subviews. + windowWidth = ( (SW_PAD / divisor) + imageWidth + (SW_SPACE / divisor) + dataWidth + (SW_PAD / divisor) ); + windowHeight = ( (SW_PAD / divisor) + contentHeight + (SW_PAD / divisor) ); + +// Constrain size to max limits. Adjust data sizes accordingly. + excessWidth = (windowWidth - maxWidth ); + excessHeight = (windowHeight - maxHeight); + + if ( excessWidth > 0.0 ) { + windowWidth = maxWidth; + dataWidth -= excessWidth; + } + + if ( excessHeight > 0.0 ) { + windowHeight = maxHeight; + dataHeight -= excessHeight; + } + + if ( [self horizontalPosition] == ITWindowPositionLeft ) { + windowOrigin.x = ( SW_BORDER + screenOrigin.x ); + } else if ( [self horizontalPosition] == ITWindowPositionCenter ) { + windowOrigin.x = ( screenOrigin.x + (screenWidth / 2) - (windowWidth / 2) ); + } else if ( [self horizontalPosition] == ITWindowPositionRight ) { + windowOrigin.x = ( screenOrigin.x + screenWidth - (windowWidth + SW_BORDER) ); + } + + if ( [self verticalPosition] == ITWindowPositionTop ) { + windowOrigin.y = ( screenOrigin.y + screenHeight - (windowHeight + SW_BORDER) ); + } else if ( [self verticalPosition] == ITWindowPositionMiddle ) { +// Middle-oriented windows should be slightly proud of the screen's middle. + windowOrigin.y = ( (screenOrigin.y + (screenHeight / 2) - (windowHeight / 2)) + (screenHeight / 8) ); + } else if ( [self verticalPosition] == ITWindowPositionBottom ) { + windowOrigin.y = ( SW_BORDER + screenOrigin.y ); + } + + [self setFrame:NSMakeRect( windowOrigin.x, + windowOrigin.y, + windowWidth, + windowHeight) display:YES animate:shouldAnimate]; + + [[[self contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; + +// Setup, position, fill, and add the image view to the content view. + imageRect = NSMakeRect( (SW_PAD / divisor), + ((SW_PAD / divisor) + ((contentHeight - imageHeight) / 2)), + imageWidth, + imageHeight ); + imageView = [[[ITImageView alloc] initWithFrame:imageRect] autorelease]; + [imageView setAutoresizingMask:(NSViewMinYMargin | NSViewMaxYMargin)]; + [imageView setImage:_image]; + [imageView setCastsShadow:YES]; + [[self contentView] addSubview:imageView]; + + return NSMakeRect( ((SW_PAD / divisor) + imageWidth + (SW_SPACE / divisor)), + ((SW_PAD / divisor) + ((contentHeight - dataHeight) / 2)), + dataWidth, + dataHeight); +} + +- (void)buildTextWindowWithString:(NSString *)text +{ + float divisor = 1.0; + float dataWidth = 0.0; + float dataHeight = 0.0; + NSRect dataRect; + NSArray *lines = [text componentsSeparatedByString:@"\n"]; + id oneLine = nil; + NSEnumerator *lineEnum = [lines objectEnumerator]; + float baseFontSize = 18.0; + ITTextField *textField; + NSFont *font; + NSDictionary *attr; + + if ( [self sizing] == ITTransientStatusWindowSmall ) { + divisor = SMALL_DIVISOR; + } else if ( [self sizing] == ITTransientStatusWindowMini ) { + divisor = MINI_DIVISOR; + } + + font = [NSFont fontWithName:@"Lucida Grande Bold" size:(baseFontSize / divisor)]; + attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; + +// Iterate over each line to get text width and height + while ( (oneLine = [lineEnum nextObject]) ) { +// Get the width of one line, adding 8.0 because Apple sucks donkey rectum. + float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 ); +// Add the height of this line to the total text height + dataHeight += [oneLine sizeWithAttributes:attr].height; +// If this line wider than the last one, set it as the text width. + dataWidth = ( ( dataWidth > oneLineWidth ) ? dataWidth : oneLineWidth ); + } + +// Add 4.0 to the final dataHeight to accomodate the shadow. + dataHeight += 4.0; + + dataRect = [self setupWindowWithDataSize:NSMakeSize(dataWidth, dataHeight)]; + +// Create, position, setup, fill, and add the text view to the content view. + textField = [[[ITTextField alloc] initWithFrame:dataRect] autorelease]; + [textField setAutoresizingMask:(NSViewHeightSizable | NSViewWidthSizable)]; + [textField setEditable:NO]; + [textField setSelectable:NO]; + [textField setBordered:NO]; + [textField setDrawsBackground:NO]; + [textField setFont:font]; + [textField setTextColor:[NSColor whiteColor]]; + [textField setCastsShadow:YES]; + [[textField cell] setWraps:NO]; + [textField setStringValue:text]; + [textField setShadowSaturation:SW_SHADOW_SAT]; + [[self contentView] addSubview:textField]; + +// Display the window. + [[self contentView] setNeedsDisplay:YES]; +} + +@end diff --git a/ITKit.h b/ITKit.h index 50dacfb..8e03709 100755 --- a/ITKit.h +++ b/ITKit.h @@ -28,5 +28,7 @@ #import #import +#import + #import #import diff --git a/ITKit.xcode/project.pbxproj b/ITKit.xcode/project.pbxproj index d77009f..ed67085 100755 --- a/ITKit.xcode/project.pbxproj +++ b/ITKit.xcode/project.pbxproj @@ -527,6 +527,47 @@ //322 //323 //324 +//370 +//371 +//372 +//373 +//374 + 3710911905C07F6D00ED0F36 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = ITIconAndTextStatusWindow.h; + refType = 4; + sourceTree = ""; + }; + 3710911A05C07F6D00ED0F36 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = ITIconAndTextStatusWindow.m; + refType = 4; + sourceTree = ""; + }; + 3710912305C0821000ED0F36 = { + fileRef = 3710911A05C07F6D00ED0F36; + isa = PBXBuildFile; + settings = { + }; + }; + 3710912805C0825900ED0F36 = { + fileRef = 3710911905C07F6D00ED0F36; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; +//370 +//371 +//372 +//373 +//374 //7C0 //7C1 //7C2 @@ -1764,6 +1805,8 @@ children = ( 7C992DF9054F5179000B93EA, 7C992DFA054F5179000B93EA, + 3710911905C07F6D00ED0F36, + 3710911A05C07F6D00ED0F36, 7C992DD8054F5179000B93EA, 7C992DD9054F5179000B93EA, 7C992DFD054F5179000B93EA, @@ -2140,6 +2183,7 @@ 7C992E32054F5179000B93EA, 2AC83141056D00F700A7D7E2, 2AC8319D056D037700A7D7E2, + 3710912805C0825900ED0F36, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -2198,6 +2242,7 @@ 7C992E31054F5179000B93EA, 2AC83142056D00F700A7D7E2, 2AC8319E056D037700A7D7E2, + 3710912305C0821000ED0F36, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; diff --git a/ITTransientStatusWindow.h b/ITTransientStatusWindow.h index 26fd426..04f13ab 100755 --- a/ITTransientStatusWindow.h +++ b/ITTransientStatusWindow.h @@ -42,6 +42,11 @@ typedef enum { ITTransientStatusWindowAquaUtility } ITTransientStatusWindowBackgroundType; +typedef enum { + ITTransientStatusWindowRegular, + ITTransientStatusWindowSmall, + ITTransientStatusWindowMini +} ITTransientStatusWindowSizing; @interface ITTransientStatusWindow : NSWindow { @@ -54,6 +59,7 @@ typedef enum { double _effectProgress; ITVerticalWindowPosition _verticalPosition; ITHorizontalWindowPosition _horizontalPosition; + ITTransientStatusWindowSizing _sizing; float _screenPadding; // int _screenNumber; @@ -73,6 +79,9 @@ typedef enum { - (void)appear:(id)sender; - (void)vanish:(id)sender; +- (void)setSizing:(ITTransientStatusWindowSizing)newSizing; +- (ITTransientStatusWindowSizing)sizing; + - (ITWindowVisibilityState)visibilityState; - (void)setVisibilityState:(ITWindowVisibilityState)newState; diff --git a/ITTransientStatusWindow.m b/ITTransientStatusWindow.m index 4f03f53..3f01c35 100755 --- a/ITTransientStatusWindow.m +++ b/ITTransientStatusWindow.m @@ -183,6 +183,16 @@ static ITTransientStatusWindow *staticWindow = nil; } } +- (void)setSizing:(ITTransientStatusWindowSizing)newSizing +{ + _sizing = newSizing; +} + +- (ITTransientStatusWindowSizing)sizing +{ + return _sizing; +} + - (ITWindowVisibilityState)visibilityState { return _visibilityState; diff --git a/Showcase/Controller.h b/Showcase/Controller.h index dfb9836..18ea801 100755 --- a/Showcase/Controller.h +++ b/Showcase/Controller.h @@ -26,15 +26,15 @@ IBOutlet ITTextField *testTextField; // ITTransientStatusWindow Support - ITTransientStatusWindow *statusWindow; - IBOutlet NSTextView *swSampleTextView; - IBOutlet NSPopUpButton *swVanishModePopup; - IBOutlet NSPopUpButton *swBackgroundTypePopup; - IBOutlet NSPopUpButton *swDefinedPositionPopup; - IBOutlet NSTextField *swVanishDelay; - IBOutlet NSTextField *swShadowSaturation; - IBOutlet NSSlider *swEntrySpeedSlider; - IBOutlet NSSlider *swExitSpeedSlider; + ITIconAndTextStatusWindow *statusWindow; + IBOutlet NSTextView *swSampleTextView; + IBOutlet NSPopUpButton *swVanishModePopup; + IBOutlet NSPopUpButton *swBackgroundTypePopup; + IBOutlet NSPopUpButton *swDefinedPositionPopup; + IBOutlet NSTextField *swVanishDelay; + IBOutlet NSTextField *swShadowSaturation; + IBOutlet NSSlider *swEntrySpeedSlider; + IBOutlet NSSlider *swExitSpeedSlider; } // ITStatusItem Support diff --git a/Showcase/Controller.m b/Showcase/Controller.m index 8455cb2..49e9e35 100755 --- a/Showcase/Controller.m +++ b/Showcase/Controller.m @@ -1,5 +1,6 @@ #import "Controller.h" -#import "ITTransientStatusWindow.h" +//#import "ITTransientStatusWindow.h" +#import "ITIconAndTextStatusWindow.h" #import "ITTSWBackgroundView.h" #import "ITTextField.h" #import "ITBevelView.h" @@ -36,7 +37,7 @@ [testTextField setCastsShadow:YES]; [tabView setAllowsDragging:YES]; [bevelView setBevelDepth:10]; - statusWindow = [ITTransientStatusWindow sharedWindow]; + statusWindow = [ITIconAndTextStatusWindow sharedWindow]; [statusWindow setEntryEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]]; [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]]; [[statusWindow entryEffect] setEffectTime:[swEntrySpeedSlider floatValue]]; @@ -148,80 +149,10 @@ - (IBAction)buildStatusWindow:(id)sender { - NSImageView *imageView = nil; - ITTextField *textField = nil; NSImage *image = [NSImage imageNamed:SW_IMAGE]; - NSRect imageRect; - NSRect textRect; - - float imageWidth = 0.0; - float imageHeight = 0.0; - float textWidth = 0.0; - float textHeight = 0.0; - float contentHeight = 0.0; - float windowWidth = 0.0; - float windowHeight = 0.0; - - NSString *text = [swSampleTextView string]; - NSArray *lines = [text componentsSeparatedByString:@"\n"]; - id oneLine = nil; - NSEnumerator *lineEnum = [lines objectEnumerator]; - - NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18]; - NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; - - // Get image width and height. - imageWidth = [image size].width; - imageHeight = [image size].height; - - // Iterate over each line to get text width and height - while ( oneLine = [lineEnum nextObject] ) { - // Get the width of one line, adding 8.0 because Apple sucks donkey rectum. - float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 ); - // Add the height of this line to the total text height - textHeight += [oneLine sizeWithAttributes:attr].height; - // If this line wider than the last one, set it as the text width. - textWidth = ( ( textWidth > oneLineWidth ) ? textWidth : oneLineWidth ); - } - - // Add 4.0 to the final textHeight to accomodate the shadow. - textHeight += 4.0; - NSLog(@"%f", textHeight); - // Set the content height to the greater of the text and image heights. - contentHeight = ( ( imageHeight > textHeight ) ? imageHeight : textHeight ); - - // Setup the Window, and remove all its contentview's subviews. - windowWidth = ( SW_PAD + imageWidth + SW_SPACE + textWidth + SW_PAD ); - windowHeight = ( SW_PAD + contentHeight + SW_PAD ); - [statusWindow setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES animate:YES]; - [[[statusWindow contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; - - // Setup, position, fill, and add the image view to the content view. - imageRect = NSMakeRect( SW_PAD, - (SW_PAD + ((contentHeight - imageHeight) / 2)), - imageWidth, - imageHeight ); - imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease]; - [imageView setImage:image]; - [[statusWindow contentView] addSubview:imageView]; - - // Setup, position, fill, and add the text view to the content view. - textRect = NSMakeRect( (SW_PAD + imageWidth + SW_SPACE), - (SW_PAD + ((contentHeight - textHeight) / 2)), - textWidth, - textHeight); - textField = [[[ITTextField alloc] initWithFrame:textRect] autorelease]; - [textField setEditable:NO]; - [textField setSelectable:NO]; - [textField setBordered:NO]; - [textField setDrawsBackground:NO]; - [textField setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:18]]; - [textField setTextColor:[NSColor whiteColor]]; - [textField setCastsShadow:YES]; - [textField setStringValue:text]; - [[statusWindow contentView] addSubview:textField]; - - [[statusWindow contentView] setNeedsDisplay:YES]; + NSString *text = [swSampleTextView string]; + [statusWindow setImage:image]; + [statusWindow buildTextWindowWithString:text]; } - (IBAction)toggleStatusWindow:(id)sender