drawable.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2015 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/SkDrawable.h"
  11. #include "include/core/SkMatrix.h"
  12. #include "include/core/SkPaint.h"
  13. #include "include/core/SkPath.h"
  14. #include "include/core/SkRect.h"
  15. #include "include/core/SkRefCnt.h"
  16. struct MyDrawable : public SkDrawable {
  17. SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
  18. void onDraw(SkCanvas* canvas) override {
  19. SkPath path;
  20. path.moveTo(10, 10);
  21. path.conicTo(10, 90, 50, 90, 0.9f);
  22. SkPaint paint;
  23. paint.setColor(SK_ColorBLUE);
  24. canvas->drawRect(path.getBounds(), paint);
  25. paint.setAntiAlias(true);
  26. paint.setColor(SK_ColorWHITE);
  27. canvas->drawPath(path, paint);
  28. }
  29. };
  30. /*
  31. * Test calling drawables w/ translate and matrices
  32. */
  33. DEF_SIMPLE_GM(drawable, canvas, 180, 275) {
  34. sk_sp<SkDrawable> drawable(new MyDrawable);
  35. canvas->translate(10, 10);
  36. canvas->drawDrawable(drawable.get());
  37. canvas->drawDrawable(drawable.get(), 0, 150);
  38. SkMatrix m = SkMatrix::MakeScale(1.5f, 0.8f);
  39. m.postTranslate(70, 0);
  40. canvas->drawDrawable(drawable.get(), &m);
  41. m.postTranslate(0, 150);
  42. canvas->drawDrawable(drawable.get(), &m);
  43. }