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

Side by Side Diff: chrome/browser/profiles/profile_info_util.cc

Issue 8700014: Utility to draw GAIA pictures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/profiles/profile_info_util.h"
6
7 #include "skia/ext/image_operations.h"
8 #include "ui/gfx/canvas_skia.h"
9 #include "ui/gfx/rect.h"
10
11 namespace profiles {
12
13 const int kAvatarIconWidth = 38;
14 const int kAvatarIconHeight = 31;
15
16 gfx::Image GetAvatarIconForMenu(const gfx::Image& image,
17 bool is_gaia_picture) {
18 if (!is_gaia_picture)
19 return image;
20
21 int length = std::min(kAvatarIconWidth, kAvatarIconHeight) - 2;
22 SkBitmap bmp = skia::ImageOperations::Resize(
23 image, skia::ImageOperations::RESIZE_BEST, length, length);
24 gfx::CanvasSkia canvas(kAvatarIconWidth, kAvatarIconHeight, false);
25
26 // Draw the icon centered on the canvas.
27 int x = (kAvatarIconWidth - length) / 2;
28 int y = (kAvatarIconHeight - length) / 2;
29 canvas.DrawBitmapInt(bmp, x, y);
30
31 // Draw a gray border on the inside of the icon.
32 SkColor color = SkColorSetARGB(83, 0, 0, 0);
33 canvas.DrawRectInt(color, x, y, length - 1, length - 1);
34
35 return gfx::Image(new SkBitmap(canvas.ExtractBitmap()));
36 }
37
38 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image,
39 bool is_gaia_picture,
40 int dst_width,
41 int dst_height) {
42 if (!is_gaia_picture)
43 return image;
44
45 int length = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight),
46 std::min(dst_width, dst_height)) - 2;
47 SkBitmap bmp = skia::ImageOperations::Resize(
48 image, skia::ImageOperations::RESIZE_BEST, length, length);
49 gfx::CanvasSkia canvas(dst_width, dst_height, false);
50
51 // Draw the icon on the bottom center of the canvas.
52 int x1 = (dst_width - length) / 2;
53 int x2 = x1 + length;
54 int y1 = dst_height - length - 1;
55 int y2 = y1 + length;
56 canvas.DrawBitmapInt(bmp, x1, y1);
57
58 // Give the icon an etched look by drawing a highlight on the bottom edge
59 // and a shadow on the remaining edges.
60 SkColor highlight_color = SkColorSetARGB(128, 255, 255, 255);
61 SkColor shadow_color = SkColorSetARGB(83, 0, 0, 0);
62 // Bottom highlight.
63 canvas.DrawLineInt(highlight_color, x1, y2 - 1, x2, y2 - 1);
64 // Top shadow.
65 canvas.DrawLineInt(shadow_color, x1, y1, x2, y1);
66 // Left shadow.
67 canvas.DrawLineInt(shadow_color, x1, y1 + 1, x1, y2 - 1);
68 // Right shadow.
69 canvas.DrawLineInt(shadow_color, x2 - 1, y1 + 1, x2 - 1, y2 - 1);
70
71 return gfx::Image(new SkBitmap(canvas.ExtractBitmap()));
72 }
73
74 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698