blob: 7ac87a7bc038e87eb31c11428a8193caac84dc1e [file] [log] [blame]
mike@reedtribe.org50e4c722012-10-22 03:59:34 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11#include "SkPath.h"
12#include "SkRegion.h"
13#include "SkShader.h"
14#include "SkUtils.h"
15#include "SkImage.h"
16#include "SkSurface.h"
17
reed@google.comc83e3522012-10-22 22:00:08 +000018#define FAT_PIXEL_COLOR SK_ColorBLACK
19#define PIXEL_CENTER_SIZE 3
20#define WIRE_FRAME_COLOR 0xFFFF0000 /*0xFF00FFFF*/
21#define WIRE_FRAME_SIZE 1.5f
22
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000023static void erase(SkSurface* surface) {
junov@google.comdbfac8a2012-12-06 21:47:40 +000024 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000025}
26
27static SkShader* createChecker() {
reed@google.com9c0bef12012-11-02 19:59:18 +000028// SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 };
29 SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF };
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000030 SkBitmap bm;
31 bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
32 bm.allocPixels();
33 bm.lockPixels();
reed@google.com9c0bef12012-11-02 19:59:18 +000034 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]);
35 *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000036 SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
37 SkShader::kRepeat_TileMode);
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +000038
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000039 SkMatrix m;
40 m.setScale(12, 12);
41 s->setLocalMatrix(m);
42 return s;
43}
44
45class FatBits {
46public:
47 FatBits() : fShader(createChecker()) {
48 fAA = false;
49 fStyle = kHair_Style;
50 fGrid = true;
reed@google.comc83e3522012-10-22 22:00:08 +000051 fShowSkeleton = true;
52 fUseGPU = false;
reed@google.com9c0bef12012-11-02 19:59:18 +000053 fUseClip = false;
skia.committer@gmail.com1aa90cf2012-11-06 13:18:25 +000054
reed@google.com9c0bef12012-11-02 19:59:18 +000055 fClipRect.set(2, 2, 11, 8 );
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000056 }
57
robertphillips@google.comca47aae2012-12-12 15:58:25 +000058 int getZoom() const { return fZoom; }
reed@google.comc83e3522012-10-22 22:00:08 +000059
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000060 bool getAA() const { return fAA; }
61 void setAA(bool aa) { fAA = aa; }
62
63 bool getGrid() const { return fGrid; }
64 void setGrid(bool g) { fGrid = g; }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +000065
reed@google.comc83e3522012-10-22 22:00:08 +000066 bool getShowSkeleton() const { return fShowSkeleton; }
67 void setShowSkeleton(bool ss) { fShowSkeleton = ss; }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +000068
reed@google.comc83e3522012-10-22 22:00:08 +000069 bool getUseGPU() const { return fUseGPU; }
70 void setUseGPU(bool ug) { fUseGPU = ug; }
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000071
reed@google.com9c0bef12012-11-02 19:59:18 +000072 bool getUseClip() const { return fUseClip; }
73 void setUseClip(bool uc) { fUseClip = uc; }
74
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000075 enum Style {
76 kHair_Style,
reed@google.comc83e3522012-10-22 22:00:08 +000077 kStroke_Style,
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000078 };
79 Style getStyle() const { return fStyle; }
80 void setStyle(Style s) { fStyle = s; }
81
82 void setWHZ(int width, int height, int zoom) {
83 fW = width;
84 fH = height;
robertphillips@google.comca47aae2012-12-12 15:58:25 +000085 fZoom = zoom;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000086 fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zoom));
87 fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom));
88 fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
89 fShader->setLocalMatrix(fMatrix);
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +000090
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000091 SkImage::Info info = {
92 width, height, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType
93 };
mike@reedtribe.orgb9476252012-11-15 02:37:45 +000094 fMinSurface.reset(SkSurface::NewRaster(info));
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000095 info.fWidth *= zoom;
96 info.fHeight *= zoom;
mike@reedtribe.orgb9476252012-11-15 02:37:45 +000097 fMaxSurface.reset(SkSurface::NewRaster(info));
mike@reedtribe.org50e4c722012-10-22 03:59:34 +000098 }
99
100 void drawBG(SkCanvas*);
101 void drawFG(SkCanvas*);
102 void drawLine(SkCanvas*, SkPoint pts[2]);
103 void drawRect(SkCanvas* canvas, SkPoint pts[2]);
104
105private:
reed@google.com9c0bef12012-11-02 19:59:18 +0000106 bool fAA, fGrid, fShowSkeleton, fUseGPU, fUseClip;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000107 Style fStyle;
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000108 int fW, fH, fZoom;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000109 SkMatrix fMatrix, fInverse;
reed@google.com9c0bef12012-11-02 19:59:18 +0000110 SkRect fBounds, fClipRect;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000111 SkAutoTUnref<SkShader> fShader;
112 SkAutoTUnref<SkSurface> fMinSurface;
113 SkAutoTUnref<SkSurface> fMaxSurface;
114
115 void setupPaint(SkPaint* paint) {
116 bool aa = this->getAA();
117 switch (fStyle) {
118 case kHair_Style:
119 paint->setStrokeWidth(0);
120 break;
121 case kStroke_Style:
reed@google.comcdbcb3e2012-10-22 22:10:20 +0000122 paint->setStrokeWidth(SK_Scalar1);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000123 break;
124 }
125 paint->setAntiAlias(aa);
126 }
127
reed@google.comc83e3522012-10-22 22:00:08 +0000128 void setupSkeletonPaint(SkPaint* paint) {
129 paint->setStyle(SkPaint::kStroke_Style);
130 paint->setStrokeWidth(WIRE_FRAME_SIZE);
131 paint->setColor(fShowSkeleton ? WIRE_FRAME_COLOR : 0);
132 paint->setAntiAlias(true);
133 }
134
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000135 void drawLineSkeleton(SkCanvas* max, const SkPoint pts[]);
136 void drawRectSkeleton(SkCanvas* max, const SkRect& r) {
137 SkPaint paint;
reed@google.comc83e3522012-10-22 22:00:08 +0000138 this->setupSkeletonPaint(&paint);
139 SkPath path;
140
141 if (fUseGPU && fAA) {
142 SkRect rr = r;
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000143 rr.inset(SkIntToScalar(fZoom)/2, SkIntToScalar(fZoom)/2);
reed@google.comc83e3522012-10-22 22:00:08 +0000144 path.addRect(rr);
145 path.moveTo(rr.fLeft, rr.fTop);
146 path.lineTo(rr.fRight, rr.fBottom);
147 rr = r;
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000148 rr.inset(-SkIntToScalar(fZoom)/2, -SkIntToScalar(fZoom)/2);
reed@google.comc83e3522012-10-22 22:00:08 +0000149 path.addRect(rr);
150 } else {
151 path.addRect(r);
152 if (fUseGPU) {
153 path.moveTo(r.fLeft, r.fTop);
154 path.lineTo(r.fRight, r.fBottom);
155 }
156 }
157 max->drawPath(path, paint);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000158 }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000159
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000160 void copyMinToMax() {
161 erase(fMaxSurface);
162 SkCanvas* canvas = fMaxSurface->getCanvas();
163 canvas->save();
164 canvas->concat(fMatrix);
165 fMinSurface->draw(canvas, 0, 0, NULL);
166 canvas->restore();
167
168 SkPaint paint;
169 paint.setXfermodeMode(SkXfermode::kClear_Mode);
170 for (int iy = 1; iy < fH; ++iy) {
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000171 SkScalar y = SkIntToScalar(iy * fZoom);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000172 canvas->drawLine(0, y - SK_ScalarHalf, 999, y - SK_ScalarHalf, paint);
173 }
174 for (int ix = 1; ix < fW; ++ix) {
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000175 SkScalar x = SkIntToScalar(ix * fZoom);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000176 canvas->drawLine(x - SK_ScalarHalf, 0, x - SK_ScalarHalf, 999, paint);
177 }
178 }
179};
180
181void FatBits::drawBG(SkCanvas* canvas) {
182 SkPaint paint;
183
184 paint.setShader(fShader);
185 canvas->drawRect(fBounds, paint);
186 paint.setShader(NULL);
187}
188
189void FatBits::drawFG(SkCanvas* canvas) {
reed@google.comc83e3522012-10-22 22:00:08 +0000190 SkPaint inner, outer;
191
192 inner.setAntiAlias(true);
193 inner.setColor(SK_ColorBLACK);
194 inner.setStrokeWidth(PIXEL_CENTER_SIZE);
195
196 outer.setAntiAlias(true);
197 outer.setColor(SK_ColorWHITE);
198 outer.setStrokeWidth(PIXEL_CENTER_SIZE + 2);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000199
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000200 SkScalar half = SkIntToScalar(fZoom) / 2;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000201 for (int iy = 0; iy < fH; ++iy) {
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000202 SkScalar y = SkIntToScalar(iy * fZoom) + half;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000203 for (int ix = 0; ix < fW; ++ix) {
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000204 SkScalar x = SkIntToScalar(ix * fZoom) + half;
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000205
reed@google.comc83e3522012-10-22 22:00:08 +0000206 canvas->drawPoint(x, y, outer);
207 canvas->drawPoint(x, y, inner);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000208 }
209 }
reed@google.com9c0bef12012-11-02 19:59:18 +0000210
211 if (fUseClip) {
212 SkPaint p;
213 p.setStyle(SkPaint::kStroke_Style);
214 p.setColor(SK_ColorLTGRAY);
215 SkRect r = {
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000216 fClipRect.fLeft * fZoom,
217 fClipRect.fTop * fZoom,
218 fClipRect.fRight * fZoom,
219 fClipRect.fBottom * fZoom
reed@google.com9c0bef12012-11-02 19:59:18 +0000220 };
221 canvas->drawRect(r, p);
222 }
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000223}
224
225void FatBits::drawLineSkeleton(SkCanvas* max, const SkPoint pts[]) {
226 SkPaint paint;
reed@google.comc83e3522012-10-22 22:00:08 +0000227 this->setupSkeletonPaint(&paint);
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000228
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000229 SkPath path;
230 path.moveTo(pts[0]);
231 path.lineTo(pts[1]);
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000232
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000233 switch (fStyle) {
234 case kHair_Style:
reed@google.comc83e3522012-10-22 22:00:08 +0000235 if (fUseGPU) {
236 SkPaint p;
237 p.setStyle(SkPaint::kStroke_Style);
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000238 p.setStrokeWidth(SK_Scalar1 * fZoom);
reed@google.comc83e3522012-10-22 22:00:08 +0000239 SkPath dst;
240 p.getFillPath(path, &dst);
241 path.addPath(dst);
242 }
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000243 break;
244 case kStroke_Style: {
245 SkPaint p;
246 p.setStyle(SkPaint::kStroke_Style);
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000247 p.setStrokeWidth(SK_Scalar1 * fZoom);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000248 SkPath dst;
249 p.getFillPath(path, &dst);
250 path = dst;
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000251
reed@google.comc83e3522012-10-22 22:00:08 +0000252 if (fUseGPU) {
253 path.moveTo(dst.getPoint(0));
254 path.lineTo(dst.getPoint(2));
255 }
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000256 } break;
257 }
258 max->drawPath(path, paint);
259}
260
261void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) {
262 SkPaint paint;
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000263
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000264 fInverse.mapPoints(pts, 2);
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000265
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000266 if (fGrid) {
reed@google.comcdbcb3e2012-10-22 22:10:20 +0000267 SkScalar dd = 0;//SK_Scalar1 / 50;
268 pts[0].set(SkScalarRoundToScalar(pts[0].fX) + dd,
269 SkScalarRoundToScalar(pts[0].fY) + dd);
270 pts[1].set(SkScalarRoundToScalar(pts[1].fX) + dd,
271 SkScalarRoundToScalar(pts[1].fY) + dd);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000272 }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000273
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000274 erase(fMinSurface);
275 this->setupPaint(&paint);
reed@google.comc83e3522012-10-22 22:00:08 +0000276 paint.setColor(FAT_PIXEL_COLOR);
reed@google.com9c0bef12012-11-02 19:59:18 +0000277 if (fUseClip) {
278 fMinSurface->getCanvas()->save();
279 SkRect r = fClipRect;
280 r.inset(SK_Scalar1/3, SK_Scalar1/3);
281 fMinSurface->getCanvas()->clipRect(r, SkRegion::kIntersect_Op, true);
282 }
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000283 fMinSurface->getCanvas()->drawLine(pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, paint);
reed@google.com9c0bef12012-11-02 19:59:18 +0000284 if (fUseClip) {
285 fMinSurface->getCanvas()->restore();
286 }
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000287 this->copyMinToMax();
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000288
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000289 SkCanvas* max = fMaxSurface->getCanvas();
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000290
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000291 fMatrix.mapPoints(pts, 2);
292 this->drawLineSkeleton(max, pts);
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000293
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000294 fMaxSurface->draw(canvas, 0, 0, NULL);
295}
296
297void FatBits::drawRect(SkCanvas* canvas, SkPoint pts[2]) {
298 SkPaint paint;
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000299
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000300 fInverse.mapPoints(pts, 2);
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000301
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000302 if (fGrid) {
303 pts[0].set(SkScalarRoundToScalar(pts[0].fX), SkScalarRoundToScalar(pts[0].fY));
304 pts[1].set(SkScalarRoundToScalar(pts[1].fX), SkScalarRoundToScalar(pts[1].fY));
305 }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000306
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000307 SkRect r;
308 r.set(pts, 2);
309
310 erase(fMinSurface);
311 this->setupPaint(&paint);
reed@google.comc83e3522012-10-22 22:00:08 +0000312 paint.setColor(FAT_PIXEL_COLOR);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000313 fMinSurface->getCanvas()->drawRect(r, paint);
314 this->copyMinToMax();
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000315
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000316 SkCanvas* max = fMaxSurface->getCanvas();
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000317
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000318 fMatrix.mapPoints(pts, 2);
319 r.set(pts, 2);
320 this->drawRectSkeleton(max, r);
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000321
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000322 fMaxSurface->draw(canvas, 0, 0, NULL);
323}
324
325///////////////////////////////////////////////////////////////////////////////////////////////////
326
327class IndexClick : public SkView::Click {
328 int fIndex;
329public:
330 IndexClick(SkView* v, int index) : SkView::Click(v), fIndex(index) {}
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000331
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000332 static int GetIndex(SkView::Click* click) {
333 return ((IndexClick*)click)->fIndex;
334 }
335};
336
337class DrawLineView : public SampleView {
338 FatBits fFB;
339 SkPoint fPts[2];
340 bool fIsRect;
341public:
342 DrawLineView() {
343 fFB.setWHZ(24, 16, 48);
reed@google.comcdbcb3e2012-10-22 22:10:20 +0000344 fPts[0].set(48, 48);
345 fPts[1].set(48 * 5, 48 * 4);
346 fIsRect = false;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000347 }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000348
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000349 void setStyle(FatBits::Style s) {
350 fFB.setStyle(s);
351 this->inval(NULL);
352 }
353
354protected:
355 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
356 if (SampleCode::TitleQ(*evt)) {
357 SampleCode::TitleR(evt, "FatBits");
358 return true;
359 }
360 SkUnichar uni;
361 if (SampleCode::CharQ(*evt, &uni)) {
362 switch (uni) {
reed@google.com9c0bef12012-11-02 19:59:18 +0000363 case 'c':
364 fFB.setUseClip(!fFB.getUseClip());
365 this->inval(NULL);
366 return true;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000367 case 'r':
368 fIsRect = !fIsRect;
369 this->inval(NULL);
370 return true;
reed@google.comc83e3522012-10-22 22:00:08 +0000371 case 'x':
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000372 fFB.setGrid(!fFB.getGrid());
373 this->inval(NULL);
374 return true;
375 case 's':
376 if (FatBits::kStroke_Style == fFB.getStyle()) {
377 this->setStyle(FatBits::kHair_Style);
378 } else {
379 this->setStyle(FatBits::kStroke_Style);
380 }
381 return true;
382 case 'a':
383 fFB.setAA(!fFB.getAA());
384 this->inval(NULL);
385 return true;
reed@google.comc83e3522012-10-22 22:00:08 +0000386 case 'w':
387 fFB.setShowSkeleton(!fFB.getShowSkeleton());
388 this->inval(NULL);
389 return true;
390 case 'g':
391 fFB.setUseGPU(!fFB.getUseGPU());
392 this->inval(NULL);
393 return true;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000394 }
395 }
396 return this->INHERITED::onQuery(evt);
397 }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000398
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000399 virtual void onDrawContent(SkCanvas* canvas) {
400 fFB.drawBG(canvas);
401 if (fIsRect) {
402 fFB.drawRect(canvas, fPts);
403 } else {
404 fFB.drawLine(canvas, fPts);
405 }
406 fFB.drawFG(canvas);
skia.committer@gmail.com1e34ff72012-10-24 02:01:24 +0000407
reed@google.comffe9d012012-10-23 15:33:41 +0000408 {
409 SkString str;
reed@google.com9c0bef12012-11-02 19:59:18 +0000410 str.printf("%s %s %s %s",
reed@google.comffe9d012012-10-23 15:33:41 +0000411 fFB.getAA() ? "AA" : "BW",
412 FatBits::kHair_Style == fFB.getStyle() ? "Hair" : "Stroke",
reed@google.com9c0bef12012-11-02 19:59:18 +0000413 fFB.getUseGPU() ? "GPU" : "CPU",
414 fFB.getUseClip() ? "clip" : "noclip");
reed@google.comffe9d012012-10-23 15:33:41 +0000415 SkPaint paint;
416 paint.setAntiAlias(true);
417 paint.setTextSize(16);
418 paint.setColor(SK_ColorBLUE);
419 canvas->drawText(str.c_str(), str.size(), 10, 16, paint);
420 }
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000421 }
422
mike@reedtribe.org093455c2013-01-28 02:21:27 +0000423 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
424 unsigned modi) SK_OVERRIDE {
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000425 SkPoint pt = { x, y };
426 int index = -1;
reed@google.comcdbcb3e2012-10-22 22:10:20 +0000427 SkScalar tol = 12;
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000428 if (fPts[0].equalsWithinTolerance(pt, tol)) {
429 index = 0;
430 } else if (fPts[1].equalsWithinTolerance(pt, tol)) {
431 index = 1;
432 }
mike@reedtribe.orgc892a152012-10-23 03:10:46 +0000433 return new IndexClick(this, index);
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000434 }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000435
mike@reedtribe.org093455c2013-01-28 02:21:27 +0000436 virtual bool onClick(Click* click) SK_OVERRIDE {
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000437 int index = IndexClick::GetIndex(click);
mike@reedtribe.orgc892a152012-10-23 03:10:46 +0000438 if (index >= 0 && index <= 1) {
439 fPts[index] = click->fCurr;
440 } else {
441 SkScalar dx = click->fCurr.fX - click->fPrev.fX;
442 SkScalar dy = click->fCurr.fY - click->fPrev.fY;
443 fPts[0].offset(dx, dy);
444 fPts[1].offset(dx, dy);
445 }
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000446 this->inval(NULL);
447 return true;
448 }
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000449
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000450private:
skia.committer@gmail.com45ba2f72012-10-23 02:01:22 +0000451
mike@reedtribe.org50e4c722012-10-22 03:59:34 +0000452 typedef SampleView INHERITED;
453};
454
455//////////////////////////////////////////////////////////////////////////////
456
457static SkView* MyFactory() { return new DrawLineView; }
458static SkViewRegister reg(MyFactory);