1/*
2   NSShadow.m
3
4   GUI implementation of a shadow effect.
5
6   Copyright (C) 2009 Free Software Foundation, Inc.
7
8   Author: Eric Wasylishen <ewasylishen@gmail.com>
9   Date: Dec 2009
10
11   This file is part of the GNUstep GUI Library.
12
13   This library is free software; you can redistribute it and/or
14   modify it under the terms of the GNU Lesser General Public
15   License as published by the Free Software Foundation; either
16   version 2 of the License, or (at your option) any later version.
17
18   This library is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21   Lesser General Public License for more details.
22
23   You should have received a copy of the GNU Lesser General Public
24   License along with this library; see the file COPYING.LIB.
25   If not, see <http://www.gnu.org/licenses/> or write to the
26   Free Software Foundation, 51 Franklin Street, Fifth Floor,
27   Boston, MA 02110-1301, USA.
28*/
29
30#import <Foundation/NSString.h>
31#import "AppKit/NSShadow.h"
32#import "AppKit/NSColor.h"
33
34@implementation NSShadow
35
36- (id) init
37{
38  if ((self = [super init]))
39    {
40      _offset = NSMakeSize(0,0);
41      _radius = 0;
42       ASSIGN(_color, [[NSColor blackColor] colorWithAlphaComponent: 0.333]);
43    }
44  return self;
45}
46
47- (id) copyWithZone: (NSZone*)zone
48{
49  NSShadow *s = (NSShadow*)NSCopyObject(self, 0, zone);
50  RETAIN(s->_color);
51  return s;
52}
53
54- (void) dealloc
55{
56  DESTROY(_color);
57  [super dealloc];
58}
59
60- (NSString *) description
61{
62  return [NSString stringWithFormat: @"NSShadow {%f, %f} blur = %f color = %@",
63	(float)_offset.width, (float)_offset.height, (float)_radius,
64	[_color description]];
65}
66
67- (NSSize) shadowOffset
68{
69  return _offset;
70}
71
72- (void) setShadowOffset: (NSSize)offset
73{
74  _offset = offset;
75}
76
77- (CGFloat) shadowBlurRadius
78{
79  return _radius;
80}
81
82- (void) setShadowBlurRadius: (CGFloat)radius
83{
84  _radius = radius;
85}
86
87- (NSColor *) shadowColor
88{
89  return _color;
90}
91
92- (void) setShadowColor: (NSColor *)color
93{
94  ASSIGN(_color, color);
95}
96
97- (void) set
98{
99  // FIXME: Implement
100}
101
102- (void) encodeWithCoder: (NSCoder*)aCoder
103{
104  if ([aCoder allowsKeyedCoding])
105    {
106      [aCoder encodeFloat: _radius forKey: @"NSShadowBlurRadius"];
107      [aCoder encodeFloat: _offset.width forKey: @"NSShadowHoriz"];
108      [aCoder encodeFloat: _offset.height forKey: @"NSShadowVert"];
109      [aCoder encodeObject: _color forKey: @"NSShadowColor"];
110    }
111  else
112    {
113      float radius = _radius;
114      [aCoder encodeValueOfObjCType: @encode(float) at: &radius];
115      [aCoder encodeSize: _offset];
116      [aCoder encodeObject: _color];
117    }
118}
119
120- (id) initWithCoder: (NSCoder*)aDecoder
121{
122  self = [super init];
123  if (self == nil)
124    return nil;
125
126  if ([aDecoder allowsKeyedCoding])
127    {
128      _radius = [aDecoder decodeFloatForKey: @"NSShadowBlurRadius"];
129      _offset = NSMakeSize([aDecoder decodeFloatForKey:  @"NSShadowHoriz"],
130                           [aDecoder decodeFloatForKey:  @"NSShadowVert"]);
131      _color = [[aDecoder decodeObjectForKey: @"NSShadowColor"] retain];
132    }
133  else
134    {
135      float radius;
136      [aDecoder decodeValueOfObjCType: @encode(float) at: &radius];
137      _radius = radius;
138      _offset = [aDecoder decodeSize];
139      _color = [[aDecoder decodeObject] retain];
140    }
141  return self;
142}
143
144@end
145