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

Unified Diff: ui/gfx/paint_vector_icon.cc

Issue 1231843002: Revert of Revert vector icon CLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge_aide_oobe_completion
Patch Set: Rebase. Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/paint_vector_icon.h ('k') | ui/gfx/vector_icons.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/paint_vector_icon.cc
diff --git a/ui/gfx/paint_vector_icon.cc b/ui/gfx/paint_vector_icon.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5260d90ea94401dc301815a006e20db0f870d9df
--- /dev/null
+++ b/ui/gfx/paint_vector_icon.cc
@@ -0,0 +1,121 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/paint_vector_icon.h"
+
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/vector_icons.h"
+#include "ui/gfx/vector_icons_public.h"
+
+namespace gfx {
+
+void PaintVectorIcon(Canvas* canvas,
+ VectorIconId id,
+ size_t dip_size,
+ SkColor color) {
+ DCHECK(VectorIconId::VECTOR_ICON_NONE != id);
+ const PathElement* path_elements = GetPathForVectorIcon(id);
+ SkPath path;
+ path.setFillType(SkPath::kEvenOdd_FillType);
+ if (dip_size != kReferenceSizeDip) {
+ SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(kReferenceSizeDip);
+ canvas->sk_canvas()->scale(scale, scale);
+ }
+
+ for (size_t i = 0; path_elements[i].type != END;) {
+ switch (path_elements[i++].type) {
+ case MOVE_TO: {
+ SkScalar x = path_elements[i++].arg;
+ SkScalar y = path_elements[i++].arg;
+ path.moveTo(x, y);
+ break;
+ }
+
+ case R_MOVE_TO: {
+ SkScalar x = path_elements[i++].arg;
+ SkScalar y = path_elements[i++].arg;
+ path.rMoveTo(x, y);
+ break;
+ }
+
+ case LINE_TO: {
+ SkScalar x = path_elements[i++].arg;
+ SkScalar y = path_elements[i++].arg;
+ path.lineTo(x, y);
+ break;
+ }
+
+ case R_LINE_TO: {
+ SkScalar x = path_elements[i++].arg;
+ SkScalar y = path_elements[i++].arg;
+ path.rLineTo(x, y);
+ break;
+ }
+
+ case H_LINE_TO: {
+ SkPoint last_point;
+ path.getLastPt(&last_point);
+ SkScalar x = path_elements[i++].arg;
+ path.lineTo(x, last_point.fY);
+ break;
+ }
+
+ case R_H_LINE_TO: {
+ SkScalar x = path_elements[i++].arg;
+ path.rLineTo(x, 0);
+ break;
+ }
+
+ case V_LINE_TO: {
+ SkPoint last_point;
+ path.getLastPt(&last_point);
+ SkScalar y = path_elements[i++].arg;
+ path.lineTo(last_point.fX, y);
+ break;
+ }
+
+ case R_V_LINE_TO: {
+ SkScalar y = path_elements[i++].arg;
+ path.rLineTo(0, y);
+ break;
+ }
+
+ case R_CUBIC_TO: {
+ SkScalar x1 = path_elements[i++].arg;
+ SkScalar y1 = path_elements[i++].arg;
+ SkScalar x2 = path_elements[i++].arg;
+ SkScalar y2 = path_elements[i++].arg;
+ SkScalar x3 = path_elements[i++].arg;
+ SkScalar y3 = path_elements[i++].arg;
+ path.rCubicTo(x1, y1, x2, y2, x3, y3);
+ break;
+ }
+
+ case CLOSE: {
+ path.close();
+ break;
+ }
+
+ case CIRCLE: {
+ SkScalar x = path_elements[i++].arg;
+ SkScalar y = path_elements[i++].arg;
+ SkScalar r = path_elements[i++].arg;
+ path.addCircle(x, y, r);
+ break;
+ }
+
+ case END:
+ NOTREACHED();
+ break;
+ }
+ }
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setAntiAlias(true);
+ paint.setColor(color);
+ canvas->DrawPath(path, paint);
+}
+
+} // namespace gfx
« no previous file with comments | « ui/gfx/paint_vector_icon.h ('k') | ui/gfx/vector_icons.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698