blob: 7c4ab54a43be66953696945f34b7cf9388b50480 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2015 The Chromium Authors
Mattias Nisslerb1fdeb5a2015-07-09 12:10:392// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_GFX_PAINT_VECTOR_ICON_H_
6#define UI_GFX_PAINT_VECTOR_ICON_H_
7
Kalvin Lee7d17d5572024-11-10 13:52:458#include "base/component_export.h"
Ali Hijazicf5c86b2022-11-09 21:41:029#include "base/memory/raw_ref.h"
Mattias Nisslerb1fdeb5a2015-07-09 12:10:3910#include "third_party/skia/include/core/SkColor.h"
Evan Stade7a9b1b432020-01-03 17:21:2611#include "ui/gfx/color_palette.h"
estadea204e0c2015-07-22 19:54:3112#include "ui/gfx/image/image_skia.h"
Mattias Nisslerb1fdeb5a2015-07-09 12:10:3913
14namespace gfx {
15
16class Canvas;
tdanderson70e20e22016-08-31 22:25:1917struct VectorIcon;
Mattias Nisslerb1fdeb5a2015-07-09 12:10:3918
estade9d068dc2017-06-01 20:48:0219// Describes an instance of an icon: an icon definition and a set of drawing
20// parameters.
Kalvin Lee7d17d5572024-11-10 13:52:4521struct COMPONENT_EXPORT(GFX) IconDescription {
estade9d068dc2017-06-01 20:48:0222 IconDescription(const IconDescription& other);
23
Evan Stade7a9b1b432020-01-03 17:21:2624 // If |dip_size| is 0, the default size of |icon| will be used.
25 // If |badge_icon| is null, the icon has no badge.
estade9d068dc2017-06-01 20:48:0226 IconDescription(const VectorIcon& icon,
Evan Stade7a9b1b432020-01-03 17:21:2627 int dip_size = 0,
28 SkColor color = gfx::kPlaceholderColor,
29 const VectorIcon* badge_icon = nullptr);
estade9d068dc2017-06-01 20:48:0230
31 ~IconDescription();
32
Ali Hijazicf5c86b2022-11-09 21:41:0233 const raw_ref<const VectorIcon> icon;
estade9d068dc2017-06-01 20:48:0234 int dip_size;
35 SkColor color;
Ali Hijazicf5c86b2022-11-09 21:41:0236 const raw_ref<const VectorIcon> badge_icon;
estade9d068dc2017-06-01 20:48:0237};
38
estadea6ce76b82017-04-03 15:27:5039// Draws a vector icon identified by |id| onto |canvas| at (0, 0). |color| is
40// used as the fill. The size will come from the .icon file (the 1x version, if
Evan Stade34fba512020-01-03 02:35:1641// multiple versions exist).
Kalvin Lee7d17d5572024-11-10 13:52:4542COMPONENT_EXPORT(GFX)
43void PaintVectorIcon(Canvas* canvas, const VectorIcon& icon, SkColor color);
estadea6ce76b82017-04-03 15:27:5044
Evan Stade34fba512020-01-03 02:35:1645// As above, with a specified size. |dip_size| is the length of a single edge
estadea6ce76b82017-04-03 15:27:5046// of the square icon, in device independent pixels.
Kalvin Lee7d17d5572024-11-10 13:52:4547COMPONENT_EXPORT(GFX)
48void PaintVectorIcon(Canvas* canvas,
49 const VectorIcon& icon,
50 int dip_size,
51 SkColor color);
Mattias Nisslerb1fdeb5a2015-07-09 12:10:3952
estade9d068dc2017-06-01 20:48:0253// Creates an ImageSkia which will render the icon on demand.
54// TODO(estade): update clients to use this version and remove the other
55// CreateVectorIcon()s.
Kalvin Lee7d17d5572024-11-10 13:52:4556COMPONENT_EXPORT(GFX) ImageSkia CreateVectorIcon(const IconDescription& params);
estade9d068dc2017-06-01 20:48:0257
estade3b7f55d2016-04-27 00:21:1958// Creates an ImageSkia which will render the icon on demand. The size will come
59// from the .icon file (the 1x version, if multiple versions exist).
Kalvin Lee7d17d5572024-11-10 13:52:4560COMPONENT_EXPORT(GFX)
61ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color);
estade3b7f55d2016-04-27 00:21:1962
63// As above, but creates the image at the given size.
Kalvin Lee7d17d5572024-11-10 13:52:4564COMPONENT_EXPORT(GFX)
65ImageSkia CreateVectorIcon(const VectorIcon& icon, int dip_size, SkColor color);
estadea204e0c2015-07-22 19:54:3166
estade7ca51e22015-08-31 19:03:3367// As above, but also paints a badge defined by |badge_id| on top of the icon.
68// The badge uses the same canvas size and default color as the icon.
Kalvin Lee7d17d5572024-11-10 13:52:4569COMPONENT_EXPORT(GFX)
70ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon,
71 int dip_size,
72 SkColor color,
73 const VectorIcon& badge_icon);
estade7ca51e22015-08-31 19:03:3374
Kalvin Lee7d17d5572024-11-10 13:52:4575#if defined(GFX_VECTOR_ICONS_UNSAFE) || defined(IS_GFX_IMPL)
estade6c874602015-08-04 22:45:2476// Takes a string of the format expected of .icon files and renders onto
77// a canvas. This should only be used as a debugging aid and should never be
78// used in production code.
Kalvin Lee7d17d5572024-11-10 13:52:4579COMPONENT_EXPORT(GFX)
80ImageSkia CreateVectorIconFromSource(const std::string& source,
81 int dip_size,
82 SkColor color);
estade6c874602015-08-04 22:45:2483#endif
84
Mattias Nisslerb1fdeb5a2015-07-09 12:10:3985} // namespace gfx
86
87#endif // UI_GFX_PAINT_VECTOR_ICON_H_