arcofzorro.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2013 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 "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkPaint.h"
  11. #include "include/core/SkRect.h"
  12. #include "include/core/SkScalar.h"
  13. #include "include/core/SkSize.h"
  14. #include "include/core/SkString.h"
  15. #include "include/utils/SkRandom.h"
  16. namespace skiagm {
  17. // This GM draws a lot of arcs in a 'Z' shape. It particularly exercises
  18. // the 'drawArc' code near a singularly of its processing (i.e., near the
  19. // edge of one of its underlying quads).
  20. class ArcOfZorroGM : public GM {
  21. public:
  22. ArcOfZorroGM() {
  23. this->setBGColor(0xFFCCCCCC);
  24. }
  25. protected:
  26. SkString onShortName() override {
  27. return SkString("arcofzorro");
  28. }
  29. SkISize onISize() override {
  30. return SkISize::Make(1000, 1000);
  31. }
  32. void onDraw(SkCanvas* canvas) override {
  33. SkRandom rand;
  34. SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200);
  35. SkPaint p;
  36. p.setStyle(SkPaint::kStroke_Style);
  37. p.setStrokeWidth(35);
  38. int xOffset = 0, yOffset = 0;
  39. int direction = 0;
  40. for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) {
  41. SkColor color = rand.nextU();
  42. color |= 0xff000000;
  43. p.setColor(color);
  44. canvas->save();
  45. canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset));
  46. canvas->drawArc(rect, 0, arc, false, p);
  47. canvas->restore();
  48. switch (direction) {
  49. case 0:
  50. xOffset += 10;
  51. if (xOffset >= 700) {
  52. direction = 1;
  53. }
  54. break;
  55. case 1:
  56. xOffset -= 10;
  57. yOffset += 10;
  58. if (xOffset < 50) {
  59. direction = 2;
  60. }
  61. break;
  62. case 2:
  63. xOffset += 10;
  64. break;
  65. }
  66. }
  67. }
  68. private:
  69. typedef GM INHERITED;
  70. };
  71. //////////////////////////////////////////////////////////////////////////////
  72. DEF_GM(return new ArcOfZorroGM;)
  73. }