Home | History | Annotate | Download | only in samplecode
      1 /*
      2  * Copyright 2011 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 #include "Sample.h"
      8 #include "SkCanvas.h"
      9 #include "SkCornerPathEffect.h"
     10 #include "SkGradientShader.h"
     11 #include "SkPath.h"
     12 #include "SkRegion.h"
     13 #include "SkShader.h"
     14 #include "SkUTF.h"
     15 
     16 class FillTypeView : public Sample {
     17     SkPath fPath;
     18 public:
     19     FillTypeView() {
     20         const SkScalar radius = SkIntToScalar(45);
     21         fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
     22         fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
     23 
     24         this->setBGColor(0xFFDDDDDD);
     25     }
     26 
     27 protected:
     28     virtual bool onQuery(Sample::Event* evt) {
     29         if (Sample::TitleQ(*evt)) {
     30             Sample::TitleR(evt, "FillType");
     31             return true;
     32         }
     33         return this->INHERITED::onQuery(evt);
     34     }
     35 
     36     void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft,
     37                   SkScalar scale, const SkPaint& paint) {
     38 
     39         const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
     40 
     41         canvas->save();
     42         canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
     43         canvas->clipRect(r);
     44         canvas->drawColor(SK_ColorWHITE);
     45         fPath.setFillType(ft);
     46         canvas->translate(r.centerX(), r.centerY());
     47         canvas->scale(scale, scale);
     48         canvas->translate(-r.centerX(), -r.centerY());
     49         canvas->drawPath(fPath, paint);
     50         canvas->restore();
     51     }
     52 
     53     void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
     54         showPath(canvas,   0,   0, SkPath::kWinding_FillType,
     55                  scale, paint);
     56         showPath(canvas, 200,   0, SkPath::kEvenOdd_FillType,
     57                  scale, paint);
     58         showPath(canvas,  00, 200, SkPath::kInverseWinding_FillType,
     59                  scale, paint);
     60         showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
     61                  scale, paint);
     62     }
     63 
     64     virtual void onDrawContent(SkCanvas* canvas) {
     65         canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
     66 
     67         SkPaint paint;
     68         const SkScalar scale = SkIntToScalar(5)/4;
     69 
     70         paint.setAntiAlias(false);
     71         paint.setColor(0x8000FF00);
     72 
     73         showFour(canvas, SK_Scalar1, paint);
     74         canvas->translate(SkIntToScalar(450), 0);
     75         showFour(canvas, scale, paint);
     76 
     77         paint.setAntiAlias(true);
     78 
     79         canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
     80         showFour(canvas, SK_Scalar1, paint);
     81         canvas->translate(SkIntToScalar(450), 0);
     82         showFour(canvas, scale, paint);
     83     }
     84 
     85 private:
     86     typedef Sample INHERITED;
     87 };
     88 
     89 //////////////////////////////////////////////////////////////////////////////
     90 
     91 DEF_SAMPLE( return new FillTypeView(); )
     92