2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2016-12-12 15:02:12 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/core/SkClipOpPriv.h"
|
2011-03-02 15:35:28 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class ComplexClipView : public Sample {
|
2011-03-02 15:35:28 +00:00
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
ComplexClipView() {
|
2011-05-05 14:03:48 +00:00
|
|
|
this->setBGColor(0xFFA0DDA0);
|
2011-03-02 15:35:28 +00:00
|
|
|
}
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2011-03-02 15:35:28 +00:00
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
virtual bool onQuery(Sample::Event* evt) {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "ComplexClip");
|
2011-03-02 15:35:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2011-03-02 15:35:28 +00:00
|
|
|
SkPath path;
|
|
|
|
path.moveTo(SkIntToScalar(0), SkIntToScalar(50));
|
|
|
|
path.quadTo(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(50), SkIntToScalar(0));
|
|
|
|
path.lineTo(SkIntToScalar(175), SkIntToScalar(0));
|
|
|
|
path.quadTo(SkIntToScalar(200), SkIntToScalar(0), SkIntToScalar(200), SkIntToScalar(25));
|
|
|
|
path.lineTo(SkIntToScalar(200), SkIntToScalar(150));
|
|
|
|
path.quadTo(SkIntToScalar(200), SkIntToScalar(200), SkIntToScalar(150), SkIntToScalar(200));
|
|
|
|
path.lineTo(SkIntToScalar(0), SkIntToScalar(200));
|
|
|
|
path.close();
|
|
|
|
path.moveTo(SkIntToScalar(50), SkIntToScalar(50));
|
|
|
|
path.lineTo(SkIntToScalar(150), SkIntToScalar(50));
|
|
|
|
path.lineTo(SkIntToScalar(150), SkIntToScalar(125));
|
|
|
|
path.quadTo(SkIntToScalar(150), SkIntToScalar(150), SkIntToScalar(125), SkIntToScalar(150));
|
|
|
|
path.lineTo(SkIntToScalar(50), SkIntToScalar(150));
|
|
|
|
path.close();
|
|
|
|
path.setFillType(SkPath::kEvenOdd_FillType);
|
|
|
|
SkColor pathColor = SK_ColorBLACK;
|
|
|
|
SkPaint pathPaint;
|
|
|
|
pathPaint.setAntiAlias(true);
|
|
|
|
pathPaint.setColor(pathColor);
|
|
|
|
|
|
|
|
SkPath clipA;
|
|
|
|
clipA.moveTo(SkIntToScalar(10), SkIntToScalar(20));
|
|
|
|
clipA.lineTo(SkIntToScalar(165), SkIntToScalar(22));
|
|
|
|
clipA.lineTo(SkIntToScalar(70), SkIntToScalar(105));
|
|
|
|
clipA.lineTo(SkIntToScalar(165), SkIntToScalar(177));
|
|
|
|
clipA.lineTo(SkIntToScalar(-5), SkIntToScalar(180));
|
|
|
|
clipA.close();
|
|
|
|
SkColor colorA = SK_ColorCYAN;
|
|
|
|
|
|
|
|
SkPath clipB;
|
|
|
|
clipB.moveTo(SkIntToScalar(40), SkIntToScalar(10));
|
|
|
|
clipB.lineTo(SkIntToScalar(190), SkIntToScalar(15));
|
|
|
|
clipB.lineTo(SkIntToScalar(195), SkIntToScalar(190));
|
|
|
|
clipB.lineTo(SkIntToScalar(40), SkIntToScalar(185));
|
|
|
|
clipB.lineTo(SkIntToScalar(155), SkIntToScalar(100));
|
|
|
|
clipB.close();
|
|
|
|
SkColor colorB = SK_ColorRED;
|
|
|
|
|
2019-01-02 17:21:01 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setSize(20);
|
|
|
|
|
2011-03-02 15:35:28 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(0);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(10),SkIntToScalar(10));
|
|
|
|
canvas->drawPath(path, pathPaint);
|
|
|
|
paint.setColor(colorA);
|
|
|
|
canvas->drawPath(clipA, paint);
|
|
|
|
paint.setColor(colorB);
|
|
|
|
canvas->drawPath(clipB, paint);
|
|
|
|
|
|
|
|
static const struct {
|
2016-12-09 14:00:50 +00:00
|
|
|
SkClipOp fOp;
|
|
|
|
const char* fName;
|
2011-03-02 15:35:28 +00:00
|
|
|
} gOps[] = { //extra spaces in names for measureText
|
2016-12-09 14:00:50 +00:00
|
|
|
{kIntersect_SkClipOp, "Isect "},
|
|
|
|
{kDifference_SkClipOp, "Diff " },
|
|
|
|
{kUnion_SkClipOp, "Union "},
|
|
|
|
{kXOR_SkClipOp, "Xor " },
|
|
|
|
{kReverseDifference_SkClipOp, "RDiff "}
|
2011-03-02 15:35:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
canvas->translate(0, SkIntToScalar(40));
|
|
|
|
canvas->scale(3 * SK_Scalar1 / 4, 3 * SK_Scalar1 / 4);
|
|
|
|
canvas->save();
|
|
|
|
|
2011-03-10 19:20:15 +00:00
|
|
|
for (int invA = 0; invA < 2; ++invA) {
|
2011-05-19 19:58:58 +00:00
|
|
|
for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); ++op) {
|
2014-01-27 13:42:58 +00:00
|
|
|
size_t idx = invA * SK_ARRAY_COUNT(gOps) + op;
|
2011-03-02 15:35:28 +00:00
|
|
|
if (!(idx % 3)) {
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, SkIntToScalar(250));
|
|
|
|
canvas->save();
|
|
|
|
}
|
|
|
|
canvas->save();
|
|
|
|
// set clip
|
|
|
|
clipA.setFillType(invA ? SkPath::kInverseEvenOdd_FillType :
|
|
|
|
SkPath::kEvenOdd_FillType);
|
|
|
|
canvas->clipPath(clipA);
|
|
|
|
canvas->clipPath(clipB, gOps[op].fOp);
|
|
|
|
|
|
|
|
// draw path clipped
|
|
|
|
canvas->drawPath(path, pathPaint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// draw path in hairline
|
|
|
|
paint.setColor(pathColor);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
|
|
|
|
// draw clips in hair line
|
|
|
|
paint.setColor(colorA);
|
|
|
|
canvas->drawPath(clipA, paint);
|
|
|
|
paint.setColor(colorB);
|
|
|
|
canvas->drawPath(clipB, paint);
|
|
|
|
|
|
|
|
SkScalar txtX = SkIntToScalar(55);
|
|
|
|
paint.setColor(colorA);
|
|
|
|
const char* aTxt = invA ? "InverseA " : "A ";
|
2019-05-07 19:38:46 +00:00
|
|
|
canvas->drawSimpleText(aTxt, strlen(aTxt), SkTextEncoding::kUTF8, txtX, SkIntToScalar(220), font, paint);
|
|
|
|
txtX += font.measureText(aTxt, strlen(aTxt), SkTextEncoding::kUTF8);
|
2011-03-02 15:35:28 +00:00
|
|
|
paint.setColor(SK_ColorBLACK);
|
2019-05-07 19:38:46 +00:00
|
|
|
canvas->drawSimpleText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8,
|
2019-01-02 17:21:01 +00:00
|
|
|
txtX, 220, font, paint);
|
2019-05-07 19:38:46 +00:00
|
|
|
txtX += font.measureText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8);
|
2011-03-02 15:35:28 +00:00
|
|
|
paint.setColor(colorB);
|
2019-05-07 19:38:46 +00:00
|
|
|
canvas->drawSimpleText("B", 1, SkTextEncoding::kUTF8, txtX, 220, font, paint);
|
2011-03-02 15:35:28 +00:00
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(250),0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2011-03-02 15:35:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new ComplexClipView(); )
|