paint_vector_icon.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2015 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. #ifndef UI_GFX_PAINT_VECTOR_ICON_H_
  5. #define UI_GFX_PAINT_VECTOR_ICON_H_
  6. #include "third_party/skia/include/core/SkColor.h"
  7. #include "ui/gfx/color_palette.h"
  8. #include "ui/gfx/gfx_export.h"
  9. #include "ui/gfx/image/image_skia.h"
  10. namespace gfx {
  11. class Canvas;
  12. struct VectorIcon;
  13. // Describes an instance of an icon: an icon definition and a set of drawing
  14. // parameters.
  15. struct GFX_EXPORT IconDescription {
  16. IconDescription(const IconDescription& other);
  17. // If |dip_size| is 0, the default size of |icon| will be used.
  18. // If |badge_icon| is null, the icon has no badge.
  19. IconDescription(const VectorIcon& icon,
  20. int dip_size = 0,
  21. SkColor color = gfx::kPlaceholderColor,
  22. const VectorIcon* badge_icon = nullptr);
  23. ~IconDescription();
  24. const VectorIcon& icon;
  25. int dip_size;
  26. SkColor color;
  27. const VectorIcon& badge_icon;
  28. };
  29. GFX_EXPORT extern const VectorIcon kNoneIcon;
  30. // Draws a vector icon identified by |id| onto |canvas| at (0, 0). |color| is
  31. // used as the fill. The size will come from the .icon file (the 1x version, if
  32. // multiple versions exist).
  33. GFX_EXPORT void PaintVectorIcon(Canvas* canvas,
  34. const VectorIcon& icon,
  35. SkColor color);
  36. // As above, with a specified size. |dip_size| is the length of a single edge
  37. // of the square icon, in device independent pixels.
  38. GFX_EXPORT void PaintVectorIcon(Canvas* canvas,
  39. const VectorIcon& icon,
  40. int dip_size,
  41. SkColor color);
  42. // Creates an ImageSkia which will render the icon on demand.
  43. // TODO(estade): update clients to use this version and remove the other
  44. // CreateVectorIcon()s.
  45. GFX_EXPORT ImageSkia CreateVectorIcon(const IconDescription& params);
  46. // Creates an ImageSkia which will render the icon on demand. The size will come
  47. // from the .icon file (the 1x version, if multiple versions exist).
  48. GFX_EXPORT ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color);
  49. // As above, but creates the image at the given size.
  50. GFX_EXPORT ImageSkia CreateVectorIcon(const VectorIcon& icon,
  51. int dip_size,
  52. SkColor color);
  53. // As above, but also paints a badge defined by |badge_id| on top of the icon.
  54. // The badge uses the same canvas size and default color as the icon.
  55. GFX_EXPORT ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon,
  56. int dip_size,
  57. SkColor color,
  58. const VectorIcon& badge_icon);
  59. #if defined(GFX_VECTOR_ICONS_UNSAFE) || defined(GFX_IMPLEMENTATION)
  60. // Takes a string of the format expected of .icon files and renders onto
  61. // a canvas. This should only be used as a debugging aid and should never be
  62. // used in production code.
  63. GFX_EXPORT ImageSkia CreateVectorIconFromSource(const std::string& source,
  64. int dip_size,
  65. SkColor color);
  66. #endif
  67. } // namespace gfx
  68. #endif // UI_GFX_PAINT_VECTOR_ICON_H_