Canvas_drawPath.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
  3. #include "tools/fiddle/examples.h"
  4. // HASH=fe2294131f422b8d6752f6a880f98ad9
  5. REG_FIDDLE(Canvas_drawPath, 256, 256, false, 0) {
  6. void draw(SkCanvas* canvas) {
  7. SkPath path;
  8. path.moveTo(20, 20);
  9. path.quadTo(60, 20, 60, 60);
  10. path.close();
  11. path.moveTo(60, 20);
  12. path.quadTo(60, 60, 20, 60);
  13. SkPaint paint;
  14. paint.setStrokeWidth(10);
  15. paint.setAntiAlias(true);
  16. paint.setStyle(SkPaint::kStroke_Style);
  17. for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) {
  18. paint.setStrokeJoin(join);
  19. for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) {
  20. paint.setStrokeCap(cap);
  21. canvas->drawPath(path, paint);
  22. canvas->translate(80, 0);
  23. }
  24. canvas->translate(-240, 60);
  25. }
  26. paint.setStyle(SkPaint::kFill_Style);
  27. for (auto fill : { SkPath::kWinding_FillType,
  28. SkPath::kEvenOdd_FillType,
  29. SkPath::kInverseWinding_FillType } ) {
  30. path.setFillType(fill);
  31. canvas->save();
  32. canvas->clipRect({0, 10, 80, 70});
  33. canvas->drawPath(path, paint);
  34. canvas->restore();
  35. canvas->translate(80, 0);
  36. }
  37. }
  38. } // END FIDDLE