blob: e9d8774b0c3918fd9a3b73818b63a69f53bb39c7 [file] [log] [blame]
robertphillips@google.com42cc2372013-12-10 15:19:32 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#ifndef SkBorder_DEFINED
10#define SkBorder_DEFINED
11
12#include "SkColor.h"
13#include "SkPaint.h"
14#include "SkScalar.h"
15#include "SkTArray.h"
16
17// This class provides a concise means of specifying all the geometry/shading
18// associated with a CSS-style box/round-rect.
19class SkBorder {
20public:
21 enum BorderStyle {
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000022 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000023 */
24 kNone_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000025 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000026 */
27 kHidden_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000028 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000029 */
30 kDotted_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000031 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000032 */
33 kDashed_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000034 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000035 */
36 kSolid_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000037 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000038 */
39 kDouble_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000040 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000041 */
42 kGroove_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000043 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000044 */
45 kRidge_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000046 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000047 */
48 kInset_BorderStyle,
skia.committer@gmail.com63ba3192013-12-11 07:02:06 +000049 /**
robertphillips@google.com42cc2372013-12-10 15:19:32 +000050 */
51 kOutset_BorderStyle,
52 };
53
54 enum BlurStyle {
55 kNormal_BlurStyle, //!< fuzzy inside and outside
56 kInner_BlurStyle, //!< fuzzy inside, nothing outside
57 };
58
59 struct ShadowInfo {
60 SkScalar fXOffset;
61 SkScalar fYOffset;
62 SkScalar fBlurSigma;
63 SkColor fColor;
64 BlurStyle fStyle;
65 };
66
67 SkBorder(SkPaint& p, SkScalar width, BorderStyle style);
68
69 SkBorder(const SkPaint paints[4], const SkScalar widths[4], const BorderStyle styles[4]);
70
71 void setBackground(SkPaint* p) {
72 if (NULL == p) {
73 fBackground.reset();
74 fFlags &= ~kDrawBackground_Flag;
75 } else {
76 fBackground = *p;
77 fFlags |= kDrawBackground_Flag;
78 }
79 }
80
81 void addShadow(ShadowInfo& info) {
82 fShadows.push_back(info);
83 }
84
85private:
86 enum Flags {
87 // One paint "fPaints[0]" is applied to all the borders
88 kOnePaint_Flag = 0x01,
89 // Use 'fBackground' to draw the background
90 kDrawBackground_Flag = 0x02,
91 };
92
93 // If kOnePaint_Flag is specified then fBorder[0] is applied to all sides.
94 // Otherwise the order is: left, top, right, bottom
95 SkPaint fPaints[4];
96 // Only valid if kDrawBackground_Flag is set.
97 SkPaint fBackground;
98 SkScalar fWidths[4];
99 BorderStyle fStyles[4];
100 SkTArray<ShadowInfo> fShadows;
101 uint32_t fFlags;
102};
103
robertphillips@google.combefb4992013-12-10 15:51:43 +0000104#endif