Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OODebugUtilities.m
Go to the documentation of this file.
1/*
2
3OODebugUtilities.m
4
5
6Oolite Debug Bundle
7
8Copyright (C) 2007 Jens Ayton
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
30#import "OODebugUtilities.h"
31
32
33@implementation OOColor (NSColorConversion)
34
35- (NSColor *)asNSColor
36{
37 float r, g, b, a;
38 [self getRed:&r green:&g blue:&b alpha:&a];
39 return [NSColor colorWithDeviceRed:r green:g blue:b alpha:a];
40}
41
42@end
43
44@implementation NSColor (OOColorConversion)
45
46+ (NSColor *)colorWithOOColorDescription:(id)description
47{
48 return [[OOColor colorWithDescription:description] asNSColor];
49}
50
51
52- (OOColor *)asOOColor
53{
54 CGFloat r, g, b, a;
55 [[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
56 return [OOColor colorWithRed:r green:g blue:b alpha:a];
57}
58
59@end
60
61
62@implementation NSAttributedString (OODebugExtensions)
63
64+ (id)stringWithString:(NSString *)string
65{
66 return [[[self alloc] initWithString:string] autorelease];
67}
68
69
70+ (id)stringWithString:(NSString *)string font:(NSFont *)font
71{
72 if (string == nil) return nil;
73 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
74 return [[[self alloc] initWithString:string attributes:attr] autorelease];
75}
76
77@end
78
79@implementation NSMutableAttributedString (OODebugExtensions)
80
81- (void)setString:(NSString *)string
82{
83 [self setAttributedString:[string asAttributedString]];
84}
85
86@end
87
88@implementation NSString (OODebugExtensions)
89
90- (NSAttributedString *)asAttributedString
91{
92 return [NSAttributedString stringWithString:self];
93}
94
95
96- (NSAttributedString *)asAttributedStringWithFont:(NSFont *)font
97{
98 return [NSAttributedString stringWithString:self font:font];
99}
100
101@end
return nil
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
Definition OOColor.m:95
OOColor * colorWithDescription:(id description)
Definition OOColor.m:127
NSColor * asNSColor()