RSS

(root)/iphone/common : 27 : Jigs/source/ImageWell.m

To get this branch, use:
bzr branch /browse/iphone/common

« back to all changes in this revision

Viewing changes to Jigs/source/ImageWell.m

Dömötör Gulyás
2009-08-13 12:31:20
Revision ID: dognotdog@gmail.com-20090813103120-y0yoc55s14agedur
improvements in Jigs GUI

Show diffs side-by-side

added added

removed removed

28
28
 
29
29
}
30
30
 
31
 
@implementation ImageWell
32
 
 
33
 
 
34
 
- (id) initWithFrame: (CGRect) frame
35
 
{
36
 
    if (!(self = [super initWithFrame: frame]))
37
 
                return nil;
38
 
 
39
 
        return self;
40
 
}
 
31
 
 
32
 
 
33
@implementation ElImageView
41
34
 
42
35
- (id) initWithCoder: (NSCoder*) coder
43
36
{
44
37
    if (!(self = [super initWithCoder: coder]))
45
38
                return nil;
46
39
        
47
 
        instructionsView = [[UITextView alloc] initWithFrame: CGRectInset([self bounds], 0.0f, 0.0f)];
48
 
        [instructionsView setText: @"Tap and hold to paste image, double-tap to select image from gallery."];
49
 
        //[instructionsView setBackgroundColor: [UIColor yellowColor]];
50
 
        [instructionsView setTextColor: [UIColor blackColor]];
51
 
        [instructionsView setBackgroundColor: [UIColor colorWithWhite: 1.0f alpha: 1.0f]];
52
 
        [instructionsView setFont: [UIFont systemFontOfSize: 17.0f]];
53
 
        [instructionsView setEditable: NO];
54
 
        [instructionsView setUserInteractionEnabled: NO];
55
 
        [instructionsView setTextAlignment: UITextAlignmentCenter];
56
 
        [self addSubview: instructionsView];
57
 
 
58
 
        [instructionsView layer].opacity = 0.0f;
59
 
 
 
40
        borderColor = [[UIColor grayColor] retain];
 
41
        cornerRadius = 5.0f;
 
42
        borderWidth = 1.0f;
 
43
        imageAlpha = 1.0f;
 
44
        
 
45
        fillView = NO;
 
46
        
 
47
        [self setBackgroundColor: [UIColor clearColor]];
60
48
 
61
49
        return self;
62
50
}
63
51
 
64
 
- (void) setFrame: (CGRect) frame
 
52
- (void) dealloc
65
53
{
66
 
        [super setFrame: frame];
67
 
        [instructionsView setFrame: CGRectInset([self bounds], 0.0f, 0.0f)];
 
54
        [image release];
 
55
        [borderColor release];
 
56
    [super dealloc];
68
57
}
69
58
 
 
59
 
70
60
- (void) drawRect: (CGRect) rect
71
61
{
72
62
        CGContextRef c = UIGraphicsGetCurrentContext();
76
66
        CGContextSaveGState(c);
77
67
        
78
68
        
79
 
        CGRect bounds = CGRectInset([self bounds], 1.0,1.0);
 
69
        CGRect bounds = CGRectInset([self bounds], 0.5*borderWidth,0.5*borderWidth);
80
70
        CGSize imgSize = [image size];
81
71
        
82
72
        
101
91
        
102
92
        CGRect drawRect = CGRectMake(bounds.origin.x + 0.5f*(bounds.size.width - drawWidth), bounds.origin.y + 0.5f*(bounds.size.height - drawHeight), drawWidth, drawHeight);
103
93
 
 
94
        if (fillView)
 
95
                drawRect = bounds;
104
96
        
105
 
        createPathInRoundedRect(c, drawRect, 5.0f);
 
97
        createPathInRoundedRect(c, drawRect, cornerRadius);
106
98
 
107
99
        CGContextClip(c);
108
100
 
109
 
        [image drawInRect: drawRect];
 
101
        [image drawInRect: drawRect blendMode: kCGBlendModeNormal alpha: imageAlpha];
110
102
 
111
103
        CGContextRestoreGState(c);
112
 
 
113
 
        [[UIColor blackColor] set];
114
 
        createPathInRoundedRect(c, drawRect, 5.0f);     
115
 
        CGContextStrokePath(c);
 
104
        if (borderWidth)
 
105
        {
 
106
                [[borderColor colorWithAlphaComponent: imageAlpha] set];
 
107
                createPathInRoundedRect(c, drawRect, cornerRadius);
 
108
                CGContextSetLineWidth(c, borderWidth);
 
109
                CGContextStrokePath(c);
 
110
        }
 
111
}
 
112
 
 
113
- (void) setImageAlpha: (float) a
 
114
{
 
115
        imageAlpha = a;
 
116
        [self setNeedsDisplay];
 
117
}
 
118
 
 
119
@synthesize image, cornerRadius, borderColor, borderWidth, fillView, imageAlpha;
 
120
 
 
121
@end
 
122
 
 
123
 
 
124
 
 
125
@implementation ImageWell
 
126
 
 
127
 
 
128
- (id) initWithFrame: (CGRect) frame
 
129
{
 
130
    if (!(self = [super initWithFrame: frame]))
 
131
                return nil;
 
132
 
 
133
        return self;
 
134
}
 
