aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode/SampleConcavePaths.cpp
blob: 1659ec08c114ca0c79c3fdea5d87c89ff65c4c8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkGraphics.h"
#include "SkImageDecoder.h"
#include "SkPath.h"
#include "SkRegion.h"
#include "SkShader.h"
#include "SkUtils.h"
#include "SkXfermode.h"
#include "SkColorPriv.h"
#include "SkColorFilter.h"
#include "SkParsePath.h"
#include "SkTime.h"
#include "SkTypeface.h"

#include "SkGeometry.h"

class ConcavePathView : public SampleView {
public:
	ConcavePathView() {}
    
protected:
    // overrides from SkEventSink
    virtual bool onQuery(SkEvent* evt) {
        if (SampleCode::TitleQ(*evt)) {
            SampleCode::TitleR(evt, "ConcavePaths");
            return true;
        }
        return this->INHERITED::onQuery(evt);
    }
    
    virtual void onDrawContent(SkCanvas* canvas) {        
        SkPaint paint;
        
        paint.setAntiAlias(true);
        paint.setStyle(SkPaint::kFill_Style);

        // Concave test
        if (1) {
            SkPath path;
            canvas->translate(0, 0);
            path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(30), SkIntToScalar(30));
            path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
            canvas->drawPath(path, paint);
        }
        // Reverse concave test
        if (1) {
            SkPath path;
            canvas->save();
            canvas->translate(100, 0);
            path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
            path.lineTo(SkIntToScalar(30), SkIntToScalar(30));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
            canvas->drawPath(path, paint);
            canvas->restore();
        }
        // Bowtie (intersection)
        if (1) {
            SkPath path;
            canvas->save();
            canvas->translate(200, 0);
            path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
            canvas->drawPath(path, paint);
            canvas->restore();
        }
        // "fake" bowtie (concave, but no intersection)
        if (1) {
            SkPath path;
            canvas->save();
            canvas->translate(300, 0);
            path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(50), SkIntToScalar(40));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
            path.lineTo(SkIntToScalar(50), SkIntToScalar(60));
            path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
            canvas->drawPath(path, paint);
            canvas->restore();
        }
        // Fish test (intersection/concave)
        if (1) {
            SkPath path;
            canvas->save();
            canvas->translate(0, 100);
            path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
            path.lineTo(SkIntToScalar(70), SkIntToScalar(50));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
            path.lineTo(SkIntToScalar(0), SkIntToScalar(50));
            canvas->drawPath(path, paint);
            canvas->restore();
        }
        // Collinear test
        if (1) {
            SkPath path;
            canvas->save();
            canvas->translate(100, 100);
            path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(50), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(50), SkIntToScalar(80));
            canvas->drawPath(path, paint);
            canvas->restore();
        }
        // Hole test
        if (1) {
            SkPath path;
            canvas->save();
            canvas->translate(200, 100);
            path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
            path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
            path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
            path.moveTo(SkIntToScalar(30), SkIntToScalar(30));
            path.lineTo(SkIntToScalar(30), SkIntToScalar(70));
            path.lineTo(SkIntToScalar(70), SkIntToScalar(70));
            path.lineTo(SkIntToScalar(70), SkIntToScalar(30));
            canvas->drawPath(path, paint);
            canvas->restore();
        }
    }
    
    virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
        this->inval(NULL);
        return this->INHERITED::onFindClickHandler(x, y);
    }
    
private:
    typedef SampleView INHERITED;
};

//////////////////////////////////////////////////////////////////////////////

static SkView* MyFactory() { return new ConcavePathView; }
static SkViewRegister reg(MyFactory);