00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import <Foundation/CPBundle.j>
00024
00025 @import "CGGeometry.j"
00026 @import "CPImage.j"
00027 @import "CPImageView.j"
00028 @import "CPView.j"
00029
00030
00031 #include "CoreGraphics/CGGeometry.h"
00032
00033 CPLightShadow = 0;
00034 CPHeavyShadow = 1;
00035
00036 var CPShadowViewLightBackgroundColor = nil,
00037 CPShadowViewHeavyBackgroundColor = nil;
00038
00039 var LIGHT_LEFT_INSET = 3.0,
00040 LIGHT_RIGHT_INSET = 3.0,
00041 LIGHT_TOP_INSET = 3.0,
00042 LIGHT_BOTTOM_INSET = 5.0,
00043
00044 HEAVY_LEFT_INSET = 7.0,
00045 HEAVY_RIGHT_INSET = 7.0,
00046 HEAVY_TOP_INSET = 5.0,
00047 HEAVY_BOTTOM_INSET = 5.0;
00048
00049 @implementation CPShadowView : CPView
00050 {
00051 CPShadowWeight _weight;
00052 }
00053
00054 + (void)initialize
00055 {
00056 if (self != [CPShadowView class])
00057 return;
00058
00059 var bundle = [CPBundle bundleForClass:[self class]];
00060
00061 CPShadowViewLightBackgroundColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
00062 [
00063 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightTopLeft.png"] size:CGSizeMake(9.0, 9.0)],
00064 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightTop.png"] size:CGSizeMake(1.0, 9.0)],
00065 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightTopRight.png"] size:CGSizeMake(9.0, 9.0)],
00066
00067 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightLeft.png"] size:CGSizeMake(9.0, 1.0)],
00068 nil,
00069 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightRight.png"] size:CGSizeMake(9.0, 1.0)],
00070
00071 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightBottomLeft.png"] size:CGSizeMake(9.0, 9.0)],
00072 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightBottom.png"] size:CGSizeMake(1.0, 9.0)],
00073 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightBottomRight.png"] size:CGSizeMake(9.0, 9.0)]
00074 ]]];
00075
00076 CPShadowViewHeavyBackgroundColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
00077 [
00078 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyTopLeft.png"] size:CGSizeMake(17.0, 17.0)],
00079 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyTop.png"] size:CGSizeMake(1.0, 17.0)],
00080 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyTopRight.png"] size:CGSizeMake(17.0, 17.0)],
00081
00082 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyLeft.png"] size:CGSizeMake(17.0, 1.0)],
00083 nil,
00084 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyRight.png"] size:CGSizeMake(17.0, 1.0)],
00085
00086 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyBottomLeft.png"] size:CGSizeMake(17.0, 17.0)],
00087 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyBottom.png"] size:CGSizeMake(1.0, 17.0)],
00088 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyBottomRight.png"] size:CGSizeMake(17.0, 17.0)]
00089 ]]];
00090 }
00091
00092 - (id)initWithFrame:(CGRect)aFrame
00093 {
00094 self = [super initWithFrame:aFrame];
00095
00096 if (self)
00097 {
00098 _weight = CPLightShadow;
00099
00100 [self setBackgroundColor:CPShadowViewLightBackgroundColor];
00101
00102 [self setHitTests:NO];
00103 }
00104
00105 return self;
00106 }
00107
00108 - (void)setWeight:(CPShadowWeight)aWeight
00109 {
00110 if (_weight == aWeight)
00111 return;
00112
00113 _weight = aWeight;
00114
00115 if (_weight == CPLightShadow)
00116 [self setBackgroundColor:CPShadowViewLightBackgroundColor];
00117
00118 else
00119 [self setBackgroundColor:CPShadowViewHeavyBackgroundColor];
00120 }
00121
00122 - (float)leftInset
00123 {
00124 return _weight == CPLightShadow ? LIGHT_LEFT_INSET : HEAVY_LEFT_INSET;
00125 }
00126
00127 - (float)rightInset
00128 {
00129 return _weight == CPLightShadow ? LIGHT_RIGHT_INSET : HEAVY_RIGHT_INSET;
00130 }
00131
00132 - (float)topInset
00133 {
00134 return _weight == CPLightShadow ? LIGHT_TOP_INSET : HEAVY_TOP_INSET;
00135 }
00136
00137 - (float)bottomInset
00138 {
00139 return _weight == CPLightShadow ? LIGHT_BOTTOM_INSET : HEAVY_BOTTOM_INSET;
00140 }
00141
00142 - (float)horizontalInset
00143 {
00144 if (_weight == CPLightShadow)
00145 return LIGHT_LEFT_INSET + LIGHT_RIGHT_INSET;
00146
00147 return HEAVY_LEFT_INSET + HEAVY_RIGHT_INSET;
00148 }
00149
00150 - (float)verticalInset
00151 {
00152 if (_weight == CPLightShadow)
00153 return LIGHT_TOP_INSET + LIGHT_BOTTOM_INSET;
00154
00155 return HEAVY_TOP_INSET + HEAVY_BOTTOM_INSET;
00156 }
00157
00158 + (CGRect)frameForContentFrame:(CGRect)aFrame withWeight:(CPShadowWeight)aWeight
00159 {
00160 if (aWeight == CPLightShadow)
00161 return CGRectMake(_CGRectGetMinX(aFrame) - LIGHT_LEFT_INSET, _CGRectGetMinY(aFrame) - LIGHT_TOP_INSET, _CGRectGetWidth(aFrame) + LIGHT_LEFT_INSET + LIGHT_RIGHT_INSET, _CGRectGetHeight(aFrame) + LIGHT_TOP_INSET + LIGHT_BOTTOM_INSET);
00162 else
00163 return CGRectMake(_CGRectGetMinX(aFrame) - HEAVY_LEFT_INSET, _CGRectGetMinY(aFrame) - HEAVY_TOP_INSET, _CGRectGetWidth(aFrame) + HEAVY_LEFT_INSET + HEAVY_RIGHT_INSET, _CGRectGetHeight(aFrame) + HEAVY_TOP_INSET + HEAVY_BOTTOM_INSET);
00164 }
00165
00166 - (CGRect)frameForContentFrame:(CGRect)aFrame
00167 {
00168 return [[self class] frameForContentFrame:aFrame withWeight:_weight];
00169 }
00170
00171 - (void)setFrameForContentFrame:(CGRect)aFrame
00172 {
00173 [self setFrame:[self frameForContentFrame:aFrame]];
00174 }
00175
00176 @end