Home | History | Annotate | Download | only in gm
      1 /*
      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 "SkPath.h"
     11 #include "SkParsePath.h"
     12 #include "SkDashPathEffect.h"
     13 
     14 /*
     15  *  Inspired by http://code.google.com/p/chromium/issues/detail?id=112145
     16  */
     17 
     18 class DashCubicsGM : public skiagm::GM {
     19 public:
     20     DashCubicsGM() {}
     21 
     22 protected:
     23     virtual SkString onShortName() {
     24         return SkString("dashcubics");
     25     }
     26 
     27     virtual SkISize onISize() {
     28         return SkISize::Make(640, 480);
     29     }
     30 
     31     virtual void onDraw(SkCanvas* canvas) {
     32         SkPath path;
     33         const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 250,212"
     34         "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231"
     35         "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250"
     36         "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269"
     37         "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288"
     38         "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269"
     39         "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250"
     40         "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231"
     41         "C 283,231 344,195 338,98";
     42 
     43         SkParsePath::FromSVGString(d, &path);
     44 
     45         SkScalar intervals[] = { 5, 10 };
     46         SkPathEffect* pe = new SkDashPathEffect(intervals, 2, 0);
     47 
     48         SkPaint paint;
     49         paint.setAntiAlias(true);
     50         paint.setStyle(SkPaint::kStroke_Style);
     51 
     52         paint.setStrokeWidth(42);
     53         canvas->drawPath(path, paint);
     54 
     55         paint.setColor(SK_ColorRED);
     56         paint.setStrokeWidth(21);
     57         paint.setPathEffect(pe)->unref();
     58         canvas->drawPath(path, paint);
     59 
     60         paint.setColor(SK_ColorGREEN);
     61         paint.setPathEffect(NULL);
     62         paint.setStrokeWidth(0);
     63         canvas->drawPath(path, paint);
     64     }
     65 
     66 private:
     67     typedef GM INHERITED;
     68 };
     69 
     70 //////////////////////////////////////////////////////////////////////////////
     71 
     72 static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; }
     73 static skiagm::GMRegistry reg(MyFactory);
     74