diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-10 15:19:32 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-10 15:19:32 +0000 |
commit | 42cc237caf9f02eaf59ad685e4529c184be78a37 (patch) | |
tree | 769ce78fba69dc4549d6d4d861b23219c08e4da4 /experimental/ChromeUtils | |
parent | 99589af4e333422639d7e873207dd323fdd6e808 (diff) |
New Composite CSS border object
https://codereview.chromium.org/86263003/
git-svn-id: http://skia.googlecode.com/svn/trunk@12597 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/ChromeUtils')
-rw-r--r-- | experimental/ChromeUtils/SkBorder.cpp | 31 | ||||
-rw-r--r-- | experimental/ChromeUtils/SkBorder.h | 107 |
2 files changed, 138 insertions, 0 deletions
diff --git a/experimental/ChromeUtils/SkBorder.cpp b/experimental/ChromeUtils/SkBorder.cpp new file mode 100644 index 0000000000..f6caa5796a --- /dev/null +++ b/experimental/ChromeUtils/SkBorder.cpp @@ -0,0 +1,31 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkBorder.h" + +SkBorder::SkBorder(SkPaint& p, SkScalar width, BorderStyle style) + : fFlags(kOnePaint_Flag) { + fPaints[0] = p; + + for (int i = 0; i < 4; ++i) { + fWidths[i] = width; + fStyles[i] = style; + } +} + +SkBorder::SkBorder(const SkPaint paints[4], + const SkScalar widths[4], + const BorderStyle styles[4]) + : fFlags(0) { + for (int i = 0; i < 4; ++i) { + fPaints[i] = paints[i]; + } + + memcpy(fWidths, widths, sizeof(fWidths)); + memcpy(fStyles, styles, sizeof(fStyles)); +} + diff --git a/experimental/ChromeUtils/SkBorder.h b/experimental/ChromeUtils/SkBorder.h new file mode 100644 index 0000000000..8f945472ed --- /dev/null +++ b/experimental/ChromeUtils/SkBorder.h @@ -0,0 +1,107 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + +#ifndef SkBorder_DEFINED +#define SkBorder_DEFINED + +#include "SkColor.h" +#include "SkPaint.h" +#include "SkScalar.h" +#include "SkTArray.h" + +// This class provides a concise means of specifying all the geometry/shading +// associated with a CSS-style box/round-rect. +class SkBorder { +public: + enum BorderStyle { + /** + */ + kNone_BorderStyle, + /** + */ + kHidden_BorderStyle, + /** + */ + kDotted_BorderStyle, + /** + */ + kDashed_BorderStyle, + /** + */ + kSolid_BorderStyle, + /** + */ + kDouble_BorderStyle, + /** + */ + kGroove_BorderStyle, + /** + */ + kRidge_BorderStyle, + /** + */ + kInset_BorderStyle, + /** + */ + kOutset_BorderStyle, + }; + + enum BlurStyle { + kNormal_BlurStyle, //!< fuzzy inside and outside + kInner_BlurStyle, //!< fuzzy inside, nothing outside + }; + + struct ShadowInfo { + SkScalar fXOffset; + SkScalar fYOffset; + SkScalar fBlurSigma; + SkColor fColor; + BlurStyle fStyle; + }; + + SkBorder(SkPaint& p, SkScalar width, BorderStyle style); + + SkBorder(const SkPaint paints[4], const SkScalar widths[4], const BorderStyle styles[4]); + + void setBackground(SkPaint* p) { + if (NULL == p) { + fBackground.reset(); + fFlags &= ~kDrawBackground_Flag; + } else { + fBackground = *p; + fFlags |= kDrawBackground_Flag; + } + } + + void addShadow(ShadowInfo& info) { + fShadows.push_back(info); + } + +private: + enum Flags { + // One paint "fPaints[0]" is applied to all the borders + kOnePaint_Flag = 0x01, + // Use 'fBackground' to draw the background + kDrawBackground_Flag = 0x02, + }; + + // If kOnePaint_Flag is specified then fBorder[0] is applied to all sides. + // Otherwise the order is: left, top, right, bottom + SkPaint fPaints[4]; + // Only valid if kDrawBackground_Flag is set. + SkPaint fBackground; + SkScalar fWidths[4]; + BorderStyle fStyles[4]; + SkTArray<ShadowInfo> fShadows; + uint32_t fFlags; +}; + + + + +#endif
\ No newline at end of file |