aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode/SampleTestGL.cpp
blob: 210d7799e1365a1eeb2474e440bf449471a03479 (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
#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "SkCornerPathEffect.h"
#include "SkCullPoints.h"
#include "SkGradientShader.h"
#include "SkPath.h"
#include "SkRegion.h"
#include "SkShader.h"
#include "SkUtils.h"

static void show_ramp(SkCanvas* canvas, const SkRect& r) {
    SkPoint pts[] = { r.fLeft, 0, r.fRight, 0 };
    SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
    SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2,
                                                 SkShader::kRepeat_TileMode);
    SkPaint p;
    p.setShader(s)->unref();
    canvas->drawRect(r, p);
    canvas->translate(r.width() + SkIntToScalar(8), 0);
    p.setDither(true);
    canvas->drawRect(r, p);
}

class TestGLView : public SkView {
public:
	TestGLView() {
    }
    
protected:
    // overrides from SkEventSink
    virtual bool onQuery(SkEvent* evt) {
        if (SampleCode::TitleQ(*evt)) {
            SampleCode::TitleR(evt, "TestGL");
            return true;
        }
        return this->INHERITED::onQuery(evt);
    }
    
    void drawBG(SkCanvas* canvas) {
        canvas->drawColor(0xFFDDDDDD);
    }
    
    virtual void onDraw(SkCanvas* canvas) {
        drawBG(canvas);
        
        SkRect r;
        r.set(0, 0, 100, 100);
        
        canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
        
        SkPaint paint;
        paint.setAntiAlias(false);
        paint.setColor(SK_ColorRED);
        
        canvas->drawRect(r, paint);

        canvas->translate(r.width() + SkIntToScalar(20), 0);
        paint.setStyle(SkPaint::kStroke_Style);
        canvas->drawRect(r, paint);

        canvas->translate(r.width() + SkIntToScalar(20), 0);
        paint.setStrokeWidth(SkIntToScalar(5));
        canvas->drawRect(r, paint);
        
        canvas->translate(r.width() * 10/9, 0);
        show_ramp(canvas, r);
    }
    
private:
    typedef SkView INHERITED;
};

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

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