Extendend color test

Some experiments on the segmented toolbar button
Updated keepasskit submodule
This commit is contained in:
michael starke
2013-08-13 02:52:16 +02:00
parent b6d6485c60
commit 5254ce0fe4
4 changed files with 38 additions and 23 deletions

View File

@@ -11,5 +11,4 @@
@interface MPContextToolbarButton : NSSegmentedControl @interface MPContextToolbarButton : NSSegmentedControl
- (void)setImage:(NSImage *)image; - (void)setImage:(NSImage *)image;
@end @end

View File

@@ -14,19 +14,11 @@
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
[self setFocusRingType:NSFocusRingTypeNone]; [self setFocusRingType:NSFocusRingTypeNone];
[self setSegmentCount:1]; [self setSegmentCount:2];
[[self cell] setTrackingMode:NSSegmentSwitchTrackingMomentary]; [[self cell] setTrackingMode:NSSegmentSwitchTrackingMomentary];
[self setSegmentStyle:NSSegmentStyleTexturedSquare]; [self setSegmentStyle:NSSegmentStyleTexturedSquare];
[[self cell] setWidth:32 forSegment:0];
// NSMutableData *data = [[NSMutableData alloc] init]; [[self cell] setWidth:20 forSegment:1];
// NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
// [[self cell] encodeWithCoder:archiver];
// [archiver finishEncoding];
//
// NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// HNHContextButtonSegmentedCell *cell = [[HNHContextButtonSegmentedCell alloc] initWithCoder:unarchiver];
// [unarchiver finishDecoding];
// [self setCell:cell];
} }
return self; return self;
} }
@@ -41,7 +33,7 @@
} }
- (void)setSegmentCount:(NSInteger)count { - (void)setSegmentCount:(NSInteger)count {
if(count == 1) { if(count == 2) {
[super setSegmentCount:count]; [super setSegmentCount:count];
} }
} }
@@ -50,4 +42,20 @@
[self setImage:image forSegment:0]; [self setImage:image forSegment:0];
} }
- (SEL)action {
NSLog(@"actionSegment:%ld", [[self cell] selectedSegment]);
if([self selectedSegment] == 1) {
return @selector(showContextMenu:);
}
return [super action];
}
- (id)target {
NSLog(@"targetSegment:%ld", [[self cell] selectedSegment]);
if([self selectedSegment] == 1) {
return self;
}
return [super target];
}
@end @end

View File

@@ -13,25 +13,25 @@
@implementation KPKTestHexColor @implementation KPKTestHexColor
- (void)testHexToColor { - (void)testHexToColor {
NSString *redHex = @"00ff0000"; NSString *redHex = @"FF000000";
NSString *blueHex = @"000000ff"; NSString *greeHex = @"00FF0000";
NSString *greeHex = @"0000ff00"; NSString *blueHex = @"0000FF00";
NSColor *red = [NSColor colorWithHexString:redHex]; NSColor *red = [NSColor colorWithHexString:redHex];
NSColor *blue = [NSColor colorWithHexString:blueHex];
NSColor *green = [NSColor colorWithHexString:greeHex]; NSColor *green = [NSColor colorWithHexString:greeHex];
NSColor *blue = [NSColor colorWithHexString:blueHex];
STAssertEquals([red redComponent], 1.0, @"Red color should have 100% red"); STAssertEquals([red redComponent], 1.0, @"Red color should have 100% red");
STAssertEquals([red blueComponent], 0.0, @"Red color should have 0% blue"); STAssertEquals([red blueComponent], 0.0, @"Red color should have 0% blue");
STAssertEquals([red greenComponent], 0.0, @"Red color should have 0% green"); STAssertEquals([red greenComponent], 0.0, @"Red color should have 0% green");
STAssertEquals([blue redComponent], 0.0, @"Blue color should have 0% red");
STAssertEquals([blue blueComponent], 1.0, @"Blue color should have 100% blue");
STAssertEquals([blue greenComponent], 0.0, @"Blue color should have 0% green");
STAssertEquals([green redComponent], 0.0, @"Green color should have 0% red"); STAssertEquals([green redComponent], 0.0, @"Green color should have 0% red");
STAssertEquals([green blueComponent], 0.0, @"Green color should have 0% blue");
STAssertEquals([green greenComponent], 1.0, @"Green color should have 100% green"); STAssertEquals([green greenComponent], 1.0, @"Green color should have 100% green");
STAssertEquals([green blueComponent], 0.0, @"Green color should have 0% blue");
STAssertEquals([blue redComponent], 0.0, @"Blue color should have 0% red");
STAssertEquals([blue greenComponent], 0.0, @"Blue color should have 0% green");
STAssertEquals([blue blueComponent], 1.0, @"Blue color should have 100% blue");
} }
- (void)testColorRefReading { - (void)testColorRefReading {
@@ -43,4 +43,12 @@
STAssertEquals([color blueComponent], 0.0, @"Blue 100%"); STAssertEquals([color blueComponent], 0.0, @"Blue 100%");
} }
- (void)testColorRefWriting {
uint32_t colorBytes = 0x000000FF;
NSData *colorData = [NSData dataWithBytesNoCopy:&colorBytes length:4 freeWhenDone:NO];
NSColor *color = [NSColor colorWithData:colorData];
NSData *newData = [color colorData];
STAssertEqualObjects(colorData, newData, @"Convertion should result in same data");
}
@end @end