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
00053 @implementation CPShadowView : CPView
00054 {
00055 CPShadowWeight _weight;
00056 }
00057
00058 + (void)initialize
00059 {
00060 if (self != [CPShadowView class])
00061 return;
00062
00063 var bundle = [CPBundle bundleForClass:[self class]];
00064
00065 CPShadowViewLightBackgroundColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
00066 [
00067 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightTopLeft.png"] size:CGSizeMake(9.0, 9.0)],
00068 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightTop.png"] size:CGSizeMake(1.0, 9.0)],
00069 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightTopRight.png"] size:CGSizeMake(9.0, 9.0)],
00070
00071 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightLeft.png"] size:CGSizeMake(9.0, 1.0)],
00072 nil,
00073 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightRight.png"] size:CGSizeMake(9.0, 1.0)],
00074
00075 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightBottomLeft.png"] size:CGSizeMake(9.0, 9.0)],
00076 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightBottom.png"] size:CGSizeMake(1.0, 9.0)],
00077 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewLightBottomRight.png"] size:CGSizeMake(9.0, 9.0)]
00078 ]]];
00079
00080 CPShadowViewHeavyBackgroundColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
00081 [
00082 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyTopLeft.png"] size:CGSizeMake(17.0, 17.0)],
00083 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyTop.png"] size:CGSizeMake(1.0, 17.0)],
00084 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyTopRight.png"] size:CGSizeMake(17.0, 17.0)],
00085
00086 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyLeft.png"] size:CGSizeMake(17.0, 1.0)],
00087 nil,
00088 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyRight.png"] size:CGSizeMake(17.0, 1.0)],
00089
00090 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyBottomLeft.png"] size:CGSizeMake(17.0, 17.0)],
00091 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyBottom.png"] size:CGSizeMake(1.0, 17.0)],
00092 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPShadowView/CPShadowViewHeavyBottomRight.png"] size:CGSizeMake(17.0, 17.0)]
00093 ]]];
00094 }
00095
00096 - (id)initWithFrame:(CGRect)aFrame
00097 {
00098 self = [super initWithFrame:aFrame];
00099
00100 if (self)
00101 {
00102 _weight = CPLightShadow;
00103
00104 [self setBackgroundColor:CPShadowViewLightBackgroundColor];
00105
00106 [self setHitTests:NO];
00107 }
00108
00109 return self;
00110 }
00111
00112 - (void)setWeight:(CPShadowWeight)aWeight
00113 {
00114 if (_weight == aWeight)
00115 return;
00116
00117 _weight = aWeight;
00118
00119 if (_weight == CPLightShadow)
00120 [self setBackgroundColor:CPShadowViewLightBackgroundColor];
00121
00122 else
00123 [self setBackgroundColor:CPShadowViewHeavyBackgroundColor];
00124 }
00125
00126 - (float)leftInset
00127 {
00128 return _weight == CPLightShadow ? LIGHT_LEFT_INSET : HEAVY_LEFT_INSET;
00129 }
00130
00131 - (float)rightInset
00132 {
00133 return _weight == CPLightShadow ? LIGHT_RIGHT_INSET : HEAVY_RIGHT_INSET;
00134 }
00135
00136 - (float)topInset
00137 {
00138 return _weight == CPLightShadow ? LIGHT_TOP_INSET : HEAVY_TOP_INSET;
00139 }
00140
00141 - (float)bottomInset
00142 {
00143 return _weight == CPLightShadow ? LIGHT_BOTTOM_INSET : HEAVY_BOTTOM_INSET;
00144 }
00145
00146 - (float)horizontalInset
00147 {
00148 if (_weight == CPLightShadow)
00149 return LIGHT_LEFT_INSET + LIGHT_RIGHT_INSET;
00150
00151 return HEAVY_LEFT_INSET + HEAVY_RIGHT_INSET;
00152 }
00153
00154 - (float)verticalInset
00155 {
00156 if (_weight == CPLightShadow)
00157 return LIGHT_TOP_INSET + LIGHT_BOTTOM_INSET;
00158
00159 return HEAVY_TOP_INSET + HEAVY_BOTTOM_INSET;
00160 }
00161
00162 + (CGRect)frameForContentFrame:(CGRect)aFrame withWeight:(CPShadowWeight)aWeight
00163 {
00164 if (aWeight == CPLightShadow)
00165 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);
00166 else
00167 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);
00168 }
00169
00170 - (CGRect)frameForContentFrame:(CGRect)aFrame
00171 {
00172 return [[self class] frameForContentFrame:aFrame withWeight:_weight];
00173 }
00174
00175 - (void)setFrameForContentFrame:(CGRect)aFrame
00176 {
00177 [self setFrame:[self frameForContentFrame:aFrame]];
00178 }
00179
00180 @end