SampleFillType.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2011 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. #include "include/core/SkCanvas.h"
  8. #include "include/core/SkPath.h"
  9. #include "include/core/SkRegion.h"
  10. #include "include/core/SkShader.h"
  11. #include "include/effects/SkCornerPathEffect.h"
  12. #include "include/effects/SkGradientShader.h"
  13. #include "samplecode/Sample.h"
  14. #include "src/utils/SkUTF.h"
  15. class FillTypeView : public Sample {
  16. SkPath fPath;
  17. public:
  18. FillTypeView() {
  19. const SkScalar radius = SkIntToScalar(45);
  20. fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
  21. fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
  22. this->setBGColor(0xFFDDDDDD);
  23. }
  24. protected:
  25. virtual SkString name() { return SkString("FillType"); }
  26. void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft,
  27. SkScalar scale, const SkPaint& paint) {
  28. const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
  29. canvas->save();
  30. canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
  31. canvas->clipRect(r);
  32. canvas->drawColor(SK_ColorWHITE);
  33. fPath.setFillType(ft);
  34. canvas->translate(r.centerX(), r.centerY());
  35. canvas->scale(scale, scale);
  36. canvas->translate(-r.centerX(), -r.centerY());
  37. canvas->drawPath(fPath, paint);
  38. canvas->restore();
  39. }
  40. void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
  41. showPath(canvas, 0, 0, SkPath::kWinding_FillType,
  42. scale, paint);
  43. showPath(canvas, 200, 0, SkPath::kEvenOdd_FillType,
  44. scale, paint);
  45. showPath(canvas, 00, 200, SkPath::kInverseWinding_FillType,
  46. scale, paint);
  47. showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
  48. scale, paint);
  49. }
  50. virtual void onDrawContent(SkCanvas* canvas) {
  51. canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
  52. SkPaint paint;
  53. const SkScalar scale = SkIntToScalar(5)/4;
  54. paint.setAntiAlias(false);
  55. paint.setColor(0x8000FF00);
  56. showFour(canvas, SK_Scalar1, paint);
  57. canvas->translate(SkIntToScalar(450), 0);
  58. showFour(canvas, scale, paint);
  59. paint.setAntiAlias(true);
  60. canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
  61. showFour(canvas, SK_Scalar1, paint);
  62. canvas->translate(SkIntToScalar(450), 0);
  63. showFour(canvas, scale, paint);
  64. }
  65. private:
  66. typedef Sample INHERITED;
  67. };
  68. //////////////////////////////////////////////////////////////////////////////
  69. DEF_SAMPLE( return new FillTypeView(); )