2015-07-07 16:43:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkDrawable.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2020-08-17 18:14:13 +00:00
|
|
|
#include "include/core/SkPathBuilder.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2015-07-07 16:43:28 +00:00
|
|
|
|
|
|
|
struct MyDrawable : public SkDrawable {
|
2015-07-07 17:22:31 +00:00
|
|
|
SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
|
2015-07-07 16:43:28 +00:00
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2020-08-17 18:14:13 +00:00
|
|
|
SkPath path = SkPathBuilder().moveTo(10, 10)
|
|
|
|
.conicTo(10, 90, 50, 90, 0.9f)
|
|
|
|
.detach();
|
2015-07-07 16:43:28 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawRect(path.getBounds(), paint);
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-07 17:22:31 +00:00
|
|
|
/*
|
|
|
|
* Test calling drawables w/ translate and matrices
|
|
|
|
*/
|
|
|
|
DEF_SIMPLE_GM(drawable, canvas, 180, 275) {
|
2016-11-04 20:26:16 +00:00
|
|
|
sk_sp<SkDrawable> drawable(new MyDrawable);
|
2015-07-07 17:22:31 +00:00
|
|
|
|
|
|
|
canvas->translate(10, 10);
|
2016-11-04 20:26:16 +00:00
|
|
|
canvas->drawDrawable(drawable.get());
|
|
|
|
canvas->drawDrawable(drawable.get(), 0, 150);
|
2015-07-07 17:22:31 +00:00
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
SkMatrix m = SkMatrix::Scale(1.5f, 0.8f);
|
2015-07-07 17:22:31 +00:00
|
|
|
m.postTranslate(70, 0);
|
2016-11-04 20:26:16 +00:00
|
|
|
canvas->drawDrawable(drawable.get(), &m);
|
2015-07-07 17:22:31 +00:00
|
|
|
|
|
|
|
m.postTranslate(0, 150);
|
2016-11-04 20:26:16 +00:00
|
|
|
canvas->drawDrawable(drawable.get(), &m);
|
2015-07-07 16:43:28 +00:00
|
|
|
}
|