1// 2// PXInfoPanelController.m 3// Pixen-XCode 4// 5// Copyright (c) 2004 Open Sword Group 6 7// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 8// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, 9//copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 10// to whom the Software is furnished to do so, subject to the following conditions: 11 12// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 13 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 16// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 19// Author : Andy Matuschak 20//on Thu Jul 29 2004. 21 22 23#import "PXInfoPanelController.h" 24 25#import <Foundation/NSUserDefaults.h> 26 27#import <AppKit/NSColor.h> 28#import <AppKit/NSGraphics.h> 29#import <AppKit/NSNibLoading.h> 30#import <AppKit/NSPanel.h> 31#import <AppKit/NSTextField.h> 32 33 34static PXInfoPanelController *singleInstance = nil; 35 36@implementation PXInfoPanelController 37 38 39-(id) init 40{ 41 if ( singleInstance ) 42 { 43 [self dealloc]; 44 return singleInstance; 45 } 46 47 if ( ! (self = [super init] ) ) 48 return nil; 49 50 if ( ! [NSBundle loadNibNamed:@"PXInfoPanel" owner:self] ) 51 { 52 //NSLog(@"warm the user here !?? !!"); 53 [self dealloc]; 54 return nil; 55 } 56 57 singleInstance = self; 58 59 return singleInstance; 60} 61 62-(void) awakeFromNib 63{ 64 [panel setBecomesKeyOnlyIfNeeded: YES]; 65 [panel setFrameAutosaveName:@"PXInfoPanelFrame"]; 66} 67 68 69+(id) sharedInfoPanelController 70{ 71 if ( ! singleInstance ) 72 singleInstance = [[self alloc] init]; 73 return singleInstance; 74} 75 76- (void)setCanvasSize:(NSSize)size 77{ 78 [width setStringValue:[NSString stringWithFormat:@"%@: %d", NSLocalizedString(@"WIDTH", @"Width"), (int)(size.width)]]; 79 [height setStringValue:[NSString stringWithFormat:@"%@: %d", NSLocalizedString(@"HEIGHT", @"Height"), (int)(size.height)]]; 80} 81 82- (void)setColorInfo:(NSColor *) color 83{ 84 if ([color colorSpaceName] != NSCalibratedRGBColorSpace) 85 color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; 86 87 [teensyHexView setColor:color]; 88 89 [red setStringValue: 90 [NSString stringWithFormat:@"%@: %d", NSLocalizedString(@"RED", @"Red"), (int)([color redComponent] * 255)]]; 91 [green setStringValue: 92 [NSString stringWithFormat:@"%@: %d", NSLocalizedString(@"GREEN", @"Green"), (int)([color greenComponent] * 255)]]; 93 [blue setStringValue: 94 [NSString stringWithFormat:@"%@: %d", NSLocalizedString(@"BLUE", @"Blue"), (int)([color blueComponent] * 255)]]; 95 [alpha setStringValue: 96 [NSString stringWithFormat:@"%@: %d", NSLocalizedString(@"ALPHA", @"Alpha"), (int)([color alphaComponent] * 255)]]; 97} 98 99- (void)setDraggingOrigin:(NSPoint)point 100{ 101 draggingOrigin = point; 102} 103 104- (void)setCursorPosition:(NSPoint)point 105{ 106 NSPoint difference = point; 107 difference.x -= draggingOrigin.x; 108 difference.y -= draggingOrigin.y; 109 110 if ( ( difference.x > 0.1 ) || ( difference.x < -0.1 ) ) { 111 [cursorX setStringValue: 112 [NSString stringWithFormat:@"X: %d (%@%d)", (int)(point.x), difference.x >= 0 ? @"+" : @"", (int)(difference.x)]]; 113 } 114 else { 115 [cursorX setStringValue:[NSString stringWithFormat:@"X: %d", (int)(point.x)]]; 116 } 117 118 if (difference.y > 0.1 || difference.y < -0.1) { 119 [cursorY setStringValue: 120 [NSString stringWithFormat:@"Y: %d (%@%d)", (int)(point.y), difference.y >= 0 ? @"+" : @"", (int)(difference.y)]]; 121 } 122 else { 123 [cursorY setStringValue:[NSString stringWithFormat:@"Y: %d", (int)(point.y)]]; 124 } 125} 126 127//Accessor 128-(NSPanel *) infoPanel 129{ 130 return panel; 131} 132 133@end 134 135