Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
Mattias Nissler | b1fdeb5a | 2015-07-09 12:10:39 | [diff] [blame] | 2 | // 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 Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 8 | #include "base/component_export.h" |
Ali Hijazi | cf5c86b | 2022-11-09 21:41:02 | [diff] [blame] | 9 | #include "base/memory/raw_ref.h" |
Mattias Nissler | b1fdeb5a | 2015-07-09 12:10:39 | [diff] [blame] | 10 | #include "third_party/skia/include/core/SkColor.h" |
Evan Stade | 7a9b1b43 | 2020-01-03 17:21:26 | [diff] [blame] | 11 | #include "ui/gfx/color_palette.h" |
estade | a204e0c | 2015-07-22 19:54:31 | [diff] [blame] | 12 | #include "ui/gfx/image/image_skia.h" |
Mattias Nissler | b1fdeb5a | 2015-07-09 12:10:39 | [diff] [blame] | 13 | |
| 14 | namespace gfx { |
| 15 | |
| 16 | class Canvas; |
tdanderson | 70e20e2 | 2016-08-31 22:25:19 | [diff] [blame] | 17 | struct VectorIcon; |
Mattias Nissler | b1fdeb5a | 2015-07-09 12:10:39 | [diff] [blame] | 18 | |
estade | 9d068dc | 2017-06-01 20:48:02 | [diff] [blame] | 19 | // Describes an instance of an icon: an icon definition and a set of drawing |
| 20 | // parameters. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 21 | struct COMPONENT_EXPORT(GFX) IconDescription { |
estade | 9d068dc | 2017-06-01 20:48:02 | [diff] [blame] | 22 | IconDescription(const IconDescription& other); |
| 23 | |
Evan Stade | 7a9b1b43 | 2020-01-03 17:21:26 | [diff] [blame] | 24 | // If |dip_size| is 0, the default size of |icon| will be used. |
| 25 | // If |badge_icon| is null, the icon has no badge. |
estade | 9d068dc | 2017-06-01 20:48:02 | [diff] [blame] | 26 | IconDescription(const VectorIcon& icon, |
Evan Stade | 7a9b1b43 | 2020-01-03 17:21:26 | [diff] [blame] | 27 | int dip_size = 0, |
| 28 | SkColor color = gfx::kPlaceholderColor, |
| 29 | const VectorIcon* badge_icon = nullptr); |
estade | 9d068dc | 2017-06-01 20:48:02 | [diff] [blame] | 30 | |
| 31 | ~IconDescription(); |
| 32 | |
Ali Hijazi | cf5c86b | 2022-11-09 21:41:02 | [diff] [blame] | 33 | const raw_ref<const VectorIcon> icon; |
estade | 9d068dc | 2017-06-01 20:48:02 | [diff] [blame] | 34 | int dip_size; |
| 35 | SkColor color; |
Ali Hijazi | cf5c86b | 2022-11-09 21:41:02 | [diff] [blame] | 36 | const raw_ref<const VectorIcon> badge_icon; |
estade | 9d068dc | 2017-06-01 20:48:02 | [diff] [blame] | 37 | }; |
| 38 | |
estade | a6ce76b8 | 2017-04-03 15:27:50 | [diff] [blame] | 39 | // 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 Stade | 34fba51 | 2020-01-03 02:35:16 | [diff] [blame] | 41 | // multiple versions exist). |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 42 | COMPONENT_EXPORT(GFX) |
| 43 | void PaintVectorIcon(Canvas* canvas, const VectorIcon& icon, SkColor color); |
estade | a6ce76b8 | 2017-04-03 15:27:50 | [diff] [blame] | 44 | |
Evan Stade | 34fba51 | 2020-01-03 02:35:16 | [diff] [blame] | 45 | // As above, with a specified size. |dip_size| is the length of a single edge |
estade | a6ce76b8 | 2017-04-03 15:27:50 | [diff] [blame] | 46 | // of the square icon, in device independent pixels. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 47 | COMPONENT_EXPORT(GFX) |
| 48 | void PaintVectorIcon(Canvas* canvas, |
| 49 | const VectorIcon& icon, |
| 50 | int dip_size, |
| 51 | SkColor color); |
Mattias Nissler | b1fdeb5a | 2015-07-09 12:10:39 | [diff] [blame] | 52 | |
estade | 9d068dc | 2017-06-01 20:48:02 | [diff] [blame] | 53 | // 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 Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 56 | COMPONENT_EXPORT(GFX) ImageSkia CreateVectorIcon(const IconDescription& params); |
estade | 9d068dc | 2017-06-01 20:48:02 | [diff] [blame] | 57 | |
estade | 3b7f55d | 2016-04-27 00:21:19 | [diff] [blame] | 58 | // 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 Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 60 | COMPONENT_EXPORT(GFX) |
| 61 | ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color); |
estade | 3b7f55d | 2016-04-27 00:21:19 | [diff] [blame] | 62 | |
| 63 | // As above, but creates the image at the given size. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 64 | COMPONENT_EXPORT(GFX) |
| 65 | ImageSkia CreateVectorIcon(const VectorIcon& icon, int dip_size, SkColor color); |
estade | a204e0c | 2015-07-22 19:54:31 | [diff] [blame] | 66 | |
estade | 7ca51e2 | 2015-08-31 19:03:33 | [diff] [blame] | 67 | // 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 Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 69 | COMPONENT_EXPORT(GFX) |
| 70 | ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon, |
| 71 | int dip_size, |
| 72 | SkColor color, |
| 73 | const VectorIcon& badge_icon); |
estade | 7ca51e2 | 2015-08-31 19:03:33 | [diff] [blame] | 74 | |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 75 | #if defined(GFX_VECTOR_ICONS_UNSAFE) || defined(IS_GFX_IMPL) |
estade | 6c87460 | 2015-08-04 22:45:24 | [diff] [blame] | 76 | // 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 Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 79 | COMPONENT_EXPORT(GFX) |
| 80 | ImageSkia CreateVectorIconFromSource(const std::string& source, |
| 81 | int dip_size, |
| 82 | SkColor color); |
estade | 6c87460 | 2015-08-04 22:45:24 | [diff] [blame] | 83 | #endif |
| 84 | |
Mattias Nissler | b1fdeb5a | 2015-07-09 12:10:39 | [diff] [blame] | 85 | } // namespace gfx |
| 86 | |
| 87 | #endif // UI_GFX_PAINT_VECTOR_ICON_H_ |