File: paint_vector_icon.h

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (99 lines) | stat: -rw-r--r-- 3,771 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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.

#ifndef UI_GFX_PAINT_VECTOR_ICON_H_
#define UI_GFX_PAINT_VECTOR_ICON_H_

#include "base/time/time.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/gfx_export.h"
#include "ui/gfx/image/image_skia.h"

namespace gfx {

class Canvas;
struct VectorIcon;

// Describes an instance of an icon: an icon definition and a set of drawing
// parameters.
struct GFX_EXPORT IconDescription {
  IconDescription(const IconDescription& other);

  IconDescription(const VectorIcon& icon,
                  int dip_size,
                  SkColor color,
                  const base::TimeDelta& elapsed_time,
                  const VectorIcon& badge_icon);

  ~IconDescription();

  const VectorIcon& icon;
  int dip_size;
  SkColor color;
  const base::TimeDelta elapsed_time;
  const VectorIcon& badge_icon;
};

GFX_EXPORT extern const VectorIcon kNoneIcon;

// Draws a vector icon identified by |id| onto |canvas| at (0, 0). |color| is
// used as the fill. The size will come from the .icon file (the 1x version, if
// multiple versions exist). |elapsed_time| is used to determine the state of
// any transitions the icon may define.
GFX_EXPORT void PaintVectorIcon(
    Canvas* canvas,
    const VectorIcon& icon,
    SkColor color,
    const base::TimeDelta& elapsed_time = base::TimeDelta());

// As above, with a specificed size. |dip_size| is the length of a single edge
// of the square icon, in device independent pixels.
GFX_EXPORT void PaintVectorIcon(
    Canvas* canvas,
    const VectorIcon& icon,
    int dip_size,
    SkColor color,
    const base::TimeDelta& elapsed_time = base::TimeDelta());

// Creates an ImageSkia which will render the icon on demand.
// TODO(estade): update clients to use this version and remove the other
// CreateVectorIcon()s.
GFX_EXPORT ImageSkia CreateVectorIcon(const IconDescription& params);

// Creates an ImageSkia which will render the icon on demand. The size will come
// from the .icon file (the 1x version, if multiple versions exist).
GFX_EXPORT ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color);

// As above, but creates the image at the given size.
GFX_EXPORT ImageSkia CreateVectorIcon(const VectorIcon& icon,
                                      int dip_size,
                                      SkColor color);

// As above, but also paints a badge defined by |badge_id| on top of the icon.
// The badge uses the same canvas size and default color as the icon.
GFX_EXPORT ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon,
                                               int dip_size,
                                               SkColor color,
                                               const VectorIcon& badge_icon);

#if defined(GFX_VECTOR_ICONS_UNSAFE) || defined(GFX_IMPLEMENTATION)
// Takes a string of the format expected of .icon files and renders onto
// a canvas. This should only be used as a debugging aid and should never be
// used in production code.
GFX_EXPORT ImageSkia CreateVectorIconFromSource(const std::string& source,
                                                int dip_size,
                                                SkColor color);
#endif

// Calculates the size that will be default for |icon|, in dip. This will be the
// smallest icon size |icon| contains.
GFX_EXPORT int GetDefaultSizeOfVectorIcon(const gfx::VectorIcon& icon);

// Calculates and returns the elapsed time at which all animations/transitions
// will be finished.
GFX_EXPORT base::TimeDelta GetDurationOfAnimation(const VectorIcon& icon);

}  // namespace gfx

#endif  // UI_GFX_PAINT_VECTOR_ICON_H_