blob: 62ca5334539146d4a658680808641cd19d4e6eb8 [file] [log] [blame]
mike@reedtribe.org37071642012-12-17 02:10:42 +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 "SkCanvas.h"
10#include "SkRRect.h"
11#include "SkPath.h"
12
13static void draw_rrect_color(SkCanvas* canvas, const SkRRect& rrect) {
14 SkPaint paint;
15 paint.setAntiAlias(true);
16
17 if (rrect.isRect()) {
18 paint.setColor(SK_ColorRED);
19 } else if (rrect.isOval()) {
20 paint.setColor(SK_ColorGREEN);
21 } else if (rrect.isSimple()) {
22 paint.setColor(SK_ColorBLUE);
23 } else {
24 paint.setColor(SK_ColorGRAY);
25 }
26 canvas->drawRRect(rrect, paint);
27}
28
29static void drawrr(SkCanvas* canvas, const SkRRect& rrect) {
30 SkRRect inner, outer, inner2;
31
32 SkScalar dx = 30;
33 SkScalar dy = 30;
34
35 rrect.outset(dx, dy, &outer);
36 rrect.inset(dx/2, dy/2, &inner);
37 rrect.inset(dx, dy, &inner2);
38
39 draw_rrect_color(canvas, outer);
40 draw_rrect_color(canvas, rrect);
41 draw_rrect_color(canvas, inner);
42 draw_rrect_color(canvas, inner2);
43
44 SkPaint paint;
45 paint.setAntiAlias(true);
46 paint.setStyle(SkPaint::kStroke_Style);
47 paint.setColor(SK_ColorDKGRAY);
48 canvas->drawRRect(rrect, paint);
49 canvas->drawRRect(inner, paint);
50 canvas->drawRRect(inner2, paint);
51}
52
53class RRectGM : public skiagm::GM {
54public:
55 RRectGM() {}
56
57protected:
58 virtual SkString onShortName() {
59 return SkString("rrect");
60 }
61
62 virtual SkISize onISize() {
63 return SkISize::Make(640, 480);
64 }
65
66 virtual void onDraw(SkCanvas* canvas) {
67 SkRRect rrect[4];
68 SkRect r = { 0, 0, 120, 240 };
69 SkVector radii[4] = {
70 { 0, 0 }, { 20, 20 }, { 10, 40 }, { 40, 40 }
71 };
72
73 rrect[0].setRect(r);
74 rrect[1].setOval(r);
75 rrect[2].setRectXY(r, 20, 20);
76 rrect[3].setRectRadii(r, radii);
77
78 canvas->translate(50, 50);
79 for (size_t i = 0; i < SK_ARRAY_COUNT(rrect); ++i) {
80 drawrr(canvas, rrect[i]);
81 canvas->translate(rrect[i].width() * 2, 0);
82 }
83 }
84
85private:
86 typedef GM INHERITED;
87};
88
89DEF_GM( return new RRectGM; )
90