Home | History | Annotate | Download | only in samplecode
      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 "SampleCode.h"
      9 #include "SkView.h"
     10 #include "SkCanvas.h"
     11 #include "SkGradientShader.h"
     12 #include "SkGraphics.h"
     13 #include "SkImageDecoder.h"
     14 #include "SkPath.h"
     15 #include "SkRegion.h"
     16 #include "SkShader.h"
     17 #include "SkUtils.h"
     18 #include "SkXfermode.h"
     19 #include "SkColorPriv.h"
     20 #include "SkColorFilter.h"
     21 #include "SkTime.h"
     22 #include "SkTypeface.h"
     23 
     24 class PathClipView : public SampleView {
     25 public:
     26     SkRect fOval;
     27     SkPoint fCenter;
     28 
     29     PathClipView() {
     30         fOval.set(0, 0, SkIntToScalar(200), SkIntToScalar(50));
     31         fCenter.set(SkIntToScalar(250), SkIntToScalar(250));
     32 
     33 //        test_ats();
     34     }
     35 
     36     virtual ~PathClipView() {}
     37 
     38 protected:
     39     // overrides from SkEventSink
     40     virtual bool onQuery(SkEvent* evt) {
     41         if (SampleCode::TitleQ(*evt)) {
     42             SampleCode::TitleR(evt, "PathClip");
     43             return true;
     44         }
     45         return this->INHERITED::onQuery(evt);
     46     }
     47 
     48     virtual void onDrawContent(SkCanvas* canvas) {
     49         SkRect oval = fOval;
     50         oval.offset(fCenter.fX - oval.centerX(), fCenter.fY - oval.centerY());
     51 
     52         SkPaint p;
     53         p.setAntiAlias(true);
     54 
     55         p.setStyle(SkPaint::kStroke_Style);
     56         canvas->drawOval(oval, p);
     57 
     58         SkRect r;
     59         r.set(SkIntToScalar(200), SkIntToScalar(200),
     60               SkIntToScalar(300), SkIntToScalar(300));
     61         canvas->clipRect(r);
     62 
     63         p.setStyle(SkPaint::kFill_Style);
     64         p.setColor(SK_ColorRED);
     65         canvas->drawRect(r, p);
     66 
     67         p.setColor(0x800000FF);
     68         r.set(SkIntToScalar(150), SkIntToScalar(10),
     69               SkIntToScalar(250), SkIntToScalar(400));
     70         canvas->drawOval(oval, p);
     71     }
     72 
     73     SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
     74         return new Click(this);
     75     }
     76 
     77     virtual bool onClick(Click* click) {
     78         fCenter.set(click->fCurr.fX, click->fCurr.fY);
     79         this->inval(NULL);
     80         return false;
     81     }
     82 
     83 private:
     84     typedef SampleView INHERITED;
     85 };
     86 
     87 //////////////////////////////////////////////////////////////////////////////
     88 
     89 static SkView* MyFactory() { return new PathClipView; }
     90 static SkViewRegister reg(MyFactory);
     91