OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ios/chrome/browser/ui/background_generator.h" | |
6 | |
7 #import <QuartzCore/QuartzCore.h> | |
8 | |
9 #include "base/mac/bundle_locations.h" | |
10 #include "base/mac/foundation_util.h" | |
11 #include "base/mac/scoped_cftyperef.h" | |
12 #import "base/mac/scoped_nsobject.h" | |
13 #import "ios/chrome/browser/ui/ui_util.h" | |
14 | |
15 namespace background_generator { | |
16 | |
17 // This is a utility function that may be used as a standalone helper function | |
18 // to generate a radial gradient UIImage. | |
19 // TODO(blundell): This probably belongs somewhere else now. | |
sdefresne
2015/04/02 17:20:28
nit: I'd prefer if we could resolve or remove this
| |
20 UIImage* GetRadialGradient(CGRect backgroundRect, | |
21 CGPoint centerPoint, | |
22 CGFloat radius, | |
23 CGFloat centerColor, | |
24 CGFloat outsideColor, | |
25 UIImage* tileImage, | |
26 UIImage* logoImage) { | |
27 UIGraphicsBeginImageContextWithOptions(backgroundRect.size, YES, 0); | |
28 CGContextRef context = UIGraphicsGetCurrentContext(); | |
29 const size_t kColorCount = 2; | |
30 CGFloat gradient_colors[kColorCount * sizeof(CGFloat)] = { | |
sdefresne
2015/04/02 17:20:28
This does not make any sense. This is initializing
| |
31 centerColor, 1.0, outsideColor, 1.0}; | |
32 base::ScopedCFTypeRef<CGColorSpaceRef> grey_space( | |
33 CGColorSpaceCreateDeviceGray()); | |
34 base::ScopedCFTypeRef<CGGradientRef> gradient( | |
35 CGGradientCreateWithColorComponents(grey_space, gradient_colors, nullptr, | |
36 kColorCount)); | |
37 CGContextDrawRadialGradient(context, gradient, centerPoint, 0, centerPoint, | |
38 radius, kCGGradientDrawsAfterEndLocation); | |
39 if (tileImage) | |
40 [tileImage drawAsPatternInRect:backgroundRect]; | |
41 if (logoImage) { | |
42 CGPoint corner = AlignPointToPixel( | |
43 CGPointMake(centerPoint.x - logoImage.size.width / 2.0, | |
44 centerPoint.y - logoImage.size.height / 2.0)); | |
45 [logoImage drawAtPoint:corner]; | |
46 } | |
47 UIImage* background = UIGraphicsGetImageFromCurrentImageContext(); | |
48 UIGraphicsEndImageContext(); | |
49 return background; | |
50 } | |
51 | |
52 void InstallBackgroundInView(UIView* view) { | |
53 UIImageView* imageView = | |
54 [[[UIImageView alloc] initWithFrame:view.bounds] autorelease]; | |
55 imageView.image = [UIImage imageNamed:@"stack_view_background_noise.jpg"]; | |
56 imageView.contentMode = UIViewContentModeScaleAspectFill; | |
57 imageView.autoresizingMask = | |
58 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | |
59 [view insertSubview:imageView atIndex:0]; | |
60 } | |
61 | |
62 } // namespace background_generator | |
OLD | NEW |