Home | History | Annotate | Download | only in ChromeUtils
      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 {
     22         /**
     23         */
     24         kNone_BorderStyle,
     25         /**
     26         */
     27         kHidden_BorderStyle,
     28         /**
     29         */
     30         kDotted_BorderStyle,
     31         /**
     32         */
     33         kDashed_BorderStyle,
     34         /**
     35         */
     36         kSolid_BorderStyle,
     37         /**
     38         */
     39         kDouble_BorderStyle,
     40         /**
     41         */
     42         kGroove_BorderStyle,
     43         /**
     44         */
     45         kRidge_BorderStyle,
     46         /**
     47         */
     48         kInset_BorderStyle,
     49         /**
     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 
    104 #endif
    105