robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 1 | /* |
| 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. |
| 19 | class SkBorder { |
| 20 | public: |
| 21 | enum BorderStyle { |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 22 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 23 | */ |
| 24 | kNone_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 25 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 26 | */ |
| 27 | kHidden_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 28 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 29 | */ |
| 30 | kDotted_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 31 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 32 | */ |
| 33 | kDashed_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 34 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 35 | */ |
| 36 | kSolid_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 37 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 38 | */ |
| 39 | kDouble_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 40 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 41 | */ |
| 42 | kGroove_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 43 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 44 | */ |
| 45 | kRidge_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 46 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 47 | */ |
| 48 | kInset_BorderStyle, |
skia.committer@gmail.com | 63ba319 | 2013-12-11 07:02:06 +0000 | [diff] [blame] | 49 | /** |
robertphillips@google.com | 42cc237 | 2013-12-10 15:19:32 +0000 | [diff] [blame] | 50 | */ |
| 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 | |
| 85 | private: |
| 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.com | befb499 | 2013-12-10 15:51:43 +0000 | [diff] [blame] | 104 | #endif |