Adding quick fix get-the-fuck-out-of-the-way positioning
[ITKit.git] / ITTextFieldCell.m
1 #import "ITTextFieldCell.h"
2 #import <CoreGraphics/CoreGraphics.h>
3 #import "ITCoreGraphicsHacks.h"
4
5
6 /*************************************************************************/
7 #pragma mark -
8 #pragma mark IMPLEMENTATION
9 /*************************************************************************/
10
11 @implementation ITTextFieldCell
12
13 /*************************************************************************/
14 #pragma mark -
15 #pragma mark INITIALIZATION METHODS
16 /*************************************************************************/
17
18 - (id)initTextCell:(NSString *)string;
19 {
20     if ( ( self = [super initTextCell:string] ) ) {
21         castsShadow      = NO;
22         shadowElevation  = 45.0;
23         shadowAzimuth    = 90.0;
24         shadowAmbient    = 0.15;
25         shadowHeight     = 1.00;
26         shadowRadius     = 4.00;
27         shadowSaturation = 1.2;
28     }
29
30     return self;
31 }
32
33 - (id)initWithCoder:(NSCoder *)coder
34 {
35     if ( ( self = [super initWithCoder:coder] ) ) {        
36         castsShadow      = NO;
37         shadowElevation  = 45.0;
38         shadowAzimuth    = 90.0;
39         shadowAmbient    = 0.15;
40         shadowHeight     = 1.00;
41         shadowRadius     = 4.00;
42         shadowSaturation = 1.0;
43     }
44     
45     return self;
46 }
47
48
49 /*************************************************************************/
50 #pragma mark -
51 #pragma mark DRAWING METHODS
52 /*************************************************************************/
53
54 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView
55 {
56     CGSGenericObj        style = nil;
57     CGShadowStyle        shadow;
58
59     if ( castsShadow ) { 
60 //      Create the shadow style to use for drawing the string
61         shadow.version    = 0;
62         shadow.elevation  = shadowElevation;
63         shadow.azimuth    = shadowAzimuth;
64         shadow.ambient    = shadowAmbient;
65         shadow.height     = shadowHeight;
66         shadow.radius     = shadowRadius;
67         shadow.saturation = shadowSaturation;
68         style = CGStyleCreateShadow(&shadow);
69         
70         // Set the context for drawing the string
71         [NSGraphicsContext saveGraphicsState];
72         CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style);
73     }
74     
75     // Draw the string
76     [super drawWithFrame:rect inView:controlView];
77     
78
79     if ( castsShadow ) { 
80         // Restore the old context
81         [NSGraphicsContext restoreGraphicsState];
82         CGStyleRelease(style);
83     }
84 }
85
86
87
88 /*************************************************************************/
89 #pragma mark -
90 #pragma mark ACCESSOR METHODS
91 /*************************************************************************/
92
93 - (BOOL)castsShadow;
94 {
95     return castsShadow;
96 }
97
98 - (void)setCastsShadow:(BOOL)newSetting;
99 {
100     castsShadow = newSetting;
101     [[self controlView] setNeedsDisplay:YES];
102 }
103
104 - (float)shadowElevation;
105 {
106     return shadowElevation;
107 }
108
109 - (void)setShadowElevation:(float)newElevation;
110 {
111     shadowElevation = newElevation;
112     [[self controlView] setNeedsDisplay:YES];
113 }
114
115 - (float)shadowAzimuth;
116 {
117     return shadowAzimuth;
118 }
119
120 - (void)setShadowAzimuth:(float)newAzimuth;
121 {
122     shadowAzimuth = newAzimuth;
123     [[self controlView] setNeedsDisplay:YES];
124 }
125
126 - (float)shadowAmbient;
127 {
128     return shadowAmbient;
129 }
130
131 - (void)setShadowAmbient:(float)newAmbient;
132 {
133     shadowAmbient = newAmbient;
134     [[self controlView] setNeedsDisplay:YES];
135 }
136
137 - (float)shadowHeight;
138 {
139     return shadowHeight;
140 }
141
142 - (void)setShadowHeight:(float)newHeight;
143 {
144     shadowHeight = newHeight;
145     [[self controlView] setNeedsDisplay:YES];
146 }
147
148 - (float)shadowRadius;
149 {
150     return shadowRadius;
151 }
152
153 - (void)setShadowRadius:(float)newRadius;
154 {
155     shadowRadius = newRadius;
156     [[self controlView] setNeedsDisplay:YES];
157 }
158
159 - (float)shadowSaturation;
160 {
161     return shadowSaturation;
162 }
163
164 - (void)setShadowSaturation:(float)newSaturation;
165 {
166     shadowSaturation = newSaturation;
167     [[self controlView] setNeedsDisplay:YES];
168 }
169
170
171 @end