blob: 5ca39e8651faca0926bfd9264d005c3ef443048f [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
29 PathClipView() {
30 fOval.set(0, 0, SkIntToScalar(200), SkIntToScalar(50));
31 fCenter.set(SkIntToScalar(250), SkIntToScalar(250));
reed@android.com54043a32009-03-05 14:14:49 +000032
33// test_ats();
reed@android.comc07d23a2009-02-06 13:30:58 +000034 }
35
36 virtual ~PathClipView() {}
37
38protected:
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
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());
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 }
reed@android.come72fee52009-11-16 14:52:01 +000072
reed@android.comc07d23a2009-02-06 13:30:58 +000073 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
reed@android.come72fee52009-11-16 14:52:01 +000074 return new Click(this);
75 }
76
77 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);
80 return NULL;
81 }
82
83private:
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);
91