1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc.
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
7bf0001d0472d727266762c5967ec0d919a6df083reed@google.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SampleCode.h"
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkView.h"
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h"
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGradientShader.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGraphics.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkImageDecoder.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRandom.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h"
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorFilter.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTime.h"
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypeface.h"
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkXfermode.h"
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkStream.h"
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkXMLParser.h"
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
28f21833999d90ad9c8c584cff3238797b39cfc00breed@google.comclass PointsView : public SampleView {
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
30ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com    PointsView() {}
31a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // overrides from SkEventSink
34a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com    virtual bool onQuery(SkEvent* evt) {
35a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com        if (SampleCode::TitleQ(*evt)) {
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SampleCode::TitleR(evt, "Points");
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            return true;
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return this->INHERITED::onQuery(evt);
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
42e0e7cfe44bb9d66d76120a79e5275c294bacaa22commit-bot@chromium.org    static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        for (size_t i = 0; i < n; i++)
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
46a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com
47f21833999d90ad9c8c584cff3238797b39cfc00breed@google.com    virtual void onDrawContent(SkCanvas* canvas) {
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        canvas->translate(SK_Scalar1, SK_Scalar1);
49a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com
50e0e7cfe44bb9d66d76120a79e5275c294bacaa22commit-bot@chromium.org        SkRandom rand;
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint  p0, p1, p2, p3;
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const size_t n = 99;
53a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        p0.setColor(SK_ColorRED);
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        p1.setColor(SK_ColorGREEN);
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        p2.setColor(SK_ColorBLUE);
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        p3.setColor(SK_ColorWHITE);
58a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        p0.setStrokeWidth(SkIntToScalar(4));
60b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com        p2.setStrokeCap(SkPaint::kRound_Cap);
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        p2.setStrokeWidth(SkIntToScalar(6));
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPoint* pts = new SkPoint[n];
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fill_pts(pts, n, &rand);
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
66a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com        canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
67a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com        canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
68a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com        canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
69a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com        canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
70a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        delete[] pts;
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
73a965a15abd57ea1bbbbfcc8dc1574d7d7a2e424dreed@google.com
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
76f21833999d90ad9c8c584cff3238797b39cfc00breed@google.com    typedef SampleView INHERITED;
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////
808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic SkView* MyFactory() { return new PointsView; }
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic SkViewRegister reg(MyFactory);
83