142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com/* 242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com * Copyright 2013 Google Inc. 342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com * 442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com * Use of this source code is governed by a BSD-style license that can be 542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com * found in the LICENSE file. 642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com#ifndef SkBorder_DEFINED 1042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com#define SkBorder_DEFINED 1142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 1242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com#include "SkColor.h" 1342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com#include "SkPaint.h" 1442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com#include "SkScalar.h" 1542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com#include "SkTArray.h" 1642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 1742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com// This class provides a concise means of specifying all the geometry/shading 1842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com// associated with a CSS-style box/round-rect. 1942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.comclass SkBorder { 2042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.compublic: 2142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com enum BorderStyle { 2263ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 2342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 2442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kNone_BorderStyle, 2563ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 2642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 2742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kHidden_BorderStyle, 2863ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 2942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 3042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kDotted_BorderStyle, 3163ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 3242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 3342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kDashed_BorderStyle, 3463ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 3542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 3642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kSolid_BorderStyle, 3763ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 3842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 3942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kDouble_BorderStyle, 4063ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 4142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 4242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kGroove_BorderStyle, 4363ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 4442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 4542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kRidge_BorderStyle, 4663ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 4742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 4842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kInset_BorderStyle, 4963ba31948392a56c191607d62a2414f16253e47bskia.committer@gmail.com /** 5042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com */ 5142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kOutset_BorderStyle, 5242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com }; 5342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 5442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com enum BlurStyle { 5542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kNormal_BlurStyle, //!< fuzzy inside and outside 5642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kInner_BlurStyle, //!< fuzzy inside, nothing outside 5742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com }; 5842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 5942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com struct ShadowInfo { 6042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkScalar fXOffset; 6142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkScalar fYOffset; 6242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkScalar fBlurSigma; 6342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkColor fColor; 6442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com BlurStyle fStyle; 6542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com }; 6642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 6742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkBorder(SkPaint& p, SkScalar width, BorderStyle style); 6842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 6942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkBorder(const SkPaint paints[4], const SkScalar widths[4], const BorderStyle styles[4]); 7042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 7142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com void setBackground(SkPaint* p) { 7242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com if (NULL == p) { 7342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com fBackground.reset(); 7442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com fFlags &= ~kDrawBackground_Flag; 7542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com } else { 7642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com fBackground = *p; 7742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com fFlags |= kDrawBackground_Flag; 7842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com } 7942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com } 8042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 8142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com void addShadow(ShadowInfo& info) { 8242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com fShadows.push_back(info); 8342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com } 8442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 8542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.comprivate: 8642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com enum Flags { 8742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com // One paint "fPaints[0]" is applied to all the borders 8842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kOnePaint_Flag = 0x01, 8942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com // Use 'fBackground' to draw the background 9042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com kDrawBackground_Flag = 0x02, 9142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com }; 9242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 9342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com // If kOnePaint_Flag is specified then fBorder[0] is applied to all sides. 9442cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com // Otherwise the order is: left, top, right, bottom 9542cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkPaint fPaints[4]; 9642cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com // Only valid if kDrawBackground_Flag is set. 9742cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkPaint fBackground; 9842cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkScalar fWidths[4]; 9942cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com BorderStyle fStyles[4]; 10042cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com SkTArray<ShadowInfo> fShadows; 10142cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com uint32_t fFlags; 10242cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com}; 10342cc237caf9f02eaf59ad685e4529c184be78a37robertphillips@google.com 104befb499da5ddf9df7c1986b56d7647f55f97f297robertphillips@google.com#endif 105