blob: ab7ed5d0fc6a9238359fd0af9232897c470abfc1 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
reed@android.comc07d23a2009-02-06 13:30:58 +00008#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"
reed@android.comc07d23a2009-02-06 13:30:58 +000015#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
reed@google.com81e3d7f2011-06-01 12:42:36 +000024class PathClipView : public SampleView {
reed@android.comc07d23a2009-02-06 13:30:58 +000025public:
26 SkRect fOval;
27 SkPoint fCenter;
28
rmistry@google.comae933ce2012-08-23 18:19:56 +000029 PathClipView() {
reed@android.comc07d23a2009-02-06 13:30:58 +000030 fOval.set(0, 0, SkIntToScalar(200), SkIntToScalar(50));
31 fCenter.set(SkIntToScalar(250), SkIntToScalar(250));
rmistry@google.comae933ce2012-08-23 18:19:56 +000032
reed@android.com54043a32009-03-05 14:14:49 +000033// test_ats();
reed@android.comc07d23a2009-02-06 13:30:58 +000034 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000035
reed@android.comc07d23a2009-02-06 13:30:58 +000036 virtual ~PathClipView() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000037
reed@android.comc07d23a2009-02-06 13:30:58 +000038protected:
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 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000047
reed@google.com81e3d7f2011-06-01 12:42:36 +000048 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.comc07d23a2009-02-06 13:30:58 +000049 SkRect oval = fOval;
50 oval.offset(fCenter.fX - oval.centerX(), fCenter.fY - oval.centerY());
rmistry@google.comae933ce2012-08-23 18:19:56 +000051
reed@android.comc07d23a2009-02-06 13:30:58 +000052 SkPaint p;
53 p.setAntiAlias(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000054
reed@android.comc07d23a2009-02-06 13:30:58 +000055 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);
rmistry@google.comae933ce2012-08-23 18:19:56 +000062
reed@android.comc07d23a2009-02-06 13:30:58 +000063 p.setStyle(SkPaint::kFill_Style);
64 p.setColor(SK_ColorRED);
65 canvas->drawRect(r, p);
rmistry@google.comae933ce2012-08-23 18:19:56 +000066
reed@android.comc07d23a2009-02-06 13:30:58 +000067 p.setColor(0x800000FF);
68 r.set(SkIntToScalar(150), SkIntToScalar(10),
69 SkIntToScalar(250), SkIntToScalar(400));
70 canvas->drawOval(oval, p);
71 }
reed@android.come72fee52009-11-16 14:52:01 +000072
mtklein36352bf2015-03-25 18:17:31 -070073 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
reed@android.come72fee52009-11-16 14:52:01 +000074 return new Click(this);
75 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000076
reed@android.come72fee52009-11-16 14:52:01 +000077 virtual bool onClick(Click* click) {
78 fCenter.set(click->fCurr.fX, click->fCurr.fY);
reed@android.comc07d23a2009-02-06 13:30:58 +000079 this->inval(NULL);
caryclark@google.com02939ce2012-06-06 12:09:51 +000080 return false;
reed@android.comc07d23a2009-02-06 13:30:58 +000081 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000082
reed@android.comc07d23a2009-02-06 13:30:58 +000083private:
reed@google.com81e3d7f2011-06-01 12:42:36 +000084 typedef SampleView INHERITED;
reed@android.comc07d23a2009-02-06 13:30:58 +000085};
86
87//////////////////////////////////////////////////////////////////////////////
88
89static SkView* MyFactory() { return new PathClipView; }
90static SkViewRegister reg(MyFactory);