135
 
 
136
- (id) initWithCoder: (NSCoder*) coder
 
137
{
 
138
    if (!(self = [super initWithCoder: coder]))
 
139
                return nil;
116
140
        
117
 
}
 
141
        instructionsView = [[UITextView alloc] initWithFrame: CGRectInset([self bounds], 0.0f, 0.0f)];
 
142
        [instructionsView setText: @"Tap and hold to paste image,\nOR\nDouble-tap to select image from gallery."];
 
143
        //[instructionsView setBackgroundColor: [UIColor yellowColor]];
 
144
        [instructionsView setTextColor: [UIColor whiteColor]];
 
145
        [instructionsView setBackgroundColor: [UIColor clearColor]];
 
146
        [instructionsView setFont: [UIFont systemFontOfSize: 24.0f]];
 
147
        [instructionsView setEditable: NO];
 
148
        [instructionsView setUserInteractionEnabled: NO];
 
149
        [instructionsView setTextAlignment: UITextAlignmentCenter];
 
150
        [self addSubview: instructionsView];
 
151
 
 
152
        [instructionsView layer].opacity = 0.0f;
 
153
 
 
154
 
 
155
        return self;
 
156
}
 
157
 
 
158
- (void) setFrame: (CGRect) frame
 
159
{
 
160
        [super setFrame: frame];
 
161
        [instructionsView setFrame: CGRectInset([self bounds], 0.0f, 0.0f)];
 
162
}
 
163
 
118
164
 
119
165
 
120
166
- (void) dealloc
121
167
{
122
 
        [image release];
123
168
    [super dealloc];
124
169
}
125
170
 
136
181
        pasteTimer = nil;
137
182
}
138
183
 
139
 
- (void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
140
 
{
141
 
//      [instructionsView layer].opacity = [[[instructionsView layer] presentationLayer] opacity];
142
 
}
143
184
 
144
185
- (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
145
186
{
147
188
        
148
189
        if ([touch tapCount] == 1)
149
190
        {
150
 
                ElFloatAnimation* anim = [[[ElFloatAnimation alloc] init] autorelease];
 
191
                ElFloatAnimation* anim = nil;
 
192
 
 
193
                anim = [[[ElFloatAnimation alloc] init] autorelease];
151
194
                
152
195
                [anim setStartValue: [[instructionsView layer] opacity]];
153
 
                [anim setEndValue: 0.5f];
 
196
                [anim setEndValue: 0.667f];
154
197
                [anim setDuration: 0.5f];
155
 
                [anim setStartTime: [ElAnimation now]];
156
198
                [anim setTarget: [instructionsView layer]];
157
199
                [anim setProperty: @"opacity"];
158
 
                [anim queueWithKey: nil];
159
 
                
160
 
                anim = [[[ElFloatAnimation alloc] init] autorelease];
161
 
                
162
 
                [anim setStartValue: 0.5f];
 
200
                [anim queueForKey: @"text-opacity" atBeginning: YES cancelPending: YES];
 
201
                
 
202
                
 
203
                anim = [[[ElFloatAnimation alloc] init] autorelease];
 
204
                
 
205
                [anim setStartValue: imageAlpha];
 
206
                [anim setEndValue: 0.333f];
 
207
                [anim setDuration: 0.5f];
 
208
                [anim setTarget: self];
 
209
                [anim setProperty: @"imageAlpha"];
 
210
                [anim queueForKey: @"image-opacity" atBeginning: YES cancelPending: YES];
 
211
                
 
212
                [[ElAnimation delayedAnimationWithDelay: 2.5f] queueForKey: @"text-opacity" atBeginning: NO cancelPending: NO];
 
213
                [[ElAnimation delayedAnimationWithDelay: 2.5f] queueForKey: @"image-opacity" atBeginning: NO cancelPending: NO];
 
214
 
 
215
                anim = [[[ElFloatAnimation alloc] init] autorelease];
 
216
                
 
217
                [anim setStartValue: 0.667f];
163
218
                [anim setEndValue: 0.0f];
164
219
                [anim setDuration: 0.5f];
165
 
                [anim setStartTime: [ElAnimation now] + 3.0f];
166
220
                [anim setTarget: [instructionsView layer]];
167
221
                [anim setProperty: @"opacity"];
168
 
                [anim queueWithKey: nil];
 
222
                [anim queueForKey: @"text-opacity" atBeginning: NO cancelPending: NO];
 
223
 
 
224
 
 
225
                anim = [[[ElFloatAnimation alloc] init] autorelease];
 
226
                
 
227
                [anim setStartValue: 0.333f];
 
228
                [anim setEndValue: 1.0f];
 
229
                [anim setDuration: 0.5f];
 
230
                [anim setTarget: self];
 
231
                [anim setProperty: @"imageAlpha"];
 
232
                [anim queueForKey: @"image-opacity" atBeginning: NO cancelPending: NO];
 
233
 
169
234
        }
170
235
 
171
236
        
229
294
}
230
295
 
231
296
 
232
 
@synthesize image, delegate;
 
297
@synthesize delegate;
233
298
 
234
299
@end

Loggerhead 1.17 is a web-based interface for Bazaar branches