increase height to include entire circle for large radial
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 31 Jan 2012 14:44:13 +0000 (14:44 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 31 Jan 2012 14:44:13 +0000 (14:44 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@3114 2bbb7eff-a529-9590-31e7-b0007b416f81

gm/gradients.cpp

index 8f2f0ab..3eb5633 100644 (file)
@@ -222,27 +222,32 @@ public:
 
 protected:
     SkString onShortName() { return SkString("radial_gradient"); }
-    virtual SkISize onISize() { return make_isize(1280, 1024); }
+    virtual SkISize onISize() { return make_isize(1280, 1280); }
     void drawBG(SkCanvas* canvas) {
         canvas->drawColor(0xFF000000);
     }
     virtual void onDraw(SkCanvas* canvas) {
+        const SkISize dim = this->getISize();
+
         this->drawBG(canvas);
  
         SkPaint paint;
         paint.setDither(true);
         SkPoint center;
-        center.set(SkIntToScalar(640), SkIntToScalar(512));
-        SkScalar radius = SkIntToScalar(640);
-        SkColor colors [3] = { 0x7f7f7f7f, 0x7f7f7f7f, 0xb2000000 };
-        SkScalar pos [3] = { SkFloatToScalar(0.0),
+        center.set(SkIntToScalar(dim.width())/2, SkIntToScalar(dim.height())/2);
+        SkScalar radius = SkIntToScalar(dim.width())/2;
+        const SkColor colors[] = { 0x7f7f7f7f, 0x7f7f7f7f, 0xb2000000 };
+        const SkScalar pos[] = { SkFloatToScalar(0.0),
                              SkFloatToScalar(0.35),
                              SkFloatToScalar(1.0) };
         SkShader* shader =
             SkGradientShader::CreateRadial(center, radius, colors,
-                                           pos, 3, SkShader::kClamp_TileMode);
+                                           pos, SK_ARRAY_COUNT(pos),
+                                           SkShader::kClamp_TileMode);
         paint.setShader(shader)->unref();
-        SkRect r = { 0, 0, SkIntToScalar(1280), SkIntToScalar(1024) };
+        SkRect r = {
+            0, 0, SkIntToScalar(dim.width()), SkIntToScalar(dim.height())
+        };
         canvas->drawRect(r, paint);
     }
 private: