blob: dd6af092532773180eed003c68647e80f7a44d15 [file] [log] [blame]
reed@google.com32287892011-10-05 16:27:44 +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 */
8
9#include "SampleCode.h"
10#include "SkView.h"
11#include "SkCanvas.h"
12#include "SkAAClip.h"
13
14static void drawClip(SkCanvas* canvas, const SkAAClip& clip) {
15 SkMask mask;
16 SkBitmap bm;
17
18 clip.copyToMask(&mask);
19 bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(),
20 mask.fBounds.height(), mask.fRowBytes);
21 bm.setPixels(mask.fImage);
22
23 SkPaint paint;
24 canvas->drawBitmap(bm, mask.fBounds.fLeft, mask.fBounds.fTop, &paint);
25}
26
27class AAClipView : public SampleView {
28public:
29 AAClipView() {
30 }
31
32protected:
33 // overrides from SkEventSink
34 virtual bool onQuery(SkEvent* evt) {
35 if (SampleCode::TitleQ(*evt)) {
36 SampleCode::TitleR(evt, "AAClip");
37 return true;
38 }
39 return this->INHERITED::onQuery(evt);
40 }
41
42 virtual void onDrawContent(SkCanvas* canvas) {
43#if 1
44 SkAAClip aaclip;
45 SkPath path;
46 SkRect bounds;
47
48 bounds.set(0, 0, 20, 20);
49 bounds.inset(SK_ScalarHalf, SK_ScalarHalf);
50
51// path.addRect(bounds);
52// path.addOval(bounds);
53 path.addRoundRect(bounds, 4, 4);
54 aaclip.setPath(path);
55 canvas->translate(30, 30);
56 drawClip(canvas, aaclip);
57
58 SkAAClip aaclip2;
59 path.offset(10, 10);
60 aaclip2.setPath(path);
61 canvas->translate(30, 0);
62 drawClip(canvas, aaclip2);
63
64 SkAAClip aaclip3;
65 aaclip3.op(aaclip, aaclip2, SkRegion::kIntersect_Op);
66 canvas->translate(30, 0);
67 drawClip(canvas, aaclip3);
68
69#endif
70
71#if 0
72 SkRect r;
73 r.set(0, 0, this->width(), this->height());
74 r.inset(20, 20);
75 canvas->clipRect(r);
76
77 SkPath path;
78 path.addRect(r);
79 SkPaint paint;
80 paint.setAntiAlias(true);
81 paint.setColor(SK_ColorRED);
82 canvas->drawPath(path, paint);
83#endif
84 }
85
86private:
87 typedef SkView INHERITED;
88};
89
90//////////////////////////////////////////////////////////////////////////////
91
92static SkView* MyFactory() { return new AAClipView; }
93static SkViewRegister reg(MyFactory);
94