Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 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 "SkTArray.h" | |
| 11 | |
| 12 namespace skiagm { | |
| 13 | |
| 14 class ConicPathsGM : public GM { | |
| 15 protected: | |
| 16 | |
| 17 virtual SkString onShortName() SK_OVERRIDE { | |
| 18 return SkString("conicpaths"); | |
| 19 } | |
| 20 | |
| 21 virtual SkISize onISize() { return make_isize(800, 600); } | |
|
reed1
2013/06/20 15:22:32
SkISize::Make()
reed1
2013/06/20 15:22:32
SK_OVERRIDE
| |
| 22 | |
| 23 virtual void onOnceBeforeDraw() SK_OVERRIDE { | |
| 24 { | |
| 25 SkPath* conicCirlce = &fPaths.push_back(); | |
| 26 conicCirlce->moveTo(0, -0); | |
| 27 conicCirlce->conicTo(SkIntToScalar(0), SkIntToScalar(50), | |
| 28 SkIntToScalar(50), SkIntToScalar(50), | |
| 29 SkScalarHalf(SkScalarSqrt(2))); | |
| 30 conicCirlce->rConicTo(SkIntToScalar(50), SkIntToScalar(0), | |
| 31 SkIntToScalar(50), SkIntToScalar(-50), | |
| 32 SkScalarHalf(SkScalarSqrt(2))); | |
| 33 conicCirlce->rConicTo(SkIntToScalar(0), SkIntToScalar(-50), | |
| 34 SkIntToScalar(-50), SkIntToScalar(-50), | |
| 35 SkScalarHalf(SkScalarSqrt(2))); | |
| 36 conicCirlce->rConicTo(SkIntToScalar(-50), SkIntToScalar(0), | |
| 37 SkIntToScalar(-50), SkIntToScalar(50), | |
| 38 SkScalarHalf(SkScalarSqrt(2))); | |
| 39 | |
| 40 } | |
| 41 { | |
| 42 SkPath* hyperbola = &fPaths.push_back(); | |
| 43 hyperbola->moveTo(0, -0); | |
| 44 hyperbola->conicTo(SkIntToScalar(0), SkIntToScalar(100), | |
| 45 SkIntToScalar(100), SkIntToScalar(100), | |
| 46 SkIntToScalar(2)); | |
| 47 } | |
| 48 { | |
| 49 SkPath* thinHyperbola = &fPaths.push_back(); | |
| 50 thinHyperbola->moveTo(0, -0); | |
| 51 thinHyperbola->conicTo(SkIntToScalar(100), SkIntToScalar(100), | |
| 52 SkIntToScalar(5), SkIntToScalar(0), | |
| 53 SkIntToScalar(2)); | |
| 54 } | |
| 55 { | |
| 56 SkPath* veryThinHyperbola = &fPaths.push_back(); | |
| 57 veryThinHyperbola->moveTo(0, -0); | |
| 58 veryThinHyperbola->conicTo(SkIntToScalar(100), SkIntToScalar(100), | |
| 59 SkIntToScalar(1), SkIntToScalar(0), | |
| 60 SkIntToScalar(2)); | |
| 61 } | |
| 62 { | |
| 63 SkPath* closedHyperbola = &fPaths.push_back(); | |
| 64 closedHyperbola->moveTo(0, -0); | |
| 65 closedHyperbola->conicTo(SkIntToScalar(100), SkIntToScalar(100), | |
| 66 SkIntToScalar(0), SkIntToScalar(0), | |
| 67 SkIntToScalar(2)); | |
| 68 } | |
| 69 { | |
| 70 // using 1 as weight defaults to using quadTo | |
| 71 SkPath* nearParabola = &fPaths.push_back(); | |
| 72 nearParabola->moveTo(0, -0); | |
| 73 nearParabola->conicTo(SkIntToScalar(0), SkIntToScalar(100), | |
| 74 SkIntToScalar(100), SkIntToScalar(100), | |
| 75 0.999); | |
| 76 } | |
| 77 { | |
| 78 SkPath* thinEllipse = &fPaths.push_back(); | |
| 79 thinEllipse->moveTo(0, -0); | |
| 80 thinEllipse->conicTo(SkIntToScalar(100), SkIntToScalar(100), | |
| 81 SkIntToScalar(5), SkIntToScalar(0), | |
| 82 SK_ScalarHalf); | |
| 83 } | |
| 84 { | |
| 85 SkPath* veryThinEllipse = &fPaths.push_back(); | |
| 86 veryThinEllipse->moveTo(0, -0); | |
| 87 veryThinEllipse->conicTo(SkIntToScalar(100), SkIntToScalar(100), | |
| 88 SkIntToScalar(1), SkIntToScalar(0), | |
| 89 SK_ScalarHalf); | |
| 90 } | |
| 91 { | |
| 92 SkPath* closedEllipse = &fPaths.push_back(); | |
| 93 closedEllipse->moveTo(0, -0); | |
| 94 closedEllipse->conicTo(SkIntToScalar(100), SkIntToScalar(100), | |
| 95 SkIntToScalar(0), SkIntToScalar(0), | |
| 96 SK_ScalarHalf); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | |
| 101 static const SkAlpha kAlphaValue[] = { 0xFF, 0x40 }; | |
| 102 | |
| 103 enum { | |
| 104 kMargin = 15, | |
| 105 }; | |
| 106 int wrapX = canvas->getDeviceSize().fWidth - kMargin; | |
| 107 | |
| 108 SkScalar maxH = 0; | |
| 109 canvas->translate(SkIntToScalar(kMargin), SkIntToScalar(kMargin)); | |
| 110 canvas->save(); | |
| 111 | |
| 112 SkScalar x = SkIntToScalar(kMargin); | |
| 113 for (int p = 0; p < fPaths.count(); ++p) { | |
| 114 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) { | |
| 115 for (int aa = 0; aa < 2; ++aa) { | |
| 116 for (int fh = 0; fh < 2; ++fh) { | |
| 117 | |
| 118 const SkRect& bounds = fPaths[p].getBounds(); | |
| 119 | |
| 120 if (x + bounds.width() > wrapX) { | |
| 121 canvas->restore(); | |
| 122 canvas->translate(0, maxH + SkIntToScalar(kMargin)); | |
| 123 canvas->save(); | |
| 124 maxH = 0; | |
| 125 x = SkIntToScalar(kMargin); | |
| 126 } | |
| 127 | |
| 128 SkPaint paint; | |
| 129 paint.setARGB(kAlphaValue[a], 0, 0, 0); | |
| 130 paint.setAntiAlias(SkToBool(aa)); | |
| 131 if (fh == 1) { | |
| 132 paint.setStyle(SkPaint::kStroke_Style); | |
| 133 paint.setStrokeWidth(0); | |
| 134 } else if (fh == 0) { | |
| 135 paint.setStyle(SkPaint::kFill_Style); | |
| 136 } | |
| 137 canvas->save(); | |
| 138 canvas->translate(-bounds.fLeft, -bounds.fTop); | |
| 139 canvas->drawPath(fPaths[p], paint); | |
| 140 canvas->restore(); | |
| 141 | |
| 142 maxH = SkMaxScalar(maxH, bounds.height()); | |
| 143 | |
| 144 SkScalar dx = bounds.width() + SkIntToScalar(kMargin); | |
| 145 x += dx; | |
| 146 canvas->translate(dx, 0); | |
| 147 } | |
| 148 } | |
| 149 } | |
| 150 } | |
| 151 canvas->restore(); | |
| 152 } | |
| 153 | |
| 154 private: | |
| 155 SkTArray<SkPath> fPaths; | |
| 156 typedef GM INHERITED; | |
| 157 }; | |
| 158 | |
| 159 ////////////////////////////////////////////////////////////////////////////// | |
| 160 | |
| 161 static GM* MyFactory(void*) { return new ConicPathsGM; } | |
|
reed1
2013/06/20 15:22:32
DEF_GM( return new ConicPathsGM; )
| |
| 162 static GMRegistry reg(MyFactory); | |
| 163 | |
| 164 } | |
| OLD | NEW |