2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "Sk64.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkKernel33MaskFilter.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkUtils.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkXMLParser.h"
|
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
class PointsView : public SampleView {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2011-02-17 15:06:52 +00:00
|
|
|
PointsView() {}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
2011-02-17 15:06:52 +00:00
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SampleCode::TitleR(evt, "Points");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2011-02-17 15:06:52 +00:00
|
|
|
static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
|
2008-12-17 15:59:43 +00:00
|
|
|
for (size_t i = 0; i < n; i++)
|
|
|
|
pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
|
|
|
|
}
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->translate(SK_Scalar1, SK_Scalar1);
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkRandom rand;
|
|
|
|
SkPaint p0, p1, p2, p3;
|
|
|
|
const size_t n = 99;
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p0.setColor(SK_ColorRED);
|
|
|
|
p1.setColor(SK_ColorGREEN);
|
|
|
|
p2.setColor(SK_ColorBLUE);
|
|
|
|
p3.setColor(SK_ColorWHITE);
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p0.setStrokeWidth(SkIntToScalar(4));
|
2009-07-10 17:02:17 +00:00
|
|
|
p2.setStrokeCap(SkPaint::kRound_Cap);
|
2008-12-17 15:59:43 +00:00
|
|
|
p2.setStrokeWidth(SkIntToScalar(6));
|
|
|
|
|
|
|
|
SkPoint* pts = new SkPoint[n];
|
|
|
|
fill_pts(pts, n, &rand);
|
|
|
|
|
2011-02-17 15:06:52 +00:00
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
|
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
delete[] pts;
|
|
|
|
}
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
typedef SampleView INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new PointsView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|
|
|
|
|