Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: ios/chrome/browser/ui/background_generator.mm

Issue 1058933002: [iOS] Upstream //ios/chrome/browser/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@upstreamMemory
Patch Set: Review comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/background_generator.h ('k') | ios/chrome/browser/ui/file_locations.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // This is a utility function that may be used as a standalone helper function
16 // to generate a radial gradient UIImage.
17 UIImage* GetRadialGradient(CGRect backgroundRect,
18 CGPoint centerPoint,
19 CGFloat radius,
20 CGFloat centerColor,
21 CGFloat outsideColor,
22 UIImage* tileImage,
23 UIImage* logoImage) {
24 UIGraphicsBeginImageContextWithOptions(backgroundRect.size, YES, 0);
25 CGContextRef context = UIGraphicsGetCurrentContext();
26 CGFloat gradient_colors[4] = {centerColor, 1.0, outsideColor, 1.0};
27 const size_t kColorCount = 2;
28 base::ScopedCFTypeRef<CGColorSpaceRef> grey_space(
29 CGColorSpaceCreateDeviceGray());
30 DCHECK_EQ(2u, CGColorSpaceGetNumberOfComponents(grey_space));
31 base::ScopedCFTypeRef<CGGradientRef> gradient(
32 CGGradientCreateWithColorComponents(grey_space, gradient_colors, nullptr,
33 kColorCount));
34 CGContextDrawRadialGradient(context, gradient, centerPoint, 0, centerPoint,
35 radius, kCGGradientDrawsAfterEndLocation);
36 if (tileImage)
37 [tileImage drawAsPatternInRect:backgroundRect];
38 if (logoImage) {
39 CGPoint corner = AlignPointToPixel(
40 CGPointMake(centerPoint.x - logoImage.size.width / 2.0,
41 centerPoint.y - logoImage.size.height / 2.0));
42 [logoImage drawAtPoint:corner];
43 }
44 UIImage* background = UIGraphicsGetImageFromCurrentImageContext();
45 UIGraphicsEndImageContext();
46 return background;
47 }
48
49 void InstallBackgroundInView(UIView* view) {
50 UIImageView* imageView =
51 [[[UIImageView alloc] initWithFrame:view.bounds] autorelease];
52 imageView.image = [UIImage imageNamed:@"stack_view_background_noise.jpg"];
53 imageView.contentMode = UIViewContentModeScaleAspectFill;
54 imageView.autoresizingMask =
55 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
56 [view insertSubview:imageView atIndex:0];
57 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/background_generator.h ('k') | ios/chrome/browser/ui/file_locations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698