Home | History | Annotate | Download | only in gm
      1 /*
      2  * Copyright 2012 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 #include "gm.h"
      9 #include "sk_tool_utils.h"
     10 #include "SkBlurMaskFilter.h"
     11 #include "SkCanvas.h"
     12 #include "SkGraphics.h"
     13 #include "SkLayerDrawLooper.h"
     14 #include "SkPath.h"
     15 #include "SkRandom.h"
     16 
     17 static SkRect inset(const SkRect& r) {
     18     SkRect rect = r;
     19     rect.inset(r.width() / 8, r.height() / 8);
     20     return rect;
     21 }
     22 
     23 class PathInteriorGM : public skiagm::GM {
     24 public:
     25     PathInteriorGM() {
     26         this->setBGColor(0xFFDDDDDD);
     27     }
     28 
     29 protected:
     30     SkISize onISize() override {
     31         return SkISize::Make(770, 770);
     32     }
     33 
     34     SkString onShortName() override {
     35         return SkString("pathinterior");
     36     }
     37 
     38     void show(SkCanvas* canvas, const SkPath& path) {
     39         SkPaint paint;
     40         paint.setAntiAlias(true);
     41 
     42         SkRect rect;
     43 #if 0
     44         bool hasInterior = path.hasRectangularInterior(&rect);
     45 #else
     46         bool hasInterior = false;
     47 #endif
     48 
     49         paint.setColor(hasInterior ? sk_tool_utils::color_to_565(0xFF8888FF) : SK_ColorGRAY);
     50         canvas->drawPath(path, paint);
     51         paint.setStyle(SkPaint::kStroke_Style);
     52         paint.setColor(SK_ColorRED);
     53         canvas->drawPath(path, paint);
     54 
     55         if (hasInterior) {
     56             paint.setStyle(SkPaint::kFill_Style);
     57             paint.setColor(0x8800FF00);
     58             canvas->drawRect(rect, paint);
     59         }
     60     }
     61 
     62     void onDraw(SkCanvas* canvas) override {
     63         canvas->translate(8.5f, 8.5f);
     64 
     65         const SkRect rect = { 0, 0, 80, 80 };
     66         const SkScalar RAD = rect.width()/8;
     67 
     68         int i = 0;
     69         for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) {
     70             for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) {
     71                 for (int outerRR = 0; outerRR <= 1; ++outerRR) {
     72                     for (int innerRR = 0; innerRR <= 1; ++innerRR) {
     73                         for (int outerCW = 0; outerCW <= 1; ++outerCW) {
     74                             for (int innerCW = 0; innerCW <= 1; ++innerCW) {
     75                                 SkPath path;
     76                                 path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
     77                                 SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
     78                                 SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
     79 
     80                                 SkRect r = insetFirst ? inset(rect) : rect;
     81                                 if (outerRR) {
     82                                     path.addRoundRect(r, RAD, RAD, outerDir);
     83                                 } else {
     84                                     path.addRect(r, outerDir);
     85                                 }
     86                                 r = insetFirst ? rect : inset(rect);
     87                                 if (innerRR) {
     88                                     path.addRoundRect(r, RAD, RAD, innerDir);
     89                                 } else {
     90                                     path.addRect(r, innerDir);
     91                                 }
     92 
     93                                 SkScalar dx = (i / 8) * rect.width() * 6 / 5;
     94                                 SkScalar dy = (i % 8) * rect.height() * 6 / 5;
     95                                 i++;
     96                                 path.offset(dx, dy);
     97 
     98                                 this->show(canvas, path);
     99                             }
    100                         }
    101                     }
    102                 }
    103             }
    104         }
    105     }
    106 
    107 private:
    108 
    109     typedef GM INHERITED;
    110 };
    111 
    112 //////////////////////////////////////////////////////////////////////////////
    113 
    114 DEF_GM( return new PathInteriorGM; )
    115