Home | History | Annotate | Download | only in gm
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 #include "gm.h"
      9 
     10 namespace skiagm {
     11 
     12 class FillTypeGM : public GM {
     13     SkPath fPath;
     14 public:
     15 	FillTypeGM() {
     16         this->setBGColor(0xFFDDDDDD);
     17         const SkScalar radius = SkIntToScalar(45);
     18         fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
     19         fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
     20     }
     21 
     22 protected:
     23     virtual SkString onShortName() {
     24         return SkString("filltypes");
     25     }
     26 
     27 	virtual SkISize onISize() {
     28         return make_isize(835, 840);
     29     }
     30 
     31     void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft,
     32                   SkScalar scale, const SkPaint& paint) {
     33 
     34         const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
     35 
     36         canvas->save();
     37         canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
     38         canvas->clipRect(r);
     39         canvas->drawColor(SK_ColorWHITE);
     40         fPath.setFillType(ft);
     41         canvas->translate(r.centerX(), r.centerY());
     42         canvas->scale(scale, scale);
     43         canvas->translate(-r.centerX(), -r.centerY());
     44         canvas->drawPath(fPath, paint);
     45         canvas->restore();
     46     }
     47 
     48     void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
     49         showPath(canvas,   0,   0, SkPath::kWinding_FillType,
     50                  scale, paint);
     51         showPath(canvas, 200,   0, SkPath::kEvenOdd_FillType,
     52                  scale, paint);
     53         showPath(canvas,  00, 200, SkPath::kInverseWinding_FillType,
     54                  scale, paint);
     55         showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
     56                  scale, paint);
     57     }
     58 
     59     virtual void onDraw(SkCanvas* canvas) {
     60         canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
     61 
     62         SkPaint paint;
     63         const SkScalar scale = SkIntToScalar(5)/4;
     64 
     65         paint.setAntiAlias(false);
     66 
     67         showFour(canvas, SK_Scalar1, paint);
     68         canvas->translate(SkIntToScalar(450), 0);
     69         showFour(canvas, scale, paint);
     70 
     71         paint.setAntiAlias(true);
     72 
     73         canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
     74         showFour(canvas, SK_Scalar1, paint);
     75         canvas->translate(SkIntToScalar(450), 0);
     76         showFour(canvas, scale, paint);
     77     }
     78 
     79 private:
     80     typedef GM INHERITED;
     81 };
     82 
     83 //////////////////////////////////////////////////////////////////////////////
     84 
     85 static GM* MyFactory(void*) { return new FillTypeGM; }
     86 static GMRegistry reg(MyFactory);
     87 
     88 }
     89 
     90