blob: f9aff281feb6326b5320b59d22b8051d98f4b8f6 [file] [log] [blame]
bsalomon@google.com82aa7482012-08-13 14:22:17 +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 "gm.h"
9#include "SkMagnifierImageFilter.h"
10
11#define WIDTH 500
12#define HEIGHT 500
13
14namespace skiagm {
15
16class ImageMagnifierGM : public GM {
17public:
18 ImageMagnifierGM() {
19 this->setBGColor(0xFF000000);
20 }
21
22protected:
23 virtual SkString onShortName() {
24 return SkString("imagemagnifier");
25 }
26
27 virtual SkISize onISize() {
28 return make_isize(WIDTH, HEIGHT);
29 }
30
31 virtual void onDraw(SkCanvas* canvas) {
32 SkPaint paint;
33 paint.setImageFilter(
34 new SkMagnifierImageFilter(
35 SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125),
36 SkIntToScalar(WIDTH / 2),
37 SkIntToScalar(HEIGHT / 2)),
38 100))->unref();
39 canvas->saveLayer(NULL, &paint);
40 paint.setAntiAlias(true);
41 const char* str = "The quick brown fox jumped over the lazy dog.";
42 srand(1234);
43 for (int i = 0; i < 25; ++i) {
44 int x = rand() % WIDTH;
45 int y = rand() % HEIGHT;
46 paint.setColor(rand() % 0x1000000 | 0xFF000000);
47 paint.setTextSize(SkIntToScalar(rand() % 300));
48 canvas->drawText(str, strlen(str), SkIntToScalar(x),
49 SkIntToScalar(y), paint);
50 }
51 canvas->restore();
52 }
53
54private:
55 typedef GM INHERITED;
56};
57
58//////////////////////////////////////////////////////////////////////////////
59
60static GM* MyFactory(void*) { return new ImageMagnifierGM; }
61static GMRegistry reg(MyFactory);
62
63}