aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-05 16:14:23 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-05 16:14:23 +0000
commit4384fabab41b26c7cf8f357a22181e7ba23e7822 (patch)
treef862e7e29fc681e499c298a7cdba514d792973fa
parent3227ab5f6454b3b553284abd5c9894a8d1c7e845 (diff)
add gm (no images yet) for two-point-radial gradients
git-svn-id: http://skia.googlecode.com/svn/trunk@4163 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gm/strokes.cpp129
-rw-r--r--gm/twopointradial.cpp97
-rw-r--r--gyp/gmslides.gypi1
3 files changed, 214 insertions, 13 deletions
diff --git a/gm/strokes.cpp b/gm/strokes.cpp
index ec265ad7ab..d4532f3b90 100644
--- a/gm/strokes.cpp
+++ b/gm/strokes.cpp
@@ -11,8 +11,6 @@
#include "gm.h"
#include "SkRandom.h"
-namespace skiagm {
-
#define W 400
#define H 400
#define N 50
@@ -36,7 +34,7 @@ static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) {
}
-class StrokesGM : public GM {
+class StrokesGM : public skiagm::GM {
public:
StrokesGM() {}
@@ -46,7 +44,7 @@ protected:
}
virtual SkISize onISize() {
- return make_isize(W, H*2);
+ return SkISize::Make(W, H*2);
}
virtual void onDraw(SkCanvas* canvas) {
@@ -76,10 +74,10 @@ protected:
}
private:
- typedef GM INHERITED;
+ typedef skiagm::GM INHERITED;
};
-class Strokes2GM : public GM {
+class Strokes2GM : public skiagm::GM {
SkPath fPath;
public:
Strokes2GM() {
@@ -98,7 +96,7 @@ protected:
}
virtual SkISize onISize() {
- return make_isize(W, H*2);
+ return SkISize::Make(W, H*2);
}
static void rotate(SkScalar angle, SkScalar px, SkScalar py, SkCanvas* canvas) {
@@ -134,16 +132,121 @@ protected:
}
private:
- typedef GM INHERITED;
+ typedef skiagm::GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
-static GM* MyFactory(void*) { return new StrokesGM; }
-static GMRegistry reg(MyFactory);
+static SkRect inset(const SkRect& r) {
+ SkRect rr(r);
+ rr.inset(r.width()/10, r.height()/10);
+ return rr;
+}
-static GM* MyFactory2(void*) { return new Strokes2GM; }
-static GMRegistry reg2(MyFactory2);
+class Strokes3GM : public skiagm::GM {
+ static void make0(SkPath* path, const SkRect& bounds, SkString* title) {
+ path->addRect(bounds, SkPath::kCW_Direction);
+ path->addRect(inset(bounds), SkPath::kCW_Direction);
+ title->set("CW CW");
+ }
+
+ static void make1(SkPath* path, const SkRect& bounds, SkString* title) {
+ path->addRect(bounds, SkPath::kCW_Direction);
+ path->addRect(inset(bounds), SkPath::kCCW_Direction);
+ title->set("CW CCW");
+ }
+
+ static void make2(SkPath* path, const SkRect& bounds, SkString* title) {
+ path->addOval(bounds, SkPath::kCW_Direction);
+ path->addOval(inset(bounds), SkPath::kCW_Direction);
+ title->set("CW CW");
+ }
+
+ static void make3(SkPath* path, const SkRect& bounds, SkString* title) {
+ path->addOval(bounds, SkPath::kCW_Direction);
+ path->addOval(inset(bounds), SkPath::kCCW_Direction);
+ title->set("CW CCW");
+ }
+
+ static void make4(SkPath* path, const SkRect& bounds, SkString* title) {
+ path->addRect(bounds, SkPath::kCW_Direction);
+ SkRect r = bounds;
+ r.inset(bounds.width() / 10, -bounds.height() / 10);
+ path->addOval(r, SkPath::kCW_Direction);
+ title->set("CW CW");
+ }
+
+ static void make5(SkPath* path, const SkRect& bounds, SkString* title) {
+ path->addRect(bounds, SkPath::kCW_Direction);
+ SkRect r = bounds;
+ r.inset(bounds.width() / 10, -bounds.height() / 10);
+ path->addOval(r, SkPath::kCCW_Direction);
+ title->set("CW CCW");
+ }
+
+public:
+ Strokes3GM() {}
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("strokes3");
+ }
+
+ virtual SkISize onISize() {
+ return SkISize::Make(W, H*2);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ SkPaint origPaint;
+ origPaint.setAntiAlias(true);
+ origPaint.setStyle(SkPaint::kStroke_Style);
+ SkPaint fillPaint(origPaint);
+ fillPaint.setColor(SK_ColorRED);
+ SkPaint strokePaint(origPaint);
+ strokePaint.setColor(0xFF4444FF);
+
+ void (*procs[])(SkPath*, const SkRect&, SkString*) = {
+ make0, make1, make2, make3, make4, make5
+ };
+
+ canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
+
+ SkRect bounds = SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50));
+ SkScalar dx = bounds.width() * 4/3;
+ SkScalar dy = bounds.height() * 5;
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
+ SkPath orig;
+ SkString str;
+ procs[i](&orig, bounds, &str);
+
+ canvas->save();
+ for (int j = 0; j < 13; ++j) {
+ strokePaint.setStrokeWidth(SK_Scalar1 * j * j);
+ canvas->drawPath(orig, strokePaint);
+ canvas->drawPath(orig, origPaint);
+ SkPath fill;
+ strokePaint.getFillPath(orig, &fill);
+ canvas->drawPath(fill, fillPaint);
+ canvas->translate(dx + strokePaint.getStrokeWidth(), 0);
+ }
+ canvas->restore();
+ canvas->translate(0, dy);
+ }
+ }
+
+private:
+ typedef skiagm::GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static skiagm::GM* F0(void*) { return new StrokesGM; }
+static skiagm::GM* F1(void*) { return new Strokes2GM; }
+static skiagm::GM* F2(void*) { return new Strokes3GM; }
+
+static skiagm::GMRegistry R0(F0);
+static skiagm::GMRegistry R1(F1);
+static skiagm::GMRegistry R2(F2);
-}
diff --git a/gm/twopointradial.cpp b/gm/twopointradial.cpp
new file mode 100644
index 0000000000..e2b06ecf43
--- /dev/null
+++ b/gm/twopointradial.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkPaint.h"
+#include "SkGradientShader.h"
+
+static void intToScalars(SkScalar dst[], const int src[], int n) {
+ for (int i = 0; i < n; ++i) {
+ dst[i] = SkIntToScalar(src[i]);
+ }
+}
+
+static void drawGrad(SkCanvas* canvas, const SkScalar d0[], const SkScalar d1[]) {
+ SkPoint c0 = { d0[0], d0[1] };
+ SkScalar r0 = d0[2];
+ SkPoint c1 = { d1[0], d1[1] };
+ SkScalar r1 = d1[2];
+
+ SkColor colors[] = { SK_ColorGREEN, SK_ColorRED };
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setShader(SkGradientShader::CreateTwoPointRadial(c0, r0, c1, r1,
+ colors, NULL, 2,
+ SkShader::kClamp_TileMode))->unref();
+ canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(-50),
+ SkIntToScalar(-50),
+ SkIntToScalar(200),
+ SkIntToScalar(100)), paint);
+
+ paint.setShader(NULL);
+ paint.setStyle(SkPaint::kStroke_Style);
+ canvas->drawCircle(c0.fX, c0.fY, r0, paint);
+ canvas->drawCircle(c1.fX, c1.fY, r1, paint);
+}
+
+class TwoPointRadialGM : public skiagm::GM {
+public:
+ TwoPointRadialGM() {}
+
+protected:
+ SkString onShortName() {
+ return SkString("two_point_radial");
+ }
+
+ SkISize onISize() { return skiagm::make_isize(480, 725); }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ if (false) {
+ SkPaint paint;
+ paint.setColor(SK_ColorBLUE);
+ canvas->drawRect(SkRect::MakeWH(this->getISize().fWidth, this->getISize().fHeight), paint);
+ }
+ SkPaint paint;
+ const int R0 = 20;
+ const int R1 = 40;
+
+ const SkScalar DX = SkIntToScalar(250);
+ const SkScalar DY = SkIntToScalar(120);
+
+ canvas->translate(SkIntToScalar(60), SkIntToScalar(60));
+
+ static const int gData[] = {
+ 0, 0, R0, 0, 0, R1,
+ 0, 0, R0, 25, 0, R1,
+ 0, 0, R0, 100, 0, R1,
+ 0, 0, R0, 0, 0, R0,
+ 0, 0, R0, 25, 0, R0,
+ 0, 0, R0, 100, 0, R0,
+ };
+
+ int count = SK_ARRAY_COUNT(gData) / 6;
+ for (int i = 0; i < count; ++i) {
+ SkScalar data[6];
+ intToScalars(data, &gData[i * 6], 6);
+
+ int n = canvas->save();
+ drawGrad(canvas, &data[0], &data[3]);
+ canvas->translate(DX, 0);
+ drawGrad(canvas, &data[3], &data[0]);
+ canvas->restoreToCount(n);
+ canvas->translate(0, DY);
+ }
+ }
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static skiagm::GM* F(void*) { return new TwoPointRadialGM; }
+
+static skiagm::GMRegistry gR(F);
+
diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi
index 2b64074334..d88ab0dcc1 100644
--- a/gyp/gmslides.gypi
+++ b/gyp/gmslides.gypi
@@ -55,6 +55,7 @@
'../gm/texdata.cpp',
'../gm/tilemodes.cpp',
'../gm/tinybitmap.cpp',
+ '../gm/twopointradial.cpp',
'../gm/verttext.cpp',
'../gm/verttext2.cpp',
'../gm/xfermodes.cpp